diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2008-09-08 07:33:14 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2008-09-08 07:33:14 +0000 |
commit | 7c688ea1908125daa0599bb101dd1c251aa10864 (patch) | |
tree | d7ae32b90933ff1ef66ffde4bcd257ad9548666a /java | |
parent | d3161b155039878697952e98f632fdae92970f13 (diff) |
Fix the Bundle-ClassPath syntax and make sure the classpath is resolved against the base bundle correctly
Use the bundle to load implementation-node classes
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@693007 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
5 files changed, 75 insertions, 17 deletions
diff --git a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHookConfigurator.java b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHookConfigurator.java index fed763096a..efe4d7bf8a 100644 --- a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHookConfigurator.java +++ b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHookConfigurator.java @@ -19,7 +19,10 @@ package org.apache.tuscany.sca.node.equinox.launcher; +import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.util.jar.Manifest; +import java.util.logging.Level; import java.util.logging.Logger; import org.eclipse.osgi.baseadaptor.HookConfigurator; @@ -45,6 +48,17 @@ public class EquinoxHookConfigurator implements HookConfigurator { // Create a single 'library' bundle for them long libraryStart = System.currentTimeMillis(); manifest = NodeLauncherUtil.libraryManifest(jarFiles); + + if (logger.isLoggable(Level.FINE)) { + try { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + manifest.write(bos); + bos.close(); + logger.fine(new String(bos.toByteArray())); + } catch (IOException e) { + } + } + logger.info("Third-party library manifest generated in " + (System.currentTimeMillis() - libraryStart) + " ms"); } diff --git a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java index 4419f22c5c..93b8936ae9 100644 --- a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java +++ b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java @@ -101,6 +101,8 @@ public class EquinoxHost { // Set startup properties props.put(EclipseStarter.PROP_CLEAN, "true"); + props.put("osgi.console", "8085"); + // Set location properties // FIXME Use proper locations props.put(LocationManager.PROP_INSTANCE_AREA, new File("target/workspace").toURI().toString()); @@ -155,11 +157,16 @@ public class EquinoxHost { for (Bundle bundle: context.getBundles()) { if ((bundle.getState() & Bundle.ACTIVE) == 0) { logger.info("Starting bundle: " + string(bundle, false)); - bundle.start(); + try { + bundle.start(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + logger.info("Bundle: " + string(bundle, false)); } } logger.info("Tuscany bundles are started in " + (System.currentTimeMillis() - activateStart) + " ms."); - return context; } catch (Exception e) { diff --git a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/LibrariesBundleFileFactoryHook.java b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/LibrariesBundleFileFactoryHook.java index db0524a7d7..4ff93ea84b 100644 --- a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/LibrariesBundleFileFactoryHook.java +++ b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/LibrariesBundleFileFactoryHook.java @@ -64,7 +64,6 @@ public class LibrariesBundleFileFactoryHook implements org.eclipse.osgi.baseadap @Override public InputStream getInputStream() throws IOException { - System.out.println(new String(bytes)); return new ByteArrayInputStream(bytes); } @@ -138,7 +137,8 @@ public class LibrariesBundleFileFactoryHook implements org.eclipse.osgi.baseadap } public BundleFile createBundleFile(Object content, BaseData data, boolean base) throws IOException { - if ("org.apache.tuscany.sca.node.launcher.equinox.libraries".equals(data.getLocation())) { + // Equinox will resolve external classpath against the base bundle + if ("org.apache.tuscany.sca.node.launcher.equinox.libraries".equals(data.getLocation()) && base) { return new LibrariesBundleFile(content, manifest); } else { return null; diff --git a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java index 5b12dfca05..f3bb8c04ae 100644 --- a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java +++ b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java @@ -25,6 +25,8 @@ import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; +import org.osgi.framework.BundleContext; + /** * A launcher for SCA nodes. * @@ -34,13 +36,14 @@ public class NodeLauncher { static final Logger logger = Logger.getLogger(NodeLauncher.class.getName()); private EquinoxHost host; + private BundleContext bundleContext; /** * Constructs a new node launcher. */ private NodeLauncher() { host = new EquinoxHost(); - host.start(); + bundleContext = host.start(); } /** @@ -62,7 +65,7 @@ public class NodeLauncher { * @throws LauncherException */ public <T> T createNodeFromURL(String configurationURL) throws LauncherException { - return (T)node(configurationURL, null, null, null, null); + return (T)node(configurationURL, null, null, null, null, bundleContext); } /** @@ -77,7 +80,7 @@ public class NodeLauncher { * @throws LauncherException */ public <T> T createNode(String compositeURI, Contribution... contributions) throws LauncherException { - return (T)node(null, compositeURI, null, contributions, null); + return (T)node(null, compositeURI, null, contributions, null, bundleContext); } /** @@ -91,7 +94,7 @@ public class NodeLauncher { */ public <T> T createNode(String compositeURI, String compositeContent, Contribution... contributions) throws LauncherException { - return (T)node(null, compositeURI, compositeContent, contributions, null); + return (T)node(null, compositeURI, compositeContent, contributions, null, bundleContext); } /** @@ -109,7 +112,7 @@ public class NodeLauncher { * @return A newly created SCA node */ public <T> T createNodeFromClassLoader(String compositeURI, ClassLoader classLoader) throws LauncherException { - return (T)node(null, compositeURI, null, null, classLoader); + return (T)node(null, compositeURI, null, null, classLoader, bundleContext); } public static void main(String[] args) throws Exception { @@ -183,6 +186,7 @@ public class NodeLauncher { public void destroy() { if (host != null) { host.stop(); + bundleContext = null; } } diff --git a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java index c058589433..d52a18e830 100644 --- a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java +++ b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java @@ -25,6 +25,7 @@ import static org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME; import static org.osgi.framework.Constants.DYNAMICIMPORT_PACKAGE; import static org.osgi.framework.Constants.EXPORT_PACKAGE; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -33,9 +34,11 @@ import java.lang.reflect.Constructor; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.util.Arrays; import java.util.HashSet; import java.util.Set; import java.util.jar.Attributes; +import java.util.jar.JarOutputStream; import java.util.jar.Manifest; import java.util.logging.Level; import java.util.regex.Matcher; @@ -43,8 +46,10 @@ import java.util.regex.Pattern; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; +import org.eclipse.osgi.util.ManifestElement; import org.osgi.framework.Bundle; -import org.osgi.framework.Constants; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; /** * Common functions and constants used by the admin components. @@ -66,21 +71,32 @@ final class NodeLauncherUtil { * Collect JAR files under the given directory. * * @p @param contributions + * @param bundleContext TODO * @throws LauncherException */ static Object node(String configurationURI, String compositeURI, String compositeContent, Contribution[] contributions, - ClassLoader contributionClassLoader) throws LauncherException { - ClassLoader tccl = Thread.currentThread().getContextClassLoader(); + ClassLoader contributionClassLoader, + BundleContext bundleContext) throws LauncherException { try { + Bundle bundle = null; + for (Bundle b : bundleContext.getBundles()) { + if ("org.apache.tuscany.sca.implementation.node.runtime".equals(b.getSymbolicName())) { + bundle = b; + break; + } + } + if (bundle == null) { + throw new IllegalStateException( + "Bundle org.apache.tuscany.sca.implementation.node.runtime is not installed"); + } // Use Java reflection to create the node as only the runtime class // loader knows the runtime classes required by the node String className = NODE_IMPLEMENTATION_LAUNCHER_BOOTSTRAP; - Class<?> bootstrapClass; - bootstrapClass = Class.forName(className, false, tccl); + Class<?> bootstrapClass = bundle.loadClass(NODE_IMPLEMENTATION_LAUNCHER_BOOTSTRAP); Object bootstrap; if (configurationURI != null) { @@ -137,7 +153,7 @@ final class NodeLauncherUtil { NodeLauncher.logger.log(Level.SEVERE, "SCA Node could not be created", e); throw new LauncherException(e); } finally { - Thread.currentThread().setContextClassLoader(tccl); + // } } @@ -254,8 +270,9 @@ final class NodeLauncherUtil { Set<String> packages = new HashSet<String>(); for (String jarFile: jarFiles) { addPackages(jarFile, packages); - classpath.append(jarFile); - classpath.append(','); + classpath.append("\"external:"); + classpath.append(file(new URL(jarFile)).getAbsolutePath().replace(File.separatorChar, '/')); + classpath.append("\","); } for (String pkg: packages) { exports.append(pkg); @@ -272,12 +289,28 @@ final class NodeLauncherUtil { attributes.putValue(BUNDLE_CLASSPATH, classpath.substring(0, classpath.length() -1)); attributes.putValue(DYNAMICIMPORT_PACKAGE, "*"); + try { + ManifestElement[] elements = ManifestElement.parseHeader(BUNDLE_CLASSPATH, classpath.substring(0, classpath.length() -1)); + for(ManifestElement e: elements) { + System.out.println(Arrays.asList(e.getValueComponents())); + } + } catch (BundleException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } return manifest; } catch (IOException e) { throw new IllegalStateException(e); } } + static byte[] generateBundle(Manifest mf) throws IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + JarOutputStream jos = new JarOutputStream(bos, mf); + jos.close(); + return bos.toByteArray(); + } + /** * Returns the location of this bundle. * |