You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2013/04/19 15:59:38 UTC

svn commit: r1469830 - /syncope/branches/1_1_X/build-tools/src/main/java/org/apache/syncope/buildtools/ApacheDSStartStopListener.java

Author: ilgrosso
Date: Fri Apr 19 13:59:38 2013
New Revision: 1469830

URL: http://svn.apache.org/r1469830
Log:
[SYNCOPE-363] Creating ApacheDS work directory and loading default content only for first run

Modified:
    syncope/branches/1_1_X/build-tools/src/main/java/org/apache/syncope/buildtools/ApacheDSStartStopListener.java

Modified: syncope/branches/1_1_X/build-tools/src/main/java/org/apache/syncope/buildtools/ApacheDSStartStopListener.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_1_X/build-tools/src/main/java/org/apache/syncope/buildtools/ApacheDSStartStopListener.java?rev=1469830&r1=1469829&r2=1469830&view=diff
==============================================================================
--- syncope/branches/1_1_X/build-tools/src/main/java/org/apache/syncope/buildtools/ApacheDSStartStopListener.java (original)
+++ syncope/branches/1_1_X/build-tools/src/main/java/org/apache/syncope/buildtools/ApacheDSStartStopListener.java Fri Apr 19 13:59:38 2013
@@ -153,9 +153,12 @@ public class ApacheDSStartStopListener i
      * partitions.
      *
      * @param workDir the directory to be used for storing the data
+     * @param loadDefaultContent if default content should be loaded
      * @throws Exception if there were some problems while initializing
      */
-    private void initDirectoryService(final ServletContext servletContext, final File workDir) throws Exception {
+    private void initDirectoryService(final ServletContext servletContext, final File workDir,
+            final boolean loadDefaultContent) throws Exception {
+
         // Initialize the LDAP service
         service = new DefaultDirectoryService();
         service.setWorkingDirectory(workDir);
@@ -180,10 +183,12 @@ public class ApacheDSStartStopListener i
         service.startup();
 
         // Finally, load content LDIF
-        final LdifURLLoader contentLoader = new LdifURLLoader(service.getAdminSession(),
-                servletContext.getResource("/WEB-INF/classes/content.ldif"));
-        final int numEntries = contentLoader.execute();
-        LOG.info("Successfully created {} entries", numEntries);
+        if (loadDefaultContent) {
+            final LdifURLLoader contentLoader = new LdifURLLoader(service.getAdminSession(),
+                    servletContext.getResource("/WEB-INF/classes/content.ldif"));
+            final int numEntries = contentLoader.execute();
+            LOG.info("Successfully created {} entries", numEntries);
+        }
     }
 
     /**
@@ -195,13 +200,16 @@ public class ApacheDSStartStopListener i
     public void contextInitialized(final ServletContextEvent sce) {
         File workDir = (File) sce.getServletContext().getAttribute("javax.servlet.context.tempdir");
         workDir = new File(workDir, "server-work");
-        if (!workDir.mkdirs()) {
+        
+        final boolean loadDefaultContent = !workDir.exists();
+        
+        if (loadDefaultContent && !workDir.mkdirs()) {
             throw new RuntimeException("Could not create " + workDir.getAbsolutePath());
         }
 
         Entry result;
         try {
-            initDirectoryService(sce.getServletContext(), workDir);
+            initDirectoryService(sce.getServletContext(), workDir, loadDefaultContent);
 
             server = new LdapServer();
             server.setTransports(