use surefire pom for surefire dependencies

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163749 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-04-04 02:57:27 +00:00
parent f1bfd0c18b
commit 11d160b52d
6 changed files with 46 additions and 161 deletions

View File

@ -36,20 +36,6 @@
<scope>runtime</scope>
</dependency>
<!-- TODO: should get these from the surefire plugin -->
<dependency>
<groupId>surefire</groupId>
<artifactId>surefire-booter</artifactId>
<version>1.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>surefire</groupId>
<artifactId>surefire</artifactId>
<version>1.2</version>
<scope>test</scope>
</dependency>
<!-- Just for install... possibly not needed here? -->
<dependency>
<groupId>classworlds</groupId>

View File

@ -97,8 +97,6 @@ public class MBoot
private boolean online = true;
private static final String[] EMPTY_STRING_ARRAY = new String[0];
private static final String SCOPE_TEST = "test";
private static final String SCOPE_COMPILE = "compile";
@ -255,6 +253,10 @@ public class MBoot
ClassLoader bootstrapClassLoader = createClassloaderFromDependencies( reader.getDependencies(), null );
reader = new ModelReader( downloader );
reader.parse( new File( basedir, "maven-plugins/maven-surefire-plugin/pom.xml" ) );
List surefireDependencies = reader.getDependencies();
reader = new ModelReader( downloader );
// Install maven-components POM
@ -282,7 +284,7 @@ public class MBoot
System.setProperty( "basedir", directory );
reader = buildProject( directory, builds[i], bootstrapClassLoader );
reader = buildProject( directory, builds[i], bootstrapClassLoader, surefireDependencies );
if ( reader.getArtifactId().equals( "maven-core" ) )
{
@ -308,7 +310,7 @@ public class MBoot
System.setProperty( "basedir", directory );
reader = buildProject( directory, pluginBuilds[i], cl );
reader = buildProject( directory, pluginBuilds[i], cl, surefireDependencies );
System.out.println( "--------------------------------------------------------------------" );
}
@ -427,7 +429,8 @@ public class MBoot
System.out.println( "Finished at: " + fullStop );
}
public ModelReader buildProject( String basedir, String projectId, ClassLoader classLoader )
public ModelReader buildProject( String basedir, String projectId, ClassLoader classLoader,
List surefireDependencies )
throws Exception
{
System.out.println( "Building project in " + basedir );
@ -578,7 +581,7 @@ public class MBoot
// Run tests
// ----------------------------------------------------------------------
runTests( basedir, classes, testClasses, reader );
runTests( basedir, classes, testClasses, reader, surefireDependencies );
// ----------------------------------------------------------------------
// Create JAR
@ -750,7 +753,8 @@ public class MBoot
}
}
private void runTests( String basedir, String classes, String testClasses, ModelReader reader )
private void runTests( String basedir, String classes, String testClasses, ModelReader reader,
List surefireDependencies )
throws Exception
{
SurefirePlugin testRunner = new SurefirePlugin();
@ -769,9 +773,13 @@ public class MBoot
String reportsDir = new File( basedir, "target/surefire-reports" ).getAbsolutePath();
String[] cp = (String[]) classpath( reader.getDependencies(), null, SCOPE_TEST ).toArray( EMPTY_STRING_ARRAY );
boolean success = testRunner.execute( repoLocal, basedir, classes, testClasses, includes, excludes, cp,
reportsDir );
List depList = new ArrayList( reader.getDependencies() );
depList.addAll( surefireDependencies );
List classpath = classpath( depList, null, SCOPE_TEST );
classpath.add( classes );
classpath.add( testClasses );
boolean success = testRunner.execute( basedir, includes, excludes, classpath, reportsDir );
if ( !success )
{

View File

@ -198,4 +198,9 @@ public class Dependency
{
return getArtifactDirectory() + "/" + getType() + "s/" + getArtifact();
}
public String toString()
{
return getRepositoryPath();
}
}

View File

@ -2,30 +2,26 @@ package test;
import util.IsolatedClassLoader;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
public class
SurefireBooter
public class SurefireBooter
{
private List batteries = new ArrayList();
private List reports = new ArrayList();
private List classpathUrls = new ArrayList();
private String reportsDir;
public SurefireBooter()
{
}
public void setReportsDirectory( String reportsDirectory )
{
this.reportsDir = reportsDirectory;
@ -33,12 +29,12 @@ public class
public void addBattery( String battery, Object[] params )
{
batteries.add( new Object[]{ battery, params } );
batteries.add( new Object[]{battery, params} );
}
public void addBattery( String battery )
{
batteries.add( new Object[]{ battery, null } );
batteries.add( new Object[]{battery, null} );
}
public void addReport( String report )
@ -73,123 +69,20 @@ public class
Object batteryExecutor = batteryExecutorClass.newInstance();
Method run = batteryExecutorClass.getMethod( "run", new Class[] { List.class, List.class, ClassLoader.class, String.class } );
Method run = batteryExecutorClass.getMethod( "run",
new Class[]{List.class, List.class, ClassLoader.class,
String.class} );
ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader( surefireClassLoader );
Boolean result = (Boolean) run.invoke( batteryExecutor, new Object[]{ reports, batteries, surefireClassLoader, reportsDir } );
Boolean result = (Boolean) run.invoke( batteryExecutor,
new Object[]{reports, batteries, surefireClassLoader, reportsDir} );
Thread.currentThread().setContextClassLoader( oldContextClassLoader );
return result.booleanValue();
}
public void reset()
{
batteries.clear();
reports.clear();
classpathUrls.clear();
}
// ----------------------------------------------------------------------
// Main
// ----------------------------------------------------------------------
public static void main( String[] args )
throws Exception
{
String basedir = args[0];
System.setProperty( "basedir", basedir );
String mavenRepoLocal = args[1];
File dependenciesFile = new File( args[2] );
List dependencies = new ArrayList();
BufferedReader buf = new BufferedReader( new FileReader( dependenciesFile ) );
String line;
while ( ( line = buf.readLine() ) != null )
{
dependencies.add( line );
}
buf.close();
File includesFile = new File( args[3] );
List includes = new ArrayList();
buf = new BufferedReader( new FileReader( includesFile ) );
line = buf.readLine();
String includesStr = line.substring( line.indexOf( "@" ) + 1 );
StringTokenizer st = new StringTokenizer( includesStr, "," );
while ( st.hasMoreTokens() )
{
String inc = st.nextToken().trim();
includes.add( inc );
}
buf.close();
File excludesFile = new File( args[4] );
List excludes = new ArrayList();
buf = new BufferedReader( new FileReader( excludesFile ) );
line = buf.readLine();
String excludesStr = line.substring( line.indexOf( "@" ) + 1 );
st = new StringTokenizer( excludesStr, "," );
while ( st.hasMoreTokens() )
{
excludes.add( st.nextToken().trim() );
}
buf.close();
SurefireBooter surefireBooter = new SurefireBooter();
surefireBooter.addBattery( "org.codehaus.surefire.battery.DirectoryBattery", new Object[]{ basedir, includes, excludes } );
surefireBooter.addClassPathUrl( new File( mavenRepoLocal, "junit/jars/junit-3.8.1.jar" ).getPath() );
surefireBooter.addClassPathUrl( new File( mavenRepoLocal, "surefire/jars/surefire-1.2-SNAPSHOT.jar" ).getPath() );
surefireBooter.addClassPathUrl( new File( basedir, "target/classes/" ).getPath() );
surefireBooter.addClassPathUrl( new File( basedir, "target/test-classes/" ).getPath() );
processDependencies( dependencies, surefireBooter );
surefireBooter.addReport( "org.codehaus.surefire.report.ConsoleReport" );
surefireBooter.run();
}
private static void processDependencies( List dependencies, SurefireBooter sureFire )
throws Exception
{
for ( Iterator i = dependencies.iterator(); i.hasNext(); )
{
String dep = (String) i.next();
sureFire.addClassPathUrl( new File( dep ).getPath() );
}
}
}

View File

@ -1,17 +1,11 @@
package test;
import java.io.File;
import java.util.Iterator;
import java.util.List;
public class SurefirePlugin
{
public boolean execute( String mavenRepoLocal,
String basedir,
String classesDirectory,
String testClassesDirectory,
List includes,
List excludes,
String[] classpathElements,
public boolean execute( String basedir, List includes, List excludes, List classpathElements,
String reportsDirectory )
throws Exception
{
@ -19,21 +13,14 @@ public class SurefirePlugin
SurefireBooter surefireBooter = new SurefireBooter();
surefireBooter.addBattery( "org.codehaus.surefire.battery.DirectoryBattery", new Object[]{basedir, includes, excludes} );
surefireBooter.addBattery( "org.codehaus.surefire.battery.DirectoryBattery",
new Object[]{basedir, includes, excludes} );
surefireBooter.addClassPathUrl( new File( mavenRepoLocal, "junit/jars/junit-3.8.1.jar" ).getPath() );
surefireBooter.addClassPathUrl( new File( mavenRepoLocal, "surefire/jars/surefire-1.2-SNAPSHOT.jar" ).getPath() );
surefireBooter.addClassPathUrl( new File( classesDirectory ).getPath() );
surefireBooter.addClassPathUrl( new File( testClassesDirectory ).getPath() );
for ( int i = 0; i < classpathElements.length; i++ )
for ( Iterator i = classpathElements.iterator(); i.hasNext(); )
{
surefireBooter.addClassPathUrl( classpathElements[i] );
surefireBooter.addClassPathUrl( (String) i.next() );
}
surefireBooter.setReportsDirectory( reportsDirectory );
surefireBooter.addReport( "org.codehaus.surefire.report.ConsoleReporter" );

View File

@ -24,5 +24,11 @@
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</model>