X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.osgi.boot%2Fsrc%2Forg%2Fargeo%2Fosgi%2Fboot%2FOsgiBootUtils.java;h=212e6baa4f208437cc217d4ab3a76df668b52549;hb=86e5f79860a8b3013b40a36c1f06c828d52f5249;hp=8c63344e5d330fa2a55de7259057116e9b89e4c8;hpb=807ccba419e96a18f7af67a66f986ae4c91c03d9;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 8c63344e5..212e6baa4 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 @@ -25,47 +25,30 @@ import java.util.StringTokenizer; import org.osgi.framework.Bundle; /** Utilities, mostly related to logging. */ -@SuppressWarnings({ "rawtypes", "unchecked" }) 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"); + private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS Z"); + + static boolean debug = Boolean.valueOf(System.getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_DEBUG, "false")) + .booleanValue(); public static void info(Object obj) { - System.out.println("# OSGiBOOT # " + dateFormat.format(new Date()) - + " # " + 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) { - System.out.println("# OSGiBOOT WARN # " + dateFormat.format(new Date()) - + " # " + obj); - } - - /** - * 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; + System.out.println("# OSGiBOOT WARN # " + dateFormat.format(new Date()) + " # " + obj); } - public static String getProperty(String name) { - return getProperty(name, null); + public static void error(Object obj, Throwable e) { + System.err.println("# OSGiBOOT ERR # " + dateFormat.format(new Date()) + " # " + obj); + if (e != null) + e.printStackTrace(); } public static String stateAsString(int state) { @@ -91,13 +74,12 @@ public class OsgiBootUtils { * @return ==0: versions are identical, <0: tested version is newer, >0: * currentVersion is newer. */ - public static int compareVersions(String currentVersion, - String testedVersion) { - List cToks = new ArrayList(); + public static int compareVersions(String currentVersion, String testedVersion) { + List cToks = new ArrayList(); StringTokenizer cSt = new StringTokenizer(currentVersion, "."); while (cSt.hasMoreTokens()) cToks.add(cSt.nextToken()); - List tToks = new ArrayList(); + List tToks = new ArrayList(); StringTokenizer tSt = new StringTokenizer(currentVersion, "."); while (tSt.hasMoreTokens()) tToks.add(tSt.nextToken());