Add support for setting start level for auto-deploy bundles. (FELIX-2678)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1029712 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/main/src/main/java/org/apache/felix/main/AutoProcessor.java b/main/src/main/java/org/apache/felix/main/AutoProcessor.java
index 7a888f7..e5d38f7 100644
--- a/main/src/main/java/org/apache/felix/main/AutoProcessor.java
+++ b/main/src/main/java/org/apache/felix/main/AutoProcessor.java
@@ -38,6 +38,10 @@
**/
public static final String AUTO_DEPLOY_ACTION_PROPERY = "felix.auto.deploy.action";
/**
+ * The property name used to specify auto-deploy start level.
+ **/
+ public static final String AUTO_DEPLOY_STARTLEVEL_PROPERY = "felix.auto.deploy.startlevel";
+ /**
* The name used for the auto-deploy install action.
**/
public static final String AUTO_DEPLOY_INSTALL_VALUE = "install";
@@ -77,8 +81,8 @@
/**
* <p>
- * Processes bundles in the auto-deploy directory, installing and then
- * starting each one.
+ * Processes bundles in the auto-deploy directory, performing the
+ * specified deploy actions.
* </p>
*/
private static void processAutoDeploy(Map configMap, BundleContext context)
@@ -103,6 +107,26 @@
// Perform auto-deploy actions.
if (actionList.size() > 0)
{
+ // Retrieve the Start Level service, since it will be needed
+ // to set the start level of the installed bundles.
+ StartLevel sl = (StartLevel) context.getService(
+ context.getServiceReference(org.osgi.service.startlevel.StartLevel.class.getName()));
+
+ // Get start level for auto-deploy bundles.
+ int startLevel = sl.getInitialBundleStartLevel();
+ if (configMap.get(AUTO_DEPLOY_STARTLEVEL_PROPERY) != null)
+ {
+ try
+ {
+ startLevel = Integer.parseInt(
+ configMap.get(AUTO_DEPLOY_STARTLEVEL_PROPERY).toString());
+ }
+ catch (NumberFormatException ex)
+ {
+ // Ignore and keep default level.
+ }
+ }
+
// Get list of already installed bundles as a map.
Map installedBundleMap = new HashMap();
Bundle[] bundles = context.getBundles();
@@ -139,6 +163,7 @@
// indicate which bundles may need to be uninstalled.
Bundle b = (Bundle) installedBundleMap.remove(
((File) jarList.get(i)).toURI().toString());
+
try
{
// If the bundle is not already installed, then install it
@@ -156,10 +181,12 @@
}
// If we have found and/or successfully installed a bundle,
- // then add it to the list of bundles to potentially start.
- if (b != null)
+ // then add it to the list of bundles to potentially start
+ // and also set its start level accordingly.
+ if ((b != null) && !isFragment(b))
{
startBundleList.add(b);
+ sl.setBundleStartLevel(b, startLevel);
}
}
catch (BundleException ex)
@@ -200,10 +227,7 @@
{
try
{
- if (!isFragment((Bundle) startBundleList.get(i)))
- {
- ((Bundle) startBundleList.get(i)).start();
- }
+ ((Bundle) startBundleList.get(i)).start();
}
catch (BundleException ex)
{