]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/build/OsgiRuntimeModularDistribution.java
Introduce bundle register
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.osgi / src / main / java / org / argeo / slc / osgi / build / OsgiRuntimeModularDistribution.java
index 1c68cf5c356917a33a30109e8d6231d56f99e80f..f18b78303b7ab9c82bee17cdc63d67ef08ce291b 100644 (file)
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.argeo.slc.osgi.build;
 
 import java.net.URL;
@@ -13,6 +29,7 @@ import org.osgi.framework.Bundle;
 import org.springframework.context.ResourceLoaderAware;
 import org.springframework.core.io.Resource;
 import org.springframework.core.io.ResourceLoader;
+import org.springframework.osgi.util.OsgiBundleUtils;
 
 public class OsgiRuntimeModularDistribution extends
                AbstractOsgiModularDistribution implements ResourceLoaderAware {
@@ -25,17 +42,41 @@ public class OsgiRuntimeModularDistribution extends
                        SortedMap<NameVersion, Distribution> distributions)
                        throws Exception {
 
-               for (Bundle bundle : getBundleContext().getBundles()) {
+               String frameworkUrl = System.getProperty("osgi.framework");
+               String frameworkBaseUrl = null;
+               if (frameworkUrl != null)
+                       frameworkBaseUrl = frameworkUrl.substring(0, frameworkUrl
+                                       .lastIndexOf('/'));
+               bundles: for (Bundle bundle : getBundleContext().getBundles()) {
                        OsgiBundle osgiBundle = new OsgiBundle(bundle);
 
-                       String location = bundle.getLocation();
-                       if (location.startsWith("reference:file:"))
-                               location = location.substring("reference:".length());
+                       String originalLocation = bundle.getLocation();
+
+                       if (OsgiBundleUtils.isSystemBundle(bundle)) {
+                               continue bundles;
+                       }
+
+                       String location = originalLocation;
+                       if (originalLocation.startsWith("reference:file:"))
+                               location = originalLocation.substring("reference:".length());
+
+                       if (frameworkBaseUrl != null
+                                       && originalLocation.startsWith("initial@reference:file:")) {
+                               location = frameworkBaseUrl
+                                               + '/'
+                                               + originalLocation.substring("initial@reference:file:"
+                                                               .length());
+                       }
+
                        try {
                                URL url = new URL(location);
                                Resource res = resourceLoader.getResource(url.toString());
                                distributions.put(osgiBundle,
                                                new VersionedResourceDistribution(osgiBundle, res));
+
+                               if (log.isTraceEnabled())
+                                       log.debug("Added url " + url + " from original location "
+                                                       + originalLocation);
                        } catch (Exception e) {
                                log.warn("Cannot interpret location " + location
                                                + " of bundle " + bundle + ": " + e);