From e153254668834a28b10411febed79bb2a07bae7b Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Sun, 1 Jul 2012 16:01:17 +0000 Subject: [PATCH] Make services lookup more robust git-svn-id: https://svn.argeo.org/slc/trunk@5412 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../org/argeo/slc/osgi/BundlesManager.java | 3 +- .../slc/osgi/OsgiExecutionModulesManager.java | 29 +++++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/BundlesManager.java b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/BundlesManager.java index 788f2da57..7d96ae4c9 100644 --- a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/BundlesManager.java +++ b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/BundlesManager.java @@ -330,7 +330,8 @@ public class BundlesManager implements BundleContextAware, FrameworkListener, bundle.getHeaders().get( Constants.BUNDLE_VERSION)), "version consistent"); - } else if (osgiBundle.getVersion() == null) { + } else if (osgiBundle.getVersion() == null + || osgiBundle.getVersion().equals("0.0.0")) { bundle = OsgiBundleUtils.findBundleBySymbolicName(bundleContext, osgiBundle.getName()); } else {// scan all bundles 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 4ae06f8b3..5a8d3da54 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 @@ -189,28 +189,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,6 +304,10 @@ 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); if (isSpringInstrumented(bundle)) { // Wait for Spring application context to be ready -- 2.39.2