Author: apopescu
Date: Sat Jun  2 18:18:45 2007
New Revision: 543820

URL: http://svn.apache.org/viewvc?view=rev&rev=543820
Log:
+ passing more parameters for TestNG
+ allow configuring testlisteners

Modified:
    
maven/sandbox/branches/surefire/apopescu/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
    
maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
    
maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
    
maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGXmlTestSuite.java
    
maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG4751Configurator.java
    
maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG52Configurator.java
    
maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java

Modified: 
maven/sandbox/branches/surefire/apopescu/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/branches/surefire/apopescu/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java?view=diff&rev=543820&r1=543819&r2=543820
==============================================================================
--- 
maven/sandbox/branches/surefire/apopescu/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
 (original)
+++ 
maven/sandbox/branches/surefire/apopescu/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
 Sat Jun  2 18:18:45 2007
@@ -561,7 +561,8 @@
 
             // TODO: properties should be passed in here too
             surefireBooter.addTestSuite( 
"org.apache.maven.surefire.testng.TestNGXmlTestSuite", new Object[]{
-                suiteXmlFiles, testSourceDirectory.getAbsolutePath(), 
testNgArtifact.getVersion()} );
+                suiteXmlFiles, testSourceDirectory.getAbsolutePath(), 
+                testNgArtifact.getVersion(), testNgArtifact.getClassifier(), 
properties} );
         }
         else
         {
@@ -610,7 +611,7 @@
             {
                 surefireBooter.addTestSuite( 
"org.apache.maven.surefire.testng.TestNGDirectoryTestSuite", new Object[]{
                     testClassesDirectory, includes, excludes, 
testSourceDirectory.getAbsolutePath(),
-                    testNgArtifact.getVersion(), properties} );
+                    testNgArtifact.getVersion(), 
testNgArtifact.getClassifier(), properties} );
             }
             else
             {

Modified: 
maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java?view=diff&rev=543820&r1=543819&r2=543820
==============================================================================
--- 
maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
 (original)
+++ 
maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
 Sat Jun  2 18:18:45 2007
@@ -20,6 +20,7 @@
  */
 
 import org.apache.maven.artifact.versioning.ArtifactVersion;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
 import org.apache.maven.surefire.report.ReporterException;
 import org.apache.maven.surefire.report.ReporterManager;
 import org.apache.maven.surefire.suite.AbstractDirectoryTestSuite;
@@ -42,18 +43,24 @@
 {
     private ArtifactVersion version;
 
+    private String classifier;
+    
     private Map options;
 
     private String testSourceDirectory;
 
     public TestNGDirectoryTestSuite( File basedir, List includes, List 
excludes, String testSourceDirectory,
-                                     ArtifactVersion artifactVersion, Map 
confOptions )
+                                     String artifactVersion, String 
artifactClassifier, Map confOptions )
     {
         super( basedir, includes, excludes );
 
         this.options = confOptions;
+        
         this.testSourceDirectory = testSourceDirectory;
-        this.version = artifactVersion;
+        
+        this.version = new DefaultArtifactVersion( artifactVersion );
+        
+        this.classifier = artifactClassifier;
     }
 
     protected SurefireTestSet createTestSet( Class testClass, ClassLoader 
classLoader )
@@ -77,7 +84,7 @@
         }
 
         TestNGExecutor.run( new Class[]{testSet.getTestClass()}, 
this.testSourceDirectory, this.options, this.version,
-                            reporterManager, this );
+                            this.classifier, reporterManager, this );
     }
 
     public void execute( ReporterManager reporterManager, ClassLoader 
classLoader )
@@ -96,6 +103,7 @@
             testClasses[i++] = testSet.getTestClass();
         }
 
-        TestNGExecutor.run( testClasses, this.testSourceDirectory, 
this.options, this.version, reporterManager, this );
+        TestNGExecutor.run( testClasses, this.testSourceDirectory, 
this.options, this.version, 
+                            this.classifier, reporterManager, this );
     }
 }

Modified: 
maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java?view=diff&rev=543820&r1=543819&r2=543820
==============================================================================
--- 
maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
 (original)
+++ 
maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
 Sat Jun  2 18:18:45 2007
@@ -28,9 +28,11 @@
 import org.apache.maven.surefire.testng.conf.TestNG4751Configurator;
 import org.apache.maven.surefire.testng.conf.TestNG52Configurator;
 import org.apache.maven.surefire.testng.conf.TestNGMapConfigurator;
