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
.DefaultNameVersion
;
12 import org
.argeo
.slc
.NameVersion
;
13 import org
.argeo
.slc
.build
.Distribution
;
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 protected void fillDistributions(
26 SortedMap
<NameVersion
, Distribution
> distributions
)
28 Enumeration
<URL
> urls
= (Enumeration
<URL
>) getBundleContext()
29 .getBundle().findEntries(libDirectory
, "*.jar", false);
30 while (urls
.hasMoreElements()) {
31 URL url
= urls
.nextElement();
32 JarInputStream in
= null;
34 in
= new JarInputStream(url
.openStream());
35 Manifest mf
= in
.getManifest();
36 String name
= mf
.getMainAttributes().getValue(
37 Constants
.BUNDLE_SYMBOLICNAME
);
38 // Skip additional specs such as
40 if (name
.indexOf(';') > -1) {
41 name
= new StringTokenizer(name
, " ;").nextToken();
44 String version
= mf
.getMainAttributes().getValue(
45 Constants
.BUNDLE_VERSION
);
46 DefaultNameVersion nameVersion
= new DefaultNameVersion(name
,
48 distributions
.put(nameVersion
,
49 new VersionedResourceDistribution(name
, version
,
50 resourceLoader
.getResource(url
.toString())));
52 IOUtils
.closeQuietly(in
);
57 public void setLibDirectory(String libDirectory
) {
58 this.libDirectory
= libDirectory
;
61 public void setResourceLoader(ResourceLoader resourceLoader
) {
62 this.resourceLoader
= resourceLoader
;
66 * @SuppressWarnings(value = { "unchecked" }) protected URL
67 * findModule(String moduleName, String version) { Enumeration<URL> urls =
68 * (Enumeration<URL>) bundleContext.getBundle() .findEntries(libDirectory,
69 * moduleName + "*", false);
71 * if (!urls.hasMoreElements()) throw new SlcException("Cannot find module "
74 * URL url = urls.nextElement();
76 * // TODO: check version as well if (urls.hasMoreElements()) throw new
77 * SlcException("More than one module with name " + moduleName); return url;