From 271d327a61ef1b2271219dae8f0ae0472ab377d0 Mon Sep 17 00:00:00 2001 From: rfeng Date: Thu, 16 Jul 2009 17:19:46 +0000 Subject: Experiement the framework launch APIs to bootstrap an OSGi runtime without dependencies on the runtime-specific code git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@794760 13f79535-47bb-0310-9956-ffa450edef68 --- .../extensibility-equinox/META-INF/MANIFEST.MF | 4 +- .../equinox/EquinoxServiceDiscovererTestCase.java | 1 + .../sca/extensibility/equinox/TestEquinoxHost.java | 78 ++++++++-------------- 3 files changed, 30 insertions(+), 53 deletions(-) (limited to 'java/sca/modules') diff --git a/java/sca/modules/extensibility-equinox/META-INF/MANIFEST.MF b/java/sca/modules/extensibility-equinox/META-INF/MANIFEST.MF index 06764168e6..a613976264 100644 --- a/java/sca/modules/extensibility-equinox/META-INF/MANIFEST.MF +++ b/java/sca/modules/extensibility-equinox/META-INF/MANIFEST.MF @@ -18,8 +18,8 @@ Bundle-Description: Apache Tuscany SCA Extensibility for Eclipse Equin Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt Import-Package: org.apache.tuscany.sca.core;version="2.0.0", org.apache.tuscany.sca.extensibility;version="2.0.0", - org.eclipse.core.runtime.adaptor;resolution:=optional, - org.osgi.framework;version="1.4" + org.osgi.framework;version="1.4", + org.osgi.framework.launch;version="1.0.0";resolution:=optional Bundle-SymbolicName: org.apache.tuscany.sca.extensibility.equinox Bundle-DocURL: http://www.apache.org/ Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6 diff --git a/java/sca/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscovererTestCase.java b/java/sca/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscovererTestCase.java index 8010ead253..2ed3cfd82c 100644 --- a/java/sca/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscovererTestCase.java +++ b/java/sca/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscovererTestCase.java @@ -130,6 +130,7 @@ public class EquinoxServiceDiscovererTestCase { testBundle.uninstall(); } host.stop(); + System.out.println("Done"); } @Test diff --git a/java/sca/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/TestEquinoxHost.java b/java/sca/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/TestEquinoxHost.java index e000faa447..b184efed48 100644 --- a/java/sca/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/TestEquinoxHost.java +++ b/java/sca/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/TestEquinoxHost.java @@ -23,67 +23,40 @@ import java.io.File; import java.util.HashMap; import java.util.Map; -import org.eclipse.core.runtime.adaptor.EclipseStarter; -import org.eclipse.core.runtime.adaptor.LocationManager; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; +import org.apache.tuscany.sca.extensibility.ServiceDiscovery; import org.osgi.framework.BundleContext; +import org.osgi.framework.launch.Framework; +import org.osgi.framework.launch.FrameworkFactory; /** * A test host that starts/stops Equinox. * * @version $Rev: $ $Date: $ */ -public class TestEquinoxHost { +public class TestEquinoxHost { + private Framework framework; - private final static String systemPackages = - "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, " - + "javax.xml, " - + "javax.xml.datatype, " - + "javax.xml.namespace, " - + "javax.xml.parsers, " - + "javax.xml.transform, " - + "javax.xml.transform.dom, " - + "javax.xml.transform.sax, " - + "javax.xml.transform.stream, " - + "javax.xml.validation, " - + "javax.xml.xpath, " - // Force the classes to be imported from the system bundle - + "javax.xml.stream, " - + "javax.xml.stream.util, " - + "javax.sql," - + "org.w3c.dom, " - + "org.xml.sax, " - + "org.xml.sax.ext, " - + "org.xml.sax.helpers, " - + "javax.security.auth, " - + "javax.security.cert, " - + "javax.security.auth.login, " - + "javax.security.auth.callback, " - + "javax.naming, " - + "javax.naming.spi, " - + "javax.naming.directory, " - + "javax.management, " - + "javax.imageio, " - + "sun.misc, " - + "javax.net, " - + "javax.net.ssl, " - + "javax.crypto, " - + "javax.rmi, " - + "javax.transaction, " - + "javax.transaction.xa"; + private BundleContext init() throws Exception { + if (framework != null) { + throw new IllegalStateException("The framework is started already"); + } + ServiceDeclaration sd = ServiceDiscovery.getInstance().getServiceDeclaration(FrameworkFactory.class.getName()); + Class factoryCls = sd.loadClass(); + FrameworkFactory factory = (FrameworkFactory)factoryCls.newInstance(); + Map props = new HashMap(); + props.put("osgi.clean", "true"); + props.put("osgi.instance.area", new File("target/workspace").toURI().toString()); + props.put("osgi.install.area", new File("target/eclipse").toURI().toString()); + props.put("osgi.configuration.area", new File("target/eclipse").toURI().toString()); + framework = factory.newFramework(props); + framework.start(); + return framework.getBundleContext(); + } public BundleContext start() { try { - Map props = new HashMap(); - props.put("org.osgi.framework.system.packages", systemPackages); - props.put(EclipseStarter.PROP_CLEAN, "true"); - props.put(LocationManager.PROP_INSTANCE_AREA, new File("target/workspace").toURI().toString()); - props.put(LocationManager.PROP_INSTALL_AREA, new File("target/eclipse").toURI().toString()); - EclipseStarter.setInitialProperties(props); - BundleContext context = EclipseStarter.startup(new String[]{}, null); - return context; + return init(); } catch (Exception e) { throw new IllegalStateException(e); } @@ -91,7 +64,10 @@ public class TestEquinoxHost { public void stop() { try { - EclipseStarter.shutdown(); + if (framework != null) { + framework.stop(); + framework = null; + } } catch (Exception e) { throw new IllegalStateException(e); } -- cgit v1.2.3