-import org.apache.maven.surefire.util.NestedRuntimeException;
+import org.apache.maven.surefire.testset.TestSetFailedException;
 import org.testng.TestNG;
 
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
@@ -47,30 +49,31 @@
     }
 
     public static void run( Class[] testClasses, String testSourceDirectory, 
Map options, ArtifactVersion version,
-                            ReporterManager reportManager, SurefireTestSuite 
suite )
+                            String classifier, ReporterManager reportManager, 
SurefireTestSuite suite )
+        throws TestSetFailedException
     {
         TestNG testng = new TestNG( false );
         Configurator configurator = getConfigurator( version );
         configurator.configure( testng, options );
-        postConfigure( testng, testSourceDirectory, reportManager, suite );
-
+        postConfigure( testng, testSourceDirectory, (String) 
options.get("listener"), classifier, reportManager, suite );
         testng.setTestClasses( testClasses );
         testng.run();
     }
 
     public static void run( List suiteFiles, String testSourceDirectory, Map 
options, ArtifactVersion version,
-                            ReporterManager reportManager, SurefireTestSuite 
suite )
+                            String classifier, ReporterManager reportManager, 
SurefireTestSuite suite )
+        throws TestSetFailedException
     {
         TestNG testng = new TestNG( false );
         Configurator configurator = getConfigurator( version );
         configurator.configure( testng, options );
-        postConfigure( testng, testSourceDirectory, reportManager, suite );
+        postConfigure( testng, testSourceDirectory, (String) 
options.get("listener"), classifier, reportManager, suite );
 
         testng.setTestSuites( suiteFiles );
         testng.run();
     }
 
-    private static Configurator getConfigurator( ArtifactVersion version )
+    private static Configurator getConfigurator( ArtifactVersion version ) 
throws TestSetFailedException
     {
         try
         {
@@ -90,30 +93,57 @@
                 return new TestNGMapConfigurator();
             }
 
-            throw new NestedRuntimeException( "Unknown TestNG version " + 
version );
+            throw new TestSetFailedException( "Unknown TestNG version " + 
version );
         }
         catch ( InvalidVersionSpecificationException invsex )
         {
-            throw new NestedRuntimeException( "Bug in plugin. Please report it 
with the attached stacktrace", invsex );
+            throw new TestSetFailedException( "Bug in plugin. Please report it 
with the attached stacktrace", invsex );
         }
     }
 
 
-    private static void postConfigure( TestNG testNG, String sourcePath, 
ReporterManager reportManager,
-                                       SurefireTestSuite suite )
+    private static void postConfigure( TestNG testNG, String sourcePath, 
String listenerClasses, 
+                                       String classifier, ReporterManager 
reportManager, SurefireTestSuite suite )
+        throws TestSetFailedException
     {
         // turn off all TestNG output
         testNG.setVerbose( 0 );
 
         TestNGReporter reporter = new TestNGReporter( reportManager, suite );
         testNG.addListener( (Object) reporter );
-        // TODO: we should have the Profile so that we can decide if this is 
needed or not
+        testNG.setListenerClasses(loadListenerClasses(listenerClasses));
+        
+        // FIXME: use classifier to decide if we need to pass along the source 
dir (onyl for JDK14)
         if ( sourcePath != null )
         {
             testNG.setSourcePath( sourcePath );
         }
+
         // 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" ) );
+    }
+    
+    private static List loadListenerClasses(String listenerClasses) throws 
TestSetFailedException
+    {
+        if (listenerClasses == null || "".equals(listenerClasses.trim())) {
+            return Collections.emptyList();
+        }
+        
+        List classes = new ArrayList();
+        String[] classNames = listenerClasses.split(" *, *");
+        for(int i = 0; i < classNames.length; i++) 
+        {
+            try 
+            {
+                classes.add(Class.forName(classNames[i]));
+            }
+            catch(Exception ex) 
+            {
+                throw new TestSetFailedException("Cannot find listener class " 
+ classNames[i], ex);
+            }              
+        }
+        
+        return classes;
     }
 }

Modified: 
maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGXmlTestSuite.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGXmlTestSuite.java?view=diff&rev=543820&r1=543819&r2=543820
==============================================================================
--- 
maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGXmlTestSuite.java
 (original)
