diff --git a/surefire/src/main/org/apache/maven/test/TestRunnerBooter.java b/surefire/src/main/org/apache/maven/test/TestRunnerBooter.java index aa66d1b8..21dc8093 100644 --- a/surefire/src/main/org/apache/maven/test/TestRunnerBooter.java +++ b/surefire/src/main/org/apache/maven/test/TestRunnerBooter.java @@ -3,29 +3,15 @@ package org.apache.maven.test; import org.apache.maven.artifact.Artifact; import org.apache.maven.model.Dependency; import org.apache.maven.project.Project; +import org.codehaus.plexus.util.DirectoryScanner; +import org.codehaus.plexus.util.StringUtils; import java.io.File; +import java.lang.reflect.Method; import java.net.MalformedURLException; import java.util.Iterator; import java.util.List; -import java.lang.reflect.Method; -/** - * A command line based tool to run tests. - *
- * java junit.textui.TestRunner [-wait] TestCaseClass - *- * TestRunner expects the name of a TestCase class as argument. - * If this class defines a static
suite method it
- * will be invoked and the returned test is run. Otherwise all
- * the methods starting with "test" having no arguments are run.
- * - * When the wait command line argument is given TestRunner - * waits until the users types RETURN. - *
- * TestRunner prints a trace as the tests are executed followed by a
- * summary at the end.
- */
public class TestRunnerBooter
{
private Project project;
@@ -40,8 +26,6 @@ public class TestRunnerBooter
{
// maven.build.dest
// maven.test.dest
- // maven.build.dest
- // maven.test.dest
IsolatedClassLoader classLoader = new IsolatedClassLoader();
@@ -51,9 +35,11 @@ public class TestRunnerBooter
Thread.currentThread().setContextClassLoader( classLoader );
- classLoader.addURL( new File ( "/home/jvanzyl/maven-repo-local/junit/jars/junit-3.8.1.jar" ).toURL() );
+ String mavenRepoLocal = project.getProperty( "maven.repo.local" );
- classLoader.addURL( new File ( "/tmp/test-runner-1.4.jar" ).toURL() );
+ classLoader.addURL( new File ( mavenRepoLocal, "junit/jars/junit-3.8.1.jar" ).toURL() );
+
+ classLoader.addURL( new File ( mavenRepoLocal, "maven/jars/surefire-runner-1.0.jar" ).toURL() );
classLoader.addURL( new File( basedir, "target/classes/" ).toURL() );
@@ -61,21 +47,22 @@ public class TestRunnerBooter
processDependencies( project, classLoader );
+ String[] tests = collectTests( basedir,
+ project.getBuild().getUnitTest().getIncludes(),
+ project.getBuild().getUnitTest().getExcludes() );
+
Class testRunnerClass = classLoader.loadClass( "org.apache.maven.test.TestRunner" );
Object testRunner = testRunnerClass.newInstance();
Method m = testRunnerClass.getMethod( "runTestClasses", new Class[] {
- File.class,
- List.class,
- List.class,
- ClassLoader.class } );
+ ClassLoader.class,
+ String[].class
+ } );
m.invoke( testRunner, new Object[]{
- basedir,
- project.getBuild().getUnitTest().getIncludes(),
- project.getBuild().getUnitTest().getExcludes(),
classLoader,
+ tests
} );
}
@@ -106,4 +93,38 @@ public class TestRunnerBooter
}
}
}
+
+ public String[] collectTests( File basedir, List includes, List excludes )
+ throws Exception
+ {
+ DirectoryScanner scanner = new DirectoryScanner();
+
+ scanner.setBasedir( new File( basedir, "target/test-classes" ) );
+
+ String[] incs = new String[includes.size()];
+
+ for ( int i = 0; i < incs.length; i++ )
+ {
+ incs[i] = StringUtils.replace( (String) includes.get( i ), "java", "class" );
+ }
+
+ scanner.setIncludes( incs );
+
+ String[] excls = new String[excludes.size() + 1];
+
+ for ( int i = 0; i < excls.length - 1; i++ )
+ {
+ excls[i] = StringUtils.replace( (String) excludes.get( i ), "java", "class" );
+ }
+
+ // Exclude inner classes
+
+ excls[excludes.size()] = "**/*$*";
+
+ scanner.setExcludes( excls );
+
+ scanner.scan();
+
+ return scanner.getIncludedFiles();
+ }
}
diff --git a/surefire/src/surefire-runner/project.xml b/surefire/src/surefire-runner/project.xml
index 991bc4f6..1269664d 100644
--- a/surefire/src/surefire-runner/project.xml
+++ b/surefire/src/surefire-runner/project.xml
@@ -6,7 +6,7 @@
- * java junit.textui.TestRunner [-wait] TestCaseClass - *- * TestRunner expects the name of a TestCase class as argument. - * If this class defines a static
suite method it
- * will be invoked and the returned test is run. Otherwise all
- * the methods starting with "test" having no arguments are run.
- * - * When the wait command line argument is given TestRunner - * waits until the users types RETURN. - *
- * TestRunner prints a trace as the tests are executed followed by a - * summary at the end. - */ public class TestRunner extends BaseTestRunner { @@ -61,57 +37,21 @@ public class TestRunner } private ClassLoader classLoader; - private List includes; - private List excludes; - private File basedir; - - public void runTestClasses( File basedir, List includes, List excludes, ClassLoader classLoader ) + + public void runTestClasses( ClassLoader classLoader, String[] tests ) throws Exception { - this.basedir = basedir; - this.includes = includes; - this.excludes = excludes; this.classLoader = classLoader; - - DirectoryScanner scanner = new DirectoryScanner(); - - scanner.setBasedir( new File( basedir, "target/test-classes" ) ); - - String[] incs = new String[includes.size()]; - - for ( int i = 0; i < incs.length; i++ ) - { - incs[i] = StringUtils.replace( (String) includes.get( i ), "java", "class" ); - } - - scanner.setIncludes( incs ); - - String[] excls = new String[excludes.size() + 1]; - - for ( int i = 0; i < excls.length - 1; i++ ) - { - excls[i] = StringUtils.replace( (String) excludes.get( i ), "java", "class" ); - } - - // Exclude inner classes - - excls[excludes.size()] = "**/*$*"; - - scanner.setExcludes( excls ); - - scanner.scan(); - - String[] files = scanner.getIncludedFiles(); String s; - for ( int i = 0; i < files.length; i++ ) + for ( int i = 0; i < tests.length; i++ ) { - s = files[i]; + s = tests[i]; s = s.substring( 0, s.indexOf( "." ) ); - s = StringUtils.replace( s, FS, "." ); + s = s.replace( FS.charAt( 0 ), ".".charAt( 0 ) ); Class clazz = null; @@ -119,7 +59,7 @@ public class TestRunner { clazz = classLoader.loadClass( s ); } - catch( ClassNotFoundException e ) + catch ( ClassNotFoundException e ) { System.out.println( "Can't find className = " + s ); @@ -142,14 +82,10 @@ public class TestRunner return failures; } - // ---------------------------------------------------------------------- - // - // ---------------------------------------------------------------------- - public TestResult run( Class testClass, String testName ) { return run( new TestSuite( testClass ), testName ); - + //return run( new MavenJUnitTestSuite( testClass, classLoader ), testName ); } @@ -210,6 +146,4 @@ public class TestRunner { resultPrinter = printer; } - - }