Author: dfabulich
Date: Sun Nov 25 12:08:06 2007
New Revision: 598047
URL: http://svn.apache.org/viewvc?rev=598047&view=rev
Log:
Incorporating changes from apopescu sandbox branch
Modified:
maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGXmlTestSuite.java
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG4751Configurator.java
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG52Configurator.java
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java
Modified:
maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java?rev=598047&r1=598046&r2=598047&view=diff
==============================================================================
---
maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
(original)
+++
maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
Sun Nov 25 12:08:06 2007
@@ -642,10 +642,10 @@
{
throw new MojoExecutionException( "suiteXmlFiles is
configured, but there is no TestNG dependency" );
}
-
+
// TODO: properties should be passed in here too
surefireBooter.addTestSuite(
"org.apache.maven.surefire.testng.TestNGXmlTestSuite", new Object[]{
- suiteXmlFiles, testSourceDirectory.getAbsolutePath(),
testNgArtifact.getVersion(), reportsDirectory} );
+ suiteXmlFiles, testSourceDirectory.getAbsolutePath(),
testNgArtifact.getVersion(), testNgArtifact.getClassifier(), properties,
reportsDirectory} );
}
else
{
@@ -705,7 +705,7 @@
{
surefireBooter.addTestSuite(
"org.apache.maven.surefire.testng.TestNGDirectoryTestSuite", new Object[] {
testClassesDirectory, includes, excludes,
testSourceDirectory.getAbsolutePath(),
- testNgArtifact.getVersion(), properties, reportsDirectory}
);
+ testNgArtifact.getVersion(),
testNgArtifact.getClassifier(), properties, reportsDirectory} );
}
else
{
Modified:
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java?rev=598047&r1=598046&r2=598047&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
(original)
+++
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
Sun Nov 25 12:08:06 2007
@@ -45,6 +45,8 @@
{
private ArtifactVersion version;
+ private String classifier;
+
private Map options;
private String testSourceDirectory;
@@ -52,21 +54,24 @@
private File reportsDirectory;
public TestNGDirectoryTestSuite( File basedir, ArrayList includes,
ArrayList excludes, String testSourceDirectory,
- String artifactVersion, Properties
confOptions, File reportsDirectory )
+ String artifactVersion, String
artifactClassifier, Properties confOptions, File reportsDirectory )
{
this( basedir, includes, excludes, testSourceDirectory, new
DefaultArtifactVersion( artifactVersion ),
- confOptions, reportsDirectory );
+ artifactClassifier, confOptions, reportsDirectory );
}
public TestNGDirectoryTestSuite( File basedir, List includes, List
excludes, String testSourceDirectory,
- ArtifactVersion artifactVersion, Map
confOptions, File reportsDirectory )
+ ArtifactVersion artifactVersion, String
artifactClassifier, Map confOptions, File reportsDirectory )
{
super( basedir, includes, excludes );
this.options = confOptions;
+
this.testSourceDirectory = testSourceDirectory;
- this.version = artifactVersion;
this.reportsDirectory = reportsDirectory;
+ this.version = artifactVersion;
+
+ this.classifier = artifactClassifier;
}
protected SurefireTestSet createTestSet( Class testClass, ClassLoader
classLoader )
@@ -90,7 +95,7 @@
}
TestNGExecutor.run( new Class[]{testSet.getTestClass()},
this.testSourceDirectory, this.options, this.version,
- reporterManager, this, reportsDirectory );
+ this.classifier, reporterManager, this,
reportsDirectory );
}
public void execute( ReporterManager reporterManager, ClassLoader
classLoader )
@@ -109,6 +114,7 @@
testClasses[i++] = testSet.getTestClass();
}
- TestNGExecutor.run( testClasses, this.testSourceDirectory,
this.options, this.version, reporterManager, this, reportsDirectory );
+ TestNGExecutor.run( testClasses, this.testSourceDirectory,
this.options, this.version,
+ this.classifier, reporterManager, this,
reportsDirectory );
}
}
Modified:
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java?rev=598047&r1=598046&r2=598047&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
(original)
+++
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGExecutor.java
Sun Nov 25 12:08:06 2007
@@ -21,6 +21,8 @@
import java.io.File;
import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -33,7 +35,7 @@
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.IReporter;
import org.testng.TestNG;
@@ -50,30 +52,33 @@
}
public static void run( Class[] testClasses, String testSourceDirectory,
Map options, ArtifactVersion version,
- ReporterManager reportManager, SurefireTestSuite
suite, File reportsDirectory )
+ String classifier, ReporterManager reportManager,
SurefireTestSuite suite, File reportsDirectory )
+ throws TestSetFailedException
{
+ // kind of ugly, but listeners are configured differently
+ final String listeners = (String) options.remove("listener");
TestNG testng = new TestNG( false );
Configurator configurator = getConfigurator( version );
configurator.configure( testng, options );
- postConfigure( testng, testSourceDirectory, reportManager, suite,
reportsDirectory );
-
+ postConfigure( testng, testSourceDirectory, listeners, classifier,
reportManager, suite, reportsDirectory );
testng.setTestClasses( testClasses );
testng.run();
}
public static void run( List suiteFiles, String testSourceDirectory, Map
options, ArtifactVersion version,
- ReporterManager reportManager, SurefireTestSuite
suite, File reportsDirectory )
+ String classifier, ReporterManager reportManager,
SurefireTestSuite suite, File reportsDirectory )
+ throws TestSetFailedException
{
TestNG testng = new TestNG( false );
Configurator configurator = getConfigurator( version );
configurator.configure( testng, options );
- postConfigure( testng, testSourceDirectory, reportManager, suite,
reportsDirectory );
+ postConfigure( testng, testSourceDirectory, (String)
options.get("listener"), classifier, reportManager, suite, reportsDirectory );
testng.setTestSuites( suiteFiles );
testng.run();
}
- private static Configurator getConfigurator( ArtifactVersion version )
+ private static Configurator getConfigurator( ArtifactVersion version )
throws TestSetFailedException
{
try
{
@@ -93,17 +98,18 @@
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, File
reportsDirectory )
+ private static void postConfigure( TestNG testNG, String sourcePath,
String listenerClasses,
+ String classifier, ReporterManager
reportManager, SurefireTestSuite suite, File reportsDirectory )
+ throws TestSetFailedException
{
// turn off all TestNG output
testNG.setVerbose( 0 );
@@ -113,10 +119,14 @@
attachNonStandardReporter( testNG, "org.testng.reporters.XMLReporter"
);
attachNonStandardReporter( testNG,
"org.testng.reporters.FailedReporter" );
// 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 );
}
+
testNG.setOutputDirectory( reportsDirectory.getAbsolutePath() );
}
@@ -140,6 +150,29 @@
}
}
+ 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;
+ }
+
private static void attachNonStandardReporter( TestNG testNG, String
className )
{
try
Modified:
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGXmlTestSuite.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGXmlTestSuite.java?rev=598047&r1=598046&r2=598047&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGXmlTestSuite.java
(original)
+++
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGXmlTestSuite.java
Sun Nov 25 12:08:06 2007
@@ -19,12 +19,6 @@
* under the License.
*/
-import org.apache.maven.artifact.versioning.ArtifactVersion;
-import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
-import org.apache.maven.surefire.report.ReporterManager;
-import org.apache.maven.surefire.suite.SurefireTestSuite;
-import org.apache.maven.surefire.testset.TestSetFailedException;
-
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
@@ -32,6 +26,14 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
+
+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;
/**
* Handles suite xml file definitions for TestNG.
@@ -50,8 +52,10 @@
private ArtifactVersion version;
- private Map options = new HashMap();
-
+ private String classifier;
+
+ private Map options;
+
private File reportsDirectory;
// Not really used
@@ -59,28 +63,34 @@
/**
* 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, File reportsDirectory )
+ public TestNGXmlTestSuite( File[] suiteFiles, String testSourceDirectory,
String artifactVersion,
+ String artifactClassifier, Properties
confOptions, File reportsDirectory )
{
this.suiteFiles = suiteFiles;
+ this.options = confOptions;
+
this.version = new DefaultArtifactVersion( artifactVersion );
+ this.classifier = artifactClassifier;
+
this.testSourceDirectory = testSourceDirectory;
this.reportsDirectory = reportsDirectory;
}
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, reportsDirectory );
+ TestNGExecutor.run( this.suiteFilePaths, this.testSourceDirectory,
this.options, this.version,
+ this.classifier, reporterManager, this,
reportsDirectory );
}
public void execute( String testSetName, ReporterManager reporterManager,
ClassLoader classLoader )
@@ -91,7 +101,6 @@
public int getNumTests()
{
- // TODO: this is not correct
return suiteFiles.length;
}
Modified:
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG4751Configurator.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG4751Configurator.java?rev=598047&r1=598046&r2=598047&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG4751Configurator.java
(original)
+++
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG4751Configurator.java
Sun Nov 25 12:08:06 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/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG52Configurator.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG52Configurator.java?rev=598047&r1=598046&r2=598047&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG52Configurator.java
(original)
+++
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG52Configurator.java
Sun Nov 25 12:08:06 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/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java?rev=598047&r1=598046&r2=598047&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java
(original)
+++
maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java
Sun Nov 25 12:08:06 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
@@ -54,7 +56,14 @@
{
val = convert( val, String.class );
}
- convertedOptions.put( "-" + key, val );
+ if ( key.startsWith("-") )
+ {
+ convertedOptions.put( key, val );
+ }
+ else
+ {
+ convertedOptions.put( "-" + key, val );
+ }
}
testng.configure( convertedOptions );