You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2015/12/04 09:22:08 UTC

svn commit: r1717909 - in /sling/trunk/bundles/extensions/settings: ./ src/main/java/org/apache/sling/settings/impl/ src/test/java/org/apache/sling/settings/impl/

Author: cziegeler
Date: Fri Dec  4 08:22:08 2015
New Revision: 1717909

URL: http://svn.apache.org/viewvc?rev=1717909&view=rev
Log:
SLING-4892 : Remove dependency to StartupHandler

Modified:
    sling/trunk/bundles/extensions/settings/pom.xml
    sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/ServicesListener.java
    sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
    sling/trunk/bundles/extensions/settings/src/test/java/org/apache/sling/settings/impl/RunModeImplTest.java
    sling/trunk/bundles/extensions/settings/src/test/java/org/apache/sling/settings/impl/SlingSettingsServiceImplTest.java

Modified: sling/trunk/bundles/extensions/settings/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/settings/pom.xml?rev=1717909&r1=1717908&r2=1717909&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/settings/pom.xml (original)
+++ sling/trunk/bundles/extensions/settings/pom.xml Fri Dec  4 08:22:08 2015
@@ -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>

Modified: sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/ServicesListener.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/ServicesListener.java?rev=1717909&r1=1717908&r2=1717909&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/ServicesListener.java (original)
+++ sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/ServicesListener.java Fri Dec  4 08:22:08 2015
@@ -21,7 +21,6 @@ package org.apache.sling.settings.impl;
 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 @@ public class ServicesListener {
     /** 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 class ServicesListener {
      */
     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 @@ public class ServicesListener {
             this.configAdminListener.deactivate();
             this.configAdminListener = null;
         }
-        this.startupListener.deactivate();
         if ( this.settingsReg != null ) {
             this.settingsReg.unregister();
             this.settingsReg = null;
@@ -214,24 +191,6 @@ public class ServicesListener {
     }
 
     /**
-     * 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 {

Modified: sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java?rev=1717909&r1=1717908&r2=1717909&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java (original)
+++ sling/trunk/bundles/extensions/settings/src/main/java/org/apache/sling/settings/impl/SlingSettingsServiceImpl.java Fri Dec  4 08:22:08 2015
@@ -36,8 +36,6 @@ import java.util.List;
 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 @@ public class SlingSettingsServiceImpl
      * 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 @@ public class SlingSettingsServiceImpl
     /**
      * 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 @@ public class SlingSettingsServiceImpl
         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

Modified: sling/trunk/bundles/extensions/settings/src/test/java/org/apache/sling/settings/impl/RunModeImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/settings/src/test/java/org/apache/sling/settings/impl/RunModeImplTest.java?rev=1717909&r1=1717908&r2=1717909&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/settings/src/test/java/org/apache/sling/settings/impl/RunModeImplTest.java (original)
+++ sling/trunk/bundles/extensions/settings/src/test/java/org/apache/sling/settings/impl/RunModeImplTest.java Fri Dec  4 08:22:08 2015
@@ -32,8 +32,6 @@ import java.util.HashSet;
 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 @@ import org.osgi.framework.ServiceRegistr
 
 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 @@ public class RunModeImplTest {
     }
 
     @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 @@ public class RunModeImplTest {
 
         {
             // 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 @@ public class RunModeImplTest {
         // 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 @@ public class RunModeImplTest {
             if ( f == null ) {
                 try {
                     f = File.createTempFile(filename, "id");
-                    f.deleteOnExit();
+                    f.delete();
                     files.put(filename, f);
                 } catch (IOException ioe) {
                     throw new RuntimeException(ioe);

Modified: sling/trunk/bundles/extensions/settings/src/test/java/org/apache/sling/settings/impl/SlingSettingsServiceImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/settings/src/test/java/org/apache/sling/settings/impl/SlingSettingsServiceImplTest.java?rev=1717909&r1=1717908&r2=1717909&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/settings/src/test/java/org/apache/sling/settings/impl/SlingSettingsServiceImplTest.java (original)
+++ sling/trunk/bundles/extensions/settings/src/test/java/org/apache/sling/settings/impl/SlingSettingsServiceImplTest.java Fri Dec  4 08:22:08 2015
@@ -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 java.util.List;
 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 @@ public class SlingSettingsServiceImplTes
         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 @@ public class SlingSettingsServiceImplTes
                 }
             }
         }
-        return new SlingSettingsServiceImpl(context, handler);
+        return new SlingSettingsServiceImpl(context);
     }
 
 }