+++ 
maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGXmlTestSuite.java
 Sat Jun  2 18:18:45 2007
@@ -21,6 +21,7 @@
 
 import org.apache.maven.artifact.versioning.ArtifactVersion;
 import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
+import org.apache.maven.surefire.report.ReporterException;
 import org.apache.maven.surefire.report.ReporterManager;
 import org.apache.maven.surefire.suite.SurefireTestSuite;
 import org.apache.maven.surefire.testset.TestSetFailedException;
@@ -49,34 +50,42 @@
     private String testSourceDirectory;
 
     private ArtifactVersion version;
+    
+    private String classifier;
 
-    private Map options = new HashMap();
+    private Map options;
 
     // Not really used
     private Map testSets;
 
     /**
      * Creates a testng testset to be configured by the specified
-     * xml file.
+     * xml file(s). The XML files are suite definitions files according to 
TestNG DTD.
      */
-    public TestNGXmlTestSuite( File[] suiteFiles, String testSourceDirectory, 
String artifactVersion )
+    public TestNGXmlTestSuite( File[] suiteFiles, String testSourceDirectory, 
String artifactVersion,
+                               String artifactClassifier, Map confOptions)
     {
         this.suiteFiles = suiteFiles;
 
+        this.options = confOptions;
+        
         this.version = new DefaultArtifactVersion( artifactVersion );
+        
+        this.classifier = artifactClassifier;
 
         this.testSourceDirectory = testSourceDirectory;
     }
 
     public void execute( ReporterManager reporterManager, ClassLoader 
classLoader )
+        throws ReporterException, TestSetFailedException
     {
         if ( testSets == null )
         {
             throw new IllegalStateException( "You must call locateTestSets 
before calling execute" );
         }
 
-        TestNGExecutor.run( this.suiteFilePaths, this.testSourceDirectory, 
this.options, this.version, reporterManager,
-                            this );
+        TestNGExecutor.run( this.suiteFilePaths, this.testSourceDirectory, 
this.options, this.version, 
+                            this.classifier, reporterManager, this );
     }
 
     public void execute( String testSetName, ReporterManager reporterManager, 
ClassLoader classLoader )
@@ -87,7 +96,6 @@
 
     public int getNumTests()
     {
-        // TODO: this is not correct
         return suiteFiles.length;
     }
 

Modified: 
maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG4751Configurator.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG4751Configurator.java?view=diff&rev=543820&r1=543819&r2=543820
==============================================================================
--- 
maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG4751Configurator.java
 (original)
+++ 
maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG4751Configurator.java
 Sat Jun  2 18:18:45 2007
@@ -29,8 +29,8 @@
  * -threadcount (int)
  * -parallel (boolean)
  * <p/>
- * Not supported yet:
- * -setListenerClasses(List<Class>) or setListeners(List<Object>)
+ * 
+ * @author <a href='mailto:the[dot]mindstorm[at]gmail[dot]com'>Alex Popescu</a>
  */
 public class TestNG4751Configurator
     extends AbstractDirectConfigurator

Modified: 
maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG52Configurator.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG52Configurator.java?view=diff&rev=543820&r1=543819&r2=543820
==============================================================================
--- 
maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG52Configurator.java
 (original)
+++ 
maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG52Configurator.java
 Sat Jun  2 18:18:45 2007
@@ -29,8 +29,8 @@
  * -threadcount (int)
  * -parallel (String)
  * <p/>
- * Not supported yet:
- * -setListenerClasses(List<Class>) or setListeners(List<Object>)
+ * 
+ * @author <a href='mailto:the[dot]mindstorm[at]gmail[dot]com'>Alex Popescu</a>
  */
 public class TestNG52Configurator
     extends AbstractDirectConfigurator

Modified: 
maven/sandbox/branches/surefire/apopescu/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/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java?view=diff&rev=543820&r1=543819&r2=543820
==============================================================================
--- 
maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java
 (original)
+++ 
maven/sandbox/branches/surefire/apopescu/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java
 Sat Jun  2 18:18:45 2007
@@ -34,6 +34,8 @@
  * <p/>
  * Test classes and/or suite files are not passed along as options parameters, 
but
  * configured separately.
+ * 
+ * @author <a href='mailto:the[dot]mindstorm[at]gmail[dot]com'>Alex Popescu</a>
  */
 public class TestNGMapConfigurator
     implements Configurator


Reply via email to