diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:07:19 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:07:19 +0000 |
commit | 6fadbc9cd1fcf03d0b3630f772d91df149b70428 (patch) | |
tree | 32752e491abb97fc8ef4f246455e3b5fd2814862 /sca-java-1.x/branches/sca-java-1.0.1/modules/osgi-runtime/src | |
parent | 5559ef5edbf8d3616f7a4b497b2a459b0ee4082b (diff) |
Moving 1.x branches
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835123 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-1.x/branches/sca-java-1.0.1/modules/osgi-runtime/src')
7 files changed, 822 insertions, 0 deletions
diff --git a/sca-java-1.x/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/EquinoxRuntime.java b/sca-java-1.x/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/EquinoxRuntime.java new file mode 100644 index 0000000000..65a453bfc2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/EquinoxRuntime.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.osgi.runtime; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import org.osgi.framework.BundleContext; + +public class EquinoxRuntime extends OSGiRuntime { + + + private static BundleContext bundleContext; + + private static EquinoxRuntime instance; + + private static Class eclipseStarterClass; + + public static OSGiRuntime getInstance() throws Exception { + if (instance == null) { + EquinoxRuntime runtime = new EquinoxRuntime(); + runtime.startRuntime(); + instance = runtime; + } + return instance; + } + + + protected BundleContext startRuntime() throws Exception { + + if (bundleContext != null) + return bundleContext; + + eclipseStarterClass = EquinoxRuntime.class.getClassLoader().loadClass("org.eclipse.core.runtime.adaptor.EclipseStarter"); + Method startupMethod = eclipseStarterClass.getMethod("startup", String [].class, Runnable.class); + + // Equinox version 3.2 upwards have a startup method which returns BundleContext + if (startupMethod.getReturnType() == BundleContext.class) { + bundleContext = (BundleContext) startupMethod.invoke(null, new String[] {"-clean", "-console"}, null ); + } + else { + + // Older versions of Equinox dont have a public method to obtain system bundlecontext + // Extract bundleContext from the private field 'context'. We are assuming that + // there is no access restriction + Method mainMethod = eclipseStarterClass.getMethod("main", String [].class); + mainMethod.invoke(null, (Object)new String[] {"-clean", "-console"}); + + Field contextField = eclipseStarterClass.getDeclaredField("context"); + contextField.setAccessible(true); + bundleContext = (BundleContext) contextField.get(null); + + } + + + return bundleContext; + + } + + @Override + public BundleContext getBundleContext() { + return bundleContext; + } + + @Override + public void shutdown() throws Exception { + + if (bundleContext == null) + return; + bundleContext = null; + instance = null; + if (eclipseStarterClass != null) { + Method shutdownMethod = eclipseStarterClass.getMethod("shutdown"); + try { + shutdownMethod.invoke(eclipseStarterClass); + } catch (Exception e) { + // Ignore errors. + } + } + super.shutdown(); + } + + + @Override + public boolean supportsBundleFragments() { + return false; + } + + + +} diff --git a/sca-java-1.x/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/FelixRuntime.java b/sca-java-1.x/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/FelixRuntime.java new file mode 100644 index 0000000000..3a9ac04230 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/FelixRuntime.java @@ -0,0 +1,194 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.osgi.runtime; + +import java.io.File; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class FelixRuntime extends OSGiRuntime implements BundleActivator { + + private static BundleContext bundleContext; + + private static FelixRuntime instance; + + private static Class felixClass; + private static Object felix; + + public static OSGiRuntime getInstance() throws Exception { + if (instance == null) { + FelixRuntime runtime = new FelixRuntime(); + runtime.startRuntime(); + instance = runtime; + } + return instance; + } + + + private static void deleteDirectory(File dir) { + + File[] files = dir.listFiles(); + for (int i = 0; i < files.length; i++) { + if (files[i].isDirectory()) + deleteDirectory(files[i]); + else + files[i].delete(); + } + dir.delete(); + + } + + protected BundleContext startRuntime() throws Exception { + + if (bundleContext != null) + return bundleContext; + + + ClassLoader cl = FelixRuntime.class.getClassLoader(); + + Class felixMainClass = cl.loadClass("org.apache.felix.main.Main"); + felixClass = cl.loadClass("org.apache.felix.framework.Felix"); + Method propsMethod = felixMainClass.getMethod("loadConfigProperties"); + Properties props = (Properties)propsMethod.invoke(null); + + File profileDir = new File(".felix"); + if (profileDir.isDirectory()) + deleteDirectory(profileDir); + else + profileDir.delete(); + profileDir.mkdir(); + profileDir.deleteOnExit(); + + props.put("felix.cache.profiledir", profileDir.getAbsolutePath()); + props.put("felix.embedded.execution", "true"); + props.put("org.osgi.framework.system.packages", + "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.osoa.sca.annotations; version=1.0.0, " + + "org.osoa.sca; version=1.0.0"); + + + try { + Constructor felixConstructor = felixClass.getConstructor(Map.class, List.class); + List<BundleActivator> activators = new ArrayList<BundleActivator>(); + felix = felixConstructor.newInstance(props, activators); + ((Bundle)felix).start(); + bundleContext = ((Bundle)felix).getBundleContext(); + + + } catch (Exception e) { + + // This is the older Felix API which has been retained temporarily to avoid build break + // TODO: Remove these once Felix 1.0.0 is released. + + Class propertyResolverClass = cl.loadClass("org.apache.felix.framework.util.MutablePropertyResolver"); + Class propertyResolverImplClass = cl.loadClass("org.apache.felix.framework.util.MutablePropertyResolverImpl"); + + Constructor implConstructor = propertyResolverImplClass.getConstructor(Map.class); + Object mutableProps = implConstructor.newInstance(props); + + + try { + Constructor felixConstructor = felixClass.getConstructor(propertyResolverClass, List.class); + List<BundleActivator> activators = new ArrayList<BundleActivator>(); + felix = felixConstructor.newInstance(mutableProps, activators); + ((Bundle)felix).start(); + bundleContext = ((Bundle)felix).getBundleContext(); + } catch (Exception e1) { + + + felix = felixClass.newInstance(); + Method startMethod = felixClass.getMethod("start", propertyResolverClass, List.class); + List<BundleActivator> activators = new ArrayList<BundleActivator>(); + BundleActivator activator = new FelixRuntime(); + activators.add(activator); + startMethod.invoke(felix, mutableProps, activators); + + synchronized (activator) { + int retries = 0; + while (bundleContext == null && retries++ < 10) { + activator.wait(1000); + } + } + } + } + + return bundleContext; + + } + + public void start(BundleContext context) throws Exception { + + bundleContext = context; + synchronized (this) { + this.notify(); + } + } + + public void stop(BundleContext context) throws Exception { + bundleContext = null; + } + + + + @Override + public BundleContext getBundleContext() { + return bundleContext; + } + + + @Override + public void shutdown() throws Exception { + + if (bundleContext == null) + return; + bundleContext = null; + instance = null; + + if (felix instanceof Bundle) { + ((Bundle)felix).stop(); + } + else if (felix != null) { + Method shutdownMethod = felixClass.getMethod("shutdown"); + try { + shutdownMethod.invoke(felix); + } catch (Exception e) { + // Ignore errors + } + felix = null; + } + super.shutdown(); + } + + @Override + public boolean supportsBundleFragments() { + return false; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/KnopflerfishRuntime.java b/sca-java-1.x/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/KnopflerfishRuntime.java new file mode 100644 index 0000000000..248ad05a39 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/KnopflerfishRuntime.java @@ -0,0 +1,157 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.osgi.runtime; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.Hashtable; + +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; + +public class KnopflerfishRuntime extends OSGiRuntime { + + private static BundleContext bundleContext; + + private static KnopflerfishRuntime instance; + + + private static Class frameworkClass; + + private static Object framework; + + public static OSGiRuntime getInstance() throws Exception { + if (instance == null) { + KnopflerfishRuntime runtime = new KnopflerfishRuntime(); + runtime.startRuntime(); + instance = runtime; + } + return instance; + } + + + + // FIXME: Knopflerfish does not expose the methods used for configuration as public methods + // It may be worth using the private methods in org.knopflerfish.framework.Main for + // configuring using reflection if security policies allow it. + // For now, a simple configuration routine reads sca.xargs from the directory in + // the classpath which contains framework.jar. The entries in init.xargs starting with + // -install are assumed to be single-line entries with full bundle location. + // + protected BundleContext startRuntime() throws Exception { + + if (bundleContext != null) + return bundleContext; + + + + System.setProperty("org.knopflerfish.framework.bundlestorage", "memory"); + + frameworkClass = KnopflerfishRuntime.class.getClassLoader().loadClass("org.knopflerfish.framework.Framework"); + Constructor frameworkConstructor = frameworkClass.getConstructor(Object.class); + framework = frameworkConstructor.newInstance(new KnopflerfishRuntime()); + Method launchMethod = frameworkClass.getMethod("launch", long.class); + launchMethod.invoke(framework, 0); + Method getContextMethod = frameworkClass.getMethod("getSystemBundleContext"); + bundleContext = (BundleContext)getContextMethod.invoke(framework); + + System.setProperty("com.gatespace.bundle.cm.store", "knopflerfish.store"); + File xargsFile = null; + String classpath = System.getProperty("java.class.path"); + String[] classpathEntries = classpath.split(System.getProperty("path.separator")); + for (int i = 0; i < classpathEntries.length; i++) { + if (classpathEntries[i].endsWith("framework.jar")) { + String path = classpathEntries[i].substring(0, classpathEntries[i].length() - "framework.jar".length()); + path = path + "sca.xargs"; + xargsFile = new File(path); + if (!xargsFile.exists()) + xargsFile = null; + break; + } + } + if (xargsFile != null) { + BufferedReader reader = new BufferedReader(new FileReader(xargsFile)); + String line; + Hashtable<String, Bundle> bundles = new Hashtable<String, Bundle>(); + while ((line = reader.readLine()) != null) { + line = line.trim(); + if (line.startsWith("-install")) { + try { + + String bundleLocation = line.substring("-install".length()).trim(); + Bundle bundle = bundleContext.installBundle(bundleLocation); + bundles.put(bundleLocation, bundle); + + } catch (BundleException e) { + e.printStackTrace(); + } + + } + if (line.startsWith("-start")) { + + try { + String bundleLocation = line.substring("-start".length()).trim(); + Bundle bundle = bundles.get(bundleLocation); + bundle.start(); + } catch (BundleException e) { + e.printStackTrace(); + } + } + } + } + + + return bundleContext; + + } + + @Override + public BundleContext getBundleContext() { + return bundleContext; + } + + @Override + public void shutdown() throws Exception { + + if (bundleContext == null) + return; + bundleContext = null; + instance = null; + if (framework != null) { + Method shutdownMethod = frameworkClass.getMethod("shutdown"); + try { + shutdownMethod.invoke(framework); + } catch (Exception e) { + // Ignore errors + } + framework = null; + } + super.shutdown(); + + } + + @Override + public boolean supportsBundleFragments() { + return true; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/OSGiRuntime.java b/sca-java-1.x/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/OSGiRuntime.java new file mode 100644 index 0000000000..6ea2a030cf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/OSGiRuntime.java @@ -0,0 +1,209 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.osgi.runtime; + +import java.io.InputStream; +import java.lang.reflect.Method; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; +import org.osgi.service.packageadmin.PackageAdmin; + +public abstract class OSGiRuntime { + private static final Logger logger = Logger.getLogger(OSGiRuntime.class.getName()); + + public abstract BundleContext getBundleContext(); + + public abstract boolean supportsBundleFragments(); + + protected abstract BundleContext startRuntime() throws Exception; + + private static OSGiRuntime instance; + + private BundleContext bundleContext; + + private PackageAdmin packageAdmin; + + /** + * System property org.apache.tuscany.implementation.osgi.runtime.OSGiRuntime can be set to the + * name of the OSGiRuntime class (eg. EquinoxRuntime). If set, start this runtime and return the + * system bundlecontext. If not set, start Equinox/Felix/Knopflerfish (in that order) from the + * classpath. + * + * @throws BundleException + */ + public synchronized static OSGiRuntime getRuntime() throws Exception { + if (instance != null) { + + if (instance.bundleContext == null) { + instance.startRuntime(); + instance.initialize(); + } + return instance; + } + String runtimeClassName = System.getProperty(OSGiRuntime.class.getName()); + + if (instance != null) + return instance; + + if (runtimeClassName != null) { + try { + Class<?> runtimeClass = OSGiRuntime.class.getClassLoader().loadClass(runtimeClassName); + Method method = runtimeClass.getMethod("getInstance"); + instance = (OSGiRuntime) method.invoke(null); + instance.initialize(); + return instance; + + } catch (Exception e) { + throw new BundleException("Could not start OSGi runtime " + runtimeClassName, e); + } + } + + try { + + instance = EquinoxRuntime.getInstance(); + instance.initialize(); + return instance; + + } catch (ClassNotFoundException e) { + // Ignore + } catch (Throwable e) { + logger.log(Level.SEVERE, e.getMessage(), e); + } + + try { + + instance = FelixRuntime.getInstance(); + instance.initialize(); + return instance; + + } catch (ClassNotFoundException e) { + // Ignore + } catch (Throwable e) { + logger.log(Level.SEVERE, e.getMessage(), e); + } + + try { + + instance = KnopflerfishRuntime.getInstance(); + instance.initialize(); + return instance; + + } catch (ClassNotFoundException e) { + // Ignore + } catch (Throwable e) { + logger.log(Level.SEVERE, e.getMessage(), e); + } + + throw new BundleException("Could not start OSGi runtime from the classpath"); + } + + + public void shutdown() throws Exception { + + bundleContext = null; + packageAdmin = null; + } + + private void initialize() { + + bundleContext = getBundleContext(); + + if (bundleContext != null) { + + org.osgi.framework.ServiceReference packageAdminReference = + bundleContext.getServiceReference("org.osgi.service.packageadmin.PackageAdmin"); + if (packageAdminReference != null) { + + packageAdmin = (PackageAdmin)bundleContext.getService(packageAdminReference); + } + } + + } + + public Bundle findBundle(String bundleSymbolicName, String bundleVersion) { + + if (bundleContext != null) { + Bundle[] installedBundles = bundleContext.getBundles(); + for (Bundle bundle : installedBundles) { + if (bundleSymbolicName.equals(bundle.getSymbolicName()) && (bundleVersion == null || bundleVersion + .equals(bundle.getHeaders().get("Bundle-Version")))) + return bundle; + } + + } + return null; + } + + public synchronized static Bundle findInstalledBundle(String bundleLocation) { + if (instance != null) { + return instance.findBundle(bundleLocation); + } + return null; + } + + public Bundle findBundle(String bundleLocation) { + + if (bundleContext != null) { + Bundle[] installedBundles = bundleContext.getBundles(); + for (Bundle bundle : installedBundles) { + if (bundle.getLocation().equals(bundleLocation)) + return bundle; + } + + } + return null; + } + + public Bundle installBundle(String bundleLocation, InputStream inputStream) { + + try { + if (bundleContext != null) { + Bundle bundle = findBundle(bundleLocation); + if (bundle != null) + return bundle; + if (inputStream == null) + bundle = bundleContext.installBundle(bundleLocation); + else + bundle = bundleContext.installBundle(bundleLocation, inputStream); + + if (bundle != null && packageAdmin != null) + packageAdmin.refreshPackages(null); + + return bundle; + } + } catch (BundleException e) { + } + return null; + } + + /** + * @return the instance + */ + public synchronized static void stop() throws Exception { + if (instance != null) { + instance.shutdown(); + instance = null; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/OSGiRuntimeModuleActivator.java b/sca-java-1.x/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/OSGiRuntimeModuleActivator.java new file mode 100644 index 0000000000..3f2064b621 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/OSGiRuntimeModuleActivator.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.osgi.runtime; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModuleActivator; + +/** + * @version $Rev$ $Date$ + */ +public class OSGiRuntimeModuleActivator implements ModuleActivator { + + /** + * @see org.apache.tuscany.sca.core.ModuleActivator#start(org.apache.tuscany.sca.core.ExtensionPointRegistry) + */ + public void start(ExtensionPointRegistry registry) { + } + + /** + * @see org.apache.tuscany.sca.core.ModuleActivator#stop(org.apache.tuscany.sca.core.ExtensionPointRegistry) + */ + public void stop(ExtensionPointRegistry registry) { + try { + OSGiRuntime.stop(); + } catch (Exception e) { + // Ignore the exception + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/sca-java-1.x/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator new file mode 100644 index 0000000000..88b8f1e021 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.0.1/modules/osgi-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator @@ -0,0 +1,36 @@ +# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# Implementation class for the ModuleActivator
+org.apache.tuscany.sca.osgi.runtime.OSGiRuntimeModuleActivator
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# Implementation class for the ModuleActivator
+org.apache.tuscany.sca.osgi.runtime.OSGiRuntimeModuleActivator
diff --git a/sca-java-1.x/branches/sca-java-1.0.1/modules/osgi-runtime/src/test/java/org/apache/tuscany/sca/osgi/runtime/OSGiRuntimeTestCase.java b/sca-java-1.x/branches/sca-java-1.0.1/modules/osgi-runtime/src/test/java/org/apache/tuscany/sca/osgi/runtime/OSGiRuntimeTestCase.java new file mode 100644 index 0000000000..8bc77b5bb6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.0.1/modules/osgi-runtime/src/test/java/org/apache/tuscany/sca/osgi/runtime/OSGiRuntimeTestCase.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.osgi.runtime; + +import junit.framework.TestCase; + +import org.osgi.framework.BundleContext; + +/** + * Test OSGi runtime. + * + */ +public class OSGiRuntimeTestCase extends TestCase { + private OSGiRuntime runtime; + + /** + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + this.runtime = OSGiRuntime.getRuntime(); + } + + /** + * @see junit.framework.TestCase#tearDown() + */ + @Override + protected void tearDown() throws Exception { + OSGiRuntime.stop(); + } + + public void testRuntime() throws Exception { + + BundleContext bc1 = runtime.getBundleContext(); + + assertNotNull(bc1); + + BundleContext bc2 = runtime.getBundleContext(); + + assertNotNull(bc2); + + assertTrue(bc1 == bc2); + + OSGiRuntime.stop(); + runtime = OSGiRuntime.getRuntime(); + + BundleContext bc3 = runtime.getBundleContext(); + + assertNotNull(bc3); + + assertTrue(bc1 != bc3); + + } + +} |