You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2012/10/05 09:47:43 UTC
svn commit: r1394398 - in /karaf/branches/karaf-2.3.x/features/core/src:
main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
test/java/org/apache/karaf/features/internal/FeaturesServiceImplTest.java
Author: jbonofre
Date: Fri Oct 5 07:47:43 2012
New Revision: 1394398
URL: http://svn.apache.org/viewvc?rev=1394398&view=rev
Log:
[KARAF-1796] Change the install/start order of features
Modified:
karaf/branches/karaf-2.3.x/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
karaf/branches/karaf-2.3.x/features/core/src/test/java/org/apache/karaf/features/internal/FeaturesServiceImplTest.java
Modified: karaf/branches/karaf-2.3.x/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java?rev=1394398&r1=1394397&r2=1394398&view=diff
==============================================================================
--- karaf/branches/karaf-2.3.x/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java (original)
+++ karaf/branches/karaf-2.3.x/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java Fri Oct 5 07:47:43 2012
@@ -582,10 +582,17 @@ public class FeaturesServiceImpl impleme
configFile.getFinalname(), configFile.isOverride(), verbose);
}
Set<Long> bundles = new TreeSet<Long>();
+ List<InstallResult> installResultList = new LinkedList<InstallResult>();
for (BundleInfo bInfo : resolve(feature)) {
- Bundle b = installBundleIfNeeded(state, bInfo, verbose);
- bundles.add(b.getBundleId());
- state.bundleInfos.put(b.getBundleId(), bInfo);
+ InstallResult result = installBundleIfNeeded(state, bInfo, verbose);
+ bundles.add(result.getBundle().getBundleId());
+ state.bundleInfos.put(result.getBundle().getBundleId(), bInfo);
+ installResultList.add(result);
+ }
+ for (InstallResult result : installResultList) {
+ if (!result.isPreviouslyInstalled()) {
+ startBundleIfNeeded(result.getBundle(), result.getStartLevel());
+ }
}
state.features.put(feature, bundles);
}
@@ -750,7 +757,33 @@ public class FeaturesServiceImpl impleme
return result;
}
- protected Bundle installBundleIfNeeded(InstallationState state, BundleInfo bundleInfo, boolean verbose) throws IOException, BundleException {
+ protected static class InstallResult {
+
+ private final boolean previouslyInstalled;
+ private final Bundle bundle;
+ private final int startLevel;
+
+ protected InstallResult(boolean previouslyInstalled, Bundle bundle, int startLevel) {
+ this.previouslyInstalled = previouslyInstalled;
+ this.bundle = bundle;
+ this.startLevel = startLevel;
+ }
+
+ public boolean isPreviouslyInstalled() {
+ return previouslyInstalled;
+ }
+
+ public Bundle getBundle() {
+ return bundle;
+ }
+
+ public int getStartLevel() {
+ return startLevel;
+ }
+
+ }
+
+ protected InstallResult installBundleIfNeeded(InstallationState state, BundleInfo bundleInfo, boolean verbose) throws IOException, BundleException {
InputStream is;
String bundleLocation = bundleInfo.getLocation();
LOGGER.debug("Checking " + bundleLocation);
@@ -788,7 +821,7 @@ public class FeaturesServiceImpl impleme
System.out.println("Found installed bundle: " + b);
}
state.bundles.add(b);
- return b;
+ return new InstallResult(true, b, 0);
}
}
}
@@ -804,20 +837,20 @@ public class FeaturesServiceImpl impleme
}
Bundle b = getBundleContext().installBundle(bundleLocation, is);
- // Define the startLevel for the bundle when defined
- int ibsl = bundleInfo.getStartLevel();
- if (ibsl > 0) {
- getStartLevel().setBundleStartLevel(b, ibsl);
- }
-
state.bundles.add(b);
state.installed.add(b);
- return b;
+ return new InstallResult(false, b, bundleInfo.getStartLevel());
} finally {
is.close();
}
}
+ private void startBundleIfNeeded(Bundle bundle, int startLevel) {
+ if (startLevel > 0) {
+ getStartLevel().setBundleStartLevel(bundle, startLevel);
+ }
+ }
+
public void installConfigurationFile(String fileLocation, String finalname, boolean override, boolean verbose) throws IOException {
LOGGER.debug("Checking configuration file " + fileLocation);
if (verbose) {
Modified: karaf/branches/karaf-2.3.x/features/core/src/test/java/org/apache/karaf/features/internal/FeaturesServiceImplTest.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/features/core/src/test/java/org/apache/karaf/features/internal/FeaturesServiceImplTest.java?rev=1394398&r1=1394397&r2=1394398&view=diff
==============================================================================
--- karaf/branches/karaf-2.3.x/features/core/src/test/java/org/apache/karaf/features/internal/FeaturesServiceImplTest.java (original)
+++ karaf/branches/karaf-2.3.x/features/core/src/test/java/org/apache/karaf/features/internal/FeaturesServiceImplTest.java Fri Oct 5 07:47:43 2012
@@ -206,12 +206,12 @@ public class FeaturesServiceImplTest ext
}
@Override
- protected Bundle installBundleIfNeeded(InstallationState state, BundleInfo bundleInfo, boolean verbose) throws IOException, BundleException {
+ protected InstallResult installBundleIfNeeded(InstallationState state, BundleInfo bundleInfo, boolean verbose) throws IOException, BundleException {
// let's return a mock bundle and bundle id to keep the features service happy
Bundle bundle = createNiceMock(Bundle.class);
expect(bundle.getBundleId()).andReturn(10l).anyTimes();
replay(bundle);
- return bundle;
+ return new InstallResult(false, bundle, 0);
}
};
impl.addRepository(getClass().getResource("repo2.xml").toURI());