incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1408855 - in /sling/trunk/launchpad/installer: pom.xml src/main/java/org/apache/sling/launchpad/installer/impl/LaunchpadConfigInstaller.java src/main/java/org/apache/sling/launchpad/installer/impl/ServicesListener.java
Date Tue, 13 Nov 2012 17:48:25 GMT
Author: cziegeler
Date: Tue Nov 13 17:48:24 2012
New Revision: 1408855

URL: http://svn.apache.org/viewvc?rev=1408855&view=rev
Log:
SLING.2649 : Add support for run modes

Modified:
    sling/trunk/launchpad/installer/pom.xml
    sling/trunk/launchpad/installer/src/main/java/org/apache/sling/launchpad/installer/impl/LaunchpadConfigInstaller.java
    sling/trunk/launchpad/installer/src/main/java/org/apache/sling/launchpad/installer/impl/ServicesListener.java

Modified: sling/trunk/launchpad/installer/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/installer/pom.xml?rev=1408855&r1=1408854&r2=1408855&view=diff
==============================================================================
--- sling/trunk/launchpad/installer/pom.xml (original)
+++ sling/trunk/launchpad/installer/pom.xml Tue Nov 13 17:48:24 2012
@@ -73,5 +73,11 @@
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.settings</artifactId>
+            <version>1.1.0</version>
+            <scope>provided</scope>
+        </dependency>
     </dependencies>
 </project>

Modified: sling/trunk/launchpad/installer/src/main/java/org/apache/sling/launchpad/installer/impl/LaunchpadConfigInstaller.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/installer/src/main/java/org/apache/sling/launchpad/installer/impl/LaunchpadConfigInstaller.java?rev=1408855&r1=1408854&r2=1408855&view=diff
==============================================================================
--- sling/trunk/launchpad/installer/src/main/java/org/apache/sling/launchpad/installer/impl/LaunchpadConfigInstaller.java
(original)
+++ sling/trunk/launchpad/installer/src/main/java/org/apache/sling/launchpad/installer/impl/LaunchpadConfigInstaller.java
Tue Nov 13 17:48:24 2012
@@ -25,6 +25,7 @@ import java.util.Dictionary;
 import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Iterator;
+import java.util.Set;
 
 import org.apache.sling.installer.api.InstallableResource;
 import org.apache.sling.installer.api.OsgiInstaller;
