X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=cms%2Forg.argeo.slc.spring%2Fsrc%2Forg%2Fargeo%2Fslc%2Fosgi%2Fbuild%2FBundleModularDistribution.java;fp=cms%2Forg.argeo.slc.spring%2Fsrc%2Forg%2Fargeo%2Fslc%2Fosgi%2Fbuild%2FBundleModularDistribution.java;h=ec7d2f6bf91a54029d2e89eb464b21ef0b798c45;hb=ecc22e604e47533c79de9cecdcdeacbc752cbff1;hp=0000000000000000000000000000000000000000;hpb=e07ded4632e53f8b8869763bc1f1f4091361e76e;p=gpl%2Fargeo-slc.git diff --git a/cms/org.argeo.slc.spring/src/org/argeo/slc/osgi/build/BundleModularDistribution.java b/cms/org.argeo.slc.spring/src/org/argeo/slc/osgi/build/BundleModularDistribution.java new file mode 100644 index 000000000..ec7d2f6bf --- /dev/null +++ b/cms/org.argeo.slc.spring/src/org/argeo/slc/osgi/build/BundleModularDistribution.java @@ -0,0 +1,81 @@ +package org.argeo.slc.osgi.build; + +import java.net.URL; +import java.util.Enumeration; +import java.util.SortedMap; +import java.util.StringTokenizer; +import java.util.jar.JarInputStream; +import java.util.jar.Manifest; + +import org.apache.commons.io.IOUtils; +import org.argeo.slc.DefaultNameVersion; +import org.argeo.slc.NameVersion; +import org.argeo.slc.build.Distribution; +import org.argeo.slc.core.build.VersionedResourceDistribution; +import org.osgi.framework.Constants; +import org.springframework.context.ResourceLoaderAware; +import org.springframework.core.io.ResourceLoader; + +public class BundleModularDistribution extends AbstractOsgiModularDistribution + implements ResourceLoaderAware { + private ResourceLoader resourceLoader; + + private String libDirectory = "/lib"; + + protected void fillDistributions( + SortedMap distributions) + throws Exception { + Enumeration urls = (Enumeration) getBundleContext() + .getBundle().findEntries(libDirectory, "*.jar", false); + while (urls.hasMoreElements()) { + URL url = urls.nextElement(); + JarInputStream in = null; + try { + in = new JarInputStream(url.openStream()); + Manifest mf = in.getManifest(); + String name = mf.getMainAttributes().getValue( + Constants.BUNDLE_SYMBOLICNAME); + // Skip additional specs such as + // ; singleton:=true + if (name.indexOf(';') > -1) { + name = new StringTokenizer(name, " ;").nextToken(); + } + + String version = mf.getMainAttributes().getValue( + Constants.BUNDLE_VERSION); + DefaultNameVersion nameVersion = new DefaultNameVersion(name, + version); + distributions.put(nameVersion, + new VersionedResourceDistribution(name, version, + resourceLoader.getResource(url.toString()))); + } finally { + IOUtils.closeQuietly(in); + } + } + } + + public void setLibDirectory(String libDirectory) { + this.libDirectory = libDirectory; + } + + public void setResourceLoader(ResourceLoader resourceLoader) { + this.resourceLoader = resourceLoader; + } + + /* + * @SuppressWarnings(value = { "unchecked" }) protected URL + * findModule(String moduleName, String version) { Enumeration urls = + * (Enumeration) bundleContext.getBundle() .findEntries(libDirectory, + * moduleName + "*", false); + * + * if (!urls.hasMoreElements()) throw new SlcException("Cannot find module " + * + moduleName); + * + * URL url = urls.nextElement(); + * + * // TODO: check version as well if (urls.hasMoreElements()) throw new + * SlcException("More than one module with name " + moduleName); return url; + * } + */ + +}