You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2009/08/03 20:24:20 UTC
svn commit: r800486 - in /felix/trunk/main: pom.xml
src/main/java/org/apache/felix/main/AutoActivator.java
src/main/java/org/apache/felix/main/Main.java
src/main/resources/config.properties
Author: rickhall
Date: Mon Aug 3 18:24:19 2009
New Revision: 800486
URL: http://svn.apache.org/viewvc?rev=800486&view=rev
Log:
Modify launcher to automatically install and start bundles in the
auto-deploy directory without need for configuration. (FELIX-1446)
Modified:
felix/trunk/main/pom.xml
felix/trunk/main/src/main/java/org/apache/felix/main/AutoActivator.java
felix/trunk/main/src/main/java/org/apache/felix/main/Main.java
felix/trunk/main/src/main/resources/config.properties
Modified: felix/trunk/main/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/main/pom.xml?rev=800486&r1=800485&r2=800486&view=diff
==============================================================================
--- felix/trunk/main/pom.xml (original)
+++ felix/trunk/main/pom.xml Mon Aug 3 18:24:19 2009
@@ -68,6 +68,10 @@
<groupId>${pom.groupId}</groupId>
<artifactId>org.osgi.core</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </exclusion>
</exclusions>
</dependency>
<dependency>
@@ -81,6 +85,10 @@
</exclusion>
<exclusion>
<groupId>${pom.groupId}</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>${pom.groupId}</groupId>
<artifactId>org.osgi.service.obr</artifactId>
</exclusion>
<exclusion>
Modified: felix/trunk/main/src/main/java/org/apache/felix/main/AutoActivator.java
URL: http://svn.apache.org/viewvc/felix/trunk/main/src/main/java/org/apache/felix/main/AutoActivator.java?rev=800486&r1=800485&r2=800486&view=diff
==============================================================================
--- felix/trunk/main/src/main/java/org/apache/felix/main/AutoActivator.java (original)
+++ felix/trunk/main/src/main/java/org/apache/felix/main/AutoActivator.java Mon Aug 3 18:24:19 2009
@@ -18,17 +18,35 @@
*/
package org.apache.felix.main;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
+import org.osgi.framework.Constants;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
import org.osgi.service.startlevel.StartLevel;
public class AutoActivator implements BundleActivator
{
/**
+ * The property name used for the bundle directory.
+ **/
+ public static final String AUTO_DEPLOY_DIR_PROPERY = "felix.auto.deploy.dir";
+ /**
+ * The default name used for the bundle directory.
+ **/
+ public static final String AUTO_DEPLOY_DIR_VALUE = "bundle";
+ /**
+ * The property name used to enable/disable automatic bundle deployment.
+ **/
+ public static final String AUTO_DEPLOY_PROP = "felix.auto.deploy";
+ /**
* The property name prefix for the launcher's auto-install property.
**/
public static final String AUTO_INSTALL_PROP = "felix.auto.install";
@@ -37,7 +55,7 @@
**/
public static final String AUTO_START_PROP = "felix.auto.start";
- private Map m_configMap;
+ private final Map m_configMap;
public AutoActivator(Map configMap)
{
@@ -52,6 +70,7 @@
**/
public void start(BundleContext context)
{
+ processAutoDeploy(context);
processAutoProperties(context);
}
@@ -64,6 +83,68 @@
// Do nothing.
}
+ private void processAutoDeploy(BundleContext context)
+ {
+ // Determine if auto deploy is enabled; default is enabled.
+ String enabled = (String) m_configMap.get(AUTO_DEPLOY_PROP);
+ enabled = (enabled == null) ? Boolean.TRUE.toString() : enabled;
+ if (Boolean.valueOf(enabled).booleanValue())
+ {
+ // Get the auto deploy directory.
+ String autoDir = (String) m_configMap.get(AUTO_DEPLOY_DIR_PROPERY);
+ autoDir = (autoDir == null) ? AUTO_DEPLOY_DIR_VALUE : autoDir;
+ // Look in the specified bundle directory to create a list
+ // of all JAR files to install.
+ File[] files = new File(autoDir).listFiles();
+ if (files != null)
+ {
+ Arrays.sort(files);
+ List bundleList = new ArrayList();
+ for (int i = 0; i < files.length; i++)
+ {
+ if (files[i].getName().endsWith(".jar"))
+ {
+ bundleList.add(files[i]);
+ }
+ }
+
+ // Install bundle JAR files and remember the bundle objects.
+ final List installedList = new ArrayList();
+ for (int i = 0; i < bundleList.size(); i++)
+ {
+ try
+ {
+ Bundle b = context.installBundle(
+ ((File) bundleList.get(i)).toURI().toString());
+ installedList.add(b);
+ }
+ catch (BundleException ex)
+ {
+ System.err.println("Auto-deploy install: "
+ + ex + ((ex.getCause() != null) ? " - " + ex.getCause() : ""));
+ }
+ }
+
+ // Start all installed bundles.
+ for (int i = 0; i < installedList.size(); i++)
+ {
+ try
+ {
+ if (!isFragment((Bundle) installedList.get(i)))
+ {
+ ((Bundle) installedList.get(i)).start();
+ }
+ }
+ catch (BundleException ex)
+ {
+ System.err.println("Auto-deploy start: "
+ + ex + ((ex.getCause() != null) ? " - " + ex.getCause() : ""));
+ }
+ }
+ }
+ }
+ }
+
/**
* <p>
* Processes the auto-install and auto-start properties from the
@@ -212,4 +293,9 @@
return retVal;
}
+
+ private static boolean isFragment(Bundle bundle)
+ {
+ return bundle.getHeaders().get(Constants.FRAGMENT_HOST) != null;
+ }
}
\ No newline at end of file
Modified: felix/trunk/main/src/main/java/org/apache/felix/main/Main.java
URL: http://svn.apache.org/viewvc/felix/trunk/main/src/main/java/org/apache/felix/main/Main.java?rev=800486&r1=800485&r2=800486&view=diff
==============================================================================
--- felix/trunk/main/src/main/java/org/apache/felix/main/Main.java (original)
+++ felix/trunk/main/src/main/java/org/apache/felix/main/Main.java Mon Aug 3 18:24:19 2009
@@ -40,6 +40,11 @@
public class Main
{
/**
+ * Switch for specifying bundle directory.
+ **/
+ public static final String BUNDLE_DIR_SWITCH = "-b";
+
+ /**
* The property name used to specify an URL to the system
* property file.
**/
@@ -163,11 +168,34 @@
**/
public static void main(String[] args) throws Exception
{
+// TODO: MAIN - SHOULD WE ADD A SHUTDOWN HOOK?
+
+ // Look for bundle directory and/or cache directory.
// We support at most one argument, which is the bundle
// cache directory.
- if (args.length > 1)
+ String bundleDir = null;
+ String cacheDir = null;
+ boolean expectBundleDir = false;
+ for (int i = 0; i < args.length; i++)
+ {
+ if (args[i].equals(BUNDLE_DIR_SWITCH))
+ {
+ expectBundleDir = true;
+ }
+ else if (expectBundleDir)
+ {
+ bundleDir = args[i];
+ expectBundleDir = false;
+ }
+ else
+ {
+ cacheDir = args[i];
+ }
+ }
+
+ if ((args.length > 3) || (expectBundleDir && bundleDir == null))
{
- System.out.println("Usage: [<bundle-cache-dir>]");
+ System.out.println("Usage: [-b <bundle-deploy-dir>] [<bundle-cache-dir>]");
System.exit(0);
}
@@ -187,11 +215,18 @@
// Copy framework properties from the system properties.
Main.copySystemProperties(configProps);
+ // If there is a passed in bundle auto-deploy directory, then
+ // that overwrites anything in the config file.
+ if (bundleDir != null)
+ {
+ configProps.setProperty(AutoActivator.AUTO_DEPLOY_DIR_PROPERY, bundleDir);
+ }
+
// If there is a passed in bundle cache directory, then
// that overwrites anything in the config file.
- if (args.length > 0)
+ if (cacheDir != null)
{
- configProps.setProperty(Constants.FRAMEWORK_STORAGE, args[0]);
+ configProps.setProperty(Constants.FRAMEWORK_STORAGE, cacheDir);
}
// Create a list for custom framework activators and
Modified: felix/trunk/main/src/main/resources/config.properties
URL: http://svn.apache.org/viewvc/felix/trunk/main/src/main/resources/config.properties?rev=800486&r1=800485&r2=800486&view=diff
==============================================================================
--- felix/trunk/main/src/main/resources/config.properties (original)
+++ felix/trunk/main/src/main/resources/config.properties Mon Aug 3 18:24:19 2009
@@ -48,10 +48,27 @@
# "none" and "onFirstInit"; the default is "none".
#org.osgi.framework.storage.clean=onFirstInit
-felix.auto.start.1= \
- file:bundle/org.apache.felix.shell-1.3.0-SNAPSHOT.jar \
- file:bundle/org.apache.felix.shell.tui-1.3.0-SNAPSHOT.jar \
- file:bundle/org.apache.felix.bundlerepository-1.5.0-SNAPSHOT.jar
+# The following properties determines whether bundles in the bundle
+# auto-deploy directory are automatically installed and started when
+# the framework starts. The value is either true or false; the
+# default is true.
+#felix.auto.deploy=true
+
+# The following property specifies the directory to use as the bundle
+# auto-deploy directory; the default is 'bundle' in the working directory.
+felix.auto.deploy.dir=bundle
+
+# The following property is a space-delimited list of bundle URLs
+# to install when the framework starts. The ending numerical component
+# is the target start level. Any number of these properties may be
+# specified for different start levels.
+#felix.auto.install.1=
+
+# The following property is a space-delimited list of bundle URLs
+# to install and start when the framework starts. The ending numerical
+# component is the target start level. Any number of these properties
+# may be specified for different start levels.
+#felix.auto.start.1=
felix.log.level=${log.level}