maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krosenv...@apache.org
Subject svn commit: r1099597 - /maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java
Date Wed, 04 May 2011 20:35:00 GMT
Author: krosenvold
Date: Wed May  4 20:35:00 2011
New Revision: 1099597

URL: http://svn.apache.org/viewvc?rev=1099597&view=rev
Log:
o Removed use of dynamic proxy.

Reflection is faster and simpler in this case.

Modified:
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java

Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java?rev=1099597&r1=1099596&r2=1099597&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java
(original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java
Wed May  4 20:35:00 2011
@@ -19,10 +19,14 @@ package org.apache.maven.surefire.booter
  * under the License.
  */
 
-import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
+import java.util.Iterator;
 import org.apache.maven.surefire.providerapi.SurefireProvider;
+import org.apache.maven.surefire.report.ReporterException;
+import org.apache.maven.surefire.suite.RunResult;
+import org.apache.maven.surefire.testset.TestSetFailedException;
+import org.apache.maven.surefire.util.ReflectionUtils;
+
 
 /**
  * Creates the surefire provider.
@@ -44,9 +48,12 @@ public class ProviderFactory
 
     private final Object reporterManagerFactory;
 
+    private static final Class[] invokeParamaters = new Class[]{ Object.class };
+
 
     public ProviderFactory( StartupConfiguration startupConfiguration, ProviderConfiguration
providerConfiguration,
-                            ClassLoader surefireClassLoader, ClassLoader testsClassLoader,
Object reporterManagerFactory )
+                            ClassLoader surefireClassLoader, ClassLoader testsClassLoader,
+                            Object reporterManagerFactory )
     {
         this.providerConfiguration = providerConfiguration;
         this.surefireClassLoader = surefireClassLoader;
@@ -74,41 +81,42 @@ public class ProviderFactory
         Object provider = surefireReflector.instantiateProvider( starterConfiguration.getProviderClassName(),
o );
         Thread.currentThread().setContextClassLoader( context );
 
-        return createClassLoaderProxy( provider );
+        return new ProviderProxy( provider );
     }
 
-    private SurefireProvider createClassLoaderProxy( Object target )
-    {
-        return (SurefireProvider) Proxy.newProxyInstance( this.getClass().getClassLoader(),
-                                                          new Class[]{ SurefireProvider.class
},
-                                                          new ClassLoaderProxy( target )
);
-    }
 
-    private class ClassLoaderProxy
-        implements InvocationHandler
+    private class ProviderProxy
+        implements SurefireProvider
     {
-        private final Object target;
+        private final Object providerInOtherClassLoader;
+
+
+        private ProviderProxy( Object providerInOtherClassLoader )
+        {
+            this.providerInOtherClassLoader = providerInOtherClassLoader;
+        }
+
+        public Iterator getSuites()
+        {
+            return (Iterator) ReflectionUtils.invokeGetter( providerInOtherClassLoader, "getSuites"
);
+        }
 
-        public ClassLoaderProxy( Object delegate )
+        public RunResult invoke( Object forkTestSet )
+            throws TestSetFailedException, ReporterException
         {
-            this.target = delegate;
+            final Method invoke =
+                ReflectionUtils.getMethod( providerInOtherClassLoader.getClass(), "invoke",
invokeParamaters );
+
+            final Object result = ReflectionUtils.invokeMethodWithArray( providerInOtherClassLoader,
invoke,
+                                                                         new Object[]{ forkTestSet
} );
+            return (RunResult) surefireReflector.convertIfRunResult( result );
         }
 
-        public Object invoke( Object proxy, Method method, Object[] args )
-            throws Throwable
+        public void cancel()
         {
-            ClassLoader original = java.lang.Thread.currentThread().getContextClassLoader();
-            Thread.currentThread().setContextClassLoader( testsClassLoader );
-            try
-            {
-                Method delegateMethod = target.getClass().getMethod( method.getName(), method.getParameterTypes()
);
-                final Object result = delegateMethod.invoke( target, args );
-                return surefireReflector.convertIfRunResult( result );
-            }
-            finally
-            {
-                Thread.currentThread().setContextClassLoader( original );
-            }
+            final Method invoke =
+                ReflectionUtils.getMethod( providerInOtherClassLoader.getClass(), "cancel",
new Class[]{ } );
+            ReflectionUtils.invokeMethodWithArray( providerInOtherClassLoader, invoke, null
);
         }
     }
 }



Mime
View raw message