You are viewing a plain text version of this content. The canonical link for it is here.
Posted to surefire-commits@maven.apache.org by kr...@apache.org on 2010/12/13 11:18:02 UTC
svn commit: r1045052 - in /maven/surefire/trunk:
surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/
surefire-integration-tests/src/test/resources/junit4-runlistener/
surefire-integration-tests/src/test/resources/junit4-runlistener/...
Author: krosenvold
Date: Mon Dec 13 10:18:01 2010
New Revision: 1045052
URL: http://svn.apache.org/viewvc?rev=1045052&view=rev
Log:
[SUREFIRE-663] Custom Junit4 runlisteners
Patch by Matthew Gillard, applied with some changes
Added:
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit4RunListenerIT.java (with props)
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/pom.xml (with props)
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileHelper.java (with props)
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileWritingRunListener1.java (with props)
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileWritingRunListener2.java (with props)
maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/JUnit4RunListenerTest.java (with props)
Modified:
maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4DirectoryTestSuite.java
maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java
maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4TestSet.java
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreWrapper.java
Added: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit4RunListenerIT.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit4RunListenerIT.java?rev=1045052&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit4RunListenerIT.java (added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit4RunListenerIT.java Mon Dec 13 10:18:01 2010
@@ -0,0 +1,82 @@
+package org.apache.maven.surefire.its;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 java.io.File;
+import java.util.List;
+
+import org.apache.maven.it.Verifier;
+import org.apache.maven.it.util.ResourceExtractor;
+import org.apache.maven.reporting.MavenReportException;
+
+/**
+ * JUnit4 RunListener Integration Test.
+ *
+ * @author <a href="mailto:matthew.gilliard@gmail.com">Matthew Gilliard</a>
+ */
+public class JUnit4RunListenerIT
+ extends AbstractSurefireIntegrationTestClass {
+ public void testJUnit4RunListener()
+ throws Exception {
+ final File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/junit4-runlistener");
+
+ final Verifier verifier = new Verifier(testDir.getAbsolutePath());
+ List goals = getInitialGoals();
+ goals.add( "-Dprovider=surefire-junit4" );
+ goals.add( "-DjunitVersion=4.4" );
+ goals.add( "test" );
+ this.executeGoals( verifier, goals );
+ verifier.verifyErrorFreeLog();
+ verifier.resetStreams();
+
+ assertResults( testDir );
+ }
+
+ private void assertResults( File testDir )
+ throws MavenReportException
+ {
+ HelperAssertions.assertTestSuiteResults( 1, 0, 0, 0, testDir );
+ final File targetDir = new File(testDir, "target");
+ assertFileExists(new File(targetDir, "runlistener-output-1.txt"));
+ assertFileExists(new File(targetDir, "runlistener-output-2.txt"));
+ }
+
+
+ public void testRunlistenerJunitCoreProvider()
+ throws Exception
+ {
+ File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/junit4-runlistener" );
+
+ Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+ List goals = getInitialGoals();
+ goals.add( "-Dprovider=surefire-junit47" );
+ goals.add( "-DjunitVersion=4.8.1" );
+ goals.add( "test" );
+ this.executeGoals( verifier, goals );
+ verifier.verifyErrorFreeLog();
+ verifier.resetStreams();
+ assertResults( testDir );
+ }
+
+ private void assertFileExists(final File file) {
+ assertTrue("File doesn't exist: " + file.getAbsolutePath(), file.exists());
+ }
+
+}
Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnit4RunListenerIT.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/pom.xml
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/pom.xml?rev=1045052&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/pom.xml (added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/pom.xml Mon Dec 13 10:18:01 2010
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you 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.
+ -->
+
+<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>junit4-runlistener</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <name>JUnit4 RunListener test</name>
+
+ <properties>
+ <junitVersion>4.4</junitVersion>
+ <provider>surefire-junit4</provider>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junitVersion}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>${surefire.version}</version>
+ <configuration>
+ <properties>
+ <property>
+ <name>listener</name>
+ <value>runListener.FileWritingRunListener1,runListener.FileWritingRunListener2</value>
+ </property>
+ </properties>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>${provider}</artifactId>
+ <version>${surefire.version}</version>
+ </dependency>
+
+ </dependencies>
+ </plugin>
+ </plugins>
+ </build>
+
+
+</project>
Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileHelper.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileHelper.java?rev=1045052&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileHelper.java (added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileHelper.java Mon Dec 13 10:18:01 2010
@@ -0,0 +1,25 @@
+package runListener;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+public class FileHelper
+{
+ public static void writeFile( String fileName, String content )
+ {
+ try
+ {
+ File target = new File( "target" ).getAbsoluteFile();
+ File listenerOutput = new File( target, fileName );
+ FileWriter out = new FileWriter( listenerOutput );
+ out.write( content );
+ out.flush();
+ out.close();
+ }
+ catch ( IOException e )
+ {
+ throw new RuntimeException( e );
+ }
+ }
+}
Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileWritingRunListener1.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileWritingRunListener1.java?rev=1045052&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileWritingRunListener1.java (added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileWritingRunListener1.java Mon Dec 13 10:18:01 2010
@@ -0,0 +1,22 @@
+package runListener;
+
+import org.junit.runner.Description;
+import org.junit.runner.notification.RunListener;
+
+/**
+ * {@link RunListener} to generate an output file whose existence can be checked by surefire-integration.
+ *
+ * @author <a href="mailto:matthew.gilliard@gmail.com">Matthew Gilliard</a>
+ */
+public class FileWritingRunListener1
+ extends RunListener
+{
+
+ @Override
+ public void testStarted( Description description )
+ throws Exception
+ {
+ FileHelper.writeFile( "runlistener-output-1.txt", "This written by RunListener#testStarted()" );
+ }
+
+}
Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileWritingRunListener1.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileWritingRunListener2.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileWritingRunListener2.java?rev=1045052&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileWritingRunListener2.java (added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileWritingRunListener2.java Mon Dec 13 10:18:01 2010
@@ -0,0 +1,22 @@
+package runListener;
+
+import org.junit.runner.Description;
+import org.junit.runner.notification.RunListener;
+
+/**
+ * {@link RunListener} to generate an output file whose existence can be checked by surefire-integration.
+ *
+ * @author <a href="mailto:matthew.gilliard@gmail.com">Matthew Gilliard</a>
+ */
+public class FileWritingRunListener2
+ extends RunListener
+{
+
+ @Override
+ public void testStarted( Description description )
+ throws Exception
+ {
+ FileHelper.writeFile( "runlistener-output-2.txt", "This written by RunListener#testStarted()" );
+ }
+
+}
Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/FileWritingRunListener2.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/JUnit4RunListenerTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/JUnit4RunListenerTest.java?rev=1045052&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/JUnit4RunListenerTest.java (added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/JUnit4RunListenerTest.java Mon Dec 13 10:18:01 2010
@@ -0,0 +1,13 @@
+package runListener;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class JUnit4RunListenerTest {
+
+ @Test
+ public void simpleTest()
+ {
+ Assert.assertEquals( 2, 1 + 1 );
+ }
+}
Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/resources/junit4-runlistener/src/test/java/runListener/JUnit4RunListenerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4DirectoryTestSuite.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4DirectoryTestSuite.java?rev=1045052&r1=1045051&r2=1045052&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4DirectoryTestSuite.java (original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4DirectoryTestSuite.java Mon Dec 13 10:18:01 2010
@@ -23,9 +23,11 @@ import org.apache.maven.surefire.suite.A
import org.apache.maven.surefire.testset.SurefireTestSet;
import org.apache.maven.surefire.testset.TestSetFailedException;
import org.apache.maven.surefire.util.DirectoryScanner;
+import org.junit.runner.notification.RunListener;
import java.io.File;
import java.util.ArrayList;
+import java.util.List;
/**
* Test suite for JUnit4 based on a directory of Java test classes. This is
@@ -37,15 +39,19 @@ import java.util.ArrayList;
public class JUnit4DirectoryTestSuite
extends AbstractDirectoryTestSuite
{
+ private List<RunListener> customRunListeners;
+
// Remove when we no longer build with surefire 2.5
public JUnit4DirectoryTestSuite( File basedir, ArrayList includes, ArrayList excludes )
{
super( basedir, includes, excludes );
+
}
- public JUnit4DirectoryTestSuite( DirectoryScanner surefireDirectoryScanner )
+ public JUnit4DirectoryTestSuite( DirectoryScanner surefireDirectoryScanner, List<RunListener> customRunListeners )
{
super( surefireDirectoryScanner );
+ this.customRunListeners = customRunListeners;
}
@@ -60,7 +66,9 @@ public class JUnit4DirectoryTestSuite
throws TestSetFailedException
{
JUnit4TestChecker jUnit4TestChecker = new JUnit4TestChecker( testsClassLoader );
- return jUnit4TestChecker.isValidJUnit4Test( testClass ) ? new JUnit4TestSet( testClass ) : null;
+ return jUnit4TestChecker.isValidJUnit4Test( testClass )
+ ? new JUnit4TestSet( testClass, customRunListeners )
+ : null;
}
}
Modified: maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java?rev=1045052&r1=1045051&r2=1045052&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java (original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java Mon Dec 13 10:18:01 2010
@@ -27,8 +27,13 @@ import org.apache.maven.surefire.report.
import org.apache.maven.surefire.suite.RunResult;
import org.apache.maven.surefire.testset.TestSetFailedException;
import org.apache.maven.surefire.util.DirectoryScanner;
+import org.apache.maven.surefire.util.ReflectionUtils;
+import org.junit.runner.notification.RunListener;
import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
/**
* @author Kristian Rosenvold
@@ -44,11 +49,16 @@ public class JUnit4Provider
private final DirectoryScanner directoryScanner;
+ private final List<RunListener> customRunListeners;
+
public JUnit4Provider( ProviderParameters booterParameters )
{
this.reporterFactory = booterParameters.getReporterFactory();
this.testClassLoader = booterParameters.getTestClassLoader();
this.directoryScanner = booterParameters.getDirectoryScanner();
+ customRunListeners =
+ createCustomListeners( booterParameters.getProviderProperties().getProperty( "listener" ) );
+
}
@SuppressWarnings( { "UnnecessaryUnboxing" } )
@@ -70,8 +80,7 @@ public class JUnit4Provider
private JUnit4DirectoryTestSuite getSuite()
{
- return new JUnit4DirectoryTestSuite( directoryScanner );
-
+ return new JUnit4DirectoryTestSuite( directoryScanner, customRunListeners );
}
public Iterator getSuites()
@@ -116,5 +125,22 @@ public class JUnit4Provider
return Boolean.TRUE;
}
+ private List<RunListener> createCustomListeners( String listenerProperty )
+ {
+ List<RunListener> result = new LinkedList<RunListener>();
+ if ( listenerProperty == null )
+ {
+ return result;
+ }
+ for ( String thisListenerName : listenerProperty.split( "," ) )
+ {
+ RunListener customRunListener =
+ (RunListener) ReflectionUtils.instantiate( Thread.currentThread().getContextClassLoader(),
+ thisListenerName );
+ result.add( customRunListener );
+ }
+
+ return result;
+ }
}
Modified: maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4TestSet.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4TestSet.java?rev=1045052&r1=1045051&r2=1045052&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4TestSet.java (original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4TestSet.java Mon Dec 13 10:18:01 2010
@@ -27,33 +27,46 @@ import org.junit.runner.Runner;
import org.junit.runner.notification.RunListener;
import org.junit.runner.notification.RunNotifier;
+import java.util.List;
+
public class JUnit4TestSet
extends AbstractTestSet
{
+ private final List<RunListener> customRunListeners;
+
/**
* Constructor.
*
* @param testClass the class to be run as a test
*/
- protected JUnit4TestSet( Class testClass )
+ protected JUnit4TestSet( Class testClass, List<RunListener> customRunListeners )
{
super( testClass );
+ this.customRunListeners = customRunListeners;
}
/**
* Actually runs the test and adds the tests results to the <code>reportManager</code>.
*
- * @see org.apache.maven.surefire.testset.SurefireTestSet#execute(org.apache.maven.surefire.report.ReporterManager,java.lang.ClassLoader)
+ * @see org.apache.maven.surefire.testset.SurefireTestSet#execute(org.apache.maven.surefire.report.ReporterManager, java.lang.ClassLoader)
*/
public void execute( ReporterManager reportManager, ClassLoader loader )
throws TestSetFailedException
{
Runner junitTestRunner = Request.aClass( getTestClass() ).getRunner();
-
+
RunNotifier fNotifier = new RunNotifier();
RunListener listener = new JUnit4TestSetReporter( this, reportManager );
fNotifier.addListener( listener );
+ if ( customRunListeners != null )
+ {
+ for ( RunListener customRunListener : customRunListeners )
+ {
+ fNotifier.addListener( customRunListener );
+ }
+ }
+
try
{
junitTestRunner.run( fNotifier );
@@ -61,6 +74,14 @@ public class JUnit4TestSet
finally
{
fNotifier.removeListener( listener );
+
+ if ( customRunListeners != null )
+ {
+ for ( RunListener customRunListener : customRunListeners )
+ {
+ fNotifier.removeListener( customRunListener );
+ }
+ }
}
}
Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java?rev=1045052&r1=1045051&r2=1045052&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java (original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java Mon Dec 13 10:18:01 2010
@@ -28,9 +28,13 @@ import org.apache.maven.surefire.report.
import org.apache.maven.surefire.suite.RunResult;
import org.apache.maven.surefire.testset.TestSetFailedException;
import org.apache.maven.surefire.util.DirectoryScanner;
+import org.apache.maven.surefire.util.ReflectionUtils;
import org.apache.maven.surefire.util.TestsToRun;
+import org.junit.runner.notification.RunListener;
import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
/**
* @author Kristian Rosenvold
@@ -49,6 +53,8 @@ public class JUnitCoreProvider
private final NonAbstractClassFilter scannerFilter;
+ private final List<RunListener> customRunListeners;
+
private TestsToRun testsToRun;
private final ReporterConfiguration reporterConfiguration;
@@ -62,6 +68,9 @@ public class JUnitCoreProvider
this.directoryScanner = booterParameters.getDirectoryScanner();
this.jUnitCoreParameters = new JUnitCoreParameters( booterParameters.getProviderProperties() );
this.scannerFilter = new NonAbstractClassFilter();
+ customRunListeners =
+ createCustomListeners( booterParameters.getProviderProperties().getProperty( "listener" ) );
+
}
public Boolean isRunnable()
@@ -91,8 +100,9 @@ public class JUnitCoreProvider
ConcurrentReportingRunListener.createInstance( this.reporterFactory, this.reporterConfiguration,
jUnitCoreParameters.isParallelClasses(),
jUnitCoreParameters.isParallelBoth() );
+ customRunListeners.add( 0, listener );
- JUnitCoreWrapper.execute( testsToRun, jUnitCoreParameters, listener );
+ JUnitCoreWrapper.execute( testsToRun, jUnitCoreParameters, customRunListeners );
return reporterFactory.close();
}
@@ -100,4 +110,25 @@ public class JUnitCoreProvider
{
return directoryScanner.locateTestClasses( testClassLoader, scannerFilter );
}
+
+ // Todo; We really need a shared java-5 language level module for the providers.
+ private List<RunListener> createCustomListeners( String listenerProperty )
+ {
+ List<RunListener> result = new LinkedList<RunListener>();
+ if ( listenerProperty == null )
+ {
+ return result;
+ }
+
+ for ( String thisListenerName : listenerProperty.split( "," ) )
+ {
+ RunListener customRunListener =
+ (RunListener) ReflectionUtils.instantiate( Thread.currentThread().getContextClassLoader(),
+ thisListenerName );
+ result.add( customRunListener );
+ }
+
+ return result;
+ }
+
}
Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreWrapper.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreWrapper.java?rev=1045052&r1=1045051&r2=1045052&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreWrapper.java (original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreWrapper.java Mon Dec 13 10:18:01 2010
@@ -23,7 +23,9 @@ import org.apache.maven.surefire.testset
import org.apache.maven.surefire.util.TestsToRun;
import org.junit.runner.Computer;
import org.junit.runner.JUnitCore;
+import org.junit.runner.notification.RunListener;
+import java.util.List;
import java.util.concurrent.ExecutionException;
/**
@@ -35,19 +37,25 @@ import java.util.concurrent.ExecutionExc
class JUnitCoreWrapper
{
public static void execute( TestsToRun testsToRun, JUnitCoreParameters jUnitCoreParameters,
- ConcurrentReportingRunListener listener )
+ List<RunListener> listeners )
throws TestSetFailedException
{
Computer computer = getComputer( jUnitCoreParameters );
JUnitCore junitCore = new JUnitCore();
- junitCore.addListener( listener );
+ for ( RunListener runListener : listeners )
+ {
+ junitCore.addListener( runListener );
+ }
try
{
junitCore.run( computer, testsToRun.getLocatedClasses() );
}
finally
{
- junitCore.removeListener( listener );
+ for ( RunListener runListener : listeners )
+ {
+ junitCore.removeListener( runListener );
+ }
closeIfConfigurable( computer );
}
}