]> git.argeo.org Git - gpl/argeo-slc.git/blob - legacy/org.argeo.slc.spring/src/org/argeo/slc/osgi/build/OsgiRuntimeModularDistribution.java
Adapt to changes in Argeo Commons
[gpl/argeo-slc.git] / legacy / org.argeo.slc.spring / src / org / argeo / slc / osgi / build / 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.NameVersion;
9 import org.argeo.slc.build.Distribution;
10 import org.argeo.slc.core.build.VersionedResourceDistribution;
11 import org.argeo.slc.osgi.OsgiBundle;
12 import org.eclipse.gemini.blueprint.util.OsgiBundleUtils;
13 import org.osgi.framework.Bundle;
14 import org.springframework.context.ResourceLoaderAware;
15 import org.springframework.core.io.Resource;
16 import org.springframework.core.io.ResourceLoader;
17
18 public class OsgiRuntimeModularDistribution extends
19 AbstractOsgiModularDistribution implements ResourceLoaderAware {
20 private final static Log log = LogFactory
21 .getLog(OsgiRuntimeModularDistribution.class);
22
23 private ResourceLoader resourceLoader;
24
25 protected void fillDistributions(
26 SortedMap<NameVersion, Distribution> distributions)
27 throws Exception {
28
29 String frameworkUrl = System.getProperty("osgi.framework");
30 String frameworkBaseUrl = null;
31 if (frameworkUrl != null)
32 frameworkBaseUrl = frameworkUrl.substring(0, frameworkUrl
33 .lastIndexOf('/'));
34 bundles: for (Bundle bundle : getBundleContext().getBundles()) {
35 OsgiBundle osgiBundle = new OsgiBundle(bundle);
36
37 String originalLocation = bundle.getLocation();
38
39 if (OsgiBundleUtils.isSystemBundle(bundle)) {
40 continue bundles;
41 }
42
43 String location = originalLocation;
44 if (originalLocation.startsWith("reference:file:"))
45 location = originalLocation.substring("reference:".length());
46
47 if (frameworkBaseUrl != null
48 && originalLocation.startsWith("initial@reference:file:")) {
49 location = frameworkBaseUrl
50 + '/'
51 + originalLocation.substring("initial@reference:file:"
52 .length());
53 }
54
55 try {
56 URL url = new URL(location);
57 Resource res = resourceLoader.getResource(url.toString());
58 distributions.put(osgiBundle,
59 new VersionedResourceDistribution(osgiBundle, res));
60
61 if (log.isTraceEnabled())
62 log.debug("Added url " + url + " from original location "
63 + originalLocation);
64 } catch (Exception e) {
65 log.warn("Cannot interpret location " + location
66 + " of bundle " + bundle + ": " + e);
67 }
68 }
69 }
70
71 public void setResourceLoader(ResourceLoader resourceLoader) {
72 this.resourceLoader = resourceLoader;
73 }
74 }