X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.support.osgi%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fosgi%2FOsgiExecutionModulesManager.java;h=15a3f0de9bbcb27b56d75ad22fdb558e1975ce0a;hb=699640c58cc0578beebfc3edd00dac9eed65ee0b;hp=f2fc44f810f19bbf6d90617442030d7cc4c868ce;hpb=934f57060b88a81f0f866a65c77f8c6fb4dcf0ff;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java index f2fc44f81..15a3f0de9 100644 --- a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java +++ b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Mathieu Baudier + * Copyright (C) 2007-2012 Mathieu Baudier * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,11 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.argeo.slc.osgi; import java.lang.management.ManagementFactory; import java.util.ArrayList; +import java.util.Dictionary; +import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -49,6 +50,7 @@ import org.osgi.framework.Bundle; import org.osgi.framework.BundleException; import org.osgi.framework.Constants; import org.osgi.framework.launch.Framework; +import org.springframework.context.ApplicationContext; import org.springframework.osgi.service.importer.OsgiServiceLifecycleListener; /** Execution modules manager implementation based on an OSGi runtime. */ @@ -282,7 +284,23 @@ public class OsgiExecutionModulesManager extends Bundle bundle = bundlesManager.findRelatedBundle(new OsgiBundle( nameVersion)); bundlesManager.startSynchronous(bundle); - } catch (BundleException e) { + boolean isSpringInstrumented = bundle.getEntryPaths( + "/META-INF/spring").hasMoreElements() + || bundle.getHeaders().get("Spring-Context") == null; + if (isSpringInstrumented) { + // Wait for Spring application context to be ready + String filter = "(Bundle-SymbolicName=" + + bundle.getSymbolicName() + ")"; + try { + bundlesManager.getServiceRefSynchronous( + ApplicationContext.class.getName(), filter); + } catch (Exception e) { + // stop if application context not found + bundle.stop(); + throw e; + } + } + } catch (Exception e) { throw new SlcException("Cannot start " + nameVersion, e); } } @@ -322,6 +340,23 @@ public class OsgiExecutionModulesManager extends md.setVersion(getHeaderSafe(bdl, Constants.BUNDLE_VERSION)); md.setTitle(getHeaderSafe(bdl, Constants.BUNDLE_NAME)); md.setDescription(getHeaderSafe(bdl, Constants.BUNDLE_DESCRIPTION)); + + // copy manifets header to meta data + Dictionary headers = bundle.getHeaders(); + Enumeration keys = headers.keys(); + while (keys.hasMoreElements()) { + Object key = keys.nextElement(); + Object value = headers.get(key); + if (value != null) + md.getMetadata().put(key.toString(), value.toString()); + } + + // check if started + if (bundle.getState() == Bundle.ACTIVE + || bundle.getState() == Bundle.STARTING) + md.setStarted(true); + else + md.setStarted(false); } private String getHeaderSafe(Bundle bundle, Object key) {