2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.osgi
.build
;
19 import java
.util
.SortedMap
;
21 import org
.apache
.commons
.logging
.Log
;
22 import org
.apache
.commons
.logging
.LogFactory
;
23 import org
.argeo
.slc
.NameVersion
;
24 import org
.argeo
.slc
.build
.Distribution
;
25 import org
.argeo
.slc
.core
.build
.VersionedResourceDistribution
;
26 import org
.argeo
.slc
.osgi
.OsgiBundle
;
27 import org
.eclipse
.gemini
.blueprint
.util
.OsgiBundleUtils
;
28 import org
.osgi
.framework
.Bundle
;
29 import org
.springframework
.context
.ResourceLoaderAware
;
30 import org
.springframework
.core
.io
.Resource
;
31 import org
.springframework
.core
.io
.ResourceLoader
;
33 public class OsgiRuntimeModularDistribution
extends
34 AbstractOsgiModularDistribution
implements ResourceLoaderAware
{
35 private final static Log log
= LogFactory
36 .getLog(OsgiRuntimeModularDistribution
.class);
38 private ResourceLoader resourceLoader
;
40 protected void fillDistributions(
41 SortedMap
<NameVersion
, Distribution
> distributions
)
44 String frameworkUrl
= System
.getProperty("osgi.framework");
45 String frameworkBaseUrl
= null;
46 if (frameworkUrl
!= null)
47 frameworkBaseUrl
= frameworkUrl
.substring(0, frameworkUrl
49 bundles
: for (Bundle bundle
: getBundleContext().getBundles()) {
50 OsgiBundle osgiBundle
= new OsgiBundle(bundle
);
52 String originalLocation
= bundle
.getLocation();
54 if (OsgiBundleUtils
.isSystemBundle(bundle
)) {
58 String location
= originalLocation
;
59 if (originalLocation
.startsWith("reference:file:"))
60 location
= originalLocation
.substring("reference:".length());
62 if (frameworkBaseUrl
!= null
63 && originalLocation
.startsWith("initial@reference:file:")) {
64 location
= frameworkBaseUrl
66 + originalLocation
.substring("initial@reference:file:"
71 URL url
= new URL(location
);
72 Resource res
= resourceLoader
.getResource(url
.toString());
73 distributions
.put(osgiBundle
,
74 new VersionedResourceDistribution(osgiBundle
, res
));
76 if (log
.isTraceEnabled())
77 log
.debug("Added url " + url
+ " from original location "
79 } catch (Exception e
) {
80 log
.warn("Cannot interpret location " + location
81 + " of bundle " + bundle
+ ": " + e
);
86 public void setResourceLoader(ResourceLoader resourceLoader
) {
87 this.resourceLoader
= resourceLoader
;