X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.osgi.boot%2Fsrc%2Forg%2Fargeo%2Fosgi%2Fboot%2FOsgiBootUtils.java;h=da142cfe9b79c0a7327021e737209c93596f85ff;hb=ebd927da42511bb5959000c50a39974c6cfa5f49;hp=20891c7f9ef3ada558496662063117755102d743;hpb=575dfe19b8516b1213b6d56d9f34fc3bcdb62026;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 20891c7f9..da142cfe9 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 @@ -27,45 +27,26 @@ import org.osgi.framework.Bundle; /** 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"); + private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS Z"); 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); + 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); + 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; + 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 getProperty(String name) { - return getProperty(name, null); - } public static String stateAsString(int state) { switch (state) { @@ -90,17 +71,16 @@ 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()); - + int comp = 0; comp: for (int i = 0; i < cToks.size(); i++) { if (tToks.size() <= i) { @@ -108,10 +88,10 @@ public class OsgiBootUtils { comp = 1; break comp; } - + String c = (String) cToks.get(i); String t = (String) tToks.get(i); - + try { int cInt = Integer.parseInt(c); int tInt = Integer.parseInt(t); @@ -130,12 +110,12 @@ public class OsgiBootUtils { } } } - + if (comp == 0 && tToks.size() > cToks.size()) { // equals until then, current shorter comp = -1; } - + return comp; }