You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2009/10/27 17:48:44 UTC

svn commit: r830245 - in /tuscany/maven-plugins/trunk/maven-osgi-junit: pom.xml src/main/java/org/apache/tuscany/maven/plugin/surefire/OSGiSurefireBooter.java

Author: rfeng
Date: Tue Oct 27 16:48:43 2009
New Revision: 830245

URL: http://svn.apache.org/viewvc?rev=830245&view=rev
Log:
Remove the compile dependency on tuscany-node-launcher-equinox 

Modified:
    tuscany/maven-plugins/trunk/maven-osgi-junit/pom.xml
    tuscany/maven-plugins/trunk/maven-osgi-junit/src/main/java/org/apache/tuscany/maven/plugin/surefire/OSGiSurefireBooter.java

Modified: tuscany/maven-plugins/trunk/maven-osgi-junit/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/maven-plugins/trunk/maven-osgi-junit/pom.xml?rev=830245&r1=830244&r2=830245&view=diff
==============================================================================
--- tuscany/maven-plugins/trunk/maven-osgi-junit/pom.xml (original)
+++ tuscany/maven-plugins/trunk/maven-osgi-junit/pom.xml Tue Oct 27 16:48:43 2009
@@ -197,8 +197,18 @@
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-node-launcher-equinox</artifactId>
             <version>2.0-SNAPSHOT</version>
+            <scope>runtime</scope>
+            <optional>true</optional>
         </dependency>
 
+        <dependency>
+            <groupId>org.eclipse</groupId>
+            <artifactId>osgi</artifactId>
+            <version>3.5.0-v20090520</version>
+            <scope>compile</scope>
+        </dependency>
+        
+
     </dependencies>
 
     <build>

Modified: tuscany/maven-plugins/trunk/maven-osgi-junit/src/main/java/org/apache/tuscany/maven/plugin/surefire/OSGiSurefireBooter.java
URL: http://svn.apache.org/viewvc/tuscany/maven-plugins/trunk/maven-osgi-junit/src/main/java/org/apache/tuscany/maven/plugin/surefire/OSGiSurefireBooter.java?rev=830245&r1=830244&r2=830245&view=diff
==============================================================================
--- tuscany/maven-plugins/trunk/maven-osgi-junit/src/main/java/org/apache/tuscany/maven/plugin/surefire/OSGiSurefireBooter.java (original)
+++ tuscany/maven-plugins/trunk/maven-osgi-junit/src/main/java/org/apache/tuscany/maven/plugin/surefire/OSGiSurefireBooter.java Tue Oct 27 16:48:43 2009
@@ -26,6 +26,7 @@
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.net.MalformedURLException;
@@ -57,7 +58,6 @@
 import org.apache.maven.surefire.booter.shade.org.codehaus.plexus.util.cli.StreamConsumer;
 import org.apache.maven.surefire.testset.TestSetFailedException;
 import org.apache.maven.surefire.util.NestedRuntimeException;
-import org.apache.tuscany.sca.node.equinox.launcher.EquinoxHost;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 
@@ -273,7 +273,11 @@
 
         // noinspection CatchGenericClass,OverlyBroadCatchBlock
         ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
-        start();
+        try {
+            start();
+        } catch (Exception e1) {
+            throw new SurefireExecutionException(e1.getMessage(), e1);
+        }
         try {
             ClassLoader testsClassLoader =
                 useSystemClassLoader() ? ClassLoader.getSystemClassLoader() : createClassLoader(classPathUrls,
@@ -314,7 +318,11 @@
 
         // noinspection CatchGenericClass,OverlyBroadCatchBlock
         ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
-        start();
+        try {
+            start();
+        } catch (Exception e1) {
+            throw new SurefireExecutionException(e1.getMessage(), e1);
+        }
 
         try {
             // The test classloader must be constructed first to avoid issues with commons-logging until we properly
@@ -894,10 +902,10 @@
         this.mainBundleName = mainBundleName;
     }
 
-    private EquinoxHost host;
+    private Object host;
     private BundleClassLoader bundleClassLoader;
 
-    public EquinoxHost start() {
+    public Object start() throws Exception {
         Set<URL> urls = new HashSet<URL>();
         
         // Merge the two classpaths so that all of them will be OSGi-enabled
@@ -915,8 +923,8 @@
             }
         }
 
-        host = new EquinoxHost(urls);
-        BundleContext context = host.start();
+        host = createEquinox(urls);
+        BundleContext context = startEquinox(host);
         Bundle mainBundle = null;
         for (Bundle bundle : context.getBundles()) {
             // Fragement bundle cannot be used to load class, use the main bundle
@@ -943,11 +951,32 @@
 
     public void stop() {
         if (host != null) {
-            host.stop();
+            try {
+                stopEquinox(host);
+            } catch (Exception e) {
+                throw new IllegalStateException(e);
+            }
             host = null;
             bundleClassLoader = null;
         }
     }
+    
+    private static Object createEquinox(Set<URL> urls) throws Exception {
+        String name = "org.apache.tuscany.sca.node.equinox.launcher.EquinoxHost";
+        Class<?> cls = Class.forName(name);
+        Constructor<?> ctor = cls.getConstructor(Set.class);
+        return ctor.newInstance(urls);
+    }
+
+    private static BundleContext startEquinox(Object host) throws Exception {
+        Method start = host.getClass().getMethod("start");
+        return (BundleContext)start.invoke(host);
+    }
+
+    private static void stopEquinox(Object host) throws Exception {
+        Method stop = host.getClass().getMethod("stop");
+        stop.invoke(host);
+    }
 
     /**
      * Returns a string representation of the given bundle.