Author: rsivaram
Date: Thu May 15 13:34:32 2008
New Revision: 656822
URL: http://svn.apache.org/viewvc?rev=656822&view=rev
Log:
Enable Equinox support in itest/osgi-tuscany
Added:
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/osgi/runtime/impl/EquinoxTestRuntime.java
(with props)
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/harness/OSGiTuscanyNonOSGiTestHarness.java
(with props)
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/tuscany/NonOSGiSamplesTestCase.java
(with props)
Removed:
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/harness/TestBundleActivator.java
Modified:
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/pom.xml
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/osgi/runtime/impl/FelixTestRuntime.java
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/osgi/runtime/impl/OSGiTestRuntime.java
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/util/OSGiRuntimeLoader.java
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/harness/OSGiTuscanyTestHarness.java
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/resources/META-INF/MANIFEST.MF
incubator/tuscany/java/sca/itest/osgi-tuscany/tuscany-manifest/src/main/java/org/apache/tuscany/sca/manifest/ManifestBundleActivator.java
incubator/tuscany/java/sca/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/OSGiBundleActivator.java
Modified:
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/pom.xml?rev=656822&r1=656821&r2=656822&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/pom.xml
(original)
+++ incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/pom.xml Thu
May 15 13:34:32 2008
@@ -31,6 +31,15 @@
<dependencies>
<dependency>
+ <groupId>org.eclipse</groupId>
+ <artifactId>osgi</artifactId>
+ <version>3.3.2.R33x_v20080105</version>
+ </dependency>
+
+
+<!-- Uncomment this section and comment out the Equinox dependency above to
run tests using Felix.
+
+ <dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.main</artifactId>
<version>1.1.0-SNAPSHOT</version>
@@ -46,7 +55,6 @@
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.configadmin</artifactId>
<version>1.0.0</version>
- <!-- Exclude the javax.servlet to avoid conflict -->
<exclusions>
<exclusion>
<groupId>org.apache.felix</groupId>
@@ -61,6 +69,8 @@
<version>1.0.0</version>
</dependency>
+End Felix dependencies -->
+
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -82,4 +92,14 @@
</plugins>
</build>
+ <repositories>
+ <repository>
+ <id>ops4j-repository</id>
+ <url>http://repository.ops4j.org/maven2</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+
</project>
Added:
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/osgi/runtime/impl/EquinoxTestRuntime.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/osgi/runtime/impl/EquinoxTestRuntime.java?rev=656822&view=auto
==============================================================================
---
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/osgi/runtime/impl/EquinoxTestRuntime.java
(added)
+++
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/osgi/runtime/impl/EquinoxTestRuntime.java
Thu May 15 13:34:32 2008
@@ -0,0 +1,91 @@
+/*
+ * 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.test.osgi.runtime.impl;
+
+import java.lang.reflect.Method;
+
+import org.osgi.framework.BundleContext;
+
+public class EquinoxTestRuntime extends OSGiTestRuntime {
+
+
+ private static BundleContext bundleContext;
+
+ private static EquinoxTestRuntime instance;
+
+ private static Class<?> eclipseStarterClass;
+
+ public static OSGiTestRuntime getInstance() throws Exception {
+ if (instance == null) {
+ eclipseStarterClass =
EquinoxTestRuntime.class.getClassLoader().loadClass("org.eclipse.core.runtime.adaptor.EclipseStarter");
+ EquinoxTestRuntime runtime = new EquinoxTestRuntime();
+ instance = runtime;
+ }
+ return instance;
+ }
+
+
+ protected BundleContext startRuntime() throws Exception {
+
+ if (bundleContext != null)
+ return bundleContext;
+
+ Method startupMethod = eclipseStarterClass.getMethod("startup", String
[].class, Runnable.class);
+
+ // Equinox version 3.2 upwards have a startup method which returns
BundleContext
+ bundleContext = (BundleContext) startupMethod.invoke(null,
+ new String[] {/*"-clean", */"-console", "-configuration",
"target/configuration"},
+ null );
+
+ return bundleContext;
+
+ }
+
+ @Override
+ public BundleContext getBundleContext() {
+ return bundleContext;
+ }
+
+ @Override
+ protected void setBundleContext(BundleContext bundleContext) {
+ super.setBundleContext(bundleContext);
+ EquinoxTestRuntime.bundleContext = 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();
+ }
+
+
+
+}
Propchange:
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/osgi/runtime/impl/EquinoxTestRuntime.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/osgi/runtime/impl/EquinoxTestRuntime.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/osgi/runtime/impl/FelixTestRuntime.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/osgi/runtime/impl/FelixTestRuntime.java?rev=656822&r1=656821&r2=656822&view=diff
==============================================================================
---
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/osgi/runtime/impl/FelixTestRuntime.java
(original)
+++
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/osgi/runtime/impl/FelixTestRuntime.java
Thu May 15 13:34:32 2008
@@ -19,13 +19,13 @@
package org.apache.tuscany.sca.test.osgi.runtime.impl;
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.apache.felix.framework.Felix;
-import org.apache.felix.main.AutoActivator;
-import org.apache.felix.main.Main;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -36,7 +36,7 @@
private static FelixTestRuntime instance;
- private static Felix felix;
+ private static Bundle felix;
public static OSGiTestRuntime getInstance() throws Exception {
@@ -77,7 +77,11 @@
if (bundleContext != null)
return bundleContext;
- Properties props = Main.loadConfigProperties();
+ ClassLoader cl = this.getClass().getClassLoader();
+ Class<?> felixMainClass = cl.loadClass("org.apache.felix.main.Main");
+ Class<?> felixClass = cl.loadClass("org.apache.felix.framework.Felix");
+ Method propsMethod = felixMainClass.getMethod("loadConfigProperties");
+ Properties props = (Properties)propsMethod.invoke(null);
//deleteProfile();
// Create profile directory
@@ -127,13 +131,17 @@
props.put("org.osgi.framework.system.packages", systemPackages);
-
+
+ Constructor felixConstructor = felixClass.getConstructor(Map.class,
List.class);
List<BundleActivator> activators = new ArrayList<BundleActivator>();
- AutoActivator autoActivator = new AutoActivator(props);
+
+ Class<?> autoActivatorClass =
cl.loadClass("org.apache.felix.main.AutoActivator");
+ Constructor autoActivatorConstructor =
autoActivatorClass.getConstructor(Map.class);
+ BundleActivator autoActivator =
(BundleActivator)autoActivatorConstructor.newInstance(props);
activators.add(autoActivator);
- felix = new Felix(props, activators);
- ((Bundle)felix).start();
- bundleContext = ((Bundle)felix).getBundleContext();
+ felix = (Bundle)felixConstructor.newInstance(props, activators);
+ felix.start();
+ bundleContext = felix.getBundleContext();
return bundleContext;
Modified:
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/osgi/runtime/impl/OSGiTestRuntime.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/osgi/runtime/impl/OSGiTestRuntime.java?rev=656822&r1=656821&r2=656822&view=diff
==============================================================================
---
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/osgi/runtime/impl/OSGiTestRuntime.java
(original)
+++
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/osgi/runtime/impl/OSGiTestRuntime.java
Thu May 15 13:34:32 2008
@@ -62,8 +62,12 @@
}
}
- instance = FelixTestRuntime.getInstance();
- // instance = EquinoxTestRuntime.getInstance();
+ try {
+ instance = EquinoxTestRuntime.getInstance();
+ } catch (Throwable e) {
+ instance = FelixTestRuntime.getInstance();
+ }
+
return instance;
}
Modified:
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/util/OSGiRuntimeLoader.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/util/OSGiRuntimeLoader.java?rev=656822&r1=656821&r2=656822&view=diff
==============================================================================
---
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/util/OSGiRuntimeLoader.java
(original)
+++
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/util/OSGiRuntimeLoader.java
Thu May 15 13:34:32 2008
@@ -18,7 +18,6 @@
*/
package org.apache.tuscany.sca.test.util;
-import org.apache.felix.main.Main;
import org.apache.tuscany.sca.test.osgi.runtime.impl.OSGiTestRuntime;
@@ -60,14 +59,15 @@
try {
- String felixDir =
Main.class.getProtectionDomain().getCodeSource().getLocation().getPath();
+ Class<?> felixMainClass =
OSGiRuntimeLoader.class.getClassLoader().loadClass("org.apache.felix.main.Main");
+ String felixDir =
felixMainClass.getProtectionDomain().getCodeSource().getLocation().getPath();
int index = 0;
if ((index = felixDir.indexOf("/org.apache.felix.main")) >= 0) {
felixDir = felixDir.substring(0, index);
System.setProperty("FELIX_DIR", felixDir);
}
- } catch (Exception e) {
+ } catch (Throwable e) {
// Ignore
}
Added:
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/harness/OSGiTuscanyNonOSGiTestHarness.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/harness/OSGiTuscanyNonOSGiTestHarness.java?rev=656822&view=auto
==============================================================================
---
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/harness/OSGiTuscanyNonOSGiTestHarness.java
(added)
+++
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/harness/OSGiTuscanyNonOSGiTestHarness.java
Thu May 15 13:34:32 2008
@@ -0,0 +1,122 @@
+/*
+ * 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.test.osgi.harness;
+
+
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.HashSet;
+
+import junit.framework.Assert;
+import junit.framework.TestResult;
+
+import org.apache.tuscany.sca.test.util.TuscanyLoader;
+
+/*
+ * Test Tuscany running in an OSGi container
+ * This harness runs Tuscany samples outside OSGi with Tuscany running in OSGi
+ */
+public class OSGiTuscanyNonOSGiTestHarness extends OSGiTuscanyTestHarness {
+
+
+
+
+ public void runTest(String... testDirs) throws Exception {
+
+ String mainTestDir = testDirs[0];
+
+ File testDir = new File(mainTestDir + "/target/test-classes");
+ if (!testDir.exists()) {
+ System.err.println("Test directory " + testDir + " does not
exist");
+ return;
+ }
+
+ System.out.println("Run tests from : " + mainTestDir);
+
+ long startTime = System.currentTimeMillis();
+
+
+ String[] dirs = new String[testDirs.length + 2];
+ int i = 0;
+ dirs[i++] = mainTestDir + "/target/test-classes";
+ dirs[i++] = "target/test-classes";
+ for (int j = 0; j < testDirs.length; j++) {
+ dirs[i++] = testDirs[j] + "/target/classes";
+ }
+
+
+ tuscanyRuntime = TuscanyLoader.loadTuscanyIntoOSGi(getBundleContext());
+ TuscanyLoader.startTuscany(tuscanyRuntime);
+
+
+ long endTime = System.currentTimeMillis();
+
+ System.out.println("Loaded Tuscany, time taken = " +
(endTime-startTime) + " ms" );
+
+ URL[] dirURLs = new URL[dirs.length];
+ for (int j = 0; j < dirs.length; j++) {
+ dirURLs[j] = new File(dirs[j]).toURI().toURL();
+ }
+ ClassLoader testClassLoader = new URLClassLoader(dirURLs,
Thread.currentThread().getContextClassLoader());
+ Thread.currentThread().setContextClassLoader(testClassLoader);
+
+ Class<?> testClass =
testClassLoader.loadClass(this.getClass().getName());
+ Method testMethod = testClass.getMethod("runAllTestsFromDirs",
ClassLoader.class, String[].class);
+ Object testObject = testClass.newInstance();
+ testMethod.invoke(testObject, testClassLoader, dirs);
+
+ }
+
+ public void getTestCases(File dir, String prefix, HashSet<String>
testCaseSet) {
+ File[] files = dir.listFiles();
+ for (File file : files) {
+ if (file.isDirectory()) {
+ String newPrefix = prefix == null?file.getName() : prefix +
"." + file.getName();
+ getTestCases(file, newPrefix, testCaseSet);
+ }
+ else if (file.getName().endsWith("TestCase.class")) {
+ String name = file.getName();
+ name = name.substring(0, name.length()-6); // remove .class
+ name = (prefix == null)?name : prefix + "." + name;
+
+ testCaseSet.add(name);
+ }
+ }
+ }
+
+
+ public void runAllTestsFromDirs(ClassLoader testClassLoader, String[]
testDirs) throws Exception {
+
+ TestResult testResult = new TestResult();
+ HashSet<String> testCaseSet = new HashSet<String>();
+ for (String testDir : testDirs) {
+ getTestCases(new File(testDir), null, testCaseSet);
+ }
+ for (String className : testCaseSet) {
+ Class testClass = testClassLoader.loadClass(className);
+ runTestCase(testClass, testResult);
+ }
+
+ Assert.assertEquals(0, testResult.errorCount());
+
+ }
+}
Propchange:
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/harness/OSGiTuscanyNonOSGiTestHarness.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/harness/OSGiTuscanyNonOSGiTestHarness.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/harness/OSGiTuscanyTestHarness.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/harness/OSGiTuscanyTestHarness.java?rev=656822&r1=656821&r2=656822&view=diff
==============================================================================
---
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/harness/OSGiTuscanyTestHarness.java
(original)
+++
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/harness/OSGiTuscanyTestHarness.java
Thu May 15 13:34:32 2008
@@ -56,7 +56,7 @@
private OSGiTestRuntime osgiRuntime;
- private Bundle tuscanyRuntime;
+ protected Bundle tuscanyRuntime;
private BundleContext bundleContext;
private Bundle testBundle;
@@ -213,109 +213,110 @@
className = className.substring(1, className.length()-6); //
remove leading / and trailing .class
className = className.replaceAll("/", ".");
Class testClass = bundle.loadClass(className);
- boolean isJunitTest = TestCase.class.isAssignableFrom(testClass);
- if (testClass.getName().endsWith("TestCase") &&
+ runTestCase(testClass, testResult);
+ }
+
+ Assert.assertEquals(0, testResult.errorCount());
+
+ }
+
+
+ public void runTestCase(Class testClass, TestResult testResult) throws
Exception {
+
+ boolean isJunitTest = TestCase.class.isAssignableFrom(testClass);
+ if (testClass.getName().endsWith("TestCase") &&
!testClass.getPackage().getName().startsWith("org.apache.tuscany.sca.test.osgi"))
{
- Object test = (Object)testClass.newInstance();
+ Object test = (Object)testClass.newInstance();
- System.out.println("Running test " + test + " ");
- int ran = 0;
- int failed = 0;
- ArrayList<Method> testMethods = new ArrayList<Method>();
- Method setupMethod = null;
- Method tearDownMethod = null;
- Method setupClassMethod = null;
- Method tearDownClassMethod = null;
- Method[] methods = testClass.getDeclaredMethods();
- for (final Method method : methods) {
- if ((isJunitTest && method.getName().startsWith("test"))
- || method.getAnnotation(Test.class) != null) {
- testMethods.add(method);
-
- }
- else if ((isJunitTest && method.getName().equals("setUp"))
+ System.out.println("Running test " + test + " ");
+ int ran = 0;
+ int failed = 0;
+ ArrayList<Method> testMethods = new ArrayList<Method>();
+ Method setupMethod = null;
+ Method tearDownMethod = null;
+ Method setupClassMethod = null;
+ Method tearDownClassMethod = null;
+ Method[] methods = testClass.getDeclaredMethods();
+ for (final Method method : methods) {
+ if ((isJunitTest && method.getName().startsWith("test"))
+ || method.getAnnotation(Test.class) != null) {
+ testMethods.add(method);
+
+ } else if ((isJunitTest && method.getName().equals("setUp"))
|| method.getAnnotation(Before.class) != null) {
-
- setupMethod = method;
- AccessController.doPrivileged(new
PrivilegedAction<Object>() {
- public Object run() {
- method.setAccessible(true);
- return null;
- }
- });
-
- }
- else if ((isJunitTest &&
method.getName().equals("tearDown"))
- || method.getAnnotation(After.class) != null) {
-
- tearDownMethod = method;
- AccessController.doPrivileged(new
PrivilegedAction<Object>() {
- public Object run() {
- method.setAccessible(true);
- return null;
- }
- });
-
- }
- else if (method.getAnnotation(BeforeClass.class) != null) {
-
- setupClassMethod = method;
- AccessController.doPrivileged(new
PrivilegedAction<Object>() {
- public Object run() {
- method.setAccessible(true);
- return null;
- }
- });
-
+
+ setupMethod = method;
+ AccessController.doPrivileged(new
PrivilegedAction<Object>() {
+ public Object run() {
+ method.setAccessible(true);
+ return null;
}
- else if (method.getAnnotation(AfterClass.class) !=
null) {
-
- tearDownClassMethod = method;
- AccessController.doPrivileged(new
PrivilegedAction<Object>() {
- public Object run() {
- method.setAccessible(true);
- return null;
- }
- });
-
+ });
+
+ } else if ((isJunitTest && method.getName().equals("tearDown"))
+ || method.getAnnotation(After.class) != null) {
+
+ tearDownMethod = method;
+ AccessController.doPrivileged(new
PrivilegedAction<Object>() {
+ public Object run() {
+ method.setAccessible(true);
+ return null;
}
- }
- try {
- if (setupClassMethod != null)
- setupClassMethod.invoke(null);
- for (Method testMethod : testMethods) {
-
- ran++;
- failed++;
- try {
- if (setupMethod != null)
- setupMethod.invoke(test);
-
- testMethod.invoke(test);
- failed--;
-
- } catch (Exception e) {
- e.printStackTrace();
- throw e;
- } finally {
- if (tearDownMethod != null)
- tearDownMethod.invoke(test);
+ });
+
+ } else if (method.getAnnotation(BeforeClass.class) != null) {
+
+ setupClassMethod = method;
+ AccessController.doPrivileged(new
PrivilegedAction<Object>() {
+ public Object run() {
+ method.setAccessible(true);
+ return null;
+ }
+ });
+
+ } else if (method.getAnnotation(AfterClass.class) != null) {
+
+ tearDownClassMethod = method;
+ AccessController.doPrivileged(new
PrivilegedAction<Object>() {
+ public Object run() {
+ method.setAccessible(true);
+ return null;
}
+ });
+
+ }
+ }
+ try {
+ if (setupClassMethod != null)
+ setupClassMethod.invoke(null);
+ for (Method testMethod : testMethods) {
+
+ ran++;
+ failed++;
+ try {
+ if (setupMethod != null)
+ setupMethod.invoke(test);
+
+ testMethod.invoke(test);
+ failed--;
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw e;
+ } finally {
+ if (tearDownMethod != null)
+ tearDownMethod.invoke(test);
}
- } catch (Exception e) {
- e.printStackTrace();
- throw e;
- } finally {
-
- System.out.println("Ran: " + ran + ", Passed: " +
(ran-failed) + ", Failed: " + failed);
- if (tearDownClassMethod != null)
- tearDownClassMethod.invoke(null);
}
- }
-
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw e;
+ } finally {
+
+ System.out.println("Ran: " + ran + ", Passed: " + (ran -
failed) + ", Failed: " + failed);
+ if (tearDownClassMethod != null)
+ tearDownClassMethod.invoke(null);
+ }
}
-
- Assert.assertEquals(0, testResult.errorCount());
-
}
}
Added:
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/tuscany/NonOSGiSamplesTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/tuscany/NonOSGiSamplesTestCase.java?rev=656822&view=auto
==============================================================================
---
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/tuscany/NonOSGiSamplesTestCase.java
(added)
+++
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/tuscany/NonOSGiSamplesTestCase.java
Thu May 15 13:34:32 2008
@@ -0,0 +1,85 @@
+/*
+ * 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.test.osgi.tuscany;
+
+
+import org.apache.tuscany.sca.test.osgi.harness.OSGiTuscanyNonOSGiTestHarness;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/*
+ * Test Tuscany running in an OSGi container
+ *
+ * Run samples which use old domain code
+ */
+public class NonOSGiSamplesTestCase {
+
+
+ private static String[] SAMPLES = {
+ "binding-notification-consumer",
+ "binding-notification-producer",
+ "calculator",
+ "implementation-composite",
+ "implementation-notification",
+ "loanapplication",
+ "simple-bigbank",
+ "simple-callback",
+ "supplychain",
+ "calculator-implementation-policies",
+ "calculator-rmi-reference",
+ "calculator-rmi-service",
+ "callback-ws-service",
+ "helloworld-ws-service-jms",
+ "helloworld-ws-service-secure",
+ "helloworld-ws-service"
+
+ };
+
+
+ private OSGiTuscanyNonOSGiTestHarness testHarness;
+
+ @Before
+ public void setUp() throws Exception {
+
+ testHarness = new OSGiTuscanyNonOSGiTestHarness();
+ testHarness.setUp();
+ }
+
+
+ @After
+ public void tearDown() throws Exception {
+
+ if (testHarness != null) {
+ testHarness.tearDown();
+ testHarness = null;
+ }
+ }
+
+
+ @Test
+ public void runTestsOutsideOSGi() throws Exception {
+
+ for (String testDir : SAMPLES) {
+ testHarness.runTest("../../../samples/" + testDir);
+ }
+ }
+
+
+}
Propchange:
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/tuscany/NonOSGiSamplesTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/tuscany/NonOSGiSamplesTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/resources/META-INF/MANIFEST.MF
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/resources/META-INF/MANIFEST.MF?rev=656822&r1=656821&r2=656822&view=diff
==============================================================================
---
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/resources/META-INF/MANIFEST.MF
(original)
+++
incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/resources/META-INF/MANIFEST.MF
Thu May 15 13:34:32 2008
@@ -14,4 +14,3 @@
org.apache.tuscany.sca.domain,
org.apache.tuscany.sca.node
DynamicImport-Package: *
-Bundle-Activator: org.apache.tuscany.sca.test.osgi.harness.TestBundleActivator
Modified:
incubator/tuscany/java/sca/itest/osgi-tuscany/tuscany-manifest/src/main/java/org/apache/tuscany/sca/manifest/ManifestBundleActivator.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/osgi-tuscany/tuscany-manifest/src/main/java/org/apache/tuscany/sca/manifest/ManifestBundleActivator.java?rev=656822&r1=656821&r2=656822&view=diff
==============================================================================
---
incubator/tuscany/java/sca/itest/osgi-tuscany/tuscany-manifest/src/main/java/org/apache/tuscany/sca/manifest/ManifestBundleActivator.java
(original)
+++
incubator/tuscany/java/sca/itest/osgi-tuscany/tuscany-manifest/src/main/java/org/apache/tuscany/sca/manifest/ManifestBundleActivator.java
Thu May 15 13:34:32 2008
@@ -32,6 +32,10 @@
private static final String TUSCANY_OSGI_MANIFEST_DIR =
"org/apache/tuscany/sca/manifest";
private ArrayList<Bundle> virtualBundles = new ArrayList<Bundle>();
+
+ private static final String[] immutableJars = {
+ "bcprov"
+ };
public void start(BundleContext bundleContext) throws Exception {
@@ -52,6 +56,13 @@
private void install3rdPartyJarsIntoOSGi(BundleContext bundleContext) {
try {
+ Bundle[] installedBundles = bundleContext.getBundles();
+ HashSet<String> installedBundleSet = new HashSet<String>();
+ for (Bundle bundle : installedBundles) {
+ if (bundle.getSymbolicName() != null)
+ installedBundleSet.add(bundle.getSymbolicName());
+ }
+
// FIXME: SDO bundles dont have the correct dependencies
System.setProperty("commonj.sdo.impl.HelperProvider",
"org.apache.tuscany.sdo.helper.HelperProviderImpl");
@@ -87,8 +98,13 @@
if (bundleName.startsWith("org.apache.felix"))
continue;
+ String bundleSymbolicName = "org.apache.tuscany.sca.3rdparty."
+ bundleName;
+ if (bundleSymbolicName.endsWith(".jar")) bundleSymbolicName =
bundleSymbolicName.substring(0, bundleSymbolicName.length()-4);
+ if (installedBundleSet.contains(bundleSymbolicName))
+ continue;
+
String bundleLocation =
tuscanyInstallDir.toURI().toURL().toString() + "/" + bundleName;
- InputStream bundleManifestStream =
createBundleManifest(tuscanyInstallDir, bundleName);
+ InputStream bundleManifestStream =
createBundleManifest(tuscanyInstallDir, bundleName, bundleSymbolicName);
HashSet<String> jarSet = new HashSet<String>();
jarSet.add(bundleName);
@@ -173,7 +189,8 @@
bundleClassPath.append(jar);
}
- manifest.getMainAttributes().putValue("Bundle-ClassPath",
bundleClassPath.toString());
+ if (thirdPartyJars.size() > 1)
+ manifest.getMainAttributes().putValue("Bundle-ClassPath",
bundleClassPath.toString());
JarOutputStream jarOut = new JarOutputStream(out, manifest);
@@ -185,8 +202,15 @@
});
- for (File jar : jars) {
- addFileToJar(jar, jarOut);
+
+ String classpath =
manifest.getMainAttributes().getValue("Bundle-ClassPath");
+ boolean embed = classpath != null && !classpath.trim().equals(".");
+ for (File jarFile : jars) {
+ if (embed)
+ addFileToJar(jarFile, jarOut);
+ else {
+ copyJar(jarFile, jarOut);
+ }
}
jarOut.close();
@@ -199,10 +223,6 @@
private void addFileToJar(File file, JarOutputStream jarOut) throws
Exception {
- if (file.isDirectory()) {
- return;
- }
-
ZipEntry ze = new ZipEntry(file.getName());
try {
@@ -216,7 +236,30 @@
}
}
- private InputStream createBundleManifest(File tuscanyDir, String
bundleName) throws Exception {
+
+ private void copyJar(File file, JarOutputStream jarOut) throws Exception {
+
+ try {
+ JarInputStream jarIn = new JarInputStream(new
FileInputStream(file));
+ ZipEntry ze;
+ byte[] readBuf = new byte[1000];
+ int bytesRead;
+ while ((ze = jarIn.getNextEntry()) != null) {
+ if (ze.getName().equals("META-INF/MANIFEST.MF"))
+ continue;
+ jarOut.putNextEntry(ze);
+ while ((bytesRead = jarIn.read(readBuf)) > 0) {
+ jarOut.write(readBuf, 0, bytesRead);
+ }
+ }
+ jarIn.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private InputStream createBundleManifest(File tuscanyDir, String
bundleName, String bundleSymbolicName) throws Exception {
+
File jarFile = new File(tuscanyDir.getPath() + File.separator +
bundleName);
if (!jarFile.exists())
return null;
@@ -224,11 +267,20 @@
Manifest manifest = jar.getManifest();
if (manifest == null)
manifest = new Manifest();
+
+ boolean isImmutableJar = false;
+ for (String immutableJar : immutableJars) {
+ if (bundleName.startsWith(immutableJar)) {
+ isImmutableJar = true;
+ break;
+ }
+ }
Attributes attributes = manifest.getMainAttributes();
if (attributes.getValue("Manifest-Version") == null) {
attributes.putValue("Manifest-Version", "1.0");
}
- attributes.putValue("Bundle-ClassPath", bundleName);
+ if (isImmutableJar)
+ attributes.putValue("Bundle-ClassPath", bundleName);
String packages = getPackagesInJar(bundleName, jar);
String version = getJarVersion(bundleName);
@@ -237,7 +289,7 @@
attributes.remove(new Attributes.Name("Import-Package"));
if (attributes.getValue("Bundle-SymbolicName") == null)
- attributes.putValue("Bundle-SymbolicName", bundleName);
+ attributes.putValue("Bundle-SymbolicName", bundleSymbolicName);
if (attributes.getValue("Bundle-Version") == null)
attributes.putValue("Bundle-Version", version);
// Existing export statements in bundles may contain versions, so they
should be used as is
Modified:
incubator/tuscany/java/sca/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/OSGiBundleActivator.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/OSGiBundleActivator.java?rev=656822&r1=656821&r2=656822&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/OSGiBundleActivator.java
(original)
+++
incubator/tuscany/java/sca/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/OSGiBundleActivator.java
Thu May 15 13:34:32 2008
@@ -24,7 +24,6 @@
private static final String TUSCANY_SCA_BUNDLE_PREFIX =
"org.apache.tuscany.sca";
private static final String TUSCANY_3RD_PARTY_BUNDLE_PREFIX =
"org.apache.tuscany.sca.3rdparty";
private OSGiRuntime runtime;
- private ClassLoader serviceDiscoveryClassLoaderParent;
private ConcurrentHashMap<Bundle, ClassLoader>
serviceDiscoveryClassLoaders = new ConcurrentHashMap<Bundle, ClassLoader>();
private BundleClassLoader threadContextClassLoader;
private ClassLoader origTCCL;
@@ -42,10 +41,11 @@
}
public void stop(BundleContext bundleContext) throws Exception {
- runtime.shutdown();
+ // runtime.shutdown();
+
if (Thread.currentThread().getContextClassLoader() ==
threadContextClassLoader)
- Thread.currentThread().setContextClassLoader(origTCCL);
+ Thread.currentThread().setContextClassLoader(origTCCL);
}
/**
@@ -61,20 +61,11 @@
origTCCL = Thread.currentThread().getContextClassLoader();
- serviceDiscoveryClassLoaderParent = origTCCL;
- try {
-
serviceDiscoveryClassLoaderParent.loadClass(this.getClass().getName());
- if (serviceDiscoveryClassLoaderParent.getParent() != null)
- serviceDiscoveryClassLoaderParent =
serviceDiscoveryClassLoaderParent.getParent();
- } catch (ClassNotFoundException e) {
- // Expected exception - ignore
- }
-
threadContextClassLoader = new BundleClassLoader(thisBundle,
origTCCL);
Thread.currentThread().setContextClassLoader(threadContextClassLoader);
- ClassLoader cl = new BundleClassLoader(thisBundle,
serviceDiscoveryClassLoaderParent);
+ ClassLoader cl = new BundleClassLoader(thisBundle, null);
ServiceDiscovery.getInstance().registerClassLoader(cl);
serviceDiscoveryClassLoaders.put(thisBundle, cl);
@@ -109,13 +100,8 @@
// This may be the third party bundle.
if
(bundle.getSymbolicName().startsWith(TUSCANY_3RD_PARTY_BUNDLE_PREFIX)) {
-
- String thisBundleVersion =
(String)thisBundle.getHeaders().get("Bundle-Version");
- String bundleVersion =
(String)bundle.getHeaders().get("Bundle-Version");
-
- if (thisBundleVersion == null || bundleVersion == null ||
thisBundleVersion.equals(bundleVersion)) {
- threadContextClassLoader.addBundle(bundle);
- }
+
+ threadContextClassLoader.addBundle(bundle);
}
else {
@@ -125,7 +111,7 @@
if (thisBundleVersion == null || bundleVersion == null ||
thisBundleVersion.equals(bundleVersion)) {
if (!threadContextClassLoader.bundles.contains(bundle)) {
- ClassLoader cl = new BundleClassLoader(bundle,
serviceDiscoveryClassLoaderParent);
+ ClassLoader cl = new BundleClassLoader(bundle, null);
ServiceDiscovery.getInstance().registerClassLoader(cl);
serviceDiscoveryClassLoaders.put(bundle, cl);
threadContextClassLoader.addBundle(bundle);