1 package org
.argeo
.slc
.osgi
.build
;
4 import java
.util
.SortedMap
;
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
;
18 public class OsgiRuntimeModularDistribution
extends
19 AbstractOsgiModularDistribution
implements ResourceLoaderAware
{
20 private final static Log log
= LogFactory
21 .getLog(OsgiRuntimeModularDistribution
.class);
23 private ResourceLoader resourceLoader
;
25 protected void fillDistributions(
26 SortedMap
<NameVersion
, Distribution
> distributions
)
29 String frameworkUrl
= System
.getProperty("osgi.framework");
30 String frameworkBaseUrl
= null;
31 if (frameworkUrl
!= null)
32 frameworkBaseUrl
= frameworkUrl
.substring(0, frameworkUrl
34 bundles
: for (Bundle bundle
: getBundleContext().getBundles()) {
35 OsgiBundle osgiBundle
= new OsgiBundle(bundle
);
37 String originalLocation
= bundle
.getLocation();
39 if (OsgiBundleUtils
.isSystemBundle(bundle
)) {
43 String location
= originalLocation
;
44 if (originalLocation
.startsWith("reference:file:"))
45 location
= originalLocation
.substring("reference:".length());
47 if (frameworkBaseUrl
!= null
48 && originalLocation
.startsWith("initial@reference:file:")) {
49 location
= frameworkBaseUrl
51 + originalLocation
.substring("initial@reference:file:"
56 URL url
= new URL(location
);
57 Resource res
= resourceLoader
.getResource(url
.toString());
58 distributions
.put(osgiBundle
,
59 new VersionedResourceDistribution(osgiBundle
, res
));
61 if (log
.isTraceEnabled())
62 log
.debug("Added url " + url
+ " from original location "
64 } catch (Exception e
) {
65 log
.warn("Cannot interpret location " + location
66 + " of bundle " + bundle
+ ": " + e
);
71 public void setResourceLoader(ResourceLoader resourceLoader
) {
72 this.resourceLoader
= resourceLoader
;