maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r382683 [2/2] - in /maven/surefire/branches/surefire-testng: surefire-api/src/main/java/org/apache/maven/surefire/ surefire-api/src/main/java/org/apache/maven/surefire/battery/ surefire-api/src/main/java/org/apache/maven/surefire/report/ su...
Date Fri, 03 Mar 2006 06:07:30 GMT
Copied: maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/IsolatedClassLoader.java (from r382020, maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/IsolatedClassLoader.java)
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/IsolatedClassLoader.java?p2=maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/IsolatedClassLoader.java&p1=maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/IsolatedClassLoader.java&r1=382020&r2=382683&rev=382683&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/IsolatedClassLoader.java (original)
+++ maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/IsolatedClassLoader.java Thu Mar  2 22:07:26 2006
@@ -1,4 +1,4 @@
-package org.apache.maven.surefire;
+package org.apache.maven.surefire.booter;
 
 /*
  * Copyright 2001-2006 The Apache Software Foundation.
@@ -21,6 +21,9 @@
 import java.util.HashSet;
 import java.util.Set;
 
+/**
+ * @noinspection CustomClassloader
+ */
 public class IsolatedClassLoader
     extends URLClassLoader
 {
@@ -30,21 +33,23 @@
 
     private boolean childDelegation = true;
 
+    private static final URL[] EMPTY_URL_ARRAY = new URL[0];
+
     public IsolatedClassLoader()
     {
-        super( new URL[0], null );
+        super( EMPTY_URL_ARRAY, null );
     }
 
     public IsolatedClassLoader( ClassLoader parent, boolean childDelegation )
     {
-        super( new URL[0], parent );
+        super( EMPTY_URL_ARRAY, parent );
 
         this.childDelegation = childDelegation;
     }
 
     public IsolatedClassLoader( ClassLoader parent )
     {
-        super( new URL[0], parent );
+        super( EMPTY_URL_ARRAY, parent );
     }
 
     public void addURL( URL url )
@@ -59,14 +64,14 @@
         }
     }
 
