]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - osgi/runtime/org.argeo.osgi.boot/src/main/java/org/argeo/osgi/boot/OsgiBootUtils.java
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org
.argeo
.osgi
.boot
;
19 import java
.text
.DateFormat
;
20 import java
.text
.SimpleDateFormat
;
21 import java
.util
.ArrayList
;
22 import java
.util
.Date
;
23 import java
.util
.List
;
24 import java
.util
.StringTokenizer
;
26 import org
.osgi
.framework
.Bundle
;
28 /** Utilities, mostly related to logging. */
29 public class OsgiBootUtils
{
30 /** ISO8601 (as per log4j) and difference to UTC */
31 private static DateFormat dateFormat
= new SimpleDateFormat(
32 "yyyy-MM-dd HH:mm:ss,SSS Z");
34 public static void info(Object obj
) {
35 System
.out
.println("# OSGiBOOT # " + dateFormat
.format(new Date())
39 public static void debug(Object obj
) {
40 System
.out
.println("# OSGiBOOT DBG # " + dateFormat
.format(new Date())
44 public static void warn(Object obj
) {
45 System
.out
.println("# OSGiBOOT WARN # " + dateFormat
.format(new Date())
50 * Gets a property value
52 * @return null when defaultValue is ""
54 public static String
getProperty(String name
, String defaultValue
) {
56 if (defaultValue
!= null)
57 value
= System
.getProperty(name
, defaultValue
);
59 value
= System
.getProperty(name
);
61 if (value
== null || value
.equals(""))
67 public static String
getProperty(String name
) {
68 return getProperty(name
, null);
71 public static String
stateAsString(int state
) {
73 case Bundle
.UNINSTALLED
:
75 case Bundle
.INSTALLED
:
86 return Integer
.toString(state
);
91 * @return ==0: versions are identical, <0: tested version is newer, >0:
92 * currentVersion is newer.
94 public static int compareVersions(String currentVersion
,
95 String testedVersion
) {
96 List cToks
= new ArrayList();
97 StringTokenizer cSt
= new StringTokenizer(currentVersion
, ".");
98 while (cSt
.hasMoreTokens())
99 cToks
.add(cSt
.nextToken());
100 List tToks
= new ArrayList();
101 StringTokenizer tSt
= new StringTokenizer(currentVersion
, ".");
102 while (tSt
.hasMoreTokens())
103 tToks
.add(tSt
.nextToken());
106 comp
: for (int i
= 0; i
< cToks
.size(); i
++) {
107 if (tToks
.size() <= i
) {
108 // equals until then, tested shorter
113 String c
= (String
) cToks
.get(i
);
114 String t
= (String
) tToks
.get(i
);
117 int cInt
= Integer
.parseInt(c
);
118 int tInt
= Integer
.parseInt(t
);
122 comp
= (cInt
- tInt
);
125 } catch (NumberFormatException e
) {
129 comp
= c
.compareTo(t
);
135 if (comp
== 0 && tToks
.size() > cToks
.size()) {
136 // equals until then, current shorter