import java.util.ArrayList;\r
import java.util.Date;\r
import java.util.List;\r
+import java.util.Map;\r
import java.util.StringTokenizer;\r
\r
import org.osgi.framework.Bundle;\r
+import org.osgi.framework.BundleException;\r
+import org.osgi.framework.launch.Framework;\r
+import org.osgi.framework.launch.FrameworkFactory;\r
\r
/** Utilities, mostly related to logging. */\r
public class OsgiBootUtils {\r
/** ISO8601 (as per log4j) and difference to UTC */\r
private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS Z");\r
\r
- static boolean debug = Boolean.valueOf(System.getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_DEBUG, "false"))\r
- .booleanValue();\r
+ static boolean debug = System.getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_DEBUG) == null ? false\r
+ : !System.getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_DEBUG).trim().equals("false");\r
\r
public static void info(Object obj) {\r
System.out.println("# OSGiBOOT # " + dateFormat.format(new Date()) + " # " + obj);\r
e.printStackTrace();\r
}\r
\r
+ public static boolean isDebug() {\r
+ return debug;\r
+ }\r
+\r
public static String stateAsString(int state) {\r
switch (state) {\r
case Bundle.UNINSTALLED:\r
}\r
\r
/**\r
- * @return ==0: versions are identical, <0: tested version is newer, >0:\r
+ * @return ==0: versions are identical, <0: tested version is newer, >0:\r
* currentVersion is newer.\r
*/\r
public static int compareVersions(String currentVersion, String testedVersion) {\r
return comp;\r
}\r
\r
+ /** Launch an OSGi framework. */\r
+ public static Framework launch(FrameworkFactory frameworkFactory, Map<String, String> configuration) {\r
+ // start OSGi\r
+ Framework framework = frameworkFactory.newFramework(configuration);\r
+ try {\r
+ framework.start();\r
+ } catch (BundleException e) {\r
+ throw new OsgiBootException("Cannot start OSGi framework", e);\r
+ }\r
+ return framework;\r
+ }\r
+\r
}\r