import org.eclipse.core.runtime.adaptor.EclipseStarter;
import org.osgi.framework.BundleContext;
+/** Command line interface. */
public class Launcher {
public static void main(String[] args) {
// Try to load system properties
- String systemPropertiesFilePath = OsgiBootUtils.getPropertyCompat(
- OsgiBoot.PROP_ARGEO_OSGI_BOOT_SYSTEM_PROPERTIES_FILE,
- OsgiBoot.PROP_SLC_OSGIBOOT_SYSTEM_PROPERTIES_FILE);
+ String systemPropertiesFilePath = OsgiBootUtils
+ .getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_SYSTEM_PROPERTIES_FILE);
if (systemPropertiesFilePath != null) {
FileInputStream in;
try {
}
protected static void startMainClass() {
- // Properties config = System.getProperties();
- // String className = config.getProperty("slc.osgiboot.appclass");
- String className = OsgiBootUtils.getPropertyCompat(
- OsgiBoot.PROP_ARGEO_OSGI_BOOT_APPCLASS,
- OsgiBoot.PROP_SLC_OSGIBOOT_APPCLASS);
+ String className = OsgiBootUtils
+ .getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_APPCLASS);
if (className == null)
return;
- // should use OsgiBootUtils.getPropertyCompat(), but it does not
- // work for "" as default value
- // so no warning displayed if PROP_SLC_OSGIBOOT_APPARGS is used
- // FIXME: change OsgiBootUtils.getPropertyCompat()
- String line = System.getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_APPARGS,
- System.getProperty(OsgiBoot.PROP_SLC_OSGIBOOT_APPARGS, ""));
-
+ String line = System.getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_APPARGS,
+ "");
+
String[] uiArgs = readArgumentsFromLine(line);
-
+
try {
// Launch main method using reflection
Class clss = Class.forName(className);
* arguments. (nested \" are not supported)
*/
private static String[] readArgumentsFromLine(String lineOrig) {
-
String line = lineOrig.trim();// remove trailing spaces
- // System.out.println("line=" + line);
List args = new Vector();
StringBuffer curr = new StringBuffer("");
boolean inQuote = false;
String[] res = new String[args.size()];
for (int i = 0; i < args.size(); i++) {
res[i] = args.get(i).toString();
- // System.out.println("res[i]=" + res[i]);
}
return res;
}
import org.osgi.service.packageadmin.ExportedPackage;
import org.osgi.service.packageadmin.PackageAdmin;
+/** Core component, performing basic provisioning of an OSGi runtime. */
public class OsgiBoot {
public final static String SYMBOLIC_NAME_OSGI_BOOT = "org.argeo.osgi.boot";
public final static String SYMBOLIC_NAME_EQUINOX = "org.eclipse.osgi";
public final static String PROP_ARGEO_OSGI_BOOT_APPCLASS = "argeo.osgi.boot.appclass";
public final static String PROP_ARGEO_OSGI_BOOT_APPARGS = "argeo.osgi.boot.appargs";
- /** @deprecated */
- public final static String PROP_SLC_OSGI_START = "slc.osgi.start";
- /** @deprecated */
- public final static String PROP_SLC_OSGI_BUNDLES = "slc.osgi.bundles";
- /** @deprecated */
- public final static String PROP_SLC_OSGI_LOCATIONS = "slc.osgi.locations";
- /** @deprecated */
- public final static String PROP_SLC_OSGI_BASE_URL = "slc.osgi.baseUrl";
- /** @deprecated */
- public final static String PROP_SLC_OSGI_MODULES_URL = "slc.osgi.modulesUrl";
-
- /** @deprecated */
- public final static String PROP_SLC_OSGIBOOT_DEBUG = "slc.osgiboot.debug";
- /** @deprecated */
- public final static String PROP_SLC_OSGIBOOT_DEFAULT_TIMEOUT = "slc.osgiboot.defaultTimeout";
- /** @deprecated */
- public final static String PROP_SLC_OSGIBOOT_MODULES_URL_SEPARATOR = "slc.osgiboot.modulesUrlSeparator";
- /** @deprecated */
- public final static String PROP_SLC_OSGIBOOT_SYSTEM_PROPERTIES_FILE = "slc.osgiboot.systemPropertiesFile";
- /** @deprecated */
- public final static String PROP_SLC_OSGIBOOT_APPCLASS = "slc.osgiboot.appclass";
- /** @deprecated */
- public final static String PROP_SLC_OSGIBOOT_APPARGS = "slc.osgiboot.appargs";
-
public final static String DEFAULT_BASE_URL = "reference:file:";
public final static String EXCLUDES_SVN_PATTERN = "**/.svn/**";
private boolean debug = Boolean.valueOf(
- System.getProperty(PROP_ARGEO_OSGI_BOOT_DEBUG,
- System.getProperty(PROP_SLC_OSGIBOOT_DEBUG, "false")))
+ System.getProperty(PROP_ARGEO_OSGI_BOOT_DEBUG, "false"))
.booleanValue();
/** Default is 10s (set in constructor) */
private long defaultTimeout;
public OsgiBoot(BundleContext bundleContext) {
this.bundleContext = bundleContext;
- defaultTimeout = Long.parseLong(OsgiBootUtils.getPropertyCompat(
- PROP_ARGEO_OSGI_BOOT_DEFAULT_TIMEOUT,
- PROP_SLC_OSGIBOOT_DEFAULT_TIMEOUT, "10000"));
- modulesUrlSeparator = OsgiBootUtils.getPropertyCompat(
- PROP_ARGEO_OSGI_BOOT_MODULES_URL_SEPARATOR,
- PROP_SLC_OSGIBOOT_MODULES_URL_SEPARATOR, ",");
+ defaultTimeout = Long.parseLong(OsgiBootUtils.getProperty(
+ PROP_ARGEO_OSGI_BOOT_DEFAULT_TIMEOUT, "10000"));
+ modulesUrlSeparator = OsgiBootUtils.getProperty(
+ PROP_ARGEO_OSGI_BOOT_MODULES_URL_SEPARATOR, ",");
initSystemProperties();
}
}
public void startBundles() {
- String bundlesToStart = OsgiBootUtils.getPropertyCompat(
- PROP_ARGEO_OSGI_START, PROP_SLC_OSGI_START);
+ String bundlesToStart = OsgiBootUtils
+ .getProperty(PROP_ARGEO_OSGI_START);
startBundles(bundlesToStart);
}
}
}
+ /** List packages exported twice. */
public Map findPackagesExportedTwice() {
ServiceReference paSr = bundleContext
.getServiceReference(PackageAdmin.class.getName());
}
public List getLocationsUrls() {
- String baseUrl = OsgiBootUtils.getPropertyCompat(
- PROP_ARGEO_OSGI_BASE_URL, PROP_SLC_OSGI_BASE_URL,
+ String baseUrl = OsgiBootUtils.getProperty(PROP_ARGEO_OSGI_BASE_URL,
DEFAULT_BASE_URL);
- String bundleLocations = OsgiBootUtils.getPropertyCompat(
- PROP_ARGEO_OSGI_LOCATIONS, PROP_SLC_OSGI_LOCATIONS);
+ String bundleLocations = OsgiBootUtils
+ .getProperty(PROP_ARGEO_OSGI_LOCATIONS);
return getLocationsUrls(baseUrl, bundleLocations);
}
public List getModulesUrls() {
List urls = new ArrayList();
- String modulesUrlStr = OsgiBootUtils.getPropertyCompat(
- PROP_ARGEO_OSGI_MODULES_URL, PROP_SLC_OSGI_MODULES_URL);
+ String modulesUrlStr = OsgiBootUtils
+ .getProperty(PROP_ARGEO_OSGI_MODULES_URL);
if (modulesUrlStr == null)
return urls;
- String baseUrl = OsgiBootUtils.getPropertyCompat(
- PROP_ARGEO_OSGI_BASE_URL, PROP_SLC_OSGI_BASE_URL);
+ String baseUrl = OsgiBootUtils.getProperty(PROP_ARGEO_OSGI_BASE_URL);
Map installedBundles = getBundles();
}
public List getBundlesUrls() {
- String baseUrl = OsgiBootUtils.getPropertyCompat(
- PROP_ARGEO_OSGI_BASE_URL, PROP_SLC_OSGI_BASE_URL,
+ String baseUrl = OsgiBootUtils.getProperty(PROP_ARGEO_OSGI_BASE_URL,
DEFAULT_BASE_URL);
- String bundlePatterns = OsgiBootUtils.getPropertyCompat(
- PROP_ARGEO_OSGI_BUNDLES, PROP_SLC_OSGI_BUNDLES);
+ String bundlePatterns = OsgiBootUtils
+ .getProperty(PROP_ARGEO_OSGI_BUNDLES);
return getBundlesUrls(baseUrl, bundlePatterns);
}
\r
package org.argeo.osgi.boot;\r
\r
+/** Utilities, mostly related to logging. */\r
public class OsgiBootUtils {\r
\r
public static void info(Object obj) {\r
}\r
\r
public static void debug(Object obj) {\r
- System.out.println("# OSGiBOOT DBG # " + obj);\r
+ System.out.println("# OSGiBOOT DBG # " + obj);\r
}\r
\r
public static void warn(Object obj) {\r
// System.err.println("# WARN " + obj);\r
}\r
\r
- //FIXE: returns null when defaultValue is ""\r
+ /**\r
+ * Gets a property value\r
+ * \r
+ * @return null when defaultValue is ""\r
+ */\r
public static String getProperty(String name, String defaultValue) {\r
final String value;\r
if (defaultValue != null)\r
value = System.getProperty(name, defaultValue);\r
else\r
value = System.getProperty(name);\r
- \r
+\r
if (value == null || value.equals(""))\r
return null;\r
else\r
return getProperty(name, null);\r
}\r
\r
- public static String getPropertyCompat(String name, String oldName) {\r
- return getPropertyCompat(name, oldName, null);\r
- }\r
-\r
- public static String getPropertyCompat(String name, String oldName,\r
- String defaultValue) {\r
- String res = null;\r
-\r
- if (defaultValue != null) {\r
- res = getProperty(name, defaultValue);\r
- if (res.equals(defaultValue)) {\r
- res = getProperty(oldName, defaultValue);\r
- if (!res.equals(defaultValue))\r
- warnDeprecated(name, oldName);\r
- }\r
- } else {\r
- res = getProperty(name, null);\r
- if (res == null) {\r
- res = getProperty(oldName, null);\r
- if (res != null)\r
- warnDeprecated(name, oldName);\r
- }\r
- }\r
- return res;\r
- }\r
-\r
- public static void warnDeprecated(String name, String oldName) {\r
- warn("Property '" + oldName\r
- + "' is deprecated and will be removed soon, use '" + name\r
- + "' instead.");\r
- } \r
- \r
}\r
--- /dev/null
+/*
+ * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.argeo.osgi.boot;
+
+import java.io.File;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.argeo.osgi.boot.OsgiBoot;
+
+/** Tests which do not require a runtime. */
+public class OsgiBootNoRuntimeTest extends TestCase {
+ public final static String BUNDLES = "src/test/bundles/some;in=*;ex=excluded,"
+ + "src/test/bundles/others;in=**/org.argeo.*";
+
+ /** Tests that location lists are properly parsed. */
+ public void testLocations() {
+ String baseUrl = "file:";
+ String locations = "/mydir/myfile" + File.pathSeparator
+ + "/myotherdir/myotherfile";
+
+ OsgiBoot osgiBoot = new OsgiBoot(null);
+ List urls = osgiBoot.getLocationsUrls(baseUrl, locations);
+ assertEquals(2, urls.size());
+ assertEquals("file:/mydir/myfile", urls.get(0));
+ assertEquals("file:/myotherdir/myotherfile", urls.get(1));
+ }
+
+ /** Tests that bundle lists are properly parsed. */
+ public void testBundles() {
+ String baseUrl = "file:";
+ String bundles = BUNDLES;
+ OsgiBoot osgiBoot = new OsgiBoot(null);
+ List urls = osgiBoot.getBundlesUrls(baseUrl, bundles);
+ for (int i = 0; i < urls.size(); i++)
+ System.out.println(urls.get(i));
+ assertEquals(3, urls.size());
+
+ List jarUrls = osgiBoot.getBundlesUrls(baseUrl,
+ "src/test/bundles/jars;in=*.jar");
+ for (int i = 0; i < jarUrls.size(); i++)
+ System.out.println(jarUrls.get(i));
+ assertEquals(1, jarUrls.size());
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.argeo.osgi.boot;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeMap;
+
+import junit.framework.TestCase;
+
+import org.argeo.osgi.boot.OsgiBoot;
+import org.eclipse.core.runtime.adaptor.EclipseStarter;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+/** Starts an Equinox runtime and provision it with OSGi boot. */
+public class OsgiBootRuntimeTest extends TestCase {
+ protected OsgiBoot osgiBoot = null;
+
+ public void testInstallAndStart() throws Exception {
+ osgiBoot.installUrls(osgiBoot.getBundlesUrls(OsgiBoot.DEFAULT_BASE_URL,
+ OsgiBootNoRuntimeTest.BUNDLES));
+ Map map = new TreeMap(osgiBoot.getBundles());
+ for (Iterator keys = map.keySet().iterator(); keys.hasNext();) {
+ Object key = keys.next();
+ Bundle bundle = (Bundle) map.get(key);
+ System.out.println(key + " : " + bundle.getLocation());
+ }
+ assertEquals(4, map.size());
+ Iterator keys = map.keySet().iterator();
+ assertEquals("org.argeo.osgi.boot.test.bundle1", keys.next());
+ assertEquals("org.argeo.osgi.boot.test.bundle2", keys.next());
+ assertEquals("org.argeo.osgi.boot.test.bundle3", keys.next());
+ assertEquals("org.eclipse.osgi", keys.next());
+
+ osgiBoot.startBundles("org.argeo.osgi.boot.test.bundle2");
+ long begin = System.currentTimeMillis();
+ while (System.currentTimeMillis() - begin < 10000) {
+ Map mapBundles = osgiBoot.getBundles();
+ Bundle bundle = (Bundle) mapBundles
+ .get("org.argeo.osgi.boot.test.bundle2");
+ if (bundle.getState() == Bundle.ACTIVE) {
+ System.out.println("Bundle " + bundle + " started.");
+ return;
+ }
+ }
+ fail("Bundle not started after timeout limit.");
+ }
+
+ protected BundleContext startRuntime() throws Exception {
+ String[] args = { "-console", "-clean" };
+ BundleContext bundleContext = EclipseStarter.startup(args, null);
+ return bundleContext;
+ }
+
+ protected void stopRuntime() throws Exception {
+ EclipseStarter.shutdown();
+ }
+
+ public void setUp() throws Exception {
+ BundleContext bundleContext = startRuntime();
+ osgiBoot = new OsgiBoot(bundleContext);
+ }
+
+ public void tearDown() throws Exception {
+ osgiBoot = null;
+ stopRuntime();
+ }
+
+}
+++ /dev/null
-/*
- * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.argeo.slc.osgiboot;
-
-import java.io.File;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.argeo.osgi.boot.OsgiBoot;
-
-public class OsgiBootNoRuntimeTest extends TestCase {
- public final static String BUNDLES = "src/test/bundles/some;in=*;ex=excluded,"
- + "src/test/bundles/others;in=**/org.argeo.*";
-
- public void testLocations() {
- String baseUrl = "file:";
- String locations = "/mydir/myfile" + File.pathSeparator
- + "/myotherdir/myotherfile";
-
- OsgiBoot osgiBoot = new OsgiBoot(null);
- List urls = osgiBoot.getLocationsUrls(baseUrl, locations);
- assertEquals(2, urls.size());
- assertEquals("file:/mydir/myfile", urls.get(0));
- assertEquals("file:/myotherdir/myotherfile", urls.get(1));
- }
-
- public void testBundles() {
- String baseUrl = "file:";
- String bundles = BUNDLES;
- OsgiBoot osgiBoot = new OsgiBoot(null);
- List urls = osgiBoot.getBundlesUrls(baseUrl, bundles);
- for (int i = 0; i < urls.size(); i++)
- System.out.println(urls.get(i));
- assertEquals(3, urls.size());
-
- List jarUrls = osgiBoot.getBundlesUrls(baseUrl,
- "src/test/bundles/jars;in=*.jar");
- for (int i = 0; i < jarUrls.size(); i++)
- System.out.println(jarUrls.get(i));
- assertEquals(1, jarUrls.size());
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.argeo.slc.osgiboot;
-
-import java.util.Iterator;
-import java.util.Map;
-import java.util.TreeMap;
-
-import junit.framework.TestCase;
-
-import org.argeo.osgi.boot.OsgiBoot;
-import org.eclipse.core.runtime.adaptor.EclipseStarter;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-
-public class OsgiBootRuntimeTest extends TestCase {
- protected OsgiBoot osgiBoot = null;
-
- public void testInstallAndStart() throws Exception {
- osgiBoot.installUrls(osgiBoot.getBundlesUrls(OsgiBoot.DEFAULT_BASE_URL,
- OsgiBootNoRuntimeTest.BUNDLES));
- Map map = new TreeMap(osgiBoot.getBundles());
- for (Iterator keys = map.keySet().iterator(); keys.hasNext();) {
- Object key = keys.next();
- Bundle bundle = (Bundle) map.get(key);
- System.out.println(key + " : " + bundle.getLocation());
- }
- assertEquals(4, map.size());
- Iterator keys = map.keySet().iterator();
- assertEquals("org.argeo.slc.osgiboot.test.bundle1", keys.next());
- assertEquals("org.argeo.slc.osgiboot.test.bundle2", keys.next());
- assertEquals("org.argeo.slc.osgiboot.test.bundle3", keys.next());
- assertEquals("org.eclipse.osgi", keys.next());
-
- osgiBoot.startBundles("org.argeo.slc.osgiboot.test.bundle2");
- long begin = System.currentTimeMillis();
- while (System.currentTimeMillis() - begin < 10000) {
- Map mapBundles = osgiBoot.getBundles();
- Bundle bundle = (Bundle) mapBundles
- .get("org.argeo.slc.osgiboot.test.bundle2");
- if (bundle.getState() == Bundle.ACTIVE) {
- System.out.println("Bundle " + bundle + " started.");
- return;
- }
- }
- fail("Bundle not started after timeout limit.");
- }
-
- protected BundleContext startRuntime() throws Exception {
- String[] args = { "-console", "-clean" };
- BundleContext bundleContext = EclipseStarter.startup(args, null);
- return bundleContext;
- }
-
- protected void stopRuntime() throws Exception {
- EclipseStarter.shutdown();
- }
-
- public void setUp() throws Exception {
- BundleContext bundleContext = startRuntime();
- osgiBoot = new OsgiBoot(bundleContext);
- }
-
- public void tearDown() throws Exception {
- osgiBoot = null;
- stopRuntime();
- }
-
-}