diff --git a/core/src/test/java/org/acegisecurity/ldap/LdapTestServer.java b/core/src/test/java/org/acegisecurity/ldap/LdapTestServer.java index 7925b9cd1b..077de0d1bc 100644 --- a/core/src/test/java/org/acegisecurity/ldap/LdapTestServer.java +++ b/core/src/test/java/org/acegisecurity/ldap/LdapTestServer.java @@ -49,8 +49,6 @@ public class LdapTestServer { private DirContext serverContext; - // Move the working dir to the temp directory - private File workingDir = new File(System.getProperty("java.io.tmpdir") + File.separator + "apacheds-work"); private MutableStartupConfiguration cfg; //~ Constructors =================================================================================================== @@ -208,9 +206,24 @@ public class LdapTestServer { private void startLdapServer() { cfg = new MutableStartupConfiguration(); + + // Attempt to use the maven target directory for the apache ds store. + // This doesn't work at the moment - need to find out if we can access maven properties somehow. + + String tempDirectory = System.getProperty("maven.build.dir"); + + if(tempDirectory == null) { + tempDirectory = System.getProperty("java.io.tmpdir"); + } + + File workingDir = new File(tempDirectory + File.separator + "apacheds-work"); + + // Delete any previous contents (often not compatible between apache-ds versions). + deleteDir(workingDir); + ((MutableStartupConfiguration) cfg).setWorkingDirectory(workingDir); - System.out.println("Working directory is " + workingDir.getAbsolutePath()); + System.out.println("Ldap Server Working directory is " + workingDir.getAbsolutePath()); Properties env = new Properties(); @@ -229,4 +242,19 @@ public class LdapTestServer { e.printStackTrace(); } } + + /** Recursively deletes a directory */ + private static boolean deleteDir(File dir) { + if (dir.isDirectory()) { + String[] children = dir.list(); + for (int i=0; i