Author: rl...@jb... Date: 2006-05-24 09:49:24 -0400 (Wed, 24 May 2006) New Revision: 4402 Added: labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/.classpath labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/.project labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/pom.xml labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/pom.xml labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test1/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test1/pom.xml labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test1/src/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test1/src/test/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test1/src/test/java/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test1/src/test/java/SurefireTest1.java labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test2/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test2/pom.xml labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test2/src/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test2/src/test/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test2/src/test/java/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test2/src/test/java/SurefireTest2.java labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test3/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test3/pom.xml labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test3/src/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test3/src/test/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test3/src/test/java/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test3/src/test/java/SurefireTest3.java labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test4/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test4/pom.xml labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test4/src/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test4/src/test-data/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test4/src/test-data/testng.xml labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test4/src/test/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test4/src/test/java/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test4/src/test/java/TestNGSuiteTest.java labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test5/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test5/pom.xml labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test5/src/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test5/src/test/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test5/src/test/java/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test5/src/test/java/TestNGJavadocTest.java labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test6/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test6/pom.xml labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test6/src/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test6/src/test/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test6/src/test/java/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test6/src/test/java/JunitTest.java labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test6/src/test/java/TestNGTest.java labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/main/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/main/java/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/main/java/org/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/main/java/org/apache/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/main/java/org/apache/maven/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/main/java/org/apache/maven/plugin/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/main/java/org/apache/maven/plugin/surefire/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/main/java/org/apache/maven/test/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/main/java/org/apache/maven/test/SurefirePlugin.java labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/site/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/site/apt/ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/site/apt/howto.apt labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/site/apt/introduction.apt labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/site/apt/testng.apt labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/site/site.xml Log: initial entry Added: labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/.classpath =================================================================== --- labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/.classpath 2006-05-24 09:53:26 UTC (rev 4401) +++ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/.classpath 2006-05-24 13:49:24 UTC (rev 4402) @@ -0,0 +1,13 @@ +<classpath> + <classpathentry kind="src" path="src/main/java"/> + <classpathentry kind="output" path="target/classes"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="lib" path="C:/projects/serialization/libs/jrunit.jar"/> + <classpathentry kind="var" path="M2_REPO/org/apache/maven/surefire/surefire-api/2.0/surefire-api-2.0.jar"/> + <classpathentry kind="var" path="M2_REPO/apache-log4j/log4j/1.2.8/log4j-1.2.8.jar"/> + <classpathentry kind="var" path="M2_REPO/ant/ant/1.6.5/ant-1.6.5.jar"/> + <classpathentry kind="var" path="M2_REPO/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar"/> + <classpathentry kind="var" path="M2_REPO/org/apache/maven/maven-plugin-api/2.0/maven-plugin-api-2.0.jar"/> + <classpathentry kind="var" path="M2_REPO/org/apache/maven/maven-artifact/2.0/maven-artifact-2.0.jar"/> + <classpathentry kind="var" path="M2_REPO/org/apache/maven/surefire/surefire-booter/2.0/surefire-booter-2.0.jar"/> +</classpath> \ No newline at end of file Added: labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/.project =================================================================== --- labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/.project 2006-05-24 09:53:26 UTC (rev 4401) +++ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/.project 2006-05-24 13:49:24 UTC (rev 4402) @@ -0,0 +1,14 @@ +<projectDescription> + <name>maven-jrunit-plugin</name> + <comment>Maven Plugins</comment> + <projects/> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments/> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> \ No newline at end of file Added: labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/pom.xml =================================================================== --- labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/pom.xml 2006-05-24 09:53:26 UTC (rev 4401) +++ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/pom.xml 2006-05-24 13:49:24 UTC (rev 4402) @@ -0,0 +1,78 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <artifactId>maven-plugins</artifactId> + <groupId>org.apache.maven.plugins</groupId> + <version>1</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>maven-jrunit-plugin</artifactId> + <packaging>maven-plugin</packaging> + <name>Maven JRunit Plugin</name> + <version>1.0</version> + <contributors> + <contributor> + <name>Joakim Erdfelt</name> + <email>jo...@er...</email> + </contributor> + </contributors> + <dependencies> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>org.apache.maven.surefire</groupId> + <artifactId>surefire-booter</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-utils</artifactId> + <version>1.1</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-artifact</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>jrunit</groupId> + <artifactId>jrunit</artifactId> + <version>3.8.1</version> + <scope>system</scope> + <systemPath>c:/projects/serialization/libs/jrunit.jar</systemPath> + </dependency> + <dependency> + <groupId>ant</groupId> + <artifactId>ant</artifactId> + <version>1.6.5</version> + </dependency> + <dependency> + <groupId>apache-log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.8</version> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://svn.labs.jboss.org/labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin</connection> + <developerConnection>scm:svn:https://svn.labs.jboss.org/labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin</developerConnection> + <url>https://svn.labs.jboss.org/labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin</url> + </scm> + + <build> + <plugins> + <!-- define a plugin for running jrunit tests --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>2.1.3</version> + </plugin> + </plugins> + + </build> + + +</project> Added: labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/pom.xml =================================================================== --- labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/pom.xml 2006-05-24 09:53:26 UTC (rev 4401) +++ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/pom.xml 2006-05-24 13:49:24 UTC (rev 4402) @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.maven.plugins.surefire</groupId> + <artifactId>it</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>pom</packaging> + <name>Surefire plugin integration tests</name> + + <modules> + <module>test1</module> + <module>test2</module> + <module>test3</module> + </modules> + +</project> Added: labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test1/pom.xml =================================================================== --- labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test1/pom.xml 2006-05-24 09:53:26 UTC (rev 4401) +++ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test1/pom.xml 2006-05-24 13:49:24 UTC (rev 4402) @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.maven.plugins.surefire</groupId> + <artifactId>test1</artifactId> + <version>1.0-SNAPSHOT</version> + <name>Test for default configuration</name> + <description>Test for default surefire configuration</description> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + </dependencies> + +</project> Added: labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test1/src/test/java/SurefireTest1.java =================================================================== --- labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test1/src/test/java/SurefireTest1.java 2006-05-24 09:53:26 UTC (rev 4401) +++ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test1/src/test/java/SurefireTest1.java 2006-05-24 13:49:24 UTC (rev 4402) @@ -0,0 +1,66 @@ +import junit.extensions.TestSetup; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class SurefireTest1 + extends TestCase +{ + + private boolean setUpCalled = false; + + private static boolean tearDownCalled = false; + + public SurefireTest1( String name, String extraName ) + { + super( name ); + } + + public static Test suite() + { + TestSuite suite = new TestSuite(); + Test test = new SurefireTest2( "testSetUp", "dummy" ); + suite.addTest( test ); + TestSetup setup = new TestSetup( suite ) + { + + protected void setUp() + { + //oneTimeSetUp(); + } + + protected void tearDown() + { + oneTimeTearDown(); + } + + }; + + return setup; + } + + protected void setUp() + { + setUpCalled = true; + tearDownCalled = false; + System.out.println( "Called setUp" ); + } + + protected void tearDown() + { + setUpCalled = false; + tearDownCalled = true; + System.out.println( "Called tearDown" ); + } + + public void testSetUp() + { + assertTrue( "setUp was not called", setUpCalled ); + } + + public static void oneTimeTearDown() + { + assertTrue( "tearDown was not called", tearDownCalled ); + } + +} Added: labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test2/pom.xml =================================================================== --- labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test2/pom.xml 2006-05-24 09:53:26 UTC (rev 4401) +++ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test2/pom.xml 2006-05-24 13:49:24 UTC (rev 4402) @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.maven.plugins.surefire</groupId> + <artifactId>test2</artifactId> + <version>1.0-SNAPSHOT</version> + <name>Test for MSUREFIRE-20</name> + <description>forkMode=pertest fails to call setUp</description> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <forkMode>pertest</forkMode> + </configuration> + </plugin> + </plugins> + </build> + +</project> Added: labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test2/src/test/java/SurefireTest2.java =================================================================== --- labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test2/src/test/java/SurefireTest2.java 2006-05-24 09:53:26 UTC (rev 4401) +++ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test2/src/test/java/SurefireTest2.java 2006-05-24 13:49:24 UTC (rev 4402) @@ -0,0 +1,66 @@ +import junit.extensions.TestSetup; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class SurefireTest2 + extends TestCase +{ + + private boolean setUpCalled = false; + + private static boolean tearDownCalled = false; + + public SurefireTest2( String name, String extraName ) + { + super( name ); + } + + public static Test suite() + { + TestSuite suite = new TestSuite(); + Test test = new SurefireTest2( "testSetUp", "dummy" ); + suite.addTest( test ); + TestSetup setup = new TestSetup( suite ) + { + + protected void setUp() + { + //oneTimeSetUp(); + } + + protected void tearDown() + { + oneTimeTearDown(); + } + + }; + + return setup; + } + + protected void setUp() + { + setUpCalled = true; + tearDownCalled = false; + System.out.println( "Called setUp" ); + } + + protected void tearDown() + { + setUpCalled = false; + tearDownCalled = true; + System.out.println( "Called tearDown" ); + } + + public void testSetUp() + { + assertTrue( "setUp was not called", setUpCalled ); + } + + public static void oneTimeTearDown() + { + assertTrue( "tearDown was not called", tearDownCalled ); + } + +} Added: labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test3/pom.xml =================================================================== --- labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test3/pom.xml 2006-05-24 09:53:26 UTC (rev 4401) +++ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test3/pom.xml 2006-05-24 13:49:24 UTC (rev 4402) @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.maven.plugins.surefire</groupId> + <artifactId>test3</artifactId> + <version>1.0-SNAPSHOT</version> + <name>Test for MSUREFIRE-54</name> + <description>XML test reports are not well-formed when failure message contains quotes.</description> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>2.1.2</version> + <configuration> + <testFailureIgnore>true</testFailureIgnore > + </configuration> + </plugin> + </plugins> + </build> + +</project> Added: labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test3/src/test/java/SurefireTest3.java =================================================================== --- labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test3/src/test/java/SurefireTest3.java 2006-05-24 09:53:26 UTC (rev 4401) +++ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test3/src/test/java/SurefireTest3.java 2006-05-24 13:49:24 UTC (rev 4402) @@ -0,0 +1,36 @@ +import junit.extensions.TestSetup; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class SurefireTest3 + extends TestCase +{ + + public SurefireTest3( ) + { + super( ); + } + + public SurefireTest3( String name ) + { + super( name ); + } + + + public void testQuote() + { + fail( "\"" ); + } + + public void testLower() + { + fail( "<" ); + } + + public void testGreater() + { + fail( ">" ); + } + +} Added: labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test4/pom.xml =================================================================== --- labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test4/pom.xml 2006-05-24 09:53:26 UTC (rev 4401) +++ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test4/pom.xml 2006-05-24 13:49:24 UTC (rev 4402) @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.maven.plugins.surefire</groupId> + <artifactId>test4</artifactId> + <version>1.0-SNAPSHOT</version> + <name>TestNG Suites</name> + <description>Uses suite xml file definitions to invoke testng tests</description> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng-jdk15</artifactId> + <version>4.4.7</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <suiteXmlFiles> + <file>src/test-data/testng.xml</file> + </suiteXmlFiles> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.5</source> + <target>1.5</target> + </configuration> + </plugin> + </plugins> + </build> + +</project> Added: labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test4/src/test/java/TestNGSuiteTest.java =================================================================== --- labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test4/src/test/java/TestNGSuiteTest.java 2006-05-24 09:53:26 UTC (rev 4401) +++ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test4/src/test/java/TestNGSuiteTest.java 2006-05-24 13:49:24 UTC (rev 4402) @@ -0,0 +1,34 @@ +import org.testng.annotations.Configuration; +import org.testng.annotations.Test; +import org.testng.internal.Utils; + + +/** + * Tests that forcing testng to run tests via the + * <code>"${maven.test.forcetestng}"</code> configuration option + * works. + * + * @author jkuhnert + */ +public class TestNGSuiteTest { + + /** + * Sets up testObject + */ + @Configuration(beforeTestClass = true) + public void configureTest() + { + testObject = new Object(); + } + + Object testObject; + + /** + * Tests reporting an error + */ + @Test + public void isTestObjectNull() + { + assert testObject != null : "testObject is null"; + } +} \ No newline at end of file Added: labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test4/src/test-data/testng.xml =================================================================== --- labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test4/src/test-data/testng.xml 2006-05-24 09:53:26 UTC (rev 4401) +++ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test4/src/test-data/testng.xml 2006-05-24 13:49:24 UTC (rev 4402) @@ -0,0 +1,11 @@ +<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > + +<suite name="Suite 1 Test" verbose="1" > + + <test name="Sample Test" > + <classes> + <class name="TestNGSuiteTest" /> + </classes> + </test> + +</suite> \ No newline at end of file Added: labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test5/pom.xml =================================================================== --- labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test5/pom.xml 2006-05-24 09:53:26 UTC (rev 4401) +++ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test5/pom.xml 2006-05-24 13:49:24 UTC (rev 4402) @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.maven.plugins.surefire</groupId> + <artifactId>test5</artifactId> + <version>1.0-SNAPSHOT</version> + <name>Test for testng jdk14 integration</name> + <description>calls testng jdk14 javadoc based tests</description> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng-jdk14</artifactId> + <version>4.4.7</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <testSourceDirectory>src/test/java</testSourceDirectory> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <groups>functional</groups> + </configuration> + </plugin> + </plugins> + </build> + +</project> Added: labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test5/src/test/java/TestNGJavadocTest.java =================================================================== --- labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test5/src/test/java/TestNGJavadocTest.java 2006-05-24 09:53:26 UTC (rev 4401) +++ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test5/src/test/java/TestNGJavadocTest.java 2006-05-24 13:49:24 UTC (rev 4402) @@ -0,0 +1,42 @@ +import org.testng.Assert; + + +/** + * Tests that forcing testng to run tests via the + * <code>"${maven.test.forcetestng}"</code> configuration option + * works. + * + * @author jkuhnert + */ +public class TestNGJavadocTest { + + /** + * Sets up testObject + * @testng.configuration beforeTestClass = "true" + * groups = "functional" + */ + public void configureTest() + { + testObject = new Object(); + } + + Object testObject; + + /** + * Tests reporting an error + * @testng.test groups = "functional, notincluded" + */ + public void isTestObjectNull() + { + Assert.assertNotNull(testObject, "testObject is null"); + } + + /** + * Sample method that shouldn't be run by test suite. + * @testng.test groups = "notincluded" + */ + public void shouldNotRun() + { + Assert.assertTrue(false, "Group specified by test shouldnt be run."); + } +} \ No newline at end of file Added: labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test6/pom.xml =================================================================== --- labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test6/pom.xml 2006-05-24 09:53:26 UTC (rev 4401) +++ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test6/pom.xml 2006-05-24 13:49:24 UTC (rev 4402) @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.maven.plugins.surefire</groupId> + <artifactId>test6</artifactId> + <version>1.0-SNAPSHOT</version> + <name>Test for testng integration</name> + <description>calls testng test</description> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng-jdk15</artifactId> + <version>4.4.7</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <groups>functional</groups> + <threadCount>3</threadCount> + <parallel>true</parallel> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.5</source> + <target>1.5</target> + </configuration> + </plugin> + </plugins> + </build> + +</project> Added: labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test6/src/test/java/JunitTest.java =================================================================== --- labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test6/src/test/java/JunitTest.java 2006-05-24 09:53:26 UTC (rev 4401) +++ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test6/src/test/java/JunitTest.java 2006-05-24 13:49:24 UTC (rev 4402) @@ -0,0 +1,29 @@ +import junit.framework.TestCase; + +/** + * Provided to ensure both junit and testng tests can run happily + * together. + * + * @author jkuhnert + */ +public class JunitTest extends TestCase { + + Object testObject; + + /** + * Creats an object instance + */ + public void setUp() + { + testObject = new Object(); + } + + /** + * Tests that object created in setup + * isn't null. + */ + public void testJunitObject() + { + assertNotNull(testObject); + } +} Added: labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test6/src/test/java/TestNGTest.java =================================================================== --- labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test6/src/test/java/TestNGTest.java 2006-05-24 09:53:26 UTC (rev 4401) +++ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/it/test6/src/test/java/TestNGTest.java 2006-05-24 13:49:24 UTC (rev 4402) @@ -0,0 +1,43 @@ +import org.testng.annotations.Configuration; +import org.testng.annotations.Test; +import org.testng.internal.Utils; + + +/** + * Tests that forcing testng to run tests via the + * <code>"${maven.test.forcetestng}"</code> configuration option + * works. + * + * @author jkuhnert + */ +public class TestNGTest { + + /** + * Sets up testObject + */ + @Configuration(beforeTestClass = true, groups = "functional") + public void configureTest() + { + testObject = new Object(); + } + + Object testObject; + + /** + * Tests reporting an error + */ + @Test(groups = {"functional", "notincluded"}) + public void isTestObjectNull() + { + assert testObject != null : "testObject is null"; + } + + /** + * Sample method that shouldn't be run by test suite. + */ + @Test(groups = "notincluded") + public void shouldNotRun() + { + assert false == true : "Group specified by test shouldnt be run."; + } +} \ No newline at end of file Added: labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java =================================================================== --- labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java 2006-05-24 09:53:26 UTC (rev 4401) +++ labs/jbossbuild/trunk/projects/maven-plugins/maven-jrunit-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java 2006-05-24 13:49:24 UTC (rev 4402) @@ -0,0 +1,787 @@ +package org.apache.maven.plugin.surefire; + +/* + * Copyright 2001-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.metadata.ArtifactMetadataSource; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.resolver.ArtifactResolutionResult; +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.surefire.booter.ForkConfiguration; +import org.apache.maven.surefire.booter.SurefireBooter; +import org.apache.maven.surefire.booter.SurefireBooterForkException; +import org.apache.maven.surefire.booter.SurefireExecutionException; +import org.apache.maven.surefire.report.BriefConsoleReporter; +import org.apache.maven.surefire.report.BriefFileReporter; +import org.apache.maven.surefire.report.ConsoleReporter; +import org.apache.maven.surefire.report.DetailedConsoleReporter; +import org.apache.maven.surefire.report.FileReporter; +import org.apache.maven.surefire.report.ForkingConsoleReporter; +import org.apache.maven.surefire.report.XMLReporter; +import org.codehaus.plexus.util.StringUtils; +import org.jboss.jrunit.controller.ant.AntBenchmarkReceiver; +import org.jboss.jrunit.controller.ant.AntDatabaseBenchmarkReceiver; +import org.jboss.jrunit.controller.ant.AntFileBenchmarkReceiver; +import org.jboss.jrunit.controller.ant.AntQuitBenchmark; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +/** + * Run tests using Surefire. + * + * @author Jason van Zyl + * @version $Id: SurefirePlugin.java 406180 2006-05-14 01:40:09Z brett $ + * @requiresDependencyResolution test + * @goal test + * @phase test + */ +public class SurefirePlugin + extends AbstractMojo +{ + /** + * Set this to 'true' to bypass unit tests entirely. Its use is NOT RECOMMENDED, but quite convenient on occasion. + * + * @parameter expression="${maven.test.skip}" + */ + private boolean skip; + + /** + * Set this to true to ignore a failure during testing. Its use is NOT RECOMMENDED, but quite convenient on occasion. + * + * @parameter expression="${maven.test.failure.ignore}" + */ + private boolean testFailureIgnore; + + /** + * The base directory of the project being tested. This can be obtained in your unit test by System.getProperty("basedir"). + * + * @parameter expression="${basedir}" + * @required + */ + private File basedir; + + /** + * The directory containing generated classes of the project being tested. + * + * @parameter expression="${project.build.outputDirectory}" + * @required + */ + private File classesDirectory; + + /** + * The directory containing generated test classes of the project being tested. + * + * @parameter expression="${project.build.testOutputDirectory}" + * @required + */ + private File testClassesDirectory; + + /** + * The classpath elements of the project being tested. + * + * @parameter expression="${project.testClasspathElements}" + * @required + * @readonly + */ + private List classpathElements; + + /** + * Base directory where all reports are written to. + * + * @parameter expression="${project.build.directory}/surefire-reports" + */ + private File reportsDirectory; + + /** + * The test source directory containing test class sources. + * + * @parameter expression="${project.build.testSourceDirectory}" + * @required + */ + private File testSourceDirectory; + + /** + * Specify this parameter if you want to use the test pattern matching notation, Ant pattern matching, to select tests to run. + * The Ant pattern will be used to create an include pattern formatted like <code>**/${test}.java</code> + * When used, the <code>includes</code> and <code>excludes</code> patterns parameters are ignored + * + * @parameter expression="${test}" + */ + private String test; + + /** + * List of patterns (separated by commas) used to specify the tests that should be included in testing. + * When not specified and whent the <code>test</code> parameter is not specified, the default includes will be + * <code>**/Test*.java **/*Test.java **/*TestCase.java</code> + * + * @parameter + */ + private List includes; + + /** + * List of patterns (separated by commas) used to specify the tests that should be excluded in testing. + * When not specified and whent the <code>test</code> parameter is not specified, the default excludes will be + * <code>**/Abstract*Test.java **/Abstract*TestCase.java **/*$*</code> + * + * @parameter + */ + private List excludes; + + /** + * ArtifactRepository of the localRepository. To obtain the directory of localRepository in unit tests use System.setProperty( "localRepository"). + * + * @parameter expression="${localRepository}" + * @required + * @readonly + */ + private ArtifactRepository localRepository; + + /** + * List of System properties to pass to the JUnit tests. + * + * @parameter + */ + private Properties systemProperties; + + /** + * Map of of plugin artifacts. + * + * @parameter expression="${plugin.artifactMap}" + * @required + * @readonly + */ + private Map pluginArtifactMap; + + /** + * Map of of project artifacts. + * + * @parameter expression="${project.artifactMap}" + * @required + * @readonly + */ + private Map projectArtifactMap; + + /** + * Option to print summary of test suites or just print the test cases that has errors. + * + * @parameter expression="${surefire.printSummary}" + * default-value="true" + */ + private boolean printSummary; + + /** + * Selects the formatting for the test report to be generated. Can be set as brief or plain. + * + * @parameter expression="${surefire.reportFormat}" + * default-value="brief" + */ + private String reportFormat; + + /** + * Option to generate a file test report or just output the test report to the console. + * + * @parameter expression="${surefire.useFile}" + * default-value="true" + */ + private boolean useFile; + + /** + * Option to specify the forking mode. Can be "never" (default), "once" or "always". + * "none" and "pertest" are also accepted for backwards compatibility. + * + * @parameter expression="${forkMode}" default-value="once" + */ + private String forkMode; + + /** + * Option to specify the jvm (or path to the java executable) to use with + * the forking options. For the default we will assume that java is in the path. + * + * @parameter expression="${jvm}" + * default-value="java" + */ + private String jvm; + + /** + * Arbitrary options to set on the command line. + * + * @parameter expression="${argLine}" + */ + private String argLine; + + /** + * Additional environments to set on the command line. + * + * @parameter + */ + private Map environmentVariables = new HashMap(); + + /** + * Command line working directory. + * + * @parameter + */ + private File workingDirectory; + + /** + * When false it makes tests run using the standard classloader delegation instead of the default + * Maven isolated classloader. Only used when forking (forkMode is not "none").<br/> + * Setting it to false helps with some problems caused by conflicts between + * xml parsers in the classpath and the Java 5 provider parser. + * + * @parameter expression="${childDelegation}" + * default-value="false" + */ + private boolean childDelegation; + + /** + * Groups for this test. Only classes/methods/etc decorated with one of the + * groups specified here will be included in test run, if specified. + * + * @parameter expression="${groups}" + */ + private String groups; + + /** + * Excluded groups. Any methods/classes/etc with one of the groups specified in this + * list will specifically not be run. + * + * @parameter expression="${excludedGroups}" + */ + private String excludedGroups; + + /** + * List of TestNG suite xml file locations, seperated by commas. It should be noted that + * if suiteXmlFiles is specified, <b>no</b> other tests will be run, ignoring other parameters, + * like includes and excludes. + * + * @parameter + */ + private File[] suiteXmlFiles; + + /** + * The attribute thread-count allows you to specify how many threads should be allocated + * for this execution. Only makes sense to use in conjunction with parallel. + * + * @parameter expression="${threadCount}" + * default-value="5" + */ + private int threadCount; + + /** + * When you use the parallel attribute, TestNG will try to run all your test methods in + * separate threads, except for methods that depend on each other, which will be run in + * the same thread in order to respect their order of execution. + * + * @parameter expression="${parallel}" + * default-value="false" + * @todo test how this works with forking, and console/file output parallelism + */ + private boolean parallel; + + /** + * Whether to trim the stack trace in the reports to just the lines within the test, or show the full trace. + * + * @parameter expression="${trimStackTrace}" default-value="true" + */ + private boolean trimStackTrace; + + /** + * @component + */ + private ArtifactResolver artifactResolver; + + /** + * @component + */ + private ArtifactFactory artifactFactory; + + /** + * @parameter expression="${project.pluginArtifactRepositories}" + */ + private List remoteRepositories; + + /** + * @component + */ + private ArtifactMetadataSource metadataSource; + + private static final String BRIEF_REPORT_FORMAT = "brief"; + + private static final String PLAIN_REPORT_FORMAT = "plain"; + + private Properties originalSystemProperties; + + /** + * @parameter expression="${disableXmlReport}" default-value="false" + */ + private boolean disableXmlReport; + + public void execute() + throws MojoExecutionException, MojoFailureException + { + this.getLog().info("JBOSS FORK HACK"); + this.getLog().info("Setting up JRUNIT"); + + org.jboss.jrunit.controller.ant.AntBenchmarkReceiver receiver = new AntBenchmarkReceiver(); + AntQuitBenchmark quit = new AntQuitBenchmark(); + AntDatabaseBenchmarkReceiver dbReceiver = new AntDatabaseBenchmarkReceiver(); + dbReceiver.setJdbcClass(null); + dbReceiver.setJdbcPassword(null); + dbReceiver.setJdbcURL(null); + dbReceiver.setJdbcUserName(null); + dbReceiver.setOnlyIf(null); + + AntFileBenchmarkReceiver fileBenchMarkReceiver = new AntFileBenchmarkReceiver(); + fileBenchMarkReceiver.setDirectory("./build"); + receiver.getReceivers().add(dbReceiver); + receiver.getReceivers().add(fileBenchMarkReceiver); + + + + + + + if ( skip ) + { + getLog().info( "Tests are skipped." ); + } + else if ( !testClassesDirectory.exists() ) + { + getLog().info( "No tests to run." ); + } + else + { + if ( parallel ) + { + if ( threadCount < 1 ) + { + throw new MojoFailureException( "Must have at least one thread in parallel mode" ); + } + } + + SurefireBooter surefireBooter = constructSurefireBooter(); + + getLog().info( "Surefire report directory: " + reportsDirectory ); + + boolean success; + try + { + success = surefireBooter.run(); + } + catch ( SurefireBooterForkException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + catch ( SurefireExecutionException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + + if ( originalSystemProperties != null ) + { + // restore system properties + System.setProperties( originalSystemProperties ); + } + + if ( !success ) + { + String msg = "There are test failures."; + + if ( testFailureIgnore ) + { + getLog().error( msg ); + } + else + { + throw new MojoFailureException( msg ); + } + } + } + } + + private SurefireBooter constructSurefireBooter() + throws MojoExecutionException, MojoFailureException + { + SurefireBooter surefireBooter = new SurefireBooter(); + + Artifact surefireArtifact = (Artifact) pluginArtifactMap.get( "org.apache.maven.surefire:surefire-booter" ); + if ( surefireArtifact == null ) + { + throw new MojoExecutionException( "Unable to locate surefire-booter in the list of plugin artifacts" ); + } + + surefireArtifact.isSnapshot(); // TODO: this is ridiculous, but it fixes getBaseVersion to be -SNAPSHOT if needed + + Artifact junitArtifact; + Artifact testNgArtifact; + try + { + addArtifact( surefireBooter, surefireArtifact ); + + junitArtifact = (Artifact) projectArtifactMap.get( "junit:junit" ); + + // TODO: this is pretty manual, but I'd rather not require the plugin > dependencies section right now + testNgArtifact = (Artifact) projectArtifactMap.get( "org.testng:testng" ); + + if ( testNgArtifact != null ) + { + VersionRange range = VersionRange.createFromVersionSpec( "[4.7,)" ); + if ( !range.containsVersion( testNgArtifact.getSelectedVersion() ) ) + { + throw new MojoFailureException( + "TestNG support requires version 4.7 or above. You have declared version " + + testNgArtifact.getVersion() ); + } + + // The plugin uses a JDK based profile to select the right testng. We might be explicity using a + // different one since its based on the source level, not the JVM. Prune using the filter. + addProvider( surefireBooter, "surefire-testng", surefireArtifact.getBaseVersion(), testNgArtifact ); + } + else + { + // only need to discover JUnit if there is no TestNG, it runs the tests for you. + if ( junitArtifact != null ) + { + addProvider( surefireBooter, "surefire-junit", surefireArtifact.getBaseVersion(), null ); + } + } + } + catch ( ArtifactNotFoundException e ) + { + throw new MojoExecutionException( + "Unable to locate required surefire provider dependency: " + e.getMessage(), e ); + } + catch ( InvalidVersionSpecificationException e ) + { + throw new MojoExecutionException( "Error determining the TestNG version requested: " + e.getMessage(), e ); + } + catch ( ArtifactResolutionException e ) + { + throw new MojoExecutionException( "Error to resolving surefire provider dependency: " + e.getMessage(), e ); + } + + if ( suiteXmlFiles != null && suiteXmlFiles.length > 0 ) + { + if ( testNgArtifact == null ) + { + throw new MojoExecutionException( "suiteXmlFiles is configured, but there is no TestNG dependency" ); + } + for ( int i = 0; i < suiteXmlFiles.length; i++ ) + { + File file = suiteXmlFiles[i]; + if ( file.exists() ) + { + surefireBooter.addTestSuite( "org.apache.maven.surefire.testng.TestNGXmlTestSuite", + new Object[]{file, testSourceDirectory.getAbsolutePath()} ); + } + } + } + else + { + List includes; + List excludes; + + if ( test != null ) + { + // Check to see if we are running a single test. The raw parameter will + // come through if it has not been set. + + // FooTest -> **/FooTest.java + + includes = new ArrayList(); + + excludes = new ArrayList(); + + String[] testRegexes = StringUtils.split( test, "," ); + + for ( int i = 0; i < testRegexes.length; i++ ) + { + includes.add( "**/" + testRegexes[i] + ".java" ); + } + } + else + { + includes = this.includes; + + excludes = this.excludes; + + // defaults here, qdox doesn't like the end javadoc value + // Have to wrap in an ArrayList as surefire expects an ArrayList instead of a List for some reason + if ( includes == null || includes.size() == 0 ) + { + includes = new ArrayList( + Arrays.asList( new String[]{"**/Test*.java", "**/*Test.java", "**/*TestCase.java"} ) ); + } + if ( excludes == null || excludes.size() == 0 ) + { + excludes = new ArrayList( + Arrays.asList( new String[]{"**/Abstract*Test.java", "**/Abstract*TestCase.java", "**/*$*"} ) ); + } + } + + if ( testNgArtifact != null ) + { + surefireBooter.addTestSuite( "org.apache.maven.surefire.testng.TestNGDirectoryTestSuite", new Object[]{ + testClassesDirectory, includes, excludes, groups, excludedGroups, Boolean.valueOf( parallel ), + new Integer( threadCount ), testSourceDirectory.getAbsolutePath()} ); + } + else if ( junitArtifact != null ) + { + surefireBooter.addTestSuite( "org.apache.maven.surefire.junit.JUnitDirectoryTestSuite", + new Object[]{testClassesDirectory, includes, excludes} ); + } + else + { + throw new MojoExecutionException( "No Java test frameworks found" ); + } + } + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + getLog().debug( "Test Classpath :" ); + + // no need to add classes/test classes directory here - they are in the classpath elements already + + for ( Iterator i = classpathElements.iterator(); i.hasNext(); ) + { + String classpathElement = (String) i.next(); + + getLog().debug( " " + classpathElement ); + + surefireBooter.addClassPathUrl( classpathElement ); + + // TODO: fix + // Some test suites (TestNG) do not utilise the separate classloader, so we need to make all the tests + // available in the main classloader as well (this is consistent with the old behaviour in Surefire 1.5) + surefireBooter.addSurefireClassPathUrl( classpathElement ); + } + + // ---------------------------------------------------------------------- + // Forking + // ---------------------------------------------------------------------- + + ForkConfiguration fork = new ForkConfiguration(); + + fork.setForkMode( forkMode ); + + processSystemProperties( !fork.isForking() ); + + if ( getLog().isDebugEnabled() ) + { + showMap( systemProperties, "system property" ); + } + + if ( fork.isForking() ) + { + fork.setSystemProperties( systemProperties ); + + fork.setJvmExecutable( jvm ); + + if ( workingDirectory != null ) + { + fork.setWorkingDirectory( workingDirectory ); + } + else + { + fork.setWorkingDirectory( basedir ); + } + + fork.setArgLine( argLine ); + + fork.setEnvironmentVariables( environmentVariables ); + + if ( getLog().isDebugEnabled() ) + { + showMap( environmentVariables, "environment variable" ); + + fork.setDebug( true ); + } + } + + surefireBooter.setForkConfiguration( fork ); + + surefireBooter.setChildDelegation( childDelegation ); + + addReporters( surefireBooter, fork.isForking() ); + + return surefireBooter; + } + + private void showMap( Map map, String setting ) + { + for ( Iterator i = map.keySet().iterator(); i.hasNext(); ) + { + String key = (String) i.next(); + String value = (String) map.get( key ); + getLog().debug( "Setting " + setting + " [" + key + "]=[" + value + "]" ); + } + } + + private void addProvider( SurefireBooter surefireBooter, String provider, String version, + Artifact filteredArtifact ) + throws ArtifactNotFoundException, ArtifactResolutionException + { + Artifact providerArtifact = artifactFactory.createDependencyArtifact( "org.apache.maven.surefire", provider, + VersionRange.createFromVersion( version ), + "jar", null, Artifact.SCOPE_TEST ); + ArtifactResolutionResult result = resolveArtifact( filteredArtifact, providerArtifact ); + + for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); ) + { + Artifact artifact = (Artifact) i.next(); + + getLog().debug( "Adding to surefire test classpath: " + artifact.getFile().getAbsolutePath() ); + + surefireBooter.addSurefireClassPathUrl( artifact.getFile().getAbsolutePath() ); + } + } + + private ArtifactResolutionResult resolveArtifact( Artifact filteredArtifact, Artifact providerArtifact ) + throws ArtifactResolutionException, ArtifactNotFoundException + { + ArtifactFilter filter = null; + if ( filteredArtifact != null ) + { + filter = new ExcludesArtifactFilter( + Collections.singletonList( filteredArtifact.getGroupId() + ":" + filteredArtifact.getArtifactId() ) ); + } + + Artifact originatingArtifact = artifactFactory.createBuildArtifact( "dummy", "dummy", "1.0", "jar" ); + + return artifactResolver.resolveTransitively( Collections.singleton( providerArtifact ), originatingArtifact, + localRepository, remoteRepositories, metadataSource, filter ); + } + + private void addArtifact( SurefireBooter surefireBooter, Artifact surefireArtifact ) + throws ArtifactNotFoundException, ArtifactResolutionException + { + ArtifactResolutionResult result = resolveArtifact( null, surefireArtifact ); + + for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); ) + { + Artifact artifact = (Artifact) i.next(); + + getLog().debug( "Adding to surefire booter test classpath: " + artifact.getFile().getAbsolutePath() ); + + surefireBooter.addSurefireBootClassPathUrl( artifact.getFile().getAbsolutePath() ); + } + } + + protected void processSystemProperties( boolean setInSystem ) + { + if ( systemProperties == null ) + { + systemProperties = new Properties(); + } + + originalSystemProperties = (Properties) System.getProperties().clone(); + + systemProperties.setProperty( "basedir", basedir.getAbsolutePath() ); + + systemProperties.setProperty( "localRepository", localRepository.getBasedir() ); + + if ( setInSystem ) + { + // Add all system properties configured by the user + Iterator iter = systemProperties.keySet().iterator(); + + while ( iter.hasNext() ) + { + String key = (String) iter.next(); + + String value = systemProperties.getProperty( key ); + + System.setProperty( key, value ); + } + } + } + + /** + * <p> Adds Reporters that will generate reports with different formatting. + * <p> The Reporter that will be added will be based on the value of the parameter + * useFile, reportFormat, and printSummary. + * + * @param surefireBooter The surefire booter that will run tests. + * @param forking + */ + private void addReporters( SurefireBooter surefireBooter, boolean forking ) + { + Boolean trimStackTrace = Boolean.valueOf( this.trimStackTrace ); + if ( useFile ) + { + if ( printSummary ) + { + if ( forking ) + { + surefireBooter.addRe... [truncated message content] |