X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.osgi.boot%2Fsrc%2Forg%2Fargeo%2Fosgi%2Fboot%2FOsgiBootUtils.java;h=9593b0cde8bf8babdec9a79fe959aba90c0a679c;hb=25eec0a9cc31c67740ba4131ed40951a028a7669;hp=54efffc8056504f7e15234c4791b742a7a406366;hpb=8260f4470f514ea347ca53f5b4dfc632c4a4de66;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.osgi.boot/src/org/argeo/osgi/boot/OsgiBootUtils.java b/org.argeo.osgi.boot/src/org/argeo/osgi/boot/OsgiBootUtils.java index 54efffc80..9593b0cde 100644 --- a/org.argeo.osgi.boot/src/org/argeo/osgi/boot/OsgiBootUtils.java +++ b/org.argeo.osgi.boot/src/org/argeo/osgi/boot/OsgiBootUtils.java @@ -20,21 +20,29 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Map; import java.util.StringTokenizer; import org.osgi.framework.Bundle; +import org.osgi.framework.BundleException; +import org.osgi.framework.launch.Framework; +import org.osgi.framework.launch.FrameworkFactory; /** Utilities, mostly related to logging. */ public class OsgiBootUtils { /** ISO8601 (as per log4j) and difference to UTC */ private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS Z"); + static boolean debug = System.getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_DEBUG) == null ? false + : !System.getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_DEBUG).trim().equals("false"); + public static void info(Object obj) { System.out.println("# OSGiBOOT # " + dateFormat.format(new Date()) + " # " + obj); } public static void debug(Object obj) { - System.out.println("# OSGiBOOT DBG # " + dateFormat.format(new Date()) + " # " + obj); + if (debug) + System.out.println("# OSGiBOOT DBG # " + dateFormat.format(new Date()) + " # " + obj); } public static void warn(Object obj) { @@ -47,26 +55,8 @@ public class OsgiBootUtils { e.printStackTrace(); } - /** - * Gets a property value - * - * @return null when defaultValue is "" - */ - public static String getProperty(String name, String defaultValue) { - final String value; - if (defaultValue != null) - value = System.getProperty(name, defaultValue); - else - value = System.getProperty(name); - - if (value == null || value.equals("")) - return null; - else - return value; - } - - public static String getProperty(String name) { - return getProperty(name, null); + public static boolean isDebug() { + return debug; } public static String stateAsString(int state) { @@ -89,7 +79,7 @@ public class OsgiBootUtils { } /** - * @return ==0: versions are identical, <0: tested version is newer, >0: + * @return ==0: versions are identical, <0: tested version is newer, >0: * currentVersion is newer. */ public static int compareVersions(String currentVersion, String testedVersion) { @@ -140,4 +130,16 @@ public class OsgiBootUtils { return comp; } + /** Launch an OSGi framework. */ + public static Framework launch(FrameworkFactory frameworkFactory, Map configuration) { + // start OSGi + Framework framework = frameworkFactory.newFramework(configuration); + try { + framework.start(); + } catch (BundleException e) { + throw new OsgiBootException("Cannot start OSGi framework", e); + } + return framework; + } + }