]> git.argeo.org Git - gpl/argeo-slc.git/blob - OsgiRuntimeModularDistribution.java
7f3b49a381867914c9b35b0f2b3bbab2b789d7a4
[gpl/argeo-slc.git] / OsgiRuntimeModularDistribution.java
1 package org.argeo.slc.osgi.build;
2
3 import java.net.URL;
4 import java.util.SortedMap;
5
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8 import org.argeo.slc.build.Distribution;
9 import org.argeo.slc.build.NameVersion;
10 import org.argeo.slc.core.build.VersionedResourceDistribution;
11 import org.argeo.slc.osgi.OsgiBundle;
12 import org.osgi.framework.Bundle;
13 import org.springframework.context.ResourceLoaderAware;
14 import org.springframework.core.io.Resource;
15 import org.springframework.core.io.ResourceLoader;
16
17 public class OsgiRuntimeModularDistribution extends
18 AbstractOsgiModularDistribution implements ResourceLoaderAware {
19 private final static Log log = LogFactory
20 .getLog(OsgiRuntimeModularDistribution.class);
21
22 private ResourceLoader resourceLoader;
23
24 protected void fillDistributions(
25 SortedMap<NameVersion, Distribution> distributions)
26 throws Exception {
27
28 for (Bundle bundle : getBundleContext().getBundles()) {
29 OsgiBundle osgiBundle = new OsgiBundle(bundle);
30
31 String originalLocation = bundle.getLocation();
32 String location = originalLocation;
33 if (originalLocation.startsWith("reference:file:"))
34 location = originalLocation.substring("reference:".length());
35
36 try {
37 URL url = new URL(location);
38 Resource res = resourceLoader.getResource(url.toString());
39 distributions.put(osgiBundle,
40 new VersionedResourceDistribution(osgiBundle, res));
41
42 if (log.isTraceEnabled())
43 log.debug("Added url " + url + " from original location "
44 + originalLocation);
45 } catch (Exception e) {
46 log.warn("Cannot interpret location " + location
47 + " of bundle " + bundle + ": " + e);
48 }
49 }
50 }
51
52 public void setResourceLoader(ResourceLoader resourceLoader) {
53 this.resourceLoader = resourceLoader;
54 }
55 }