Author: apopescu
Date: Mon May 14 15:26:26 2007
New Revision: 538006

URL: http://svn.apache.org/viewvc?view=rev&rev=538006
Log:
last bits

Modified:
    
maven/sandbox/branches/surefire/surefire-collab2/surefire-providers/surefire-testng/pom.xml
    
maven/sandbox/branches/surefire/surefire-collab2/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
    
maven/sandbox/branches/surefire/surefire-collab2/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/AbstractDirectConfigurator.java
    
maven/sandbox/branches/surefire/surefire-collab2/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java

Modified: 
maven/sandbox/branches/surefire/surefire-collab2/surefire-providers/surefire-testng/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/sandbox/branches/surefire/surefire-collab2/surefire-providers/surefire-testng/pom.xml?view=diff&rev=538006&r1=538005&r2=538006
==============================================================================
--- 
maven/sandbox/branches/surefire/surefire-collab2/surefire-providers/surefire-testng/pom.xml
 (original)
+++ 
maven/sandbox/branches/surefire/surefire-collab2/surefire-providers/surefire-testng/pom.xml
 Mon May 14 15:26:26 2007
@@ -43,7 +43,7 @@
         <dependency>
           <groupId>org.testng</groupId>
           <artifactId>testng</artifactId>
-          <version>5.1</version>
+          <version>5.6</version>
           <classifier>jdk14</classifier>
         </dependency>
       </dependencies>
@@ -57,7 +57,7 @@
         <dependency>
           <groupId>org.testng</groupId>
           <artifactId>testng</artifactId>
-          <version>5.1</version>
+          <version>5.6</version>
           <classifier>jdk15</classifier>
         </dependency>
       </dependencies>

Modified: 
maven/sandbox/branches/surefire/surefire-collab2/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/branches/surefire/surefire-collab2/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java?view=diff&rev=538006&r1=538005&r2=538006
==============================================================================
--- 
maven/sandbox/branches/surefire/surefire-collab2/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
 (original)
+++ 
maven/sandbox/branches/surefire/surefire-collab2/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
 Mon May 14 15:26:26 2007
@@ -47,17 +47,23 @@
     }
        
        public static void run(Class[] testClasses, Map options, ExecEnv 
execEnv) {
-               TestNG testng = initialize(execEnv, (String) 
options.remove(SOURCE_DIRS_OPTION));
+               String testSrcPath = (String) 
options.remove(SOURCE_DIRS_OPTION);
+               TestNG testng = new TestNG(false);
                IConfigurator configurator = 
getConfigurator(execEnv.getVersion());
                configurator.configure(testng, options);
+               postConfigure(testng, testSrcPath, execEnv);
+               
                testng.setTestClasses(testClasses);
                testng.run();
        }
 
        public static void run(List suiteFiles, Map options, ExecEnv execEnv) {
-               TestNG testng = initialize(execEnv, (String) 
options.remove(SOURCE_DIRS_OPTION));
+               String testSrcPath = (String) 
options.remove(SOURCE_DIRS_OPTION);
+               TestNG testng = new TestNG(false);
                IConfigurator configurator = 
getConfigurator(execEnv.getVersion());
                configurator.configure(testng, options);
+               postConfigure(testng, testSrcPath, execEnv);
+               
                testng.setTestSuites(suiteFiles);
                testng.run();
        }
@@ -80,14 +86,12 @@
                        throw new NestedRuntimeException("Unknown TestNG 
version " + version);
                }
                catch(InvalidVersionSpecificationException invsex) {
-                       throw new NestedRuntimeException("", invsex);
+                       throw new NestedRuntimeException("Bug in plugin. Please 
report it with the attached stacktrace", invsex);
                }
        }
                
        
-       private static TestNG initialize(ExecEnv env, String sourcePath) {
-               TestNG testNG = new TestNG( false );
-               
+       private static void postConfigure(TestNG testNG, String sourcePath, 
ExecEnv env) {
                // turn off all TestNG output
                testNG.setVerbose( 0 );
                
@@ -100,7 +104,5 @@
         // workaround for SUREFIRE-49
         // TestNG always creates an output directory, and if not set the name 
for the directory is "null"
         testNG.setOutputDirectory( System.getProperty( "java.io.tmpdir" ) );
-        
-        return testNG;
        }
 }

