You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by pi...@apache.org on 2012/10/09 11:37:43 UTC

svn commit: r1395934 - in /karaf/trunk: assemblies/features/framework/src/main/filtered-resources/resources/etc/ features/core/src/main/java/org/apache/karaf/features/internal/ features/core/src/main/resources/OSGI-INF/blueprint/ manual/src/main/webapp...

Author: pieber
Date: Tue Oct  9 09:37:43 2012
New Revision: 1395934

URL: http://svn.apache.org/viewvc?rev=1395934&view=rev
Log:
[KARAF-1878] Honor the startlvl during feature installation

This patch includes documentation and an option to deactivate the
feature via a configuration.

Signed-off-by: Andreas Pieber <an...@gmail.com>
(cherry picked from commit 72cb5eef04801a1424181ee7c3cf8a64fc862275)

Signed-off-by: Andreas Pieber <an...@gmail.com>

Modified:
    karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/etc/org.apache.karaf.features.cfg
    karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
    karaf/trunk/features/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
    karaf/trunk/manual/src/main/webapp/users-guide/provisioning.conf

Modified: karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/etc/org.apache.karaf.features.cfg
URL: http://svn.apache.org/viewvc/karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/etc/org.apache.karaf.features.cfg?rev=1395934&r1=1395933&r2=1395934&view=diff
==============================================================================
--- karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/etc/org.apache.karaf.features.cfg (original)
+++ karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/etc/org.apache.karaf.features.cfg Tue Oct  9 09:37:43 2012
@@ -18,6 +18,15 @@
 ################################################################################
 
 #
+# Defines if the startlvl should be respected during feature startup. The default value is true. The default
+# behavior for 2.x is false (!) for this property
+#
+# Be aware that this property is deprecated and will be removed in Karaf 4.0. So, if you need to
+# set this to false, please use this only as a temporary solution!
+#
+#respectStartLvlDuringFeatureStartup=true
+
+#
 # Comma separated list of features repositories to register by default
 #
 featuresRepositories=mvn:org.apache.karaf.features/standard/${project.version}/xml/features,mvn:org.apache.karaf.features/enterprise/${project.version}/xml/features

Modified: karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
URL: http://svn.apache.org/viewvc/karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java?rev=1395934&r1=1395933&r2=1395934&view=diff
==============================================================================
--- karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java (original)
+++ karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java Tue Oct  9 09:37:43 2012
@@ -16,7 +16,28 @@
  */
 package org.apache.karaf.features.internal;
 
-import static java.lang.String.format;
+import org.apache.felix.utils.version.VersionRange;
+import org.apache.felix.utils.version.VersionTable;
+import org.apache.karaf.features.BundleInfo;
+import org.apache.karaf.features.Conditional;
+import org.apache.karaf.features.Dependency;
+import org.apache.karaf.features.Feature;
+import org.apache.karaf.features.FeatureEvent;
+import org.apache.karaf.features.FeaturesListener;
+import org.apache.karaf.features.FeaturesService;
+import org.apache.karaf.features.Repository;
+import org.apache.karaf.features.RepositoryEvent;
+import org.apache.karaf.features.Resolver;
+import org.apache.karaf.features.internal.BundleManager.BundleInstallerResult;
+import org.apache.karaf.util.collections.CopyOnWriteArrayIdentityList;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+import org.osgi.framework.startlevel.BundleStartLevel;
+import org.osgi.util.tracker.ServiceTracker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.Closeable;
 import java.io.File;
@@ -30,6 +51,7 @@ import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.Dictionary;
 import java.util.EnumSet;
 import java.util.Enumeration;
