X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.lib.detached%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Flib%2Fdetached%2FDetachedLauncher.java;h=d9ff2f6be118c7f2fbd84e01fae688f1fb2d1ad5;hb=d2f1498d82864a131a6e2e589c115d04af32b4f6;hp=505fa66633f47db757a4bcf13fe0aec970175390;hpb=8eb028e332cb2be50ed311a0501f7efce5849d44;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.lib.detached/src/main/java/org/argeo/slc/lib/detached/DetachedLauncher.java b/runtime/org.argeo.slc.lib.detached/src/main/java/org/argeo/slc/lib/detached/DetachedLauncher.java index 505fa6663..d9ff2f6be 100644 --- a/runtime/org.argeo.slc.lib.detached/src/main/java/org/argeo/slc/lib/detached/DetachedLauncher.java +++ b/runtime/org.argeo.slc.lib.detached/src/main/java/org/argeo/slc/lib/detached/DetachedLauncher.java @@ -1,5 +1,10 @@ package org.argeo.slc.lib.detached; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.slc.SlcException; @@ -8,6 +13,7 @@ import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ResourceLoaderAware; +import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.osgi.context.BundleContextAware; @@ -25,6 +31,9 @@ public class DetachedLauncher extends JvmProcess implements BundleContextAware, private String xmlapisBundleName = "com.springsource.org.apache.xmlcommons"; private String xercesBundleName = "com.springsource.org.apache.xerces"; + private List excludeBundleNames = new ArrayList(); + private List includeBundleUrls = new ArrayList(); + /** * Required by Spring for JDK 1.4. see * http://forum.springsource.org/showthread.php?t=74555 @@ -48,41 +57,79 @@ public class DetachedLauncher extends JvmProcess implements BundleContextAware, else getClasspath().add(osgiFramework); + StringBuffer osgiBundles = new StringBuffer(""); StringBuffer osgiLocations = new StringBuffer(""); bundles: for (Bundle bundle : bundleContext.getBundles()) { String name = bundle.getSymbolicName(); + if (excludeBundleNames.contains(name)) + continue bundles;// skip excluded + + String location = bundle.getLocation(); + location = removeInitialReference(location); + // Special bundles if (osgibootBundleName.equals(name)) - getClasspath().add(findOsgiboot(bundle)); + getClasspath().add(asResource(location)); else if (equinoxBundleName.equals(name)) continue bundles;// skip framework else if (xmlapisBundleName.equals(name) && prependXmlJars) - getPBootClasspath().add(asResource(bundle.getLocation())); + getPBootClasspath().add(asResource(location)); else if (xercesBundleName.equals(name) && prependXmlJars) - getPBootClasspath().add(asResource(bundle.getLocation())); + getPBootClasspath().add(asResource(location)); + + if (location.startsWith("file:")) { + File file = new File(location.substring("file:".length())); + if (osgiLocations.length() != 0) + osgiLocations.append(File.pathSeparatorChar); + osgiLocations.append(file.getPath().replace('/', + File.separatorChar)); + } else { + if (osgiBundles.length() != 0) + osgiBundles.append(','); + osgiBundles.append(location.replace('/', File.separatorChar)); + } + } - if (osgiLocations.length() != 0) - osgiLocations.append(','); - osgiLocations.append(bundle.getLocation()); + for (String url : includeBundleUrls) { + if (osgiBundles.length() != 0) + osgiBundles.append(','); + osgiBundles.append(url); } getSystemProperties().setProperty("osgi.bundles", + osgiBundles.toString()); + getSystemProperties().setProperty("slc.osgi.locations", osgiLocations.toString()); } - protected Resource findOsgiboot(Bundle bundle) { - String location = bundle.getLocation(); + protected String removeInitialReference(String location) { if (location.startsWith("initial@reference:file:")) - location = System.getProperty("osgi.install.area") + "/../" + location = System.getProperty("osgi.install.area") + location.substring("initial@reference:file:".length()); if (location.charAt(location.length() - 1) == '/') location.substring(0, location.length() - 1); - return asResource(location); + return location; } protected Resource asResource(String location) { - Resource res = resourceLoader.getResource(location); + // Resource res = resourceLoader.getResource(location); + + final Resource res; + if (location.startsWith("file:")) { + File file = new File(location.substring("file:".length())); + if (!file.exists()) + throw new SlcException("File " + file + " does not exist"); + + try { + res = new FileSystemResource(file.getCanonicalFile()); + } catch (IOException e) { + throw new SlcException("Cannot create resource based on " + + file, e); + } + } else + res = resourceLoader.getResource(location); + if (log.isDebugEnabled()) log.debug("Converted " + location + " to " + res); return res; @@ -120,4 +167,12 @@ public class DetachedLauncher extends JvmProcess implements BundleContextAware, this.prependXmlJars = prependXmlJars; } + public void setExcludeBundleNames(List excludeBundleNames) { + this.excludeBundleNames = excludeBundleNames; + } + + public void setIncludeBundleUrls(List includeBundleUrls) { + this.includeBundleUrls = includeBundleUrls; + } + }