summaryrefslogtreecommitdiffstats
path: root/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java340
1 files changed, 202 insertions, 138 deletions
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 aabfd4bcfe..7cbcdab693 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
@@ -19,20 +19,24 @@
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 java.lang.System.currentTimeMillis;
+import static java.lang.System.setProperty;
+import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.bundleName;
+import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.file;
+import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.fixupBundle;
+import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.runtimeClasspathEntries;
import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.string;
-import static org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME;
+import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.thirdPartyLibraryBundle;
+import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.thisBundleLocation;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.jar.JarFile;
-import java.util.jar.Manifest;
+import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -49,10 +53,16 @@ public class EquinoxHost {
private BundleContext bundleContext;
private Bundle launcherBundle;
- private EquinoxLauncherBundleHelper launcherActivator;
+ private boolean startedEclipse;
+ private List<String> bundleFiles = new ArrayList<String>();
+ private List<String> bundleNames = new ArrayList<String>();
+ private List<String> jarFiles = new ArrayList<String>();
+ private Map<String, Bundle> allBundles = new HashMap<String, Bundle>();
+ private List<Bundle> installedBundles = new ArrayList<Bundle>();
private final static String systemPackages =
- "org.osgi.framework; version=1.3.0," + "org.osgi.service.packageadmin; version=1.2.0, "
+ "org.osgi.framework; version=1.3.0,"
+ + "org.osgi.service.packageadmin; version=1.2.0, "
+ "org.osgi.service.startlevel; version=1.0.0, "
+ "org.osgi.service.url; version=1.0.0, "
+ "org.osgi.util.tracker; version=1.3.2, "
@@ -67,8 +77,8 @@ public class EquinoxHost {
+ "javax.xml.validation, "
+ "javax.xml.xpath, "
// Force the classes to be imported from the system bundle
- // + "javax.xml.stream, "
- // + "javax.xml.stream.util, "
+ + "javax.xml.stream, "
+ + "javax.xml.stream.util, "
+ "javax.sql,"
+ "org.w3c.dom, "
+ "org.xml.sax, "
@@ -88,91 +98,187 @@ public class EquinoxHost {
+ "javax.net.ssl, "
+ "javax.crypto, "
+ "javax.rmi, "
- + "javax.transaction, "
- + "javax.transaction.xa";
-
+ //+ "javax.transaction, "
+ //+ "javax.transaction.xa, "
+ + "org.omg.CosNaming, "
+ + "org.omg.CORBA, "
+ + "org.omg.CORBA.portable, "
+ + "org.omg.PortableServer, "
+ + "org.omg.CosNaming, "
+ + "org.omg.CosNaming.NamingContextExtPackage, "
+ + "org.omg.CosNaming.NamingContextPackage, "
+ + "org.omg.CORBA_2_3.portable, "
+ + "org.omg.IOP, "
+ + "org.omg.PortableInterceptor, "
+ + "org.omg.stub.java.rmi, "
+ + "javax.rmi.CORBA";
+
+ /**
+ * Start the Equinox host.
+ *
+ * @return
+ */
public BundleContext start() {
try {
- // Configure Eclipse properties
- Map<Object, Object> props = new HashMap<Object, Object>();
-
- // Set system packages
- props.put("org.osgi.framework.system.packages", systemPackages);
+ if (!EclipseStarter.isRunning()) {
- // Use the boot classloader as the parent classloader
- props.put("osgi.contextClassLoaderParent", "boot");
-
- // Set startup properties
- props.put(EclipseStarter.PROP_CLEAN, "true");
-
- if (logger.isLoggable(Level.FINE)) {
- props.put("osgi.console", "8085");
- }
-
- // Set location properties
- // FIXME Use proper locations
- props.put(LocationManager.PROP_INSTANCE_AREA, new File("target/workspace").toURI().toString());
- props.put(LocationManager.PROP_INSTALL_AREA, new File("target/eclipse/install").toURI().toString());
- props.put(LocationManager.PROP_CONFIG_AREA, new File("target/eclipse/config").toURI().toString());
- props.put(LocationManager.PROP_USER_AREA, new File("target/eclipse/user").toURI().toString());
-
- // Find the Tuscany JARs
- File tuscanyInstallDir = findTuscanyInstallDir();
- List<URL> urls;
- if (tuscanyInstallDir != null) {
- urls = JarFileFinder.findJarFiles(tuscanyInstallDir, new JarFileFinder.StandAloneJARFileNameFilter());
+ // Configure Eclipse properties
+ Map<Object, Object> props = new HashMap<Object, Object>();
+
+ // Set system packages
+ props.put("org.osgi.framework.system.packages", systemPackages);
+
+ // Use the boot classloader as the parent classloader
+ props.put("osgi.contextClassLoaderParent", "boot");
+
+ // Set startup properties
+ props.put(EclipseStarter.PROP_CLEAN, "true");
+
+ if (logger.isLoggable(Level.FINE)) {
+ props.put("osgi.console", "8085");
+ }
+
+ // Set location properties
+ // FIXME Use proper locations
+ props.put(LocationManager.PROP_INSTANCE_AREA, new File("target/workspace").toURI().toString());
+ props.put(LocationManager.PROP_INSTALL_AREA, new File("target/eclipse/install").toURI().toString());
+ props.put(LocationManager.PROP_CONFIG_AREA, new File("target/eclipse/config").toURI().toString());
+ props.put(LocationManager.PROP_USER_AREA, new File("target/eclipse/user").toURI().toString());
+
+ EclipseStarter.setInitialProperties(props);
+
+ // Start Eclipse
+ bundleContext = EclipseStarter.startup(new String[]{}, null);
+ startedEclipse = true;
+
} else {
- urls = JarFileFinder.getClassPathEntries(JarFileFinder.class.getClassLoader(), false);
+
+ // Get bundle context from the running Eclipse instance
+ bundleContext = EclipseStarter.getSystemBundleContext();
}
+
+ // Determine the runtime classpath entries
+ Set<URL> urls = runtimeClasspathEntries();
// Sort out which are bundles (and not already installed) and which are just
// regular JARs
- StringBuffer bundleFiles = new StringBuffer();
- StringBuffer bundleNames = new StringBuffer();
- StringBuffer jarFiles = new StringBuffer();
for (URL url : urls) {
- File file = NodeLauncherUtil.file(url);
- String bundleName = getBundleName(file);
+ File file = file(url);
+ String bundleName = bundleName(file);
if (bundleName != null) {
- bundleFiles.append(url.toString() + ";");
- bundleNames.append(bundleName + ";");
+ bundleFiles.add(url.toString());
+ bundleNames.add(bundleName);
} else {
if (file.isFile()) {
- jarFiles.append(url.toString() + ";");
+ jarFiles.add(url.toString());
}
}
}
- props.put("org.apache.tuscany.sca.node.launcher.equinox.bundleFiles", bundleFiles.toString());
- props.put("org.apache.tuscany.sca.node.launcher.equinox.bundleNames", bundleNames.toString());
- props.put("org.apache.tuscany.sca.node.launcher.equinox.jarFiles", jarFiles.toString());
-
- EclipseStarter.setInitialProperties(props);
-
- // Start Eclipse
- bundleContext = EclipseStarter.startup(new String[]{}, null);
+
+ // Get the already installed bundles
+ for (Bundle bundle: bundleContext.getBundles()) {
+ allBundles.put(bundle.getSymbolicName(), bundle);
+ }
+
+ // Install the launcher bundle if necessary
+ String launcherBundleName = "org.apache.tuscany.sca.node.launcher.equinox";
+ String launcherBundleLocation;
+ launcherBundle = allBundles.get(launcherBundleName);
+ if (launcherBundle == null) {
+ launcherBundleLocation = thisBundleLocation();
+ logger.info("Installing launcher bundle: " + launcherBundleLocation);
+ fixupBundle(launcherBundleLocation);
+ launcherBundle = bundleContext.installBundle(launcherBundleLocation);
+ allBundles.put(launcherBundleName, launcherBundle);
+ installedBundles.add(launcherBundle);
+ } else {
+ logger.info("Launcher bundle is already installed: " + string(launcherBundle, false));
+ launcherBundleLocation = thisBundleLocation(launcherBundle);
+ }
- // Install the launcher bundle
- String bundleLocation = bundleLocation();
- logger.info("Installing launcher bundle: " + bundleLocation);
- launcherBundle = installBundle(bundleContext, bundleLocation);
- logger.info("Starting bundle: " + string(launcherBundle, false));
- launcherBundle.start();
+ // Install the Tuscany bundles
+ long start = currentTimeMillis();
+
+ // FIXME: SDO bundles dont have the correct dependencies
+ setProperty("commonj.sdo.impl.HelperProvider", "org.apache.tuscany.sdo.helper.HelperProviderImpl");
+
+ // Install a single 'library' bundle for the third-party JAR files
+ String libraryBundleName = "org.apache.tuscany.sca.node.launcher.equinox.libraries";
+ Bundle libraryBundle = allBundles.get(libraryBundleName);
+ if (libraryBundle == null) {
+ logger.info("Generating third-party library bundle.");
+ for (String jarFile: jarFiles) {
+ logger.info("Adding third-party jar: " + jarFile);
+ }
+ long libraryStart = currentTimeMillis();
+ InputStream library = thirdPartyLibraryBundle(jarFiles);
+ logger.info("Third-party library bundle generated in " + (currentTimeMillis() - libraryStart) + " ms.");
+ libraryStart = currentTimeMillis();
+ libraryBundle = bundleContext.installBundle("org.apache.tuscany.sca.node.launcher.equinox.libraries", library);
+ allBundles.put(libraryBundleName, libraryBundle);
+ installedBundles.add(libraryBundle);
+ logger.info("Third-party library bundle installed in " + (currentTimeMillis() - libraryStart) + " ms: " + string(libraryBundle, false));
+ } else {
+ logger.info("Third-party library bundle is already installed: " + string(libraryBundle, false));
+ }
- // Manually call the LauncherBundleActivator for now
- launcherActivator = new EquinoxLauncherBundleHelper();
- launcherActivator.start(launcherBundle.getBundleContext());
+ // Install all the other bundles that are not already installed
+ for (int i =0, n = bundleFiles.size(); i < n; i++) {
+ String bundleFile = bundleFiles.get(i);
+ fixupBundle(bundleFile);
+ }
+ for (int i =0, n = bundleFiles.size(); i < n; i++) {
+ String bundleFile = bundleFiles.get(i);
+ String bundleName = bundleNames.get(i);
+ if (bundleName.contains("org.eclipse.jdt.junit")) {
+ continue;
+ }
+ if (bundleName.contains("host.openejb")) {
+ continue;
+ }
+ Bundle bundle = allBundles.get(bundleName);
+ if (bundle == null) {
+ long installStart = currentTimeMillis();
+ bundle = bundleContext.installBundle(bundleFile);
+ logger.info("Bundle installed in " + (currentTimeMillis() - installStart) + " ms: " + string(bundle, false));
+ allBundles.put(bundleName, bundle);
+ installedBundles.add(bundle);
+ }
+ }
+
+ long end = currentTimeMillis();
+ logger.info("Tuscany bundles are installed in " + (end - start) + " ms.");
- // Start all bundles for now to help diagnose any class loading issues
+ // Start the extensiblity and launcher bundles
long activateStart = System.currentTimeMillis();
+ String extensibilityBundleName = "org.apache.tuscany.sca.extensibility.equinox";
+ Bundle extensibilityBundle = allBundles.get(extensibilityBundleName);
+ if ((extensibilityBundle.getState() & Bundle.ACTIVE) == 0) {
+ logger.info("Starting bundle: " + string(extensibilityBundle, false));
+ extensibilityBundle.start();
+ } else {
+ logger.info("Bundle is already started: " + string(extensibilityBundle, false));
+ }
+ if ((launcherBundle.getState() & Bundle.ACTIVE) == 0) {
+ logger.info("Starting bundle: " + string(launcherBundle, false));
+ launcherBundle.start();
+ } else {
+ logger.info("Bundle is already started: " + string(launcherBundle, false));
+ }
+
+ // Start all our bundles for now to help diagnose any class loading issues
for (Bundle bundle: bundleContext.getBundles()) {
- if ((bundle.getState() & Bundle.ACTIVE) == 0) {
- logger.info("Starting bundle: " + string(bundle, false));
- try {
- bundle.start();
- } catch (Exception e) {
- logger.log(Level.SEVERE, e.getMessage(), e);
+ if (bundle.getSymbolicName().startsWith("org.apache.tuscany.sca")) {
+ if ((bundle.getState() & Bundle.ACTIVE) == 0) {
+ logger.info("Starting bundle: " + string(bundle, false));
+ try {
+ bundle.start();
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, e.getMessage(), e);
+ throw e;
+ }
+ logger.info("Bundle: " + string(bundle, false));
}
- logger.info("Bundle: " + string(bundle, false));
}
}
logger.info("Tuscany bundles are started in " + (System.currentTimeMillis() - activateStart) + " ms.");
@@ -182,78 +288,36 @@ public class EquinoxHost {
throw new IllegalStateException(e);
}
}
-
+
+ /**
+ * Stop the Equinox host.
+ */
public void stop() {
try {
- // Uninstall the launcher bundle
- if (launcherActivator != null) {
- launcherActivator.stop(launcherBundle.getBundleContext());
+ // Uninstall all the bundles we've installed
+ for (int i = installedBundles.size() -1; i >= 0; i--) {
+ Bundle bundle = installedBundles.get(i);
+ try {
+ //if (logger.isLoggable(Level.FINE)) {
+ logger.info("Uninstalling bundle: " + string(bundle, false));
+ //}
+ bundle.uninstall();
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, e.getMessage(), e);
+ }
}
- if (launcherBundle != null) {
- logger.info("Uninstalling bundle: " + string(launcherBundle, false));
- launcherBundle.uninstall();
+ installedBundles.clear();
+
+ // Shutdown Eclipse if we started it ourselves
+ if (startedEclipse) {
+ startedEclipse = false;
+ EclipseStarter.shutdown();
}
-
- // Shutdown Eclipse
- EclipseStarter.shutdown();
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
- private static File findTuscanyInstallDir() throws IOException {
- String tuscanyDirName = JarFileFinder.getProperty(JarFileFinder.TUSCANY_HOME);
- if (tuscanyDirName != null) {
- File tuscanyInstallDir = new File(tuscanyDirName);
- if (tuscanyInstallDir.exists() && tuscanyInstallDir.isDirectory())
- return tuscanyInstallDir;
- }
- return null;
- }
-
- /**
- * Returns the name of a bundle, or null if the given file is not a bundle.
- *
- * @param file
- * @return
- * @throws IOException
- */
- private static String getBundleName(File file) throws IOException {
- if (!file.exists()) {
- return null;
- }
- String bundleName = null;
- if (file.isDirectory()) {
- File mf = new File(file, "META-INF/MANIFEST.MF");
- 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);
- Manifest manifest = jar.getManifest();
- bundleName = manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME);
- jar.close();
- }
- if (bundleName == null) {
- return bundleName;
- }
- int sc = bundleName.indexOf(';');
- if (sc != -1) {
- bundleName = bundleName.substring(0, sc);
- }
- return bundleName;
- }
-
}