@@ -44,28 +66,7 @@ import java.util.TreeSet;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.felix.utils.version.VersionRange;
-import org.apache.felix.utils.version.VersionTable;
-import org.apache.karaf.features.BundleInfo;
-import org.apache.karaf.features.Conditional;
-import org.apache.karaf.features.Dependency;
-import org.apache.karaf.features.Feature;
-import org.apache.karaf.features.FeatureEvent;
-import org.apache.karaf.features.FeaturesListener;
-import org.apache.karaf.features.FeaturesService;
-import org.apache.karaf.features.Repository;
-import org.apache.karaf.features.RepositoryEvent;
-import org.apache.karaf.features.Resolver;
-import org.apache.karaf.features.internal.BundleManager.BundleInstallerResult;
-import org.apache.karaf.util.collections.CopyOnWriteArrayIdentityList;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.Constants;
-import org.osgi.framework.Version;
-import org.osgi.framework.startlevel.BundleStartLevel;
-import org.osgi.util.tracker.ServiceTracker;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import static java.lang.String.format;
 
 /**
  * The Features service implementation.
@@ -79,6 +80,7 @@ public class FeaturesServiceImpl impleme
     private final BundleManager bundleManager;
     private final FeatureConfigInstaller configManager;
 
+    private boolean respectStartLvlDuringFeatureStartup;
     private long resolverTimeout = 5000;
     private Set<URI> uris;
     private Map<URI, Repository> repositories = new HashMap<URI, Repository>();
@@ -105,6 +107,10 @@ public class FeaturesServiceImpl impleme
         this.resolverTimeout = resolverTimeout;
     }
 
+    public void setRespectStartLvlDuringFeatureStartup(boolean respectStartLvlDuringFeatureStartup) {
+        this.respectStartLvlDuringFeatureStartup = respectStartLvlDuringFeatureStartup;
+    }
+
     public void registerListener(FeaturesListener listener) {
         listeners.add(listener);
         for (Repository repository : listRepositories()) {
@@ -359,8 +365,8 @@ public class FeaturesServiceImpl impleme
      * @throws Exception in case of install failure.
      */
     public void installFeatures(Set<Feature> features, EnumSet<Option> options) throws Exception {
-        InstallationState state = new InstallationState();
-        InstallationState failure = new InstallationState();
+        final InstallationState state = new InstallationState();
+        final InstallationState failure = new InstallationState();
         boolean verbose = options.contains(FeaturesService.Option.Verbose);
         try {
             // Install everything
@@ -398,8 +404,18 @@ public class FeaturesServiceImpl impleme
             	}
             }
             bundleManager.refreshBundles(state.bundles, state.installed, options);
-            // Start all bundles
-            for (Bundle b : state.bundles) {
+            // start all bundles sorted by startlvl if wished for
+            List<Bundle> bundlesSortedByStartLvl = new ArrayList<Bundle>(state.bundles);
+            if (respectStartLvlDuringFeatureStartup) {
+                Collections.sort(bundlesSortedByStartLvl, new Comparator<Bundle>() {
+                    @Override
+                    public int compare(Bundle bundle, Bundle bundle1) {
+                        return state.bundleInfos.get(bundle.getBundleId()).getStartLevel() -
+                                state.bundleInfos.get(bundle1.getBundleId()).getStartLevel();
+                    }
+                });
+            }
+            for (Bundle b : bundlesSortedByStartLvl) {
                 LOGGER.debug("Starting bundle: {}", b.getSymbolicName());
                 startBundle(state, b);
             }

Modified: karaf/trunk/features/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/features/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml?rev=1395934&r1=1395933&r2=1395934&view=diff
==============================================================================
--- karaf/trunk/features/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml (original)
+++ karaf/trunk/features/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml Tue Oct  9 09:37:43 2012
@@ -34,6 +34,7 @@ http://aries.apache.org/blueprint/xmlns/
             <ext:property name="featuresRepositories" value=""/>
             <ext:property name="featuresBoot" value=""/>
             <ext:property name="resolverTimeout" value="5000"/>
+            <ext:property name="respectStartLvlDuringFeatureStartup" value="true"/>
         </ext:default-properties>
         <ext:location>file:$(karaf.base)/etc/org.apache.karaf.features.cfg</ext:location>
     </ext:property-placeholder>
@@ -49,6 +50,7 @@ http://aries.apache.org/blueprint/xmlns/
     	<argument ref="bundleManager" />
     	<argument ref="configInstaller" />
         <property name="urls" value="$[featuresRepositories]" />
+        <property name="respectStartLvlDuringFeatureStartup" value="$[respectStartLvlDuringFeatureStartup]" />
         <property name="resolverTimeout" value="$[resolverTimeout]" />
     </bean>
     

Modified: karaf/trunk/manual/src/main/webapp/users-guide/provisioning.conf
URL: http://svn.apache.org/viewvc/karaf/trunk/manual/src/main/webapp/users-guide/provisioning.conf?rev=1395934&r1=1395933&r2=1395934&view=diff
==============================================================================
--- karaf/trunk/manual/src/main/webapp/users-guide/provisioning.conf (original)
+++ karaf/trunk/manual/src/main/webapp/users-guide/provisioning.conf Tue Oct  9 09:37:43 2012
@@ -160,6 +160,10 @@ The OSGI specification allows for instal
   </feature> 
 {code}
 
+{warning}
+Before Karaf 3.0 the start-level was NOT considered during the feature startup, but only the order in which bundles are defined in your feature.xml. Starting with 3.0 the start-level is no considered correctly. If you need to use the old behavior you can uncomment and change the respectStartLvlDuringFeatureStartup variable in org.apache.karaf.features.xml to false. But please be aware that it will be removed in 4.0 and should therefore be used only temporarily.
+{warning}
+
 h4. Bundle 'dependency'
 
 A bundle can be flagged as being a dependency.  Such information can be used by resolvers to compute the full list of bundles to be installed.