2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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.
17 package org
.argeo
.slc
.osgi
.build
;
20 import java
.util
.SortedMap
;
22 import org
.apache
.commons
.logging
.Log
;
23 import org
.apache
.commons
.logging
.LogFactory
;
24 import org
.argeo
.slc
.NameVersion
;
25 import org
.argeo
.slc
.build
.Distribution
;
26 import org
.argeo
.slc
.core
.build
.VersionedResourceDistribution
;
27 import org
.argeo
.slc
.osgi
.OsgiBundle
;
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
;
32 import org
.springframework
.osgi
.util
.OsgiBundleUtils
;
34 public class OsgiRuntimeModularDistribution
extends
35 AbstractOsgiModularDistribution
implements ResourceLoaderAware
{
36 private final static Log log
= LogFactory
37 .getLog(OsgiRuntimeModularDistribution
.class);
39 private ResourceLoader resourceLoader
;
41 protected void fillDistributions(
42 SortedMap
<NameVersion
, Distribution
> distributions
)
45 String frameworkUrl
= System
.getProperty("osgi.framework");
46 String frameworkBaseUrl
= null;
47 if (frameworkUrl
!= null)
48 frameworkBaseUrl
= frameworkUrl
.substring(0, frameworkUrl
50 bundles
: for (Bundle bundle
: getBundleContext().getBundles()) {
51 OsgiBundle osgiBundle
= new OsgiBundle(bundle
);
53 String originalLocation
= bundle
.getLocation();
55 if (OsgiBundleUtils
.isSystemBundle(bundle
)) {
59 String location
= originalLocation
;
60 if (originalLocation
.startsWith("reference:file:"))
61 location
= originalLocation
.substring("reference:".length());
63 if (frameworkBaseUrl
!= null
64 && originalLocation
.startsWith("initial@reference:file:")) {
65 location
= frameworkBaseUrl
67 + originalLocation
.substring("initial@reference:file:"
72 URL url
= new URL(location
);
73 Resource res
= resourceLoader
.getResource(url
.toString());
74 distributions
.put(osgiBundle
,
75 new VersionedResourceDistribution(osgiBundle
, res
));
77 if (log
.isTraceEnabled())
78 log
.debug("Added url " + url
+ " from original location "
80 } catch (Exception e
) {
81 log
.warn("Cannot interpret location " + location
82 + " of bundle " + bundle
+ ": " + e
);
87 public void setResourceLoader(ResourceLoader resourceLoader
) {
88 this.resourceLoader
= resourceLoader
;