From 3779f02dcb5f24beee8fc08b5f5876af446dab41 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Sun, 14 Feb 2010 22:06:30 +0000 Subject: [PATCH 1/1] MOve project to PDE git-svn-id: https://svn.argeo.org/slc/trunk@3343 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- runtime/org.argeo.slc.support.osgi/.classpath | 6 +-- runtime/org.argeo.slc.support.osgi/.project | 9 ++++- runtime/org.argeo.slc.support.osgi/pom.xml | 18 +++++++++ .../org/argeo/slc/osgi/BundlesManager.java | 6 ++- .../build/OsgiRuntimeModularDistribution.java | 21 +++++++++- .../slc/osgi/deploy/OsgiResourceSet.java | 39 +++++++++++++++++-- 6 files changed, 89 insertions(+), 10 deletions(-) diff --git a/runtime/org.argeo.slc.support.osgi/.classpath b/runtime/org.argeo.slc.support.osgi/.classpath index 3e386d407..a0707243b 100644 --- a/runtime/org.argeo.slc.support.osgi/.classpath +++ b/runtime/org.argeo.slc.support.osgi/.classpath @@ -1,10 +1,10 @@ - + - - + + diff --git a/runtime/org.argeo.slc.support.osgi/.project b/runtime/org.argeo.slc.support.osgi/.project index e0c27e6fa..bd5f8a1ca 100644 --- a/runtime/org.argeo.slc.support.osgi/.project +++ b/runtime/org.argeo.slc.support.osgi/.project @@ -11,13 +11,18 @@ - org.maven.ide.eclipse.maven2Builder + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder - org.maven.ide.eclipse.maven2Nature org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature diff --git a/runtime/org.argeo.slc.support.osgi/pom.xml b/runtime/org.argeo.slc.support.osgi/pom.xml index 9f38f480c..3897000f2 100644 --- a/runtime/org.argeo.slc.support.osgi/pom.xml +++ b/runtime/org.argeo.slc.support.osgi/pom.xml @@ -12,16 +12,34 @@ jar + bin + + + src/main/resources + + + . + + META-INF/** + + + org.apache.maven.plugins maven-jar-plugin + + + META-INF/MANIFEST.MF + + org.apache.felix maven-bundle-plugin ${version.maven-bundle-plugin} + META-INF org.argeo.slc.* 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 f282f9483..2f846ccb7 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 @@ -22,6 +22,7 @@ import org.springframework.osgi.context.event.OsgiBundleApplicationContextListen import org.springframework.osgi.context.event.OsgiBundleContextClosedEvent; import org.springframework.osgi.context.event.OsgiBundleContextFailedEvent; import org.springframework.osgi.context.event.OsgiBundleContextRefreshedEvent; +import org.springframework.osgi.util.OsgiBundleUtils; import org.springframework.osgi.util.OsgiFilterUtils; import org.springframework.util.Assert; @@ -302,7 +303,10 @@ public class BundlesManager implements BundleContextAware, FrameworkListener, Assert.isTrue(osgiBundle.getVersion().equals( bundle.getHeaders().get(Constants.BUNDLE_VERSION)), "version consistent"); - } else { + } else if (osgiBundle.getVersion() == null) { + bundle = OsgiBundleUtils.findBundleBySymbolicName(bundleContext, + osgiBundle.getName()); + } else {// scan all bundles bundles: for (Bundle b : bundleContext.getBundles()) { if (b.getSymbolicName() == null) { log.warn("Bundle " + b + " has no symbolic name defined."); diff --git a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/build/OsgiRuntimeModularDistribution.java b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/build/OsgiRuntimeModularDistribution.java index 7f3b49a38..cb6353c35 100644 --- a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/build/OsgiRuntimeModularDistribution.java +++ b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/build/OsgiRuntimeModularDistribution.java @@ -13,6 +13,7 @@ import org.osgi.framework.Bundle; import org.springframework.context.ResourceLoaderAware; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; +import org.springframework.osgi.util.OsgiBundleUtils; public class OsgiRuntimeModularDistribution extends AbstractOsgiModularDistribution implements ResourceLoaderAware { @@ -25,14 +26,32 @@ public class OsgiRuntimeModularDistribution extends SortedMap distributions) throws Exception { - for (Bundle bundle : getBundleContext().getBundles()) { + String frameworkUrl = System.getProperty("osgi.framework"); + String frameworkBaseUrl = null; + if (frameworkUrl != null) + frameworkBaseUrl = frameworkUrl.substring(0, frameworkUrl + .lastIndexOf('/')); + bundles: for (Bundle bundle : getBundleContext().getBundles()) { OsgiBundle osgiBundle = new OsgiBundle(bundle); String originalLocation = bundle.getLocation(); + + if (OsgiBundleUtils.isSystemBundle(bundle)) { + continue bundles; + } + String location = originalLocation; if (originalLocation.startsWith("reference:file:")) location = originalLocation.substring("reference:".length()); + if (frameworkBaseUrl != null + && originalLocation.startsWith("initial@reference:file:")) { + location = frameworkBaseUrl + + '/' + + originalLocation.substring("initial@reference:file:" + .length()); + } + try { URL url = new URL(location); Resource res = resourceLoader.getResource(url.toString()); diff --git a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/deploy/OsgiResourceSet.java b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/deploy/OsgiResourceSet.java index 13ba5fe19..48185da59 100644 --- a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/deploy/OsgiResourceSet.java +++ b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/deploy/OsgiResourceSet.java @@ -1,24 +1,57 @@ package org.argeo.slc.osgi.deploy; -import org.argeo.slc.core.deploy.RelativeResourceSet; +import org.argeo.slc.core.deploy.DefaultResourceSet; +import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; +import org.springframework.core.io.ResourceLoader; import org.springframework.osgi.context.BundleContextAware; +import org.springframework.osgi.io.OsgiBundleResourceLoader; import org.springframework.osgi.io.OsgiBundleResourcePatternResolver; +import org.springframework.osgi.util.OsgiBundleUtils; -public class OsgiResourceSet extends RelativeResourceSet implements +public class OsgiResourceSet extends DefaultResourceSet implements BundleContextAware { private BundleContext bundleContext; + private Bundle bundle = null; + private String bundleSymbolicName = null; + + private OsgiBundleResourceLoader osgiBundleResourceLoader = null; @Override public void afterPropertiesSet() throws Exception { + osgiBundleResourceLoader = new OsgiBundleResourceLoader(getBundle()); if (getResourcePatternResolver() == null) setResourcePatternResolver(new OsgiBundleResourcePatternResolver( - bundleContext.getBundle())); + osgiBundleResourceLoader)); super.afterPropertiesSet(); } + public Bundle getBundle() { + if (bundle != null) + return bundle; + else if (bundleSymbolicName != null)// do not cache + return OsgiBundleUtils.findBundleBySymbolicName(bundleContext, + bundleSymbolicName); + else + // containing bundle + return bundleContext.getBundle(); + } + public void setBundleContext(BundleContext bundleContext) { this.bundleContext = bundleContext; } + @Override + public ResourceLoader getResourceLoaderToUse() { + return osgiBundleResourceLoader; + } + + public void setBundle(Bundle bundle) { + this.bundle = bundle; + } + + public void setBundleSymbolicName(String bundleSymbolicName) { + this.bundleSymbolicName = bundleSymbolicName; + } + } -- 2.39.2