-    public synchronized Class loadClass( String className )
+    public synchronized Class loadClass( String name )
         throws ClassNotFoundException
     {
         Class c;
 
         if ( childDelegation )
         {
-            c = findLoadedClass( className );
+            c = findLoadedClass( name );
 
             ClassNotFoundException ex = null;
 
@@ -74,7 +79,7 @@
             {
                 try
                 {
-                    c = findClass( className );
+                    c = findClass( name );
                 }
                 catch ( ClassNotFoundException e )
                 {
@@ -82,7 +87,7 @@
 
                     if ( parent != null )
                     {
-                        c = parent.loadClass( className );
+                        c = parent.loadClass( name );
                     }
                 }
             }
@@ -94,7 +99,7 @@
         }
         else
         {
-            c = super.loadClass( className );
+            c = super.loadClass( name );
         }
 
         return c;

Propchange: maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/IsolatedClassLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/IsolatedClassLoader.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java (from r382212, maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooter.java)
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java?p2=maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java&p1=maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooter.java&r1=382212&r2=382683&rev=382683&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooter.java (original)
+++ maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java Thu Mar  2 22:07:26 2006
@@ -1,4 +1,4 @@
-package org.apache.maven.surefire;
+package org.apache.maven.surefire.booter;
 
 /*
  * Copyright 2001-2006 The Apache Software Foundation.
@@ -16,7 +16,8 @@
  * limitations under the License.
  */
 
-import org.codehaus.plexus.util.StringUtils;
+import org.apache.maven.surefire.Surefire;
+import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.cli.CommandLineException;
 import org.codehaus.plexus.util.cli.CommandLineUtils;
 import org.codehaus.plexus.util.cli.Commandline;
@@ -25,13 +26,17 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.io.Writer;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -44,763 +49,410 @@
  */
 public class SurefireBooter
 {
-    protected static final String EOL = System.getProperty( "line.separator" );
-
-    protected static final String PS = System.getProperty( "path.separator" );
-
-    private static String RUNNER = "org.apache.maven.surefire.SurefireBooter";
-
-    private static String BATTERY_EXECUTOR = "org.apache.maven.surefire.Surefire";
-
-    private static String SINGLE_TEST_BATTERY = "org.apache.maven.surefire.battery.JUnitBattery";
-
-    private List batteries = new ArrayList();
-
     private List reports = new ArrayList();
 
-    private List classpathUrls = new ArrayList();
-
-    private String testSourceDirectory;
-
-    private String reportsDirectory;
-
-    private String forkMode;
-
-    private String basedir;
-
-    private String jvm;
-
-    private Properties systemProperties;
+    private List classPathUrls = new ArrayList();
 
-    private String argLine;
+    private List surefireClassPathUrls = new ArrayList();
 
-    private Map environmentVariables;
-
-    private File workingDirectory;
-
-    private boolean childDelegation;
-
-    private boolean debug;
-
-    private String groups;
-
-    private String excludedGroups;
-
-    private int threadCount;
-
-    private boolean parallel;
-
-    private String surefireBooterJar;
-
-    private String plexusUtilsJar;
+    private List testSuites = new ArrayList();
 
     // ----------------------------------------------------------------------
     //
     // ----------------------------------------------------------------------
 
-    public static final String FORK_ONCE = "once";
-
-    public static final String FORK_PERTEST = "pertest";
-
-    public static final String FORK_NONE = "none";
-
-    public static final String SUREFIRE_PROPERTIES = "surefire.properties";
+    private ForkConfiguration forkConfiguration;
 
-    public static final String SYSTEM_PROPERTIES = "surefire-system.properties";
+    private static final int TESTS_SUCCEEDED_EXIT_CODE = 0;
 
-    public static final String CLASSLOADER_PROPERTIES = "surefire-classloader.properties";
-
-    static int TESTS_SUCCEEDED = 0;
-
-    static int TESTS_FAILED = 255;
-
-    static int ILLEGAL_ARGUMENT_EXCEPTION = 100;
-
-    static int OTHER_EXCEPTION = 200;
+    private static final int TESTS_FAILED_EXIT_CODE = 255;
 
     // ----------------------------------------------------------------------
     // Accessors
     // ----------------------------------------------------------------------
 
-    public void setReportsDirectory( String reportsDirectory )
-    {
-        this.reportsDirectory = reportsDirectory;
-    }
-
-    public String getReportsDirectory()
-    {
-        return this.reportsDirectory;
-    }
-
-    public void addBattery( String battery, Object[] params )
-    {
-        batteries.add( new Object[]{battery, params} );
-    }
-
-    public void addBattery( String battery )
+    public void addReport( String report )
     {
-        batteries.add( new Object[]{battery, null} );
+        addReport( report, null );
     }
 
-    public void addReport( String report )
+    public void addReport( String report, Object[] constructorParams )
     {
-        reports.add( report );
+        reports.add( new Object[]{report, constructorParams} );
     }
 
     public void addClassPathUrl( String path )
     {
-        if ( !classpathUrls.contains( path ) )
+        if ( !classPathUrls.contains( path ) )
         {
-            classpathUrls.add( path );
+            classPathUrls.add( path );
         }
     }
 
-    public void setClassPathUrls( List classpathUrls )
+    public void addTestSuite( String suiteClassName, Object[] constructorParams )
     {
-        this.classpathUrls = classpathUrls;
+        testSuites.add( new Object[]{suiteClassName, constructorParams} );
     }
 
-    public void setTestSourceDirectory( String dirPath )
+    public void addSurefireClassPathUrl( String path )
     {
-        this.testSourceDirectory = dirPath;
-    }
-
-    // ----------------------------------------------------------------------
-    // Forking options
-    // ----------------------------------------------------------------------
-
-    public void setForkMode( String forkMode )
-    {
-        if ( forkMode.equals( FORK_NONE ) || forkMode.equals( FORK_ONCE ) || forkMode.equals( FORK_PERTEST ) )
+        if ( !surefireClassPathUrls.contains( path ) )
         {
-            this.forkMode = forkMode;
+            surefireClassPathUrls.add( path );
         }
-        else
-        {
-            throw new IllegalArgumentException( "Fork mode " + forkMode + " is not a legal value" );
-        }
-    }
-
-    public void setJvm( String jvm )
-    {
-        this.jvm = jvm;
-    }
-
-    public void setGroups( String groups )
-    {
-        this.groups = groups;
-    }
-
-    public void setExcludedGroups( String excludedGroups )
-    {
-        this.excludedGroups = excludedGroups;
-    }
-
-    public void setThreadCount( int threadCount )
-    {
-        this.threadCount = threadCount;
-    }
-
-    public void setParallel( boolean parallel )
-    {
-        this.parallel = parallel;
-    }
-
-    public void setSystemProperties( Properties systemProperties )
-    {
-        this.systemProperties = systemProperties;
-    }
-
-    public void setArgLine( String argLine )
-    {
-        this.argLine = argLine;
-    }
-
-    public void setEnvironmentVariables( Map environmentVariables )
-    {
-        this.environmentVariables = environmentVariables;
-    }
-
-    public void setBasedir( String basedir )
-    {
-        this.basedir = basedir;
-    }
-
-    public void setWorkingDirectory( File dir )
-    {
-        this.workingDirectory = dir;
-    }
-
-    public void setChildDelegation( boolean childDelegation )
-    {
-        this.childDelegation = childDelegation;
     }
 
-    public void setDebug( boolean debug )
+    public void setForkConfiguration( ForkConfiguration forkConfiguration )
     {
-        this.debug = debug;
+        this.forkConfiguration = forkConfiguration;
     }
 
-    // ----------------------------------------------------------------------
-    //
-    // ----------------------------------------------------------------------
-
+    // TODO: fix error handling
     public boolean run()
-        throws Exception
+        throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InstantiationException,
+        InvocationTargetException, MalformedURLException, SurefireBooterForkException
     {
         boolean result = false;
 
-        if ( forkMode.equals( FORK_NONE ) )
+        if ( ForkConfiguration.FORK_NONE.equals( forkConfiguration.getForkMode() ) )
         {
-            result = runTestsInProcess();
+            result = runSuitesInProcess( false );
         }
-        else if ( forkMode.equals( FORK_ONCE ) )
+        else if ( ForkConfiguration.FORK_ONCE.equals( forkConfiguration.getForkMode() ) )
         {
-            result = runTestsForkOnce();
+            result = runSuitesForkOnce();
         }
-        else if ( forkMode.equals( FORK_PERTEST ) )
+        else if ( ForkConfiguration.FORK_PERTEST.equals( forkConfiguration.getForkMode() ) )
         {
-            result = runTestsForkEach();
+            result = runSuitesForkPerTestSet();
         }
-
         return result;
     }
 
-    private ClassLoader createClassLoader()
-        throws Exception
+    private boolean runSuitesInProcess( String testSet, boolean childDelegation )
+        throws MalformedURLException, ClassNotFoundException, IllegalAccessException, InstantiationException,
+        NoSuchMethodException, InvocationTargetException
     {
-        return createClassLoader( classpathUrls, childDelegation );
-    }
-
-    static private ClassLoader createClassLoader( List classpathUrls, boolean childDelegation )
-        throws Exception
-    {
-        ArrayList urls = new ArrayList();
-
-        for ( Iterator i = classpathUrls.iterator(); i.hasNext(); )
-        {
-            String url = (String) i.next();
-
-            if ( url == null )
-            {
-                continue;
-            }
-
-            File f = new File( url );
-            urls.add( f.toURL() );
-        }
-
-        if ( childDelegation )
-        {
-            IsolatedClassLoader surefireClassLoader =
-                new IsolatedClassLoader( ClassLoader.getSystemClassLoader(), true );
-            for ( Iterator iter = urls.iterator(); iter.hasNext(); )
-            {
-                URL url = (URL) iter.next();
-                surefireClassLoader.addURL( url );
-            }
-            return surefireClassLoader;
-        }
-        else
+        if ( testSuites.size() != 1 )
         {
-            URL u[] = new URL[urls.size()];
-            urls.toArray( u );
-            return new URLClassLoader( u, ClassLoader.getSystemClassLoader() );
+            throw new IllegalArgumentException( "Cannot only specify testSet for single test suites" );
         }
-    }
-
-    private static ClassLoader createForkingClassLoader( String basedir )
-        throws Exception
-    {
-        Properties p = loadProperties( basedir, CLASSLOADER_PROPERTIES );
-
-        String cp = p.getProperty( "classpath" );
 
-        boolean childDelegation = "true".equals( p.getProperty( "childDelegation", "false" ) );
+        // TODO: replace with plexus
 
-        List urls = Arrays.asList( cp.split( ":" ) );
+        ClassLoader surefireClassLoader = createClassLoader( surefireClassPathUrls, getClass().getClassLoader() );
 
-        return createClassLoader( urls, childDelegation );
-    }
-
-
-    private boolean runTestsInProcess()
-        throws Exception
-    {
-        ClassLoader surefireClassLoader = createClassLoader();
+        ClassLoader testsClassLoader = createClassLoader( classPathUrls, childDelegation );
 
-        Class batteryExecutorClass = surefireClassLoader.loadClass( BATTERY_EXECUTOR );
+        Class surefireClass = surefireClassLoader.loadClass( Surefire.class.getName() );
 
-        Object batteryExecutor = batteryExecutorClass.newInstance();
+        Object surefire = surefireClass.newInstance();
 
-        Method run = batteryExecutorClass.getMethod( "run", new Class[]{List.class, List.class, ClassLoader.class,
-            String.class, String.class, String.class, Integer.class, Boolean.class, String.class} );
+        Method run = surefireClass.getMethod( "run", new Class[]{List.class, Object[].class, String.class,
+            ClassLoader.class, ClassLoader.class} );
 
         ClassLoader oldContextClassLoader = Thread.currentThread() .getContextClassLoader();
 
-        Thread.currentThread().setContextClassLoader( surefireClassLoader );
+        Thread.currentThread().setContextClassLoader( testsClassLoader );
 
-        Boolean result = (Boolean) run.invoke( batteryExecutor, new Object[]{reports, batteries, surefireClassLoader,
-            reportsDirectory, groups, excludedGroups, new Integer( threadCount ),
-            parallel ? Boolean.TRUE : Boolean.FALSE, testSourceDirectory} );
+        Boolean result = (Boolean) run.invoke( surefire, new Object[]{reports, testSuites.get( 0 ), testSet,
+            surefireClassLoader, testsClassLoader} );
 
         Thread.currentThread().setContextClassLoader( oldContextClassLoader );
 
         return result.booleanValue();
     }
 
-    private boolean runTestsForkOnce()
-        throws Exception
+    private boolean runSuitesInProcess( boolean childDelegation )
+        throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException,
+        InvocationTargetException, MalformedURLException
     {
-        getForkOnceArgs();
+        // TODO: replace with plexus
 
-        return fork( true );
-    }
+        ClassLoader surefireClassLoader = createClassLoader( surefireClassPathUrls, getClass().getClassLoader() );
 
-    private boolean runTestsForkEach()
-        throws Exception
-    {
-        boolean noFailures = true;
+        ClassLoader testsClassLoader = createClassLoader( classPathUrls, childDelegation );
 
-        List testClasses = getTestClasses();
+        Class surefireClass = surefireClassLoader.loadClass( Surefire.class.getName() );
 
-        for ( int i = 0; i < testClasses.size(); i++ )
-        {
-            String testClass = (String) testClasses.get( i );
+        Object surefire = surefireClass.newInstance();
 
-            getForkPerTestArgs( testClass );
+        Method run =
+            surefireClass.getMethod( "run", new Class[]{List.class, List.class, ClassLoader.class, ClassLoader.class} );
 
-            // Only show the heading for the first run
-            boolean result = fork( i == 0 );
+        ClassLoader oldContextClassLoader = Thread.currentThread() .getContextClassLoader();
 
-            if ( !result )
-            {
-                noFailures = false;
-            }
-        }
+        Thread.currentThread().setContextClassLoader( testsClassLoader );
 
-        return noFailures;
-    }
+        Boolean result =
+            (Boolean) run.invoke( surefire, new Object[]{reports, testSuites, surefireClassLoader, testsClassLoader} );
 
-    private boolean fork( boolean showHeading )
-        throws Exception
-    {
-        Commandline cli = new Commandline();
+        Thread.currentThread().setContextClassLoader( oldContextClassLoader );
 
-        cli.setWorkingDirectory( basedir );
+        return result.booleanValue();
+    }
 
-        cli.setExecutable( jvm );
+    private boolean runSuitesForkOnce()
+        throws SurefireBooterForkException
+    {
+        return forkSuites( testSuites, true );
+    }
 
-        if ( argLine != null )
+    private boolean runSuitesForkPerTestSet()
+        throws SurefireBooterForkException
+    {
+        ClassLoader testsClassLoader;
+        ClassLoader surefireClassLoader;
+        try
         {
-            cli.addArguments( StringUtils.split( argLine, " " ) );
+            testsClassLoader = createClassLoader( classPathUrls, false );
+            surefireClassLoader = createClassLoader( surefireClassPathUrls, false );
         }
-
-        if ( environmentVariables != null )
+        catch ( MalformedURLException e )
         {
-            Iterator iter = environmentVariables.keySet().iterator();
+            throw new SurefireBooterForkException( "Unable to create classloader to find test suites", e );
+        }
 
-            while ( iter.hasNext() )
-            {
-                String key = (String) iter.next();
+        boolean failed = false;
 
-                String value = (String) environmentVariables.get( key );
+        boolean showHeading = true;
+        for ( Iterator i = testSuites.iterator(); i.hasNext(); )
+        {
+            Object[] testSuite = (Object[]) i.next();
 
-                cli.addEnvironment( key, value );
+            Map testSets = getTestSets( testSuite, testsClassLoader, surefireClassLoader );
 
-                if ( debug )
+            for ( Iterator j = testSets.keySet().iterator(); j.hasNext(); )
+            {
+                String testSet = (String) j.next();
+                boolean result = forkSuite( testSuite, testSet, showHeading );
+                if ( !result )
                 {
-                    System.out.println( "Environment: " + key + "=" + value + " added." );
+                    failed = true;
                 }
-
+                showHeading = false;
             }
-
         }
 
-        cli.createArgument().setValue( "-classpath" );
-
-        cli.createArgument().setValue( surefireBooterJar + PS + plexusUtilsJar );
-
-        cli.createArgument().setValue( RUNNER );
-
-        cli.createArgument().setValue( basedir );
-
-        if ( workingDirectory != null )
-        {
-            //both cli's working directory and  system property "user.dir" must have the same value
-            cli.setWorkingDirectory( workingDirectory.getAbsolutePath() );
-
-            cli.createArgument().setValue( workingDirectory.getAbsolutePath() );
-        }
-
-        if ( debug )
-        {
-            System.out.println( Commandline.toString( cli.getCommandline() ) );
-        }
-
-        Writer consoleWriter = new OutputStreamWriter( System.out );
+        return !failed;
+    }
 
-        StreamConsumer out = new ForkingWriterStreamConsumer( consoleWriter, showHeading );
+    private Map getTestSets( Object[] testSuite, ClassLoader testsClassLoader, ClassLoader surefireClassLoader )
+        throws SurefireBooterForkException
+    {
+        String className = (String) testSuite[0];
 
-        StreamConsumer err = new ForkingWriterStreamConsumer( consoleWriter, showHeading );
+        Object[] params = (Object[]) testSuite[1];
 
-        int returnCode;
+        Object suite = Surefire.instantiateObject( className, params, surefireClassLoader );
 
+        Map testSets;
         try
         {
-            returnCode = CommandLineUtils.executeCommandLine( cli, out, err );
+            Method m = suite.getClass().getMethod( "locateTestSets", new Class[]{ClassLoader.class} );
+
+            testSets = (Map) m.invoke( suite, new Object[]{testsClassLoader} );
         }
-        catch ( CommandLineException e )
+        catch ( IllegalAccessException e )
         {
-            throw new Exception( "Error while executing forked tests.", e );
+            throw new SurefireBooterForkException( "Error obtaining test sets", e );
         }
-        catch ( Exception e )
+        catch ( NoSuchMethodException e )
         {
-            throw new SurefireBooterForkException( "Error while executing forked tests.", e );
+            throw new SurefireBooterForkException( "Error obtaining test sets", e );
         }
-
-        if ( returnCode != 0 )
+        catch ( InvocationTargetException e )
         {
-            return false;
+            throw new SurefireBooterForkException( "Error obtaining test sets", e );
         }
-
-        return true;
+        return testSets;
     }
 
-    private List getTestClasses()
-        throws Exception
+    private boolean forkSuites( List testSuites, boolean showHeading )
+        throws SurefireBooterForkException
     {
-        ClassLoader classLoader = createClassLoader();
-
-        List instantiatedBatteries =
-            Surefire.instantiateBatteries( batteries, classLoader, testSourceDirectory, groups );
-
-        List testClasses = new ArrayList();
+        Properties properties = createForkProperties( testSuites );
 
-        for ( Iterator i = instantiatedBatteries.iterator(); i.hasNext(); )
-        {
-            Object o = i.next();
-
-            Method m = o.getClass().getMethod( "getSubBatteryClassNames", new Class[]{} );
-
-            List tests = (List) m.invoke( o, new Object[]{} );
-
-            // This class comes from a different classloader then the isolated classloader.
-            // This is the battery class that is from a different loader.
-
-            testClasses.addAll( tests );
-        }
-
-        return testClasses;
+        return fork( properties, showHeading );
     }
 
-    private void getForkOnceArgs()
-        throws Exception
+    private boolean forkSuite( Object[] testSuite, String testSet, boolean showHeading )
+        throws SurefireBooterForkException
     {
-        getForkArgs( getStringArrayFromBatteries()[0] );
-    }
+        Properties properties = createForkProperties( Collections.singletonList( testSuite ) );
 
-    private void getForkPerTestArgs( String testClass )
-        throws Exception
-    {
-        getForkArgs( SINGLE_TEST_BATTERY + "|" + testClass );
-    }
+        properties.setProperty( "testSet", testSet );
 
+        return fork( properties, showHeading );
+    }
 
-    private void getForkArgs( String batteryConfig )
-        throws Exception
+    private Properties createForkProperties( List testSuites )
     {
-        String reportClassNames = getListOfStringsAsString( reports, "," );
+        Properties properties = new Properties();
 
-        Properties p = new Properties();
+        addPropertiesForTypeHolder( reports, properties, "report." );
+        addPropertiesForTypeHolder( testSuites, properties, "testSuite." );
 
-        String cp = "";
-        for ( int i = 0; i < classpathUrls.size(); i++ )
+        for ( int i = 0; i < classPathUrls.size(); i++ )
         {
-            String url = (String) classpathUrls.get( i );
-
-            // Exclude the surefire booter
-            if ( url.indexOf( "surefire-booter" ) > 0 )
-            {
-                surefireBooterJar = url;
-            }
-            else if ( url.indexOf( "plexus-utils" ) > 0 )
-            {
-                plexusUtilsJar = url;
-            }
-            else
-            {
-                if ( cp.length() == 0 )
-                {
-                    cp = url;
-                }
-                else
-                {
-                    cp += ":" + url;
-                }
-            }
+            String url = (String) classPathUrls.get( i );
+            properties.setProperty( "classPathUrl." + i, url );
         }
 
-        p.setProperty( "classpath", cp );
-
-        p.setProperty( "childDelegation", String.valueOf( childDelegation ) );
-
-        FileOutputStream fos = new FileOutputStream( new File( basedir, CLASSLOADER_PROPERTIES ) );
-
-        p.store( fos, "classpath entries" );
-
-        fos.close();
-
-        if ( systemProperties != null )
+        for ( int i = 0; i < surefireClassPathUrls.size(); i++ )
         {
-            File f = new File( basedir, SYSTEM_PROPERTIES );
-
-            fos = new FileOutputStream( f );
-
-            systemProperties.store( fos, "system properties" );
-
-            fos.close();
+            String url = (String) surefireClassPathUrls.get( i );
+            properties.setProperty( "surefireClassPathUrl." + i, url );
         }
 
-        p = new Properties();
-
-        p.setProperty( "reportClassNames", reportClassNames );
-
-        p.setProperty( "reportsDirectory", reportsDirectory );
-
-        p.setProperty( "batteryExecutorName", BATTERY_EXECUTOR );
-
-        p.setProperty( "forkMode", forkMode );
-
-        p.setProperty( "batteryConfig", batteryConfig );
-
-        p.setProperty( "debug", String.valueOf( debug ) );
-
-        fos = new FileOutputStream( new File( basedir, SUREFIRE_PROPERTIES ) );
-
-        p.store( fos, "surefire properties" );
-
-        fos.close();
-
+        properties.setProperty( "childDelegation", String.valueOf( forkConfiguration.isChildDelegation() ) );
+        return properties;
     }
 
-    public void reset()
+    private File writePropertiesFile( String name, Properties properties )
+        throws IOException
     {
-        batteries.clear();
-
-        reports.clear();
+        File file = File.createTempFile( name, "tmp" );
+        file.deleteOnExit();
 
-        classpathUrls.clear();
-    }
-
-    private String getListOfStringsAsString( List listOfStrings, String delimiterParm )
-    {
-        StringBuffer stringBuffer = new StringBuffer();
+        FileOutputStream out = new FileOutputStream( file );
 
-        Iterator listOfStringsIterator = listOfStrings.iterator();
-
-        String delimiter = "";
-
-        while ( listOfStringsIterator.hasNext() )
+        try
         {
-            String string = (String) listOfStringsIterator.next();
-
-            stringBuffer.append( delimiter );
-
-            stringBuffer.append( string );
-
-            delimiter = delimiterParm;
+            properties.store( out, name );
+        }
+        finally
+        {
+            IOUtil.close( out );
         }
 
-        return new String( stringBuffer );
+        return file;
     }
 
-    private String[] getStringArrayFromBatteries()
+    private void addPropertiesForTypeHolder( List typeHolderList, Properties properties, String propertyPrefix )
     {
-        String[] batteryConfig = new String[batteries.size()];
-
-        StringBuffer batteryBuffer = new StringBuffer();
-
-        int batteryCounter = 0;
-
-        for ( Iterator j = batteries.iterator(); j.hasNext(); )
+        for ( int i = 0; i < typeHolderList.size(); i++ )
         {
-            Object[] batteryArray = (Object[]) j.next();
+            Object[] report = (Object[]) typeHolderList.get( i );
 
-            batteryBuffer.append( (String) batteryArray[0] );
+            String className = (String) report[0];
+            Object[] params = (Object[]) report[1];
 
-            if ( batteryArray[1] != null )
-            {
-                Object[] batteryParms = (Object[]) batteryArray[1];
+            properties.setProperty( propertyPrefix + i, className );
 
-                for ( int i = 0; i < 3; i++ )
+            if ( params != null )
+            {
+                String paramProperty = params[0].toString();
+                String typeProperty = params[0].getClass().getName();
+                for ( int j = 1; j < params.length; j++ )
                 {
-                    batteryBuffer.append( "|" );
-
-                    batteryBuffer.append( batteryParms[i] );
+                    paramProperty += "|" + params[j].toString();
+                    typeProperty += "|" + params[j].getClass().getName();
                 }
+                properties.setProperty( propertyPrefix + i + ".params", paramProperty );
+                properties.setProperty( propertyPrefix + i + ".types", typeProperty );
             }
-
-            batteryConfig[batteryCounter++] = new String( batteryBuffer );
         }
-
-        return batteryConfig;
     }
 
-    // ----------------------------------------------------------------------
-    //
-    // ----------------------------------------------------------------------
-
-    private static Properties loadProperties( String basedir, String file )
-        throws Exception
+    private boolean fork( Properties properties, boolean showHeading )
+        throws SurefireBooterForkException
     {
-        File f = new File( basedir, file );
-
-        Properties p = new Properties();
-
-        if ( !f.exists() )
+        File surefireProperties;
+        File systemProperties = null;
+        try
         {
-            return p;
+            surefireProperties = writePropertiesFile( "surefire", properties );
+            if ( forkConfiguration.getSystemProperties() != null )
+            {
+                systemProperties = writePropertiesFile( "surefire", forkConfiguration.getSystemProperties() );
+            }
         }
-
-        f.deleteOnExit();
-
-        p.load( new FileInputStream( f ) );
-
-        return p;
-    }
-
-    private static Properties getSurefireProperties( String basedir )
-        throws Exception
-    {
-        return loadProperties( basedir, SUREFIRE_PROPERTIES );
-    }
-
-    private static void setSystemProperties( String basedir )
-        throws Exception
-    {
-        Properties p = loadProperties( basedir, SYSTEM_PROPERTIES );
-
-        for ( Iterator i = p.keySet().iterator(); i.hasNext(); )
+        catch ( IOException e )
         {
-            String key = (String) i.next();
-
-            System.setProperty( key, p.getProperty( key ) );
+            throw new SurefireBooterForkException( "Error creating properties files for forking", e );
         }
-    }
 
-    /**
-     * This method is invoked when Surefire is forked - this method parses and
-     * organizes the arguments passed to it and then calls the Surefire class'
-     * run method.
-     *
-     * @param args
-     * @throws Exception
-     */
-    public static void main( String[] args )
-        throws Exception
-    {
-        String basedir = args[0];
+        Commandline cli = forkConfiguration.createCommandLine( surefireClassPathUrls );
 
-        String workingDirectory = null;
+        cli.createArgument().setFile( surefireProperties );
 
-        if ( args.length == 2 )
+        if ( systemProperties != null )
         {
-            workingDirectory = args[1];
+            cli.createArgument().setFile( systemProperties );
         }
 
-        ClassLoader classLoader = createForkingClassLoader( basedir );
-
-        Thread.currentThread().setContextClassLoader( classLoader );
-
-        setSystemProperties( basedir );
+        Writer consoleWriter = new OutputStreamWriter( System.out );
 
-        if ( workingDirectory != null )
-        {
-            System.setProperty( "user.dir", workingDirectory );
-        }
+        StreamConsumer out = new ForkingWriterStreamConsumer( consoleWriter, showHeading );
 
-        Properties p = getSurefireProperties( basedir );
+        StreamConsumer err = new ForkingWriterStreamConsumer( consoleWriter, showHeading );
 
-        boolean debug = "true".equals( p.getProperty( "debug", "false" ) );
-        if ( debug )
+        if ( forkConfiguration.isDebug() )
         {
-            logClassLoader( classLoader );
+            System.out.println( "Forking command line: " + cli );
         }
 
-        String batteryExecutorName = p.getProperty( "batteryExecutorName" );
-
-        Class batteryExecutorClass = classLoader.loadClass( batteryExecutorName );
-
-        Object batteryExecutor = batteryExecutorClass.newInstance();
-
-        String reports = p.getProperty( "reportClassNames" );
-
-        String[] reportClasses = reports.split( "," );
-
-        List reportList = Arrays.asList( reportClasses );
-
-        String batteryConfig = p.getProperty( "batteryConfig" );
-
-        String[] batteryParts = batteryConfig.split( "\\|" );
-
-        String batteryClassName = batteryParts[0];
-
-        Object[] batteryParms;
-
-        String forkMode = p.getProperty( "forkMode" );
+        int returnCode;
 
-        if ( forkMode.equals( FORK_ONCE ) )
+        try
         {
-            batteryParms = new Object[batteryParts.length - 1];
-
-            batteryParms[0] = new File( batteryParts[1] );
-
-            batteryParms[1] = processStringList( batteryParts[2] );
-
-            batteryParms[2] = processStringList( batteryParts[3] );
+            returnCode = CommandLineUtils.executeCommandLine( cli, out, err );
         }
-        else
+        catch ( CommandLineException e )
         {
-            batteryParms = new Object[1];
-
-            batteryParms[0] = batteryParts[1];
+            throw new SurefireBooterForkException( "Error while executing forked tests.", e );
         }
 
-        List batteryHolders = new ArrayList();
-
-        batteryHolders.add( new Object[]{batteryClassName, batteryParms} );
-
-        String reportsDirectory = p.getProperty( "reportsDirectory" );
+        return returnCode == 0;
+    }
 
-        Method run = batteryExecutorClass.getMethod( "run", new Class[]{List.class, List.class, String.class} );
+    private static ClassLoader createClassLoader( List classPathUrls, ClassLoader parent )
+        throws MalformedURLException
+    {
+        return createClassLoader( classPathUrls, parent, false );
+    }
 
-        Object[] parms = new Object[]{reportList, batteryHolders, reportsDirectory};
+    private static ClassLoader createClassLoader( List classPathUrls, boolean childDelegation )
+        throws MalformedURLException
+    {
+        return createClassLoader( classPathUrls, ClassLoader.getSystemClassLoader(), childDelegation );
+    }
 
-        int returnCode = TESTS_FAILED;
+    private static ClassLoader createClassLoader( List classPathUrls, ClassLoader parent, boolean childDelegation )
+        throws MalformedURLException
+    {
+        List urls = new ArrayList();
 
-        try
+        for ( Iterator i = classPathUrls.iterator(); i.hasNext(); )
         {
-            boolean result = ( (Boolean) run.invoke( batteryExecutor, parms ) ).booleanValue();
+            String url = (String) i.next();
 
-            if ( result )
+            if ( url != null )
             {
-                returnCode = TESTS_SUCCEEDED;
+                File f = new File( url );
+                urls.add( f.toURL() );
             }
-
         }
-        catch ( IllegalArgumentException e )
+
+        ClassLoader classLoader;
+        if ( childDelegation )
         {
-            returnCode = ILLEGAL_ARGUMENT_EXCEPTION;
+            IsolatedClassLoader isolatedClassLoader = new IsolatedClassLoader( parent, true );
+            for ( Iterator iter = urls.iterator(); iter.hasNext(); )
+            {
+                URL url = (URL) iter.next();
+                isolatedClassLoader.addURL( url );
+            }
+            classLoader = isolatedClassLoader;
         }
-        catch ( Exception e )
+        else
         {
-            e.printStackTrace();
-
-            returnCode = OTHER_EXCEPTION;
+            URL[] u = new URL[urls.size()];
+            urls.toArray( u );
+            classLoader = new URLClassLoader( u, parent );
         }
-
-        System.exit( returnCode );
+        return classLoader;
     }
 
     private static List processStringList( String stringList )
@@ -823,30 +475,140 @@
         return list;
     }
 
-    private static void logClassLoader( ClassLoader classLoader )
+    private static Properties loadProperties( File file )
+        throws IOException
+    {
+        Properties p = new Properties();
+
+        if ( file != null && file.exists() )
+        {
+            FileInputStream inStream = new FileInputStream( file );
+            try
+            {
+                p.load( inStream );
+            }
+            finally
+            {
+                IOUtil.close( inStream );
+            }
+        }
+
+        return p;
+    }
+
+    private static void setSystemProperties( File file )
+        throws IOException
+    {
+        Properties p = loadProperties( file );
+
+        for ( Iterator i = p.keySet().iterator(); i.hasNext(); )
+        {
+            String key = (String) i.next();
+
+            System.setProperty( key, p.getProperty( key ) );
+        }
+    }
+
+    private static Object[] constructParamObjects( String paramProperty, String typeProperty )
+    {
+        Object[] paramObjects = null;
+        if ( paramProperty != null )
+        {
+            String[] params = paramProperty.split( "\\|" );
+            String[] types = typeProperty.split( "\\|" );
+
+            paramObjects = new Object[params.length];
+
+            for ( int i = 0; i < types.length; i++ )
+            {
+                if ( types[i].equals( String.class.getName() ) )
+                {
+                    paramObjects[i] = params[i];
+                }
+                else if ( types[i].equals( File.class.getName() ) )
+                {
+                    paramObjects[i] = new File( params[i] );
+                }
+                else if ( types[i].equals( ArrayList.class.getName() ) )
+                {
+                    paramObjects[i] = processStringList( params[i] );
+                }
+                else
+                {
+                    // TODO: could attempt to construct with a String constructor if needed
+                    throw new IllegalArgumentException( "Unknown parameter type: " + types[i] );
+                }
+            }
+        }
+        return paramObjects;
+    }
+
+    /**
+     * This method is invoked when Surefire is forked - this method parses and
+     * organizes the arguments passed to it and then calls the Surefire class'
+     * run method.
+     * <p/>
+     * The system exit code will be 1 if an exception is thrown.
+     *
+     * @param args
+     */
+    public static void main( String[] args )
+        throws ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException,
+        NoSuchMethodException, IOException
     {
-        if ( classLoader.getParent() != null )
+        if ( args.length > 1 )
         {
-            logClassLoader( classLoader.getParent() );
+            setSystemProperties( new File( args[1] ) );
         }
 
-        if ( classLoader instanceof URLClassLoader )
+        Properties p = loadProperties( new File( args[0] ) );
+
+        SurefireBooter surefireBooter = new SurefireBooter();
+
+        for ( Enumeration e = p.propertyNames(); e.hasMoreElements(); )
         {
-            System.out.println( "ClassLoader: type" + classLoader.getClass() + ", value=" + classLoader );
+            String name = (String) e.nextElement();
 
-            URLClassLoader ucl = (URLClassLoader) classLoader;
+            if ( name.startsWith( "report." ) && !name.endsWith( ".params" ) && !name.endsWith( ".types" ) )
+            {
+                String className = p.getProperty( name );
 
-            URL[] u = ucl.getURLs();
+                String params = p.getProperty( name + ".params" );
+                String types = p.getProperty( name + ".types" );
+                surefireBooter.addReport( className, constructParamObjects( params, types ) );
+            }
+            else if ( name.startsWith( "testSuite." ) && !name.endsWith( ".params" ) && !name.endsWith( ".types" ) )
+            {
+                String className = p.getProperty( name );
 
-            for ( int i = 0; i < u.length; i++ )
+                String params = p.getProperty( name + ".params" );
+                String types = p.getProperty( name + ".types" );
+                surefireBooter.addTestSuite( className, constructParamObjects( params, types ) );
+            }
+            else if ( name.startsWith( "classPathUrl." ) )
             {
-                System.out.println( "           : " + u[i] );
+                surefireBooter.addClassPathUrl( p.getProperty( name ) );
+            }
+            else if ( name.startsWith( "surefireClassPathUrl." ) )
+            {
+                surefireBooter.addSurefireClassPathUrl( p.getProperty( name ) );
             }
         }
+
+        boolean childDelegation = Boolean.valueOf( p.getProperty( "childDelegation" ) ).booleanValue();
+        String testSet = p.getProperty( "testSet" );
+        boolean result;
+        if ( testSet != null )
+        {
+            result = surefireBooter.runSuitesInProcess( testSet, childDelegation );
+        }
         else
         {
-            System.out.println( "ClassLoader: type" + classLoader.getClass() + ", value=" + classLoader );
+            result = surefireBooter.runSuitesInProcess( childDelegation );
         }
+
+        //noinspection CallToSystemExit
+        System.exit( result ? TESTS_SUCCEEDED_EXIT_CODE : TESTS_FAILED_EXIT_CODE );
     }
 }
 

Propchange: maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooterForkException.java (from r382020, maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooterForkException.java)
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooterForkException.java?p2=maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooterForkException.java&p1=maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooterForkException.java&r1=382020&r2=382683&rev=382683&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooterForkException.java (original)
+++ maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooterForkException.java Thu Mar  2 22:07:26 2006
@@ -1,4 +1,4 @@
-package org.apache.maven.surefire;
+package org.apache.maven.surefire.booter;
 
 /*
  * Copyright 2001-2006 The Apache Software Foundation.

Propchange: maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooterForkException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooterForkException.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitDirectoryTestSuite.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitDirectoryTestSuite.java?rev=382683&view=auto
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitDirectoryTestSuite.java (added)
+++ maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitDirectoryTestSuite.java Thu Mar  2 22:07:26 2006
@@ -0,0 +1,48 @@
+package org.apache.maven.surefire.junit;
+
+/*
+ * 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.surefire.suite.AbstractDirectoryTestSuite;
+import org.apache.maven.surefire.testset.SurefireTestSet;
+
+import java.io.File;
+import java.util.ArrayList;
+
+/**
+ * TODO: Description.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public class JUnitDirectoryTestSuite
+    extends AbstractDirectoryTestSuite
+{
+    public JUnitDirectoryTestSuite( File basedir, ArrayList includes, ArrayList excludes )
+    {
+        super( basedir, includes, excludes );
+    }
+
+    protected Object[] createConstructorArguments( String className )
+    {
+        return new Object[]{JUnitTestSet.class.getName(), new Object[]{className}};
+    }
+
+    protected SurefireTestSet createTestSet( String className, ClassLoader classLoader )
+        throws ClassNotFoundException
+    {
+        return new JUnitTestSet( className, classLoader );
+    }
+}

Propchange: maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitDirectoryTestSuite.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitDirectoryTestSuite.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java (from r382036, maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/battery/JUnitBattery.java)
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java?p2=maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java&p1=maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/battery/JUnitBattery.java&r1=382036&r2=382683&rev=382683&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/battery/JUnitBattery.java (original)
+++ maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java Thu Mar  2 22:07:26 2006
@@ -1,4 +1,4 @@
-package org.apache.maven.surefire.battery;
+package org.apache.maven.surefire.junit;
 
 /*
  * Copyright 2001-2006 The Apache Software Foundation.
@@ -16,8 +16,10 @@
  * limitations under the License.
  */
 
-import org.apache.maven.surefire.battery.assertion.BatteryTestFailedException;
 import org.apache.maven.surefire.report.ReporterManager;
+import org.apache.maven.surefire.testset.AbstractTestSet;
+import org.apache.maven.surefire.testset.TestListenerInvocationHandler;
+import org.apache.maven.surefire.testset.TestSetFailedException;
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
@@ -25,8 +27,8 @@
 import java.lang.reflect.Modifier;
 import java.lang.reflect.Proxy;
 
-public final class JUnitBattery
-    extends AbstractBattery
+public final class JUnitTestSet
+    extends AbstractTestSet
 {
     public static final String TEST_CASE = "junit.framework.TestCase";
 
@@ -54,8 +56,6 @@
 
     private Class testResultClass;
 
-    private ClassLoader classLoader;
-
     private Class testClass;
 
     private Method addListenerMethod;
@@ -68,41 +68,26 @@
 
     private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
 
-    public JUnitBattery( String testClassName )
-        throws Exception
-    {
-        processTestClass( getClass().getClassLoader().loadClass( testClassName ), getClass().getClassLoader() );
-    }
-
-    public JUnitBattery( String testClass, ClassLoader loader )
-        throws Exception
+    public JUnitTestSet( String testClassName, ClassLoader classLoader )
+        throws ClassNotFoundException
     {
-        processTestClass( loader.loadClass( testClass ), loader );
+        testClass = classLoader.loadClass( testClassName );
     }
 
-    public JUnitBattery( Class testClass, ClassLoader loader )
-        throws Exception
-    {
-        processTestClass( testClass, loader );
-    }
-
-    private void processTestClass( Class testClass, ClassLoader loader )
-        throws Exception
+    public JUnitTestSet( Class testClass )
     {
         if ( testClass == null )
         {
             throw new NullPointerException( "testClass is null" );
         }
 
-        if ( loader == null )
-        {
-            throw new NullPointerException( "classLoader is null" );
-        }
-
-        this.classLoader = loader;
-
         this.testClass = testClass;
+    }
 
+    private void processTestClass( ClassLoader loader )
+        throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, InstantiationException,
+        NoSuchMethodException
+    {
         testResultClass = loader.loadClass( TEST_RESULT );
 
         Class testCaseClass = loader.loadClass( TEST_CASE );
@@ -136,6 +121,7 @@
         }
         catch ( NoSuchMethodException e )
         {
+            // No suite method
         }
 
         if ( testObject == null && testCaseClass.isAssignableFrom( testClass ) )
@@ -187,7 +173,7 @@
             {
                 countTestCasesMethod = testClass.getMethod( COUNT_TEST_CASES_METHOD, EMPTY_CLASS_ARRAY );
             }
-            catch ( Exception e )
+            catch ( NoSuchMethodException e )
             {
                 countTestCasesMethod = null; // for clarity
             }
@@ -196,7 +182,7 @@
             {
                 runMethod = testClass.getMethod( RUN_METHOD, new Class[]{testResultClass} );
             }
-            catch ( Exception e )
+            catch ( NoSuchMethodException e )
             {
                 runMethod = null;    // for clarity
             }
@@ -213,21 +199,47 @@
         return testObject;
     }
 
-    public void execute( ReporterManager reportManager )
-        throws Exception
+    public void execute( ReporterManager reportManager, ClassLoader loader )
+        throws TestSetFailedException
     {
+        try
+        {
+            processTestClass( loader );
+        }
+        catch ( ClassNotFoundException e )
+        {
+            throw new TestSetFailedException( "JUnit classes not available", e );
+        }
+        catch ( IllegalAccessException e )
+        {
+            throw new TestSetFailedException( "Unknown access exception creating JUnit classes", e );
+        }
+        catch ( InvocationTargetException e )
+        {
+            throw new TestSetFailedException( "Unknown invocation exception creating JUnit classes", e );
+        }
+        catch ( InstantiationException e )
+        {
+            throw new TestSetFailedException( "Unknown instantiation exception creating JUnit classes", e );
+        }
+        catch ( NoSuchMethodException e )
+        {
+            throw new TestSetFailedException( "Class is not a JUnit TestCase", e );
+        }
+
+        // TODO: why do we accept runMethod == null? That means it doesn't extend TestCase
         if ( runMethod != null )
         {
-            executeJUnit( reportManager );
+            executeJUnit( reportManager, loader );
         }
         else
         {
-            super.execute( reportManager );
+            super.execute( reportManager, loader );
         }
     }
 
-    private void executeJUnit( ReporterManager reportManager )
-        throws BatteryTestFailedException
+    private void executeJUnit( ReporterManager reportManager, ClassLoader classLoader )
+        throws TestSetFailedException
     {
         try
         {
@@ -249,23 +261,24 @@
         }
         catch ( IllegalArgumentException e )
         {
-            throw new BatteryTestFailedException( testObject.getClass().getName(), e );
+            throw new TestSetFailedException( testObject.getClass().getName(), e );
         }
         catch ( InstantiationException e )
         {
-            throw new BatteryTestFailedException( testObject.getClass().getName(), e );
+            throw new TestSetFailedException( testObject.getClass().getName(), e );
         }
         catch ( IllegalAccessException e )
         {
-            throw new BatteryTestFailedException( testObject.getClass().getName(), e );
+            throw new TestSetFailedException( testObject.getClass().getName(), e );
         }
         catch ( InvocationTargetException e )
         {
-            throw new BatteryTestFailedException( testObject.getClass().getName(), e );
+            throw new TestSetFailedException( testObject.getClass().getName(), e );
         }
     }
 
     public int getTestCount()
+        throws TestSetFailedException
     {
         try
         {
@@ -284,19 +297,19 @@
         }
         catch ( IllegalAccessException e )
         {
-            throw new BatteryTestFailedException( testObject.getClass().getName(), e );
+            throw new TestSetFailedException( testObject.getClass().getName(), e );
         }
         catch ( IllegalArgumentException e )
         {
-            throw new BatteryTestFailedException( testObject.getClass().getName(), e );
+            throw new TestSetFailedException( testObject.getClass().getName(), e );
         }
         catch ( InvocationTargetException e )
         {
-            throw new BatteryTestFailedException( testObject.getClass().getName(), e );
+            throw new TestSetFailedException( testObject.getClass().getName(), e );
         }
     }
 
-    public String getBatteryName()
+    public String getName()
     {
         return testClass.getName();
     }

Propchange: maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/surefire/branches/surefire-testng/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnitTestSet.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java?rev=382683&view=auto
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java (added)
+++ maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java Thu Mar  2 22:07:26 2006
@@ -0,0 +1,51 @@
+package org.apache.maven.surefire.testng;
+
+/*
+ * 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.surefire.suite.AbstractDirectoryTestSuite;
+import org.apache.maven.surefire.testset.SurefireTestSet;
+
+import java.io.File;
+import java.util.ArrayList;
+
+/**
+ * Test suite for TestNG based on a directory of Java test classes.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public class TestNGDirectoryTestSuite
+    extends AbstractDirectoryTestSuite
+{
+    public TestNGDirectoryTestSuite( File basedir, ArrayList includes, ArrayList excludes, String groups,
+                                     String excludedGroups, Boolean parallel, Integer threadCount )
+    {
+        super( basedir, includes, excludes );
+
+        // TODO
+    }
+
+    protected Object[] createConstructorArguments( String className )
+    {
+        return new Object[]{TestNGTestSet.class.getName(), new Object[]{className}};
+    }
+
+    protected SurefireTestSet createTestSet( String className, ClassLoader classLoader )
+        throws ClassNotFoundException
+    {
+        return new TestNGTestSet( className );
+    }
+}

Propchange: maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java?rev=382683&r1=382682&r2=382683&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java (original)
+++ maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java Thu Mar  2 22:07:26 2006
@@ -17,13 +17,8 @@
  */
 
 import org.apache.maven.surefire.Surefire;
-import org.apache.maven.surefire.report.ReportEntry;
 import org.apache.maven.surefire.report.ReporterManager;
-import org.testng.ISuite;
-import org.testng.ISuiteListener;
-import org.testng.ITestContext;
 import org.testng.ITestListener;
-import org.testng.ITestResult;
 import org.testng.TestNG;
 
 /**
@@ -34,7 +29,7 @@
  * @author jkuhnert
  */
 public class TestNGReporter
-    implements ITestListener, ISuiteListener
+//    implements ITestListener, ISuiteListener (TODO)
 {
 
     /**
@@ -73,9 +68,7 @@
         }
     }
 
-    /* (non-Javadoc)
-    * @see org.testng.ITestListener#onTestStart(org.testng.ITestResult)
-    */
+/* TODO
     public void onTestStart( ITestResult result )
     {
         String rawString = Surefire.getResourceString( "testStarting" );
@@ -88,17 +81,11 @@
 
     }
 
-    /* (non-Javadoc)
-     * @see org.testng.ITestListener#onTestSuccess(org.testng.ITestResult)
-     */
     public void onTestSuccess( ITestResult result )
     {
         reportManager.testSucceeded( createReport( result, "testSuccessful" ) );
     }
 
-    /* (non-Javadoc)
-     * @see org.testng.ITestListener#onTestFailure(org.testng.ITestResult)
-     */
     public void onTestFailure( ITestResult result )
     {
         String rawString = Surefire.getResourceString( "executeException" );
@@ -111,9 +98,6 @@
         reportManager.testFailed( report );
     }
 
-    /* (non-Javadoc)
-    * @see org.testng.ITestListener#onTestSkipped(org.testng.ITestResult)
-    */
     public void onTestSkipped( ITestResult result )
     {
         // TODO: is this correct?
@@ -125,9 +109,6 @@
         return new ReportEntry( surefire, result.getName(), Surefire.getResourceString( key ) );
     }
 
-    /* (non-Javadoc)
-     * @see org.testng.ITestListener#onTestFailedButWithinSuccessPercentage(org.testng.ITestResult)
-     */
     public void onTestFailedButWithinSuccessPercentage( ITestResult result )
     {
         String rawString = Surefire.getResourceString( "executeException" );
@@ -139,9 +120,6 @@
         reportManager.testError( report );
     }
 
-    /* (non-Javadoc)
-     * @see org.testng.ITestListener#onStart(org.testng.ITestContext)
-     */
     public void onStart( ITestContext context )
     {
         String rawString = Surefire.getResourceString( "suiteExecutionStarting" );
@@ -150,12 +128,9 @@
 
         ReportEntry report = new ReportEntry( surefire, context.getName(), group, rawString );
 
-        reportManager.batteryStarting( report );
+        reportManager.testSetStarting( report );
     }
 
-    /* (non-Javadoc)
-    * @see org.testng.ITestListener#onFinish(org.testng.ITestContext)
-    */
     public void onFinish( ITestContext context )
     {
         String rawString = Surefire.getResourceString( "suiteCompletedNormally" );
@@ -163,11 +138,11 @@
         ReportEntry report =
             new ReportEntry( surefire, context.getName(), groupString( context.getIncludedGroups(), null ), rawString );
 
-        reportManager.batteryCompleted( report );
+        reportManager.testSetCompleted( report );
 
         reportManager.runCompleted();
 
-        reportManager.dispose();
+        reportManager.reset();
     }
 
     public void onFinish( ISuite suite )
@@ -177,6 +152,7 @@
     public void onStart( ISuite suite )
     {
     }
+*/
 
     /**
      * Creates a string out of the list of testng groups in the

Copied: maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGTestSet.java (from r382212, maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGBattery.java)
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGTestSet.java?p2=maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGTestSet.java&p1=maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGBattery.java&r1=382212&r2=382683&rev=382683&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGBattery.java (original)
+++ maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGTestSet.java Thu Mar  2 22:07:26 2006
@@ -17,10 +17,8 @@
  */
 
 import org.apache.maven.surefire.Surefire;
-import org.apache.maven.surefire.battery.AbstractBattery;
 import org.apache.maven.surefire.report.ReporterManager;
-import org.testng.ISuiteListener;
-import org.testng.ITestListener;
+import org.apache.maven.surefire.testset.AbstractTestSet;
 import org.testng.TestNG;
 import org.testng.internal.TestNGClassFinder;
 import org.testng.internal.Utils;
@@ -39,41 +37,33 @@
  *
  * @author jkuhnert
  */
-public class TestNGBattery
-    extends AbstractBattery
+public class TestNGTestSet
+    extends AbstractTestSet
 {
     private String testSourceDirectory;
 
     private Class testClass;
 
-    private String groups;
-
     private static IAnnotationFinder annotationFinder;
 
     /**
-     * Creates a new test battery that will process the class being
+     * Creates a new test testset that will process the class being
      * passed in to determine the testing configuration.
-     *
-     * @param testClass
-     * @param loader
      */
-    public TestNGBattery( Class testClass, ClassLoader loader, String testSourceDirectory, String groups )
+    public TestNGTestSet( String testClass )
+        throws ClassNotFoundException
     {
         if ( testClass == null )
         {
             throw new NullPointerException( "testClass is null" );
         }
 
-        if ( loader == null )
-        {
-            throw new NullPointerException( "classLoader is null" );
-        }
-
-        this.testClass = testClass;
+        // TODO: broken. the test class uses testng from the project tree, but we use the other one. Annotations aren't found.
+        this.testClass = getClass().getClassLoader().loadClass( testClass );
 
+/*
         this.testSourceDirectory = testSourceDirectory;
-
-        this.groups = groups;
+*/
     }
 
     public Class getTestClass()
@@ -108,24 +98,33 @@
         }
     }
 
-    public void execute( ReporterManager reportManager )
+    public void execute( ReporterManager reportManager, ClassLoader loader )
     {
-        // TODO: maybe don't execute this for every battery
+        // TODO: maybe don't execute this for every testset
 
         TestNG testNG = new TestNG();
         List classes = new ArrayList();
         classes.add( testClass );
 
+        String groups = null;
+
+        if ( !TestNGClassFinder.isTestNGClass( testClass, getAnnotationFinder() ) )
+        {
+//            testNG.setJUnit( Boolean.TRUE );
+        }
+
         //configure testng parameters
         ClassSuite classSuite = new ClassSuite( groups != null ? groups : "TestNG Suite", Utils.classesToXmlClasses(
             (Class[]) classes.toArray( new Class[classes.size()] ) ) );
         testNG.setCommandLineSuite( classSuite );
-        testNG.setOutputDirectory( reportManager.getReportsDirectory() );
+        // TODO
+//        testNG.setOutputDirectory( reportManager.getReportsDirectory() );
         Surefire surefire = new Surefire(); // TODO: blatently wrong
         TestNGReporter testngReporter = new TestNGReporter( reportManager, surefire );
+/* TODO
         testNG.addListener( (ITestListener) testngReporter );
         testNG.addListener( (ISuiteListener) testngReporter );
-        testNG.setUseDefaultListeners( false );
+*/
 
         // TODO: maybe this was running junit tests for us so that parallel would work
 //        testNG.setThreadCount( threadCount );
@@ -152,27 +151,12 @@
 //        nbTests += result.size(); TODO
     }
 
-    public String getBatteryName()
+    public String getName()
     {
         return testClass.getName();
     }
 
-    /**
-     * @todo belongs in a factory. This is reflected only.
-     */
-    public static Boolean canInstantiate( Class testClass )
-    {
-        if ( TestNGClassFinder.isTestNGClass( testClass, getAnnotationFinder() ) )
-        {
-            return Boolean.TRUE;
-        }
-        else
-        {
-            return Boolean.FALSE;
-        }
-    }
-
-    public static IAnnotationFinder getAnnotationFinder()
+    private static IAnnotationFinder getAnnotationFinder()
     {
         if ( annotationFinder == null )
         {

Propchange: maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGTestSet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGTestSet.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Copied: maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNgXmlTestSuite.java (from r382020, maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGXMLBattery.java)
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNgXmlTestSuite.java?p2=maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNgXmlTestSuite.java&p1=maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGXMLBattery.java&r1=382020&r2=382683&rev=382683&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGXMLBattery.java (original)
+++ maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNgXmlTestSuite.java Thu Mar  2 22:07:26 2006
@@ -16,8 +16,8 @@
  * limitations under the License.
  */
 
-import org.apache.maven.surefire.battery.Battery;
 import org.apache.maven.surefire.report.ReporterManager;
+import org.apache.maven.surefire.suite.SurefireTestSuite;
 import org.testng.ISuiteListener;
 import org.testng.ITestListener;
 import org.testng.TestNG;
@@ -32,14 +32,15 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 
 /**
  * Handles suite xml file definitions for TestNG.
  *
  * @author jkuhnert
  */
-public class TestNGXMLBattery
-    implements Battery
+public class TestNgXmlTestSuite
+    implements SurefireTestSuite
 {
     protected File suiteFile;
 
@@ -50,30 +51,38 @@
     protected String m_suiteName = "TestNG XML Suite";
 
     /**
-     * Creates a testng battery to be configured by the specified
+     * Creates a testng testset to be configured by the specified
      * xml file.
      */
-    public TestNGXMLBattery( File suiteFile )
+    public TestNgXmlTestSuite( File suiteFile )
     {
         this.suiteFile = suiteFile;
         parseSuite();
     }
 
-    public void discoverBatteryClassNames()
+    public void execute( ReporterManager reportManager, ClassLoader loader )
     {
+        testRunner.runSuitesLocally();
     }
 
-    public void execute( ReporterManager reportManager )
+    public void execute( String testSetName, ReporterManager reporterManager, ClassLoader testsClassLoader )
     {
-        testRunner.runSuitesLocally();
+        // TODO: if this can't be implemented here, I should have the booter recognise that and prevent it from getting
+        // the pertest treatment
+    }
+
+    public int getNumTests()
+    {
+        // TODO
+        return 0;  //To change body of implemented methods use File | Settings | File Templates.
     }
 
-    public String getBatteryName()
+    public String getName()
     {
         return m_suiteName;
     }
 
-    public List getSubBatteryClassNames()
+    public List getSubBatteries()
     {
         return Collections.EMPTY_LIST;
     }
@@ -130,4 +139,11 @@
         // TODO: return when TestNG brings it back
 //        testRunner.setReportResults(false);
     }
+
+    public Map locateTestSets( ClassLoader classLoader )
+    {
+        // TODO
+        return Collections.EMPTY_MAP;
+    }
+
 }

Propchange: maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNgXmlTestSuite.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/surefire/branches/surefire-testng/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNgXmlTestSuite.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



Mime
View raw message