You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2015/09/06 22:58:33 UTC

[02/17] maven-surefire git commit: [SUREFIRE] added missing interface MainCliOptionsAware

[SUREFIRE] added missing interface MainCliOptionsAware


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/67af00f1
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/67af00f1
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/67af00f1

Branch: refs/heads/master
Commit: 67af00f1cba38c56cb2036d247dd178016ebaf9c
Parents: 668b1b9
Author: Tibor17 <ti...@lycos.com>
Authored: Sat Jul 25 03:28:20 2015 +0200
Committer: Tibor17 <ti...@lycos.com>
Committed: Sun Sep 6 22:57:54 2015 +0200

----------------------------------------------------------------------
 .../surefire/booter/SurefireReflector.java      | 31 ++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/67af00f1/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java
----------------------------------------------------------------------
diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java b/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java
index 0e53a8f..b271171 100644
--- a/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java
+++ b/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java
@@ -24,6 +24,8 @@ import java.io.PrintStream;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
@@ -41,6 +43,8 @@ import org.apache.maven.surefire.util.ReflectionUtils;
 import org.apache.maven.surefire.util.RunOrder;
 import org.apache.maven.surefire.util.SurefireReflectionException;
 
+import static java.util.Collections.checkedList;
+
 /**
  * Does reflection based invocation of the surefire methods.
  * <p/>
@@ -84,7 +88,10 @@ public class SurefireReflector
 
     private final Class<?> mainCliOptions;
 
+    private final Class<Enum> commandLineOptionsClass;
+
 
+    @SuppressWarnings( "unchecked" )
     public SurefireReflector( ClassLoader surefireClassLoader )
     {
         this.surefireClassLoader = surefireClassLoader;
@@ -107,6 +114,8 @@ public class SurefireReflector
             booterParameters = surefireClassLoader.loadClass( ProviderParameters.class.getName() );
             testListResolver = surefireClassLoader.loadClass( TestListResolver.class.getName() );
             mainCliOptions = surefireClassLoader.loadClass( MainCliOptionsAware.class.getName() );
+            commandLineOptionsClass =
+                (Class<Enum>) surefireClassLoader.loadClass( CommandLineOption.class.getName() );
         }
         catch ( ClassNotFoundException e )
         {
@@ -272,7 +281,16 @@ public class SurefireReflector
     {
         if ( mainCliOptions.isAssignableFrom( o.getClass() ) )
         {
-            ReflectionUtils.invokeSetter( o, "setMainCliOptions", List.class, options );
+            List<Enum> newOptions = checkedList( new ArrayList<Enum>( options.size() ), commandLineOptionsClass );
+            Collection<Integer> ordinals = toOrdinals( options );
+            for ( Enum e : commandLineOptionsClass.getEnumConstants() )
+            {
+                if ( ordinals.contains( e.ordinal() ) )
+                {
+                    newOptions.add( e );
+                }
+            }
+            ReflectionUtils.invokeSetter( o, "setMainCliOptions", List.class, newOptions );
         }
     }
 
@@ -288,7 +306,6 @@ public class SurefireReflector
         ReflectionUtils.invokeSetter( o, "setRunOrderParameters", this.runOrderParameters, param );
     }
 
-
     public void setTestSuiteDefinitionAware( Object o, TestRequest testSuiteDefinition2 )
     {
         if ( testSuiteDefinitionAware.isAssignableFrom( o.getClass() ) )
@@ -365,4 +382,14 @@ public class SurefireReflector
         return runResult.isAssignableFrom( o.getClass() );
     }
 
+    private static Collection<Integer> toOrdinals( Collection<? extends Enum> enums )
+    {
+        Collection<Integer> ordinals = new ArrayList<Integer>( enums.size() );
+        for ( Enum e : enums )
+        {
+            ordinals.add( e.ordinal() );
+        }
+        return ordinals;
+    }
+
 }