jvanzyl 2004/01/10 00:23:42
Modified: surefire/src/main/org/apache/maven/test
TestRunnerBooter.java
surefire/src/surefire-runner project.xml
surefire/src/surefire-runner/src/main/org/apache/maven/test
TestRunner.java
Log:
o remove the hardwiring to my setup
o remove dep on plexus-utils in the test runner
Revision Changes Path
1.2 +49 -28
maven-plugins/surefire/src/main/org/apache/maven/test/TestRunnerBooter.java
Index: TestRunnerBooter.java
===================================================================
RCS file:
/home/cvs/maven-plugins/surefire/src/main/org/apache/maven/test/TestRunnerBooter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestRunnerBooter.java 9 Jan 2004 16:22:59 -0000 1.1
+++ TestRunnerBooter.java 10 Jan 2004 08:23:42 -0000 1.2
@@ -3,29 +3,15 @@
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.
- * <pre>
- * java junit.textui.TestRunner [-wait] TestCaseClass
- * </pre>
- * TestRunner expects the name of a TestCase class as argument.
- * If this class defines a static <code>suite</code> method it
- * will be invoked and the returned test is run. Otherwise all
- * the methods starting with "test" having no arguments are run.
- * <p>
- * When the wait command line argument is given TestRunner
- * waits until the users types RETURN.
- * <p>
- * 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 @@
{
// maven.build.dest
// maven.test.dest
- // maven.build.dest
- // maven.test.dest
IsolatedClassLoader classLoader = new IsolatedClassLoader();
@@ -51,9 +35,11 @@
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 @@
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
} );
}
@@ -105,5 +92,39 @@
}
}
}
+ }
+
+ 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();
}
}
1.2 +1 -1 maven-plugins/surefire/src/surefire-runner/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/maven-plugins/surefire/src/surefire-runner/project.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- project.xml 9 Jan 2004 16:22:59 -0000 1.1
+++ project.xml 10 Jan 2004 08:23:42 -0000 1.2
@@ -6,7 +6,7 @@
<id>surefire-runner</id>
<artifactId>surefire-runner</artifactId>
<name>Surefire Test Runner</name>
- <currentVersion>1.0-SNAPSHOT</currentVersion>
+ <currentVersion>1.0</currentVersion>
<description/>
<shortDescription>Run JUnit tests</shortDescription>
<url>http://maven.apache.org/reference/plugins/surefire-runner</url>
1.2 +8 -74
maven-plugins/surefire/src/surefire-runner/src/main/org/apache/maven/test/TestRunner.java
Index: TestRunner.java
===================================================================
RCS file:
/home/cvs/maven-plugins/surefire/src/surefire-runner/src/main/org/apache/maven/test/TestRunner.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestRunner.java 9 Jan 2004 16:23:01 -0000 1.1
+++ TestRunner.java 10 Jan 2004 08:23:42 -0000 1.2
@@ -5,33 +5,9 @@
import junit.framework.TestSuite;
import junit.runner.BaseTestRunner;
import junit.runner.TestSuiteLoader;
-import org.codehaus.plexus.util.DirectoryScanner;
-import org.codehaus.plexus.util.StringUtils;
-import java.io.File;
import java.io.PrintStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * A command line based tool to run tests.
- * <pre>
- * java junit.textui.TestRunner [-wait] TestCaseClass
- * </pre>
- * TestRunner expects the name of a TestCase class as argument.
- * If this class defines a static <code>suite</code> method it
- * will be invoked and the returned test is run. Otherwise all
- * the methods starting with "test" having no arguments are run.
- * <p>
- * When the wait command line argument is given TestRunner
- * waits until the users types RETURN.
- * <p>
- * 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 @@
}
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 @@
{
clazz = classLoader.loadClass( s );
}
- catch( ClassNotFoundException e )
+ catch ( ClassNotFoundException e )
{
System.out.println( "Can't find className = " + s );
@@ -142,14 +82,10 @@
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 @@
{
resultPrinter = printer;
}
-
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]