SLING-4892 : Remove dependency to StartupHandler

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1717909 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index f7bad08..74f27ee 100644
--- a/pom.xml
+++ b/pom.xml
@@ -100,12 +100,6 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.launchpad.api</artifactId>
-            <version>1.1.0</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>
diff --git a/src/main/java/org/apache/sling/settings/impl/ServicesListener.java b/src/main/java/org/apache/sling/settings/impl/ServicesListener.java
index accb6b3..8ac0e96 100644
--- a/src/main/java/org/apache/sling/settings/impl/ServicesListener.java
+++ b/src/main/java/org/apache/sling/settings/impl/ServicesListener.java
@@ -21,7 +21,6 @@
 import java.util.Dictionary;
 import java.util.Hashtable;
 
-import org.apache.sling.launchpad.api.StartupHandler;
 import org.apache.sling.settings.SlingSettingsService;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -41,9 +40,6 @@
     /** The bundle context. */
     private final BundleContext bundleContext;
 
-    /** The listener for the startup handler. */
-    private final Listener startupListener;
-
     /** The listener for configuration admin. */
     private ConfigAdminListener configAdminListener;
 
@@ -59,25 +55,7 @@
      */
     public ServicesListener(final BundleContext bundleContext) {
         this.bundleContext = bundleContext;
-        this.startupListener = new Listener(StartupHandler.class.getName());
-        this.startupListener.start();
-    }
-
-    /**
-     * Notify of service changes from the listeners.
-     * If all services are available, register listener and pass resources
-     * to the OSGi installer.
-     */
-    public synchronized void notifyChange() {
-        // check if all services are available
-        final StartupHandler handler = (StartupHandler)this.startupListener.getService();
-        if ( handler != null && this.settingsReg == null ) {
-            this.activate(handler);
-        }
-    }
-
-    private void activate(final StartupHandler handler) {
-        final SlingSettingsServiceImpl settingsService = new SlingSettingsServiceImpl(bundleContext, handler);
+        final SlingSettingsServiceImpl settingsService = new SlingSettingsServiceImpl(bundleContext);
 
         final Dictionary<String, String> props = new Hashtable<String, String>();
         props.put(Constants.SERVICE_DESCRIPTION,
@@ -110,7 +88,6 @@
             this.configAdminListener.deactivate();
             this.configAdminListener = null;
         }
-        this.startupListener.deactivate();
         if ( this.settingsReg != null ) {
             this.settingsReg.unregister();
             this.settingsReg = null;
@@ -214,24 +191,6 @@
     }
 
     /**
-     * Helper class listening for service events for a defined service.
-     */
-    private final class Listener extends AbstractListener {
-
-        /**
-         * Constructor
-         */
-        public Listener(final String serviceName) {
-            super(serviceName);
-        }
-
-        @Override
-        protected void serviceChanged() {
-            notifyChange();
-        }
-    }
-
-    /**
      * Helper class listening for service events for config admin
      */
     private final class ConfigAdminListener extends AbstractListener {
diff --git a/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java b/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
index 56b5aa7..28f2f78 100644
--- a/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
+++ b/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
@@ -36,8 +36,6 @@
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.sling.launchpad.api.StartupHandler;
-import org.apache.sling.launchpad.api.StartupMode;
 import org.apache.sling.settings.SlingSettingsService;
 import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
@@ -85,16 +83,12 @@
      * Setup run modes
      * @param context The bundle context
      */
-    public SlingSettingsServiceImpl(final BundleContext context,
-            final StartupHandler handler) {
+    public SlingSettingsServiceImpl(final BundleContext context) {
         this.setupSlingProps(context);
         this.setupSlingHome(context);
         this.setupSlingId(context);
 
-        final StartupMode mode = handler.getMode();
-        logger.debug("Settings: Using startup mode : {}", mode);
-
-        this.setupRunModes(context, mode);
+        this.setupRunModes(context);
 
     }
 
@@ -197,8 +191,7 @@
     /**
      * Set up run modes.
      */
-    private void setupRunModes(final BundleContext context,
-            final StartupMode startupMode) {
+    private void setupRunModes(final BundleContext context) {
         final Set<String> modesSet = new HashSet<String>();
 
         // check configuration property first
@@ -214,26 +207,21 @@
         this.handleOptions(modesSet, context.getProperty(RUN_MODE_OPTIONS));
 
         // handle configured install options
-        if ( startupMode != StartupMode.INSTALL ) {
-            // read persisted options if restart or update
-            final List<Options> storedOptions = readOptions(context);
-            if ( storedOptions != null ) {
-                for(final Options o : storedOptions) {
-                    for(final String m : o.modes) {
-                        modesSet.remove(m);
-                    }
-                    modesSet.add(o.selected);
+        // read persisted options if restart or update
+        final List<Options> storedOptions = readOptions(context);
+        if ( storedOptions != null ) {
+            for(final Options o : storedOptions) {
+                for(final String m : o.modes) {
+                    modesSet.remove(m);
                 }
+                modesSet.add(o.selected);
             }
         }
 
         // now install options
-        if ( startupMode != StartupMode.RESTART ) {
-            // process new install options if install or update
-            final List<Options> optionsList = this.handleOptions(modesSet, context.getProperty(RUN_MODE_INSTALL_OPTIONS));
-            // and always save new install options
-            writeOptions(context, optionsList);
-        }
+        final List<Options> optionsList = this.handleOptions(modesSet, context.getProperty(RUN_MODE_INSTALL_OPTIONS));
+        // and always save new install options
+        writeOptions(context, optionsList);
 
         // make the set unmodifiable and synced
         // we probably don't need a synced set as it is read only
diff --git a/src/test/java/org/apache/sling/settings/impl/RunModeImplTest.java b/src/test/java/org/apache/sling/settings/impl/RunModeImplTest.java
index d32f5e6..ee47135 100644
--- a/src/test/java/org/apache/sling/settings/impl/RunModeImplTest.java
+++ b/src/test/java/org/apache/sling/settings/impl/RunModeImplTest.java
@@ -32,8 +32,6 @@
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.sling.launchpad.api.StartupHandler;
-import org.apache.sling.launchpad.api.StartupMode;
 import org.apache.sling.settings.SlingSettingsService;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -48,33 +46,8 @@
 
 public class RunModeImplTest {
 
-    private final class StartupHandlerImpl implements StartupHandler {
-
-        private final StartupMode mode;
-
-        public StartupHandlerImpl() {
-            this(StartupMode.INSTALL);
-        }
-
-        public StartupHandlerImpl(final StartupMode mode) {
-            this.mode = mode;
-        }
-
-        public void waitWithStartup(final boolean flag) {
-            // nothing to do
-        }
-
-        public boolean isFinished() {
-            return false;
-        }
-
-        public StartupMode getMode() {
-            return this.mode;
-        }
-    };
-
     private void assertParse(String str, String [] expected) {
-        final SlingSettingsService rm = new SlingSettingsServiceImpl(new BundleContextMock(str, null, null), new StartupHandlerImpl());
+        final SlingSettingsService rm = new SlingSettingsServiceImpl(new BundleContextMock(str, null, null));
         final Set<String> modes = rm.getRunModes();
 
         Set<String> expectedSet = new HashSet<String>(expected.length);
@@ -103,61 +76,61 @@
     }
 
     @org.junit.Test public void testMatchesNotEmpty() {
-        final SlingSettingsService rm = new SlingSettingsServiceImpl(new BundleContextMock("foo,bar", null, null), new StartupHandlerImpl());
+        final SlingSettingsService rm = new SlingSettingsServiceImpl(new BundleContextMock("foo,bar", null, null));
         assertActive(rm, true, "foo", "bar");
         assertActive(rm, false, "wiz", "bah", "");
     }
 
     @org.junit.Test public void testOptions() {
-        final SlingSettingsService rm = new SlingSettingsServiceImpl(new BundleContextMock("foo,bar", "a,b,c|d,e,f", null), new StartupHandlerImpl());
+        final SlingSettingsService rm = new SlingSettingsServiceImpl(new BundleContextMock("foo,bar", "a,b,c|d,e,f", null));
         assertActive(rm, true, "foo", "bar", "a", "d");
         assertActive(rm, false, "b", "c", "e", "f");
     }
 
     @org.junit.Test public void testEmptyRunModesWithOptions() {
-        final SlingSettingsService rm = new SlingSettingsServiceImpl(new BundleContextMock("", "a,b,c|d,e,f", null), new StartupHandlerImpl());
+        final SlingSettingsService rm = new SlingSettingsServiceImpl(new BundleContextMock("", "a,b,c|d,e,f", null));
         assertActive(rm, true, "a", "d");
         assertActive(rm, false, "b", "c", "e", "f");
     }
 
     @org.junit.Test public void testOptionsSelected() {
-        final SlingSettingsService rm = new SlingSettingsServiceImpl(new BundleContextMock("foo,bar,c,e", "a,b,c|d,e,f", null), new StartupHandlerImpl());
+        final SlingSettingsService rm = new SlingSettingsServiceImpl(new BundleContextMock("foo,bar,c,e", "a,b,c|d,e,f", null));
         assertActive(rm, true, "foo", "bar", "c", "e");
         assertActive(rm, false, "a", "b", "d", "f");
     }
 
     @org.junit.Test public void testOptionsMultipleSelected() {
-        final SlingSettingsService rm = new SlingSettingsServiceImpl(new BundleContextMock("foo,bar,c,e,f,a", "a,b,c|d,e,f", null), new StartupHandlerImpl());
+        final SlingSettingsService rm = new SlingSettingsServiceImpl(new BundleContextMock("foo,bar,c,e,f,a", "a,b,c|d,e,f", null));
         assertActive(rm, true, "foo", "bar", "a", "e");
         assertActive(rm, false, "b", "c", "d", "f");
     }
 
     @org.junit.Test public void testOptionsMultipleSelected2() {
-        final SlingSettingsService rm = new SlingSettingsServiceImpl(new BundleContextMock("foo,bar,c,f,a,d", "a,b,c|d,e,f", null), new StartupHandlerImpl());
+        final SlingSettingsService rm = new SlingSettingsServiceImpl(new BundleContextMock("foo,bar,c,f,a,d", "a,b,c|d,e,f", null));
         assertActive(rm, true, "foo", "bar", "a", "d");
         assertActive(rm, false, "b", "c", "e", "f");
     }
 
     @org.junit.Test public void testInstallOptions() {
-        final SlingSettingsService rm = new SlingSettingsServiceImpl(new BundleContextMock("foo,bar", null, "a,b,c|d,e,f"), new StartupHandlerImpl());
+        final SlingSettingsService rm = new SlingSettingsServiceImpl(new BundleContextMock("foo,bar", null, "a,b,c|d,e,f"));
         assertActive(rm, true, "foo", "bar", "a", "d");
         assertActive(rm, false, "b", "c", "e", "f");
     }
 
     @org.junit.Test public void testInstallOptionsSelected() {
-        final SlingSettingsService rm = new SlingSettingsServiceImpl(new BundleContextMock("foo,bar,c,e", null , "a,b,c|d,e,f"), new StartupHandlerImpl());
+        final SlingSettingsService rm = new SlingSettingsServiceImpl(new BundleContextMock("foo,bar,c,e", null , "a,b,c|d,e,f"));
         assertActive(rm, true, "foo", "bar", "c", "e");
         assertActive(rm, false, "a", "b", "d", "f");
     }
 
     @org.junit.Test public void testInstallOptionsMultipleSelected() {
-        final SlingSettingsService rm = new SlingSettingsServiceImpl(new BundleContextMock("foo,bar,c,e,f,a", null, "a,b,c|d,e,f"), new StartupHandlerImpl());
+        final SlingSettingsService rm = new SlingSettingsServiceImpl(new BundleContextMock("foo,bar,c,e,f,a", null, "a,b,c|d,e,f"));
         assertActive(rm, true, "foo", "bar", "a", "e");
         assertActive(rm, false, "b", "c", "d", "f");
     }
 
     @org.junit.Test public void testInstallOptionsMultipleSelected2() {
-        final SlingSettingsService rm = new SlingSettingsServiceImpl(new BundleContextMock("foo,bar,c,d,f,a", null, "a,b,c|d,e,f"), new StartupHandlerImpl());
+        final SlingSettingsService rm = new SlingSettingsServiceImpl(new BundleContextMock("foo,bar,c,d,f,a", null, "a,b,c|d,e,f"));
         assertActive(rm, true, "foo", "bar", "a", "d");
         assertActive(rm, false, "b", "c", "e", "f");
     }
@@ -167,13 +140,13 @@
 
         {
             // create first context to simulate install
-            final SlingSettingsService rm = new SlingSettingsServiceImpl(bc, new StartupHandlerImpl());
+            final SlingSettingsService rm = new SlingSettingsServiceImpl(bc);
             assertActive(rm, true, "foo", "bar", "a", "e");
             assertActive(rm, false, "b", "c", "d", "f");
         }
 
         {
-            final SlingSettingsService rm = new SlingSettingsServiceImpl(bc, new StartupHandlerImpl(StartupMode.RESTART));
+            final SlingSettingsService rm = new SlingSettingsServiceImpl(bc);
             assertActive(rm, true, "foo", "bar", "a", "e");
             assertActive(rm, false, "b", "c", "d", "f");
         }
@@ -182,7 +155,7 @@
         // mentioned in the .options properties are ignored
         bc.update("foo,doo,a,b,c,d,e,f,waa");
         {
-            final SlingSettingsService rm = new SlingSettingsServiceImpl(bc, new StartupHandlerImpl(StartupMode.RESTART));
+            final SlingSettingsService rm = new SlingSettingsServiceImpl(bc);
             assertActive(rm, true, "foo", "doo", "a", "e", "waa");
             assertActive(rm, false, "bar", "b", "c", "d", "f");
         }
@@ -257,7 +230,7 @@
             if ( f == null ) {
                 try {
                     f = File.createTempFile(filename, "id");
-                    f.deleteOnExit();
+                    f.delete();
                     files.put(filename, f);
                 } catch (IOException ioe) {
                     throw new RuntimeException(ioe);
diff --git a/src/test/java/org/apache/sling/settings/impl/SlingSettingsServiceImplTest.java b/src/test/java/org/apache/sling/settings/impl/SlingSettingsServiceImplTest.java
index f50fed2..6f8820a 100644
--- a/src/test/java/org/apache/sling/settings/impl/SlingSettingsServiceImplTest.java
+++ b/src/test/java/org/apache/sling/settings/impl/SlingSettingsServiceImplTest.java
@@ -18,6 +18,11 @@
  */
 package org.apache.sling.settings.impl;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -28,16 +33,10 @@
 import org.apache.commons.lang.RandomStringUtils;
 import org.apache.sling.settings.SlingSettingsService;
 import org.junit.After;
-import org.apache.sling.launchpad.api.StartupHandler;
 import org.junit.Before;
 import org.junit.Test;
 import org.osgi.framework.BundleContext;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
 public class SlingSettingsServiceImplTest {
 
     private static final String SLING_ID_FILE_NAME = "sling.id.file";
@@ -111,7 +110,6 @@
         BundleContext context = mock(BundleContext.class);
         when(context.getDataFile(SLING_ID_FILE_NAME)).thenReturn(slingIdFile);
         when(context.getDataFile(OPTIONS_FILE_NAME)).thenReturn(optionsFile);
-        final StartupHandler handler = mock(StartupHandler.class);
         // write options
         final List<SlingSettingsServiceImpl.Options> options = new ArrayList<SlingSettingsServiceImpl.Options>();
         FileOutputStream fos = null;
@@ -138,7 +136,7 @@
                 }
             }
         }
-        return new SlingSettingsServiceImpl(context, handler);
+        return new SlingSettingsServiceImpl(context);
     }
 
 }