@@ -41,27 +42,37 @@ public class LaunchpadConfigInstaller {
     /**
      * Resources supplied under this path by
      * LaunchpadContentProvider are considered for installation
+     */
+    private static final String ROOT_PATH = "resources";
+
+    /**
+     * Resources supplied under this path by
+     * LaunchpadContentProvider are considered for installation
      * as configurations
      */
-    private static final String ROOT_CONFIG_PATH = "resources/config";
+    private static final String CONFIG_NAME = "config";
 
     /**
      * Resources supplied under this path by
      * LaunchpadContentProvider are considered for installation
      * as files
      */
-    private static final String ROOT_INSTALL_PATH = "resources/install";
+    private static final String INSTALL_NAME = "install";
+    private static final String INSTALL_PREFIX = "install.";
 
     /** Artifact priority. */
     private static final Integer PRIORITY = new Integer(50);
+    private static final int PRIORITY_BOOST = 5;
 
     /**
      * Check the path for installable artifacts.
      */
     private static boolean checkPath(final LaunchpadContentProvider resourceProvider,
+            final Set<String> activeRunModes,
             final Collection<InstallableResource> installables,
             final String rootPath,
-            final String resourceType) {
+            final String resourceType,
+            final Integer prio) {
         int count = 0;
         final Logger logger = LoggerFactory.getLogger(LaunchpadConfigInstaller.class);
         final Iterator<String> configPaths = resourceProvider.getChildren(rootPath);
@@ -73,18 +84,27 @@ public class LaunchpadConfigInstaller {
                 if ( path.endsWith("/") ) {
                     path = path.substring(0, path.length() - 1);
                 }
-                if ( !checkPath(resourceProvider, installables, path, resourceType) ) {
-                    logger.info("Launchpad {} will be installed: {}", resourceType, path);
+                if ( !checkPath(resourceProvider, activeRunModes, installables, path, resourceType,
prio) ) {
                     final URL url = resourceProvider.getResource(path);
                     Dictionary<String, Object> dict = null;
                     if ( InstallableResource.TYPE_FILE.equals(resourceType) ) {
                         dict = new Hashtable<String, Object>();
-                        dict.put(InstallableResource.INSTALLATION_HINT, hint);
+                        if ( !hint.startsWith(INSTALL_NAME) ) {
+                            dict.put(InstallableResource.INSTALLATION_HINT, hint);
+                        }
                         try {
                             dict.put(InstallableResource.RESOURCE_URI_HINT, url.toURI().toString());
                         } catch (final URISyntaxException e) {
                             // we just ignore this
                         }
+                    } else {
+                        // if this is a configuration, hint could be run Modes
+                        if ( !hint.equals(CONFIG_NAME) ) {
+                            if ( isActive(hint, activeRunModes) == 0 ) {
+                                logger.debug("Launchpad ignoring {} : {} due to unactivated
run mode", resourceType, path);
+                                continue;
+                            }
+                        }
                     }
                     long lastModified = -1;
                     try {
@@ -92,9 +112,10 @@ public class LaunchpadConfigInstaller {
                     } catch (final IOException e) {
                         // we ignore this
                     }
+                    logger.debug("Launchpad {} will be installed: {}", resourceType, path);
                     final String digest = (lastModified > 0 ? String.valueOf(lastModified)
: null);
                     final InputStream stream = resourceProvider.getResourceAsStream(path);
-                    installables.add(new InstallableResource(path, stream, dict, digest,
resourceType, PRIORITY));
+                    installables.add(new InstallableResource(path, stream, dict, digest,
resourceType, prio));
                     count++;
                 }
             }
@@ -102,22 +123,59 @@ public class LaunchpadConfigInstaller {
         return count > 0;
     }
 
+    private static int isActive(final String runModesString, final Set<String> activeRunModes)
{
+        final String[] runModes = runModesString.split(".");
+        boolean active = true;
+        for(final String mode : runModes) {
+            if ( !activeRunModes.contains(mode) ) {
+                active = false;
+            }
+        }
+        return active ? runModes.length : 0;
+    }
+
     /**
      * Install artifacts
      */
     public static void install(final OsgiInstaller installer,
-            final LaunchpadContentProvider resourceProvider) {
+            final LaunchpadContentProvider resourceProvider,
+            final Set<String> activeRunModes) {
         final Logger logger = LoggerFactory.getLogger(LaunchpadConfigInstaller.class);
-        logger.info("Activating launchpad config installer, configuration path={}, install
path={}",
-                ROOT_CONFIG_PATH, ROOT_INSTALL_PATH);
+        logger.info("Activating launchpad config installer, configuration path={}/{}, install
path={}/{}",
+                new Object[] {ROOT_PATH, CONFIG_NAME, ROOT_PATH, INSTALL_NAME});
 
         final Collection<InstallableResource> installables = new HashSet<InstallableResource>();
 
-        // configurations
-        checkPath(resourceProvider, installables, ROOT_CONFIG_PATH, InstallableResource.TYPE_PROPERTIES);
-
-        // files
-        checkPath(resourceProvider, installables, ROOT_INSTALL_PATH, InstallableResource.TYPE_FILE);
+        final Iterator<String> configPaths = resourceProvider.getChildren(ROOT_PATH);
+        if ( configPaths != null ) {
+            while ( configPaths.hasNext() ) {
+                String path = configPaths.next();
+                logger.debug("Found launchpad resource {}", path);
+                if ( path.endsWith("/") ) {
+                    path = path.substring(0, path.length() - 1);
+                }
+                final int namePos = path.lastIndexOf('/');
+                String name = path.substring(namePos + 1);
+                if ( name.equals(CONFIG_NAME) ) {
+                    // configurations
+                    checkPath(resourceProvider, activeRunModes, installables, path, InstallableResource.TYPE_PROPERTIES,
PRIORITY);
+                } else if ( name.equals(INSTALL_NAME) ) {
+                    // files
+                    checkPath(resourceProvider, activeRunModes, installables, path, InstallableResource.TYPE_FILE,
PRIORITY);
+                } else if ( name.startsWith(INSTALL_PREFIX) ) {
+                    final int activeModes = isActive(name.substring(INSTALL_PREFIX.length()),
activeRunModes);
+                    if ( activeModes > 0 ) {
+                        // files
+                        final int prio = PRIORITY + PRIORITY_BOOST * activeModes;
+                        checkPath(resourceProvider, activeRunModes, installables, path, InstallableResource.TYPE_FILE,
prio);
+                    } else {
+                        logger.debug("Ignoring path {} due to unactivated run mode", path);
+                    }
+                } else {
+                    logger.debug("Ignoring path {} - not an installation path", path);
+                }
+            }
+        }
 
         final InstallableResource [] toInstall = installables.toArray(new InstallableResource
[]{});
         installer.registerResources("launchpad", (toInstall));

Modified: sling/trunk/launchpad/installer/src/main/java/org/apache/sling/launchpad/installer/impl/ServicesListener.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/installer/src/main/java/org/apache/sling/launchpad/installer/impl/ServicesListener.java?rev=1408855&r1=1408854&r2=1408855&view=diff
==============================================================================
--- sling/trunk/launchpad/installer/src/main/java/org/apache/sling/launchpad/installer/impl/ServicesListener.java
(original)
+++ sling/trunk/launchpad/installer/src/main/java/org/apache/sling/launchpad/installer/impl/ServicesListener.java
Tue Nov 13 17:48:24 2012
@@ -25,6 +25,7 @@ import org.apache.sling.installer.api.Os
 import org.apache.sling.installer.api.event.InstallationListener;
 import org.apache.sling.launchpad.api.LaunchpadContentProvider;
 import org.apache.sling.launchpad.api.StartupHandler;
+import org.apache.sling.settings.SlingSettingsService;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.InvalidSyntaxException;
@@ -51,6 +52,9 @@ public class ServicesListener {
     /** The listener for the startup handler. */
     private final Listener startupListener;
 
+    /** The listener for the settings service. */
+    private final Listener settingsListener;
+
     /** The registration of the launchpad listener. */
     private ServiceRegistration launchpadListenerReg;
 
@@ -67,9 +71,11 @@ public class ServicesListener {
         this.installerListener = new Listener(OsgiInstaller.class.getName());
         this.providerListener = new Listener(LaunchpadContentProvider.class.getName());
         this.startupListener = new Listener(StartupHandler.class.getName());
+        this.settingsListener = new Listener(SlingSettingsService.class.getName());
         this.startupListener.start();
         this.installerListener.start();
         this.providerListener.start();
+        this.settingsListener.start();
     }
 
     /**
@@ -82,8 +88,8 @@ public class ServicesListener {
         final OsgiInstaller installer = (OsgiInstaller)this.installerListener.getService();
         final LaunchpadContentProvider lcp = (LaunchpadContentProvider)this.providerListener.getService();
         final StartupHandler handler = (StartupHandler)this.startupListener.getService();
-
-        if ( installer != null && lcp != null && handler != null ) {
+        final SlingSettingsService settings = (SlingSettingsService)this.settingsListener.getService();
+        if ( installer != null && lcp != null && handler != null &&
settings != null ) {
             if ( !this.installed ) {
                 this.installed = true;
                 this.launchpadListener = new LaunchpadListener(handler);
@@ -91,7 +97,7 @@ public class ServicesListener {
                 props.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Launchpad Startup
Listener");
                 props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
                 this.launchpadListenerReg = this.bundleContext.registerService(InstallationListener.class.getName(),
launchpadListener, props);
-                LaunchpadConfigInstaller.install(installer, lcp);
+                LaunchpadConfigInstaller.install(installer, lcp, settings.getRunModes());
             }
         }
     }
@@ -103,6 +109,7 @@ public class ServicesListener {
         this.installerListener.deactivate();
         this.providerListener.deactivate();
         this.startupListener.deactivate();
+        this.settingsListener.deactivate();
         if ( this.launchpadListenerReg != null ) {
             this.launchpadListener.stop();
             this.launchpadListenerReg.unregister();



Mime
View raw message