1 package org
.argeo
.slc
.osgi
.build
;
4 import java
.util
.Enumeration
;
5 import java
.util
.SortedMap
;
6 import java
.util
.StringTokenizer
;
7 import java
.util
.jar
.JarInputStream
;
8 import java
.util
.jar
.Manifest
;
10 import org
.apache
.commons
.io
.IOUtils
;
11 import org
.argeo
.slc
.build
.BasicNameVersion
;
12 import org
.argeo
.slc
.build
.Distribution
;
13 import org
.argeo
.slc
.build
.NameVersion
;
14 import org
.argeo
.slc
.core
.build
.VersionedResourceDistribution
;
15 import org
.osgi
.framework
.Constants
;
16 import org
.springframework
.context
.ResourceLoaderAware
;
17 import org
.springframework
.core
.io
.ResourceLoader
;
19 public class BundleModularDistribution
extends AbstractOsgiModularDistribution
20 implements ResourceLoaderAware
{
21 private ResourceLoader resourceLoader
;
23 private String libDirectory
= "/lib";
25 @SuppressWarnings(value
= { "unchecked" })
26 protected void fillDistributions(
27 SortedMap
<NameVersion
, Distribution
> distributions
)
29 Enumeration
<URL
> urls
= (Enumeration
<URL
>) getBundleContext()
30 .getBundle().findEntries(libDirectory
, "*.jar", false);
31 while (urls
.hasMoreElements()) {
32 URL url
= urls
.nextElement();
33 JarInputStream in
= null;
35 in
= new JarInputStream(url
.openStream());
36 Manifest mf
= in
.getManifest();
37 String name
= mf
.getMainAttributes().getValue(
38 Constants
.BUNDLE_SYMBOLICNAME
);
39 // Skip additional specs such as
41 if (name
.indexOf(';') > -1) {
42 name
= new StringTokenizer(name
, " ;").nextToken();
45 String version
= mf
.getMainAttributes().getValue(
46 Constants
.BUNDLE_VERSION
);
47 BasicNameVersion nameVersion
= new BasicNameVersion(name
,
49 distributions
.put(nameVersion
,
50 new VersionedResourceDistribution(name
, version
,
51 resourceLoader
.getResource(url
.toString())));
53 IOUtils
.closeQuietly(in
);
58 public void setLibDirectory(String libDirectory
) {
59 this.libDirectory
= libDirectory
;
62 public void setResourceLoader(ResourceLoader resourceLoader
) {
63 this.resourceLoader
= resourceLoader
;
67 * @SuppressWarnings(value = { "unchecked" }) protected URL
68 * findModule(String moduleName, String version) { Enumeration<URL> urls =
69 * (Enumeration<URL>) bundleContext.getBundle() .findEntries(libDirectory,
70 * moduleName + "*", false);
72 * if (!urls.hasMoreElements()) throw new SlcException("Cannot find module "
75 * URL url = urls.nextElement();
77 * // TODO: check version as well if (urls.hasMoreElements()) throw new
78 * SlcException("More than one module with name " + moduleName); return url;