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