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=d46ad48c5b3b09b71247dbcea719ec1a28d2a947;hb=5187ffaff5610275cf3dbc5fb913f59126576da8;hp=58ae32a655ee9f7f521c98f7473a2a01636b8d03;hpb=7b8669f41556f46a0f229192d05e2f2592c57d5f;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 58ae32a65..d46ad48c5 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) 2007-2012 Mathieu Baudier + * Copyright (C) 2007-2012 Argeo GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,7 +45,7 @@ import org.argeo.slc.execution.ExecutionFlowDescriptor; import org.argeo.slc.execution.ExecutionFlowDescriptorConverter; import org.argeo.slc.execution.ExecutionModuleDescriptor; import org.argeo.slc.execution.ExecutionModulesListener; -import org.argeo.slc.process.RealizedFlow; +import org.argeo.slc.execution.RealizedFlow; import org.osgi.framework.Bundle; import org.osgi.framework.BundleEvent; import org.osgi.framework.BundleException; @@ -100,6 +100,8 @@ public class OsgiExecutionModulesManager extends log.debug("Launch unique flow " + flow + " from module " + module); try { OsgiBundle osgiBundle = bundlesManager.findFromPattern(module); + if (osgiBundle == null) + throw new SlcException("No OSGi bundle found for " + module); Bundle moduleBundle = bundlesManager.findRelatedBundle(osgiBundle); bundlesManager.startSynchronous(moduleBundle); RealizedFlow lastLaunch = findRealizedFlow(module, flow); @@ -189,28 +191,41 @@ public class OsgiExecutionModulesManager extends protected ExecutionFlow findExecutionFlow(String moduleName, String moduleVersion, String flowName) { - String filter = "(&(Bundle-SymbolicName=" + moduleName - + ")(org.springframework.osgi.bean.name=" + flowName + "))"; + String filter = moduleVersion == null || moduleVersion.equals("0.0.0") ? "(&(Bundle-SymbolicName=" + + moduleName + + ")(org.springframework.osgi.bean.name=" + + flowName + "))" + : "(&(Bundle-SymbolicName=" + moduleName + ")(Bundle-Version=" + + moduleVersion + + ")(org.springframework.osgi.bean.name=" + flowName + + "))"; return bundlesManager.getSingleServiceStrict(ExecutionFlow.class, filter, true); } protected ExecutionContext findExecutionContext(String moduleName, String moduleVersion) { - String filter = "(&(Bundle-SymbolicName=" + moduleName - + ")(Bundle-Version=" + moduleVersion + "))"; + String filter = moduleFilter(moduleName, moduleVersion); return bundlesManager.getSingleServiceStrict(ExecutionContext.class, filter, true); } protected ExecutionFlowDescriptorConverter findExecutionFlowDescriptorConverter( String moduleName, String moduleVersion) { - String filter = "(&(Bundle-SymbolicName=" + moduleName - + ")(Bundle-Version=" + moduleVersion + "))"; + String filter = moduleFilter(moduleName, moduleVersion); return bundlesManager.getSingleService( ExecutionFlowDescriptorConverter.class, filter, false); } + /** Only based on symbolic name if version is null or "0.0.0" */ + protected String moduleFilter(String moduleName, String moduleVersion) { + return moduleVersion == null || moduleVersion.equals("0.0.0") ? "(Bundle-SymbolicName=" + + moduleName + ")" + : "(&(Bundle-SymbolicName=" + moduleName + ")(Bundle-Version=" + + moduleVersion + "))"; + + } + /** * Builds a minimal realized flow, based on the provided information * (typically from the command line). @@ -291,11 +306,12 @@ public class OsgiExecutionModulesManager extends try { Bundle bundle = bundlesManager.findRelatedBundle(new OsgiBundle( nameVersion)); + if (bundle == null) + throw new SlcException("Counld not find bundle for " + + nameVersion); + bundlesManager.startSynchronous(bundle); - boolean isSpringInstrumented = bundle.getEntryPaths( - "/META-INF/spring").hasMoreElements() - || bundle.getHeaders().get("Spring-Context") == null; - if (isSpringInstrumented) { + if (isSpringInstrumented(bundle)) { // Wait for Spring application context to be ready String filter = "(Bundle-SymbolicName=" + bundle.getSymbolicName() + ")"; @@ -313,6 +329,18 @@ public class OsgiExecutionModulesManager extends } } + /** Do it calmly in order to avoid NPE */ + private Boolean isSpringInstrumented(Bundle bundle) { + Dictionary headers = bundle.getHeaders(); + if (headers != null && headers.get("Spring-Context") != null) + return true; + Enumeration springEntryPaths = bundle + .getEntryPaths("/META-INF/spring"); + if (springEntryPaths != null && springEntryPaths.hasMoreElements()) + return true; + return false; + } + public void stop(NameVersion nameVersion) { try { Bundle bundle = bundlesManager.findRelatedBundle(new OsgiBundle(