Index: features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java =================================================================== --- features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java (revision 1376198) +++ features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java (working copy) @@ -478,11 +478,18 @@ configFile.getFinalname(), configFile.isOverride(), verbose); } Set bundles = new TreeSet(); + List installResultList = new LinkedList(); 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.wasPreviouslyInstalled()) { + startBundleIfNeeded(result.getBundle(),result.getStartLevel()); + } + } state.features.put(feature, bundles); } @@ -645,8 +652,32 @@ } return result; } + + 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; + } - protected Bundle installBundleIfNeeded(InstallationState state, BundleInfo bundleInfo, boolean verbose) throws IOException, BundleException { + public boolean wasPreviouslyInstalled() { + 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); @@ -684,7 +715,7 @@ System.out.println("Found installed bundle: " + b); } state.bundles.add(b); - return b; + return new InstallResult(true,b,0); } } } @@ -701,19 +732,25 @@ Bundle b = getBundleContext().installBundle(bundleLocation, is); // Define the startLevel for the bundle when defined - int ibsl = bundleInfo.getStartLevel(); + /*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) {