From 06a8a8402076f753c78ab48a9f19d568e2080e72 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Wed, 14 Apr 2010 14:44:00 +0000 Subject: [PATCH] Improve OSGi boot git-svn-id: https://svn.argeo.org/commons/trunk@3460 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../java/org/argeo/slc/osgiboot/OsgiBoot.java | 57 ++++++++++++++++--- pom.xml | 2 +- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/osgi/runtime/org.argeo.osgi.boot/src/main/java/org/argeo/slc/osgiboot/OsgiBoot.java b/osgi/runtime/org.argeo.osgi.boot/src/main/java/org/argeo/slc/osgiboot/OsgiBoot.java index e8c9754c1..d54fa8899 100644 --- a/osgi/runtime/org.argeo.osgi.boot/src/main/java/org/argeo/slc/osgiboot/OsgiBoot.java +++ b/osgi/runtime/org.argeo.osgi.boot/src/main/java/org/argeo/slc/osgiboot/OsgiBoot.java @@ -20,8 +20,13 @@ import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleException; import org.osgi.framework.Constants; +import org.osgi.framework.ServiceReference; +import org.osgi.service.packageadmin.PackageAdmin; 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_DATA_DIR = "argeo.osgi.data.dir"; public final static String PROP_ARGEO_OSGI_START = "argeo.osgi.start"; @@ -101,7 +106,6 @@ public class OsgiBoot { } System.setProperty(PROP_ARGEO_OSGI_DATA_DIR, dataDir.getAbsolutePath()); - info(PROP_ARGEO_OSGI_DATA_DIR + "=" + dataDir.getAbsolutePath()); } public static String removeFilePrefix(String url) { @@ -114,12 +118,18 @@ public class OsgiBoot { } public void bootstrap() { - info("SLC OSGi bootstrap starting..."); + System.out.println(); + info("OSGi bootstrap starting..."); + info("Writable data directory : " + + System.getProperty(PROP_ARGEO_OSGI_DATA_DIR) + + " (set as system property " + PROP_ARGEO_OSGI_DATA_DIR + ")"); installUrls(getBundlesUrls()); installUrls(getLocationsUrls()); installUrls(getModulesUrls()); + checkUnresolved(); startBundles(); - info("SLC OSGi bootstrap completed"); + info("OSGi bootstrap completed"); + System.out.println(); } public void installUrls(List urls) { @@ -140,8 +150,17 @@ public class OsgiBoot { + " from " + url); } } catch (BundleException e) { - warn("Could not install bundle from " + url + ": " - + e.getMessage()); + String message = e.getMessage(); + if ((message.contains("Bundle \"" + SYMBOLIC_NAME_OSGI_BOOT + + "\"") || message.contains("Bundle \"" + + SYMBOLIC_NAME_EQUINOX + "\"")) + && message.contains("has already been installed")) { + // silent, in order to avoid warnings: we know that both + // have already been installed... + } else { + warn("Could not install bundle from " + url + ": " + + message); + } if (debug) e.printStackTrace(); } @@ -247,6 +266,28 @@ public class OsgiBoot { + " not started because it was not found."); } + protected void checkUnresolved() { + // Refresh + ServiceReference packageAdminRef = bundleContext + .getServiceReference(PackageAdmin.class.getName()); + PackageAdmin packageAdmin = (PackageAdmin) bundleContext + .getService(packageAdminRef); + packageAdmin.resolveBundles(null); + + Bundle[] bundles = bundleContext.getBundles(); + List /* Bundle */unresolvedBundles = new ArrayList(); + for (int i = 0; i < bundles.length; i++) { + int bundleState = bundles[i].getState(); + if (!(bundleState == Bundle.ACTIVE + || bundleState == Bundle.RESOLVED || bundleState == Bundle.STARTING)) + unresolvedBundles.add(bundles[i]); + } + + if (unresolvedBundles.size() != 0) { + warn("Unresolved bundles " + unresolvedBundles); + } + } + protected void waitForBundleResolvedOrActive(long startBegin, Bundle bundle) throws Exception { int originalState = bundle.getState(); @@ -590,16 +631,16 @@ public class OsgiBoot { } protected static void info(Object obj) { - System.out.println("#OSGiBOOT# " + obj); + System.out.println("# OSGiBOOT # " + obj); } protected void debug(Object obj) { if (debug) - System.out.println("#OSGiBOOT DEBUG# " + obj); + System.out.println("# OSGiBOOT DBG # " + obj); } protected void warn(Object obj) { - System.out.println("# WARN " + obj); + System.out.println("# OSGiBOOT WARN # " + obj); // Because of a weird bug under Windows when starting it in a forked VM // if (System.getProperty("os.name").contains("Windows")) // System.out.println("# WARN " + obj); diff --git a/pom.xml b/pom.xml index a51cf4322..cac53d44c 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ 0.1 1.0.4-SNAPSHOT 0.12.4-SNAPSHOT - 0.1.27 + 0.1.28-SNAPSHOT 2.0.1 0.8.3.0 file:///var/argeo/projects/commons/www/site -- 2.30.2