From 6a633dee838417ed68cf91fbd2e9b3b9fa07bd8f Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Fri, 19 Sep 2008 05:31:14 +0000 Subject: Simplified ServiceDiscoverer. Started to use it to create factories to resolve ClassNotFoundExceptions. Renamed calculator-osgi to calculator-equinox and a few fixes to get it working in Eclipse. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@696924 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/node/equinox/launcher/EquinoxHost.java | 12 +++++++++- .../launcher/EquinoxLauncherBundleHelper.java | 4 +++- .../node/equinox/launcher/NodeLauncherUtil.java | 28 ++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) (limited to 'branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany') diff --git a/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java b/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java index 6efdcb0da5..aabfd4bcfe 100644 --- a/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java +++ b/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java @@ -20,6 +20,7 @@ package org.apache.tuscany.sca.node.equinox.launcher; import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.bundleLocation; +import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.installBundle; import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.string; import static org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME; @@ -153,7 +154,7 @@ public class EquinoxHost { // Install the launcher bundle String bundleLocation = bundleLocation(); logger.info("Installing launcher bundle: " + bundleLocation); - launcherBundle = bundleContext.installBundle(bundleLocation); + launcherBundle = installBundle(bundleContext, bundleLocation); logger.info("Starting bundle: " + string(launcherBundle, false)); launcherBundle.start(); @@ -229,6 +230,15 @@ public class EquinoxHost { if (mf.isFile()) { Manifest manifest = new Manifest(new FileInputStream(mf)); bundleName = manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME); + } else { + if (file.getPath().endsWith("target/classes")) { + // Development mode, MANIFEST.MF is outside the bundle location + mf = new File(file.getParentFile().getParentFile(), "META-INF/MANIFEST.MF"); + if (mf.isFile()) { + Manifest manifest = new Manifest(new FileInputStream(mf)); + bundleName = manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME); + } + } } } else { JarFile jar = new JarFile(file, false); diff --git a/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxLauncherBundleHelper.java b/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxLauncherBundleHelper.java index 3f88bd89e9..b2c80f6fd7 100644 --- a/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxLauncherBundleHelper.java +++ b/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxLauncherBundleHelper.java @@ -3,6 +3,7 @@ package org.apache.tuscany.sca.node.equinox.launcher; import static java.lang.System.currentTimeMillis; import static java.lang.System.getProperty; import static java.lang.System.setProperty; +import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.installBundle; import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.libraryBundle; import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.string; @@ -77,9 +78,10 @@ public class EquinoxLauncherBundleHelper implements BundleListener { continue; } long installStart = currentTimeMillis(); - Bundle bundle = bundleContext.installBundle(bundleFile); + Bundle bundle = installBundle(bundleContext, bundleFile); logger.info("Bundle installed in " + (currentTimeMillis() - installStart) + " ms: " + string(bundle, false)); installedBundles.add(bundle); + alreadyInstalledBundleNames.add(bundleName); } } diff --git a/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java b/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java index bf65c3f323..0bbf09d101 100644 --- a/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java +++ b/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java @@ -31,8 +31,10 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.lang.reflect.Constructor; import java.net.URI; import java.net.URISyntaxException; @@ -50,6 +52,7 @@ import java.util.zip.ZipInputStream; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; /** * Common functions and constants used by the admin components. @@ -344,6 +347,31 @@ final class NodeLauncherUtil { return path; } } + + static Bundle installBundle(BundleContext bundleContext, String location) throws BundleException, IOException { + // Development mode, copy the MANIFEST.MF file to the bundle location + if (location.endsWith("/target/classes/")) { + File target = file(new URL(location)); + File targetManifest = new File(target, "META-INF/MANIFEST.MF"); + File sourceManifest = new File(target.getParentFile().getParentFile(), "META-INF/MANIFEST.MF"); + targetManifest.getParentFile().mkdirs(); + OutputStream os = new FileOutputStream(targetManifest); + InputStream is = new FileInputStream(sourceManifest); + byte[] buf = new byte[2048]; + for (;;) { + int l = is.read(buf); + if (l == -1) { + break; + } + os.write(buf, 0, l); + } + is.close(); + os.close(); + } + + Bundle bundle = bundleContext.installBundle(location); + return bundle; + } static String string(Bundle b, boolean verbose) { StringBuffer sb = new StringBuffer(); -- cgit v1.2.3