Modified: 
maven/sandbox/branches/surefire/surefire-collab2/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/AbstractDirectConfigurator.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/branches/surefire/surefire-collab2/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/AbstractDirectConfigurator.java?view=diff&rev=538006&r1=538005&r2=538006
==============================================================================
--- 
maven/sandbox/branches/surefire/surefire-collab2/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/AbstractDirectConfigurator.java
 (original)
+++ 
maven/sandbox/branches/surefire/surefire-collab2/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/AbstractDirectConfigurator.java
 Mon May 14 15:26:26 2007
@@ -16,7 +16,7 @@
        protected void setOptions(TestNG testng, Map options) throws 
NestedRuntimeException {
                Map setters = getSetters();
                
-               for(Iterator it = options.keySet().iterator(); it.hasNext(); ) {
+               for(Iterator it = options.entrySet().iterator(); it.hasNext(); 
) {
                        Map.Entry entry = (Map.Entry) it.next();
                        String key = (String) entry.getKey();
                        Object val = entry.getValue();

Modified: 
maven/sandbox/branches/surefire/surefire-collab2/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/branches/surefire/surefire-collab2/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java?view=diff&rev=538006&r1=538005&r2=538006
==============================================================================
--- 
maven/sandbox/branches/surefire/surefire-collab2/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java
 (original)
+++ 
maven/sandbox/branches/surefire/surefire-collab2/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java
 Mon May 14 15:26:26 2007
@@ -1,5 +1,7 @@
 package org.apache.maven.surefire.testng.conf;
 
+import java.util.HashMap;
+import java.util.Iterator;
 import java.util.Map;
 
 import org.testng.TestNG;
@@ -8,15 +10,48 @@
  * TestNG configurator for 5.3+ versions. TestNG exposes
  * a [EMAIL PROTECTED] org.testng.TestNG#configure(java.util.Map)} method.
  * All suppported TestNG options are passed in String format, except
- * <code>TestNGCommandLineArgs.LISTENER_COMMAND_OPT</code> which is 
<code>List<Class></code>.
+ * <code>TestNGCommandLineArgs.LISTENER_COMMAND_OPT</code> which is 
<code>List<Class></code>
+ * and <code>TestNGCommandLineArgs.JUNIT_DEF_OPT</code> which is a 
<code>Boolean</code>.
  * <p/>
  * Test classes and/or suite files are not passed along as options parameters, 
but
  * configured separately.
  */
 public class TestNGMapConfigurator implements IConfigurator {
-
+       private static final Map TYPE_CONVERSIONS = new HashMap() {
+               {
+                       put("junit", Boolean.class);
+                       put("threadcount", String.class);
+               }
+       };
+       
        public void configure(TestNG testng, Map options) {
+               Map convertedOptions = new HashMap();
+               for(Iterator it = options.entrySet().iterator(); it.hasNext(); 
) {
+                       Map.Entry entry = (Map.Entry) it.next();
+                       String key = (String) entry.getKey();
+                       Object val = entry.getValue();
+                       Class valType = (Class) TYPE_CONVERSIONS.get(key);
+                       if(valType != null) {
+                               val = convert(val, valType);
+                       }
+                       convertedOptions.put("-" + key, val);
+               }
                
+               testng.configure(convertedOptions);
        }
        
+       protected Object convert(Object val, Class type) {
+               if(val == null) return null;
+               if(type.isAssignableFrom(val.getClass())) return val;
+               
+               if( (Boolean.class.equals(type) || boolean.class.equals(type)) 
&& String.class.equals(val.getClass())) {
+                       return Boolean.valueOf((String) val); 
+               }
+               
+               if(String.class.equals(type)) {
+                       return val.toString();
+               }
+               
+               return val;
+       }
 }


Reply via email to