maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krosenv...@apache.org
Subject svn commit: r1033250 - in /maven/surefire/trunk: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ surefire-booter/src/main/java/org/apache/maven/surefire/booter/
Date Tue, 09 Nov 2010 21:50:28 GMT
Author: krosenvold
Date: Tue Nov  9 21:50:28 2010
New Revision: 1033250

URL: http://svn.apache.org/viewvc?rev=1033250&view=rev
Log:
o Extracted a couple of other small classes from the booter

Cleaned up on a few other minor style-wise irritations that were left over from the larger refactoring
in previous commit

Added:
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java   (with props)
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java   (with props)
Modified:
    maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterConfiguration.java
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkConfiguration.java
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java

Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java?rev=1033250&r1=1033249&r2=1033250&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java Tue Nov  9 21:50:28 2010
@@ -36,6 +36,7 @@ import org.apache.maven.plugin.MojoExecu
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter;
 import org.apache.maven.surefire.booter.BooterConfiguration;
+import org.apache.maven.surefire.booter.ClasspathConfiguration;
 import org.apache.maven.surefire.booter.ForkConfiguration;
 import org.apache.maven.surefire.report.BriefConsoleReporter;
 import org.apache.maven.surefire.report.BriefFileReporter;
@@ -66,7 +67,8 @@ import java.util.Set;
  * @version $Id: SurefirePlugin.java 945065 2010-05-17 10:26:22Z stephenc $
  */
 public abstract class AbstractSurefireMojo
-    extends AbstractMojo implements SurefireExecutionParameters
+    extends AbstractMojo
+    implements SurefireExecutionParameters
 {
 
     private static final String BRIEF_REPORT_FORMAT = "brief";
@@ -163,7 +165,7 @@ public abstract class AbstractSurefireMo
         Artifact configurableParallelComputer =
             (Artifact) getProjectArtifactMap().get( "org.jdogma.junit:configurable-parallel-computer" );
         getProperties().setProperty( "configurableParallelComputerPresent",
-                                Boolean.toString( configurableParallelComputer != null ) );
+                                     Boolean.toString( configurableParallelComputer != null ) );
 
     }
 
@@ -210,16 +212,20 @@ public abstract class AbstractSurefireMo
 
     protected boolean isForkModeNever()
     {
-        return ForkConfiguration.FORK_NEVER.equals( getForkMode()); 
+        return ForkConfiguration.FORK_NEVER.equals( getForkMode() );
     }
 
     protected BooterConfiguration createBooterConfiguration()
         throws MojoExecutionException, MojoFailureException
     {
         final ForkConfiguration fork = getForkConfiguration();
-        BooterConfiguration booterConfiguration = new BooterConfiguration( fork );
+        final ClasspathConfiguration classpathConfiguration =
+            new ClasspathConfiguration( isEnableAssertions(), isChildDelegation() );
 
-        Artifact surefireArtifact = (Artifact) getPluginArtifactMap().get( "org.apache.maven.surefire:surefire-booter" );
+        BooterConfiguration booterConfiguration = new BooterConfiguration( fork, classpathConfiguration );
+
+        Artifact surefireArtifact =
+            (Artifact) getPluginArtifactMap().get( "org.apache.maven.surefire:surefire-booter" );
         if ( surefireArtifact == null )
         {
             throw new MojoExecutionException( "Unable to locate surefire-booter in the list of plugin artifacts" );
@@ -231,7 +237,7 @@ public abstract class AbstractSurefireMo
         Artifact testNgArtifact;
         try
         {
-            addArtifact( booterConfiguration, surefireArtifact );
+            addArtifact( classpathConfiguration, surefireArtifact );
 
             junitArtifact = (Artifact) getProjectArtifactMap().get( getJunitArtifactName() );
             // SUREFIRE-378, junit can have an alternate artifact name
@@ -249,8 +255,8 @@ public abstract class AbstractSurefireMo
                 if ( !range.containsVersion( new DefaultArtifactVersion( testNgArtifact.getVersion() ) ) )
                 {
                     throw new MojoFailureException(
-                        "TestNG support requires version 4.7 or above. You have declared version "
-                            + testNgArtifact.getVersion() );
+                        "TestNG support requires version 4.7 or above. You have declared version " +
+                            testNgArtifact.getVersion() );
                 }
 
                 convertTestNGParameters();
@@ -260,29 +266,30 @@ public abstract class AbstractSurefireMo
                     getProperties().setProperty( "testng.test.classpath", getTestClassesDirectory().getAbsolutePath() );
                 }
 
-                addArtifact( booterConfiguration, testNgArtifact );
+                addArtifact( classpathConfiguration, testNgArtifact );
 
                 // The plugin uses a JDK based profile to select the right testng. We might be explicity using a
                 // different one since its based on the source level, not the JVM. Prune using the filter.
-                addProvider( booterConfiguration, "surefire-testng", surefireArtifact.getBaseVersion(), testNgArtifact );
+                addProvider( classpathConfiguration, "surefire-testng", surefireArtifact.getBaseVersion(),
+                             testNgArtifact );
             }
             else if ( junitArtifact != null && isAnyJunit4( junitArtifact ) )
             {
                 if ( isAnyConcurrencySelected() && isJunit47Compatible( junitArtifact ) )
                 {
                     convertJunitCoreParameters();
-                    addProvider( booterConfiguration, "surefire-junit47", surefireArtifact.getBaseVersion(), null );
+                    addProvider( classpathConfiguration, "surefire-junit47", surefireArtifact.getBaseVersion(), null );
                 }
                 else
                 {
-                    addProvider( booterConfiguration, "surefire-junit4", surefireArtifact.getBaseVersion(), null );
+                    addProvider( classpathConfiguration, "surefire-junit4", surefireArtifact.getBaseVersion(), null );
                 }
             }
             else
             {
                 // add the JUnit provider as default - it doesn't require JUnit to be present,
                 // since it supports POJO tests.
-                addProvider( booterConfiguration, "surefire-junit", surefireArtifact.getBaseVersion(), null );
+                addProvider( classpathConfiguration, "surefire-junit", surefireArtifact.getBaseVersion(), null );
             }
         }
         catch ( ArtifactNotFoundException e )
@@ -308,9 +315,10 @@ public abstract class AbstractSurefireMo
 
             // TODO: properties should be passed in here too
             booterConfiguration.addTestSuite( "org.apache.maven.surefire.testng.TestNGXmlTestSuite",
-                                         new Object[]{ getSuiteXmlFiles(), getTestSourceDirectory().getAbsolutePath(),
-                                             testNgArtifact.getVersion(), testNgArtifact.getClassifier(),
-                                             getProperties(), getReportsDirectory() } );
+                                              new Object[]{ getSuiteXmlFiles(),
+                                                  getTestSourceDirectory().getAbsolutePath(),
+                                                  testNgArtifact.getVersion(), testNgArtifact.getClassifier(),
+                                                  getProperties(), getReportsDirectory() } );
         }
         else
         {
@@ -361,17 +369,17 @@ public abstract class AbstractSurefireMo
                 }
                 if ( excludes == null || excludes.size() == 0 )
                 {
-                    excludes = new ArrayList( Arrays.asList( new String[]{"**/*$*"} ) );
+                    excludes = new ArrayList( Arrays.asList( new String[]{ "**/*$*" } ) );
                 }
             }
 
             if ( testNgArtifact != null )
             {
                 booterConfiguration.addTestSuite( "org.apache.maven.surefire.testng.TestNGDirectoryTestSuite",
-                                             new Object[]{ getTestClassesDirectory(), includes, excludes,
-                                                 getTestSourceDirectory().getAbsolutePath(), testNgArtifact.getVersion(),
-                                                 testNgArtifact.getClassifier(), getProperties(),
-                                                 getReportsDirectory() } );
+                                                  new Object[]{ getTestClassesDirectory(), includes, excludes,
+                                                      getTestSourceDirectory().getAbsolutePath(),
+                                                      testNgArtifact.getVersion(), testNgArtifact.getClassifier(),
+                                                      getProperties(), getReportsDirectory() } );
             }
             else
             {
@@ -381,8 +389,8 @@ public abstract class AbstractSurefireMo
                     junitDirectoryTestSuite = "org.apache.maven.surefire.junitcore.JUnitCoreDirectoryTestSuite";
                     getLog().info( "Concurrency config is " + getProperties().toString() );
                     booterConfiguration.addTestSuite( junitDirectoryTestSuite,
-                                                 new Object[]{ getTestClassesDirectory(), includes, excludes,
-                                                     getProperties() } );
+                                                      new Object[]{ getTestClassesDirectory(), includes, excludes,
+                                                          getProperties() } );
                 }
                 else
                 {
@@ -397,7 +405,7 @@ public abstract class AbstractSurefireMo
                         junitDirectoryTestSuite = "org.apache.maven.surefire.junit.JUnitDirectoryTestSuite";
                     }
                     booterConfiguration.addTestSuite( junitDirectoryTestSuite,
-                                                 new Object[]{ getTestClassesDirectory(), includes, excludes} );
+                                                      new Object[]{ getTestClassesDirectory(), includes, excludes } );
                 }
             }
         }
@@ -420,7 +428,7 @@ public abstract class AbstractSurefireMo
 
             getLog().debug( "  " + classpathElement );
 
-            booterConfiguration.addClassPathUrl( classpathElement );
+            classpathConfiguration.addClassPathUrl( classpathElement );
         }
 
         Toolchain tc = getToolchain();
@@ -442,15 +450,10 @@ public abstract class AbstractSurefireMo
             }
         }
 
-
         booterConfiguration.setFailIfNoTests( getFailIfNoTests() != null && getFailIfNoTests().booleanValue() );
 
         booterConfiguration.setRedirectTestOutputToFile( isRedirectTestOutputToFile() );
 
-        booterConfiguration.setChildDelegation( isChildDelegation() );
-
-        booterConfiguration.setEnableAssertions( isEnableAssertions() );
-
         addReporters( booterConfiguration, fork.isForking() );
 
         return booterConfiguration;
@@ -589,7 +592,7 @@ public abstract class AbstractSurefireMo
 
     /**
      * Return a new set containing only the artifacts accepted by the given filter.
-     * 
+     *
      * @param artifacts
      * @param filter
      */
@@ -600,7 +603,7 @@ public abstract class AbstractSurefireMo
         for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
         {
             Artifact artifact = (Artifact) iter.next();
-            if ( ! filter.include( artifact ) )
+            if ( !filter.include( artifact ) )
             {
                 filteredArtifacts.add( artifact );
             }
@@ -619,22 +622,25 @@ public abstract class AbstractSurefireMo
         }
     }
 
-    private void addProvider( BooterConfiguration booterConfiguration, String provider, String version,
+    private void addProvider( ClasspathConfiguration classpathConfiguration, String provider, String version,
                               Artifact filteredArtifact )
         throws ArtifactNotFoundException, ArtifactResolutionException
     {
-        Artifact providerArtifact = getArtifactFactory().createDependencyArtifact( "org.apache.maven.surefire", provider,
-                                                                              VersionRange.createFromVersion( version ),
-                                                                              "jar", null, Artifact.SCOPE_TEST );
+        Artifact providerArtifact =
+            getArtifactFactory().createDependencyArtifact( "org.apache.maven.surefire", provider,
+                                                           VersionRange.createFromVersion( version ), "jar", null,
+                                                           Artifact.SCOPE_TEST );
         ArtifactResolutionResult result = resolveArtifact( filteredArtifact, providerArtifact );
 
         for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); )
         {
             Artifact artifact = (Artifact) i.next();
 
-            getLog().debug( "Adding to " + getPluginName() + " test classpath: " + artifact.getFile().getAbsolutePath() + " Scope: " + artifact.getScope() );
+            getLog().debug(
+                "Adding to " + getPluginName() + " test classpath: " + artifact.getFile().getAbsolutePath() +
+                    " Scope: " + artifact.getScope() );
 
-            booterConfiguration.addSurefireClassPathUrl( artifact.getFile().getAbsolutePath() );
+            classpathConfiguration.addSurefireClassPathUrl( artifact.getFile().getAbsolutePath() );
         }
     }
 
@@ -650,12 +656,12 @@ public abstract class AbstractSurefireMo
 
         Artifact originatingArtifact = getArtifactFactory().createBuildArtifact( "dummy", "dummy", "1.0", "jar" );
 
-        return getArtifactResolver().resolveTransitively( Collections.singleton( providerArtifact ), originatingArtifact,
-                                                          getLocalRepository(), getRemoteRepositories(),
-                                                          getMetadataSource(), filter );
+        return getArtifactResolver().resolveTransitively( Collections.singleton( providerArtifact ),
+                                                          originatingArtifact, getLocalRepository(),
+                                                          getRemoteRepositories(), getMetadataSource(), filter );
     }
 
-    private void addArtifact( BooterConfiguration booterConfiguration, Artifact surefireArtifact )
+    private void addArtifact( ClasspathConfiguration classpathConfiguration, Artifact surefireArtifact )
         throws ArtifactNotFoundException, ArtifactResolutionException
     {
         ArtifactResolutionResult result = resolveArtifact( null, surefireArtifact );
@@ -664,9 +670,10 @@ public abstract class AbstractSurefireMo
         {
             Artifact artifact = (Artifact) i.next();
 
-            getLog().debug( "Adding to " + getPluginName() + " booter test classpath: " + artifact.getFile().getAbsolutePath() + " Scope: " + artifact.getScope() );
+            getLog().debug( "Adding to " + getPluginName() + " booter test classpath: " +
+                                artifact.getFile().getAbsolutePath() + " Scope: " + artifact.getScope() );
 
-            booterConfiguration.addSurefireBootClassPathUrl( artifact.getFile().getAbsolutePath() );
+            classpathConfiguration.addSurefireBootClassPathUrl( artifact.getFile().getAbsolutePath() );
         }
     }
 
@@ -743,9 +750,8 @@ public abstract class AbstractSurefireMo
         }
         catch ( Exception e )
         {
-            String msg =
-                "Build uses Maven 2.0.x, cannot propagate system properties"
-                    + " from command line to tests (cf. SUREFIRE-121)";
+            String msg = "Build uses Maven 2.0.x, cannot propagate system properties" +
+                " from command line to tests (cf. SUREFIRE-121)";
             if ( getLog().isDebugEnabled() )
             {
                 getLog().warn( msg, e );
@@ -781,40 +787,43 @@ public abstract class AbstractSurefireMo
             {
                 if ( forking )
                 {
-                    booterConfiguration.addReport( ForkingConsoleReporter.class.getName(), new Object[]{trimStackTrace} );
+                    booterConfiguration.addReport( ForkingConsoleReporter.class.getName(),
+                                                   new Object[]{ trimStackTrace } );
                 }
                 else
                 {
-                    booterConfiguration.addReport( ConsoleReporter.class.getName(), new Object[]{trimStackTrace} );
+                    booterConfiguration.addReport( ConsoleReporter.class.getName(), new Object[]{ trimStackTrace } );
                 }
             }
 
             if ( BRIEF_REPORT_FORMAT.equals( getReportFormat() ) )
             {
                 booterConfiguration.addReport( BriefFileReporter.class.getName(),
-                                          new Object[]{ getReportsDirectory(), trimStackTrace} );
+                                               new Object[]{ getReportsDirectory(), trimStackTrace } );
             }
             else if ( PLAIN_REPORT_FORMAT.equals( getReportFormat() ) )
             {
                 booterConfiguration.addReport( FileReporter.class.getName(),
-                                          new Object[]{ getReportsDirectory(), trimStackTrace} );
+                                               new Object[]{ getReportsDirectory(), trimStackTrace } );
             }
         }
         else
         {
             if ( BRIEF_REPORT_FORMAT.equals( getReportFormat() ) )
             {
-                booterConfiguration.addReport( BriefConsoleReporter.class.getName(), new Object[]{trimStackTrace} );
+                booterConfiguration.addReport( BriefConsoleReporter.class.getName(), new Object[]{ trimStackTrace } );
             }
             else if ( PLAIN_REPORT_FORMAT.equals( getReportFormat() ) )
             {
-                booterConfiguration.addReport( DetailedConsoleReporter.class.getName(), new Object[]{trimStackTrace} );
+                booterConfiguration.addReport( DetailedConsoleReporter.class.getName(),
+                                               new Object[]{ trimStackTrace } );
             }
         }
 
         if ( !isDisableXmlReport() )
         {
-            booterConfiguration.addReport( XMLReporter.class.getName(), new Object[]{ getReportsDirectory(), trimStackTrace} );
+            booterConfiguration.addReport( XMLReporter.class.getName(),
+                                           new Object[]{ getReportsDirectory(), trimStackTrace } );
         }
     }
 
@@ -831,16 +840,17 @@ public abstract class AbstractSurefireMo
 
         if ( !getWorkingDirectory().isDirectory() )
         {
-            throw new MojoFailureException( "workingDirectory " + getWorkingDirectory() + " exists and is not a directory" );
+            throw new MojoFailureException(
+                "workingDirectory " + getWorkingDirectory() + " exists and is not a directory" );
         }
     }
 
     protected void ensureParallelRunningCompatibility()
         throws MojoFailureException
     {
-        if (isMavenParallel() && isForkModeNever())
+        if ( isMavenParallel() && isForkModeNever() )
         {
-            throw new MojoFailureException( "parallel maven execution is not compatible with surefire forkmode NEVER");
+            throw new MojoFailureException( "parallel maven execution is not compatible with surefire forkmode NEVER" );
         }
     }
 

Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterConfiguration.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterConfiguration.java?rev=1033250&r1=1033249&r2=1033250&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterConfiguration.java (original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterConfiguration.java Tue Nov  9 21:50:28 2010
@@ -29,8 +29,8 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Enumeration;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Properties;
 import java.util.SortedMap;
@@ -65,18 +65,14 @@ public class BooterConfiguration
 
     private static final String TYPES_SUFIX = ".types";
 
-    private final List reports = new ArrayList();
-
-    private final List classPathUrls = new ArrayList();
+    private final ForkConfiguration forkConfiguration;
 
-    private final List surefireClassPathUrls = new ArrayList();
+    private final ClasspathConfiguration classpathConfiguration;
 
-    private final List surefireBootClassPathUrls = new ArrayList();
+    private final List reports = new ArrayList();
 
     private final List testSuites = new ArrayList();
 
-    private final ForkConfiguration forkConfiguration;
-
     private boolean failIfNoTests = false;
 
     private boolean redirectTestOutputToFile = false;
@@ -88,38 +84,28 @@ public class BooterConfiguration
      */
     private boolean forked;
 
-    /**
-     *
-     */
-    // todo: @deprecated because the IsolatedClassLoader is really isolated - no parent.
-    private boolean childDelegation = true;
-
-
-    /**
-     * Whether to enable assertions or not (can be affected by the fork arguments, and the ability to do so based on the
-     * JVM).
-     */
-    private boolean enableAssertions;
-
-    public BooterConfiguration( ForkConfiguration forkConfiguration )
+    public BooterConfiguration( ForkConfiguration forkConfiguration, ClasspathConfiguration classpathConfiguration )
     {
         this.forkConfiguration = forkConfiguration;
+        this.classpathConfiguration = classpathConfiguration;
     }
 
     /*
     * Reads the config from the supplied stream. Closes the stream.
      */
-    public BooterConfiguration( InputStream config )
+    BooterConfiguration( InputStream config )
         throws IOException
     {
         this.forked = true;
         properties = loadProperties( config );
+        boolean enableAssertions = false;
+        boolean childDelegation = true;
 
         SortedMap classPathUrls = new TreeMap();
 
         SortedMap surefireClassPathUrls = new TreeMap();
 
-        BooterConfiguration booterConfiguration = this;
+        Collection booterClassPathUrl = new ArrayList();
 
         forkConfiguration = new ForkConfiguration();
         forkConfiguration.setForkMode( "never" );
@@ -135,7 +121,7 @@ public class BooterConfiguration
 
                 String params = properties.getProperty( name + PARAMS_SUFIX );
                 String types = properties.getProperty( name + TYPES_SUFIX );
-                booterConfiguration.addReport( className, constructParamObjects( params, types ) );
+                addReport( className, constructParamObjects( params, types ) );
             }
             else if ( name.startsWith( TEST_SUITE_PROPERTY_PREFIX ) && !name.endsWith( PARAMS_SUFIX ) &&
                 !name.endsWith( TYPES_SUFIX ) )
@@ -144,7 +130,7 @@ public class BooterConfiguration
 
                 String params = properties.getProperty( name + PARAMS_SUFIX );
                 String types = properties.getProperty( name + TYPES_SUFIX );
-                booterConfiguration.addTestSuite( className, constructParamObjects( params, types ) );
+                addTestSuite( className, constructParamObjects( params, types ) );
             }
             else if ( name.startsWith( "classPathUrl." ) )
             {
@@ -158,74 +144,57 @@ public class BooterConfiguration
             }
             else if ( name.startsWith( "surefireBootClassPathUrl." ) )
             {
-                booterConfiguration.addSurefireBootClassPathUrl( properties.getProperty( name ) );
+                booterClassPathUrl.add( properties.getProperty( name ) );
             }
             else if ( "childDelegation".equals( name ) )
             {
-                booterConfiguration.childDelegation =
-                    Boolean.valueOf( properties.getProperty( "childDelegation" ) ).booleanValue();
+                childDelegation = Boolean.valueOf( properties.getProperty( "childDelegation" ) ).booleanValue();
             }
             else if ( "enableAssertions".equals( name ) )
             {
-                booterConfiguration.enableAssertions =
-                    Boolean.valueOf( properties.getProperty( "enableAssertions" ) ).booleanValue();
+                enableAssertions = Boolean.valueOf( properties.getProperty( "enableAssertions" ) ).booleanValue();
             }
             else if ( "useSystemClassLoader".equals( name ) )
             {
                 boolean value = Boolean.valueOf( properties.getProperty( "useSystemClassLoader" ) ).booleanValue();
-                booterConfiguration.forkConfiguration.setUseSystemClassLoader( value );
+                forkConfiguration.setUseSystemClassLoader( value );
             }
             else if ( "useManifestOnlyJar".equals( name ) )
             {
                 boolean value = Boolean.valueOf( properties.getProperty( "useManifestOnlyJar" ) ).booleanValue();
-                booterConfiguration.forkConfiguration.setUseManifestOnlyJar( value );
+                forkConfiguration.setUseManifestOnlyJar( value );
             }
             else if ( "failIfNoTests".equals( name ) )
             {
                 boolean value = Boolean.valueOf( properties.getProperty( "failIfNoTests" ) ).booleanValue();
-                booterConfiguration.setFailIfNoTests( value );
+                setFailIfNoTests( value );
             }
         }
 
-        for ( Iterator cpi = classPathUrls.keySet().iterator(); cpi.hasNext(); )
-        {
-            String url = (String) classPathUrls.get( cpi.next() );
-            booterConfiguration.addClassPathUrl( url );
-        }
-
-        for ( Iterator scpi = surefireClassPathUrls.keySet().iterator(); scpi.hasNext(); )
-        {
-            String url = (String) surefireClassPathUrls.get( scpi.next() );
-            booterConfiguration.addSurefireClassPathUrl( url );
-        }
+        classpathConfiguration =
+            new ClasspathConfiguration( classPathUrls, surefireClassPathUrls, booterClassPathUrl, enableAssertions,
+                                        childDelegation );
+    }
 
+    ClasspathConfiguration getClasspathConfiguration()
+    {
+        return classpathConfiguration;
     }
 
-    public void setForkProperties( List testSuites, Properties properties )
+    void setForkProperties( List testSuites, Properties properties )
     {
         addPropertiesForTypeHolder( reports, properties, REPORT_PROPERTY_PREFIX );
         addPropertiesForTypeHolder( testSuites, properties, TEST_SUITE_PROPERTY_PREFIX );
 
-        for ( int i = 0; i < classPathUrls.size(); i++ )
-        {
-            String url = (String) classPathUrls.get( i );
-            properties.setProperty( "classPathUrl." + i, url );
-        }
-
-        for ( int i = 0; i < surefireClassPathUrls.size(); i++ )
-        {
-            String url = (String) surefireClassPathUrls.get( i );
-            properties.setProperty( "surefireClassPathUrl." + i, url );
-        }
+        classpathConfiguration.setForkProperties( properties );
 
-        properties.setProperty( "childDelegation", String.valueOf( childDelegation ) );
-        properties.setProperty( "enableAssertions", String.valueOf( enableAssertions ) );
         properties.setProperty( "useSystemClassLoader", String.valueOf( useSystemClassLoader() ) );
-        properties.setProperty( "useManifestOnlyJar", String.valueOf( useManifestOnlyJar() ) );
+        properties.setProperty( "useManifestOnlyJar",
+                                String.valueOf( forkConfiguration.isManifestOnlyJarRequestedAndUsable() ) );
         properties.setProperty( "failIfNoTests", String.valueOf( failIfNoTests ) );
     }
 
-    public File writePropertiesFile( String name, Properties properties )
+    File writePropertiesFile( String name, Properties properties )
         throws IOException
     {
         File file = File.createTempFile( name, "tmp", forkConfiguration.getTempDirectory() );
@@ -239,7 +208,7 @@ public class BooterConfiguration
         return file;
     }
 
-    public void writePropertiesFile( File file, String name, Properties properties )
+    void writePropertiesFile( File file, String name, Properties properties )
         throws IOException
     {
         FileOutputStream out = new FileOutputStream( file );
@@ -311,15 +280,11 @@ public class BooterConfiguration
         }
     }
 
-    private boolean useSystemClassLoader()
+    public boolean useSystemClassLoader()
     {
         return forkConfiguration.isUseSystemClassLoader() && ( forked || forkConfiguration.isForking() );
     }
 
-    private boolean useManifestOnlyJar()
-    {
-        return forkConfiguration.isUseSystemClassLoader() && forkConfiguration.isUseManifestOnlyJar();
-    }
 
     private static List processStringList( String stringList )
     {
@@ -438,16 +403,6 @@ public class BooterConfiguration
     }
 
 
-    public void setChildDelegation( boolean childDelegation )
-    {
-        this.childDelegation = childDelegation;
-    }
-
-    public void setEnableAssertions( boolean enableAssertions )
-    {
-        this.enableAssertions = enableAssertions;
-    }
-
     public List getReports()
     {
         return reports;
@@ -463,26 +418,6 @@ public class BooterConfiguration
         return redirectTestOutputToFile;
     }
 
-    public boolean isChildDelegation()
-    {
-        return childDelegation;
-    }
-
-    public boolean isEnableAssertions()
-    {
-        return enableAssertions;
-    }
-
-    public List getSurefireClassPathUrls()
-    {
-        return surefireClassPathUrls;
-    }
-
-    public List getSurefireBootClassPathUrls()
-    {
-        return surefireBootClassPathUrls;
-    }
-
     public List getTestSuites()
     {
         return testSuites;
@@ -508,30 +443,6 @@ public class BooterConfiguration
         testSuites.add( new Object[]{ suiteClassName, constructorParams } );
     }
 
-    public void addClassPathUrl( String path )
-    {
-        if ( !classPathUrls.contains( path ) )
-        {
-            classPathUrls.add( path );
-        }
-    }
-
-    public void addSurefireClassPathUrl( String path )
-    {
-        if ( !surefireClassPathUrls.contains( path ) )
-        {
-            surefireClassPathUrls.add( path );
-        }
-    }
-
-    public void addSurefireBootClassPathUrl( String path )
-    {
-        if ( !surefireBootClassPathUrls.contains( path ) )
-        {
-            surefireBootClassPathUrls.add( path );
-        }
-    }
-
     /**
      * Setting this to true will cause a failure if there are no tests to run
      *
@@ -557,16 +468,5 @@ public class BooterConfiguration
     {
         return forkConfiguration.isForking();
     }
-
-
-    public List getClassPathUrls()
-    {
-        return classPathUrls;
-    }
-
-    public boolean isForked()
-    {
-        return this.forked;
-    }
 }
 

Added: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java?rev=1033250&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java (added)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java Tue Nov  9 21:50:28 2010
@@ -0,0 +1,281 @@
+package org.apache.maven.surefire.booter;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.surefire.util.NestedRuntimeException;
+import org.apache.maven.surefire.util.UrlUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.util.SortedMap;
+
+/**
+ * Represents the classpaths for the BooterConfiguration.
+ * <p/>
+ *
+ * @author Jason van Zyl
+ * @author Emmanuel Venisse
+ * @author Kristian Rosenvold
+ * @version $Id$
+ */
+public class ClasspathConfiguration
+{
+
+    private final List classPathUrls = new ArrayList();
+
+    private final List surefireClassPathUrls = new ArrayList();
+
+    private final List surefireBootClassPathUrls = new ArrayList();
+
+    /**
+     * Whether to enable assertions or not (can be affected by the fork arguments, and the ability to do so based on the
+     * JVM).
+     */
+    private final boolean enableAssertions;
+
+    // todo: @deprecated because the IsolatedClassLoader is really isolated - no parent.
+    private final boolean childDelegation;
+
+
+
+    public ClasspathConfiguration( boolean enableAssertions, boolean childDelegation)
+    {
+        this.enableAssertions = enableAssertions;
+        this.childDelegation = childDelegation;
+    }
+
+    /*
+   * Reads the config from the supplied stream. Closes the stream.
+    */
+    public ClasspathConfiguration( SortedMap classPathUrls, SortedMap surefireClassPathUrls, Collection booterClassPath,
+                                   boolean enableAssertions, boolean childDelegation )
+        throws IOException
+    {
+
+        this.enableAssertions = enableAssertions;
+        this.childDelegation = childDelegation;
+        for ( Iterator cpi = classPathUrls.keySet().iterator(); cpi.hasNext(); )
+        {
+            String url = (String) classPathUrls.get( cpi.next() );
+            this.classPathUrls.add( url );
+        }
+
+        for ( Iterator scpi = surefireClassPathUrls.keySet().iterator(); scpi.hasNext(); )
+        {
+            String url = (String) surefireClassPathUrls.get( scpi.next() );
+            this.surefireClassPathUrls.add( url );
+        }
+        for ( Iterator scpi = booterClassPath.iterator(); scpi.hasNext(); )
+        {
+            String url = (String) surefireClassPathUrls.get( scpi.next() );
+            this.surefireBootClassPathUrls.add( url );
+        }
+
+    }
+
+
+    public void setForkProperties( Properties properties )
+    {
+        for ( int i = 0; i < classPathUrls.size(); i++ )
+        {
+            String url = (String) classPathUrls.get( i );
+            properties.setProperty( "classPathUrl." + i, url );
+        }
+
+        for ( int i = 0; i < surefireClassPathUrls.size(); i++ )
+        {
+            String url = (String) surefireClassPathUrls.get( i );
+            properties.setProperty( "surefireClassPathUrl." + i, url );
+        }
+
+        properties.setProperty( "enableAssertions", String.valueOf( enableAssertions ) );
+        properties.setProperty( "childDelegation", String.valueOf( childDelegation ) );
+    }
+
+
+    private static Method assertionStatusMethod;
+
+    static
+    {
+        try
+        {
+            assertionStatusMethod =
+                ClassLoader.class.getMethod( "setDefaultAssertionStatus", new Class[]{ boolean.class } );
+        }
+        catch ( NoSuchMethodException e )
+        {
+            assertionStatusMethod = null;
+        }
+    }
+
+    public List getBootClasspath( boolean useSystemClassLoader )
+    {
+        List bootClasspath = new ArrayList( getSurefireBootClassPathUrls().size() + getClassPathUrls().size() );
+
+        bootClasspath.addAll( getSurefireBootClassPathUrls() );
+
+        if ( useSystemClassLoader )
+        {
+            bootClasspath.addAll( getClassPathUrls() );
+        }
+        return bootClasspath;
+    }
+
+    public String getTestClassPathAsString()
+    {
+        StringBuffer sb = new StringBuffer();
+        for ( int i = 0; i < getClassPathUrls().size(); i++ )
+        {
+            sb.append( getClassPathUrls().get( i ) ).append( File.pathSeparatorChar );
+        }
+        return sb.toString();
+    }
+
+    public ClassLoader createTestClassLoaderConditionallySystem( boolean useSystemClassLoader )
+        throws SurefireExecutionException
+    {
+        return useSystemClassLoader ? ClassLoader.getSystemClassLoader() : createTestClassLoader( this.childDelegation );
+    }
+
+    public ClassLoader createTestClassLoader( boolean childDelegation )
+        throws SurefireExecutionException
+    {
+        return createClassLoaderSEE( getClassPathUrls(), null, childDelegation );
+    }
+
+    public ClassLoader createTestClassLoader( )
+        throws SurefireExecutionException
+    {
+        return createClassLoaderSEE( getClassPathUrls(), null, this.childDelegation );
+    }
+
+    public ClassLoader createSurefireClassLoader( ClassLoader parent )
+        throws SurefireExecutionException
+    {
+        return createClassLoaderSEE( getSurefireClassPathUrls(), parent, false );
+    }
+
+    private ClassLoader createClassLoaderSEE( List classPathUrls, ClassLoader parent, boolean childDelegation )
+        throws SurefireExecutionException
+    {
+        try
+        {
+            return createClassLoader( classPathUrls, parent, childDelegation );
+        }
+        catch ( MalformedURLException e )
+        {
+            throw new SurefireExecutionException( "When creating classloader", e );
+        }
+
+    }
+
+    private ClassLoader createClassLoader( List classPathUrls, ClassLoader parent, boolean childDelegation )
+        throws MalformedURLException
+    {
+        List urls = new ArrayList();
+
+        for ( Iterator i = classPathUrls.iterator(); i.hasNext(); )
+        {
+            String url = (String) i.next();
+
+            if ( url != null )
+            {
+                File f = new File( url );
+                urls.add( UrlUtils.getURL( f ) );
+            }
+        }
+
+        IsolatedClassLoader classLoader = new IsolatedClassLoader( parent, childDelegation );
+        if ( assertionStatusMethod != null )
+        {
+            try
+            {
+                Object[] args = new Object[]{ enableAssertions ? Boolean.TRUE : Boolean.FALSE };
+                if ( parent != null )
+                {
+                    assertionStatusMethod.invoke( parent, args );
+                }
+                assertionStatusMethod.invoke( classLoader, args );
+            }
+            catch ( IllegalAccessException e )
+            {
+                throw new NestedRuntimeException( "Unable to access the assertion enablement method", e );
+            }
+            catch ( InvocationTargetException e )
+            {
+                throw new NestedRuntimeException( "Unable to invoke the assertion enablement method", e );
+            }
+        }
+        for ( Iterator iter = urls.iterator(); iter.hasNext(); )
+        {
+            URL url = (URL) iter.next();
+            classLoader.addURL( url );
+        }
+        return classLoader;
+    }
+
+    public List getSurefireClassPathUrls()
+    {
+        return surefireClassPathUrls;
+    }
+
+    public List getSurefireBootClassPathUrls()
+    {
+        return surefireBootClassPathUrls;
+    }
+
+    public void addClassPathUrl( String path )
+    {
+        if ( !classPathUrls.contains( path ) )
+        {
+            classPathUrls.add( path );
+        }
+    }
+
+    public void addSurefireClassPathUrl( String path )
+    {
+        if ( !surefireClassPathUrls.contains( path ) )
+        {
+            surefireClassPathUrls.add( path );
+        }
+    }
+
+    public void addSurefireBootClassPathUrl( String path )
+    {
+        if ( !surefireBootClassPathUrls.contains( path ) )
+        {
+            surefireBootClassPathUrls.add( path );
+        }
+    }
+
+    public List getClassPathUrls()
+    {
+        return classPathUrls;
+    }
+}

Propchange: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkConfiguration.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkConfiguration.java?rev=1033250&r1=1033249&r2=1033250&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkConfiguration.java (original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkConfiguration.java Tue Nov  9 21:50:28 2010
@@ -157,12 +157,11 @@ public class ForkConfiguration
 
     /**
      * @throws SurefireBooterForkException
-     * @deprecated use the 2-arg alternative.
      */
     public Commandline createCommandLine( List classPath )
         throws SurefireBooterForkException
     {
-        return createCommandLine( classPath, false );
+        return createCommandLine( classPath, isManifestOnlyJarRequestedAndUsable() );
     }
 
     public Commandline createCommandLine( List classPath, boolean useJar )
@@ -289,4 +288,10 @@ public class ForkConfiguration
     {
         return useManifestOnlyJar;
     }
+
+    public boolean isManifestOnlyJarRequestedAndUsable()
+    {
+        return isUseSystemClassLoader() && isUseManifestOnlyJar();
+    }
+
 }

Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java?rev=1033250&r1=1033249&r2=1033250&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java (original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java Tue Nov  9 21:50:28 2010
@@ -27,8 +27,6 @@ import org.apache.maven.surefire.booter.
 import org.apache.maven.surefire.booter.output.SupressFooterOutputConsumerProxy;
 import org.apache.maven.surefire.booter.output.SupressHeaderOutputConsumerProxy;
 import org.apache.maven.surefire.testset.TestSetFailedException;
-import org.apache.maven.surefire.util.NestedRuntimeException;
-import org.apache.maven.surefire.util.UrlUtils;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.cli.CommandLineException;
 import org.codehaus.plexus.util.cli.CommandLineUtils;
@@ -42,9 +40,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
@@ -65,26 +60,6 @@ public class SurefireBooter
 
     private File reportsDirectory;
 
-    /**
-     * This field is set to true if it's running from main. It's used to help decide what classloader to use.
-     */
-//    private final boolean isForked;
-
-    private static Method assertionStatusMethod;
-
-    static
-    {
-        try
-        {
-            assertionStatusMethod =
-                ClassLoader.class.getMethod( "setDefaultAssertionStatus", new Class[]{ boolean.class } );
-        }
-        catch ( NoSuchMethodException e )
-        {
-            assertionStatusMethod = null;
-        }
-    }
-
     public SurefireBooter( BooterConfiguration booterConfiguration, File reportsDirectory )
     {
         this.booterConfiguration = booterConfiguration;
@@ -96,10 +71,6 @@ public class SurefireBooter
         this.booterConfiguration = booterConfiguration;
     }
 
-    // ----------------------------------------------------------------------
-    // Accessors
-    // ----------------------------------------------------------------------
-
     public int run()
         throws SurefireBooterForkException, SurefireExecutionException
     {
@@ -135,41 +106,21 @@ public class SurefireBooter
 
         // TODO: replace with plexus
 
-        // noinspection CatchGenericClass,OverlyBroadCatchBlock
         ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
         try
         {
-            ClassLoader testsClassLoader = useSystemClassLoader()
-                ? ClassLoader.getSystemClassLoader()
-                : createClassLoader( booterConfiguration.getClassPathUrls(), null,
-                                     booterConfiguration.isChildDelegation() );
+            ClassLoader testsClassLoader = getClasspathConfiguration().createTestClassLoaderConditionallySystem(
+                booterConfiguration.useSystemClassLoader() );
 
             // TODO: assertions = true shouldn't be required for this CL if we had proper separation (see TestNG)
-            ClassLoader surefireClassLoader =
-                createClassLoader( booterConfiguration.getSurefireClassPathUrls(), testsClassLoader );
+            ClassLoader surefireClassLoader = getClasspathConfiguration().createSurefireClassLoader( testsClassLoader );
 
-            Class surefireClass = surefireClassLoader.loadClass( Surefire.class.getName() );
-
-            Object surefire = surefireClass.newInstance();
-
-            Method run = surefireClass.getMethod( "run", new Class[]{ List.class, Object[].class, String.class,
-                ClassLoader.class, ClassLoader.class, Properties.class, Boolean.class } );
+            SurefireReflector reflector = new SurefireReflector( surefireClassLoader );
 
             Thread.currentThread().setContextClassLoader( testsClassLoader );
-
-            Integer result = (Integer) run.invoke( surefire, new Object[]{ booterConfiguration.getReports(),
-                booterConfiguration.getTestSuites().get( 0 ), testSet, surefireClassLoader, testsClassLoader, results,
-                booterConfiguration.isFailIfNoTests() } );
-
-            return result.intValue();
-        }
-        catch ( InvocationTargetException e )
-        {
-            throw new SurefireExecutionException( e.getTargetException().getMessage(), e.getTargetException() );
-        }
-        catch ( Exception e )
-        {
-            throw new SurefireExecutionException( "Unable to instantiate and execute Surefire", e );
+            return reflector.run( booterConfiguration.getReports(),
+                                  (Object[]) booterConfiguration.getTestSuites().get( 0 ), testSet, surefireClassLoader,
+                                  testsClassLoader, results, booterConfiguration.isFailIfNoTests() );
         }
         finally
         {
@@ -190,9 +141,9 @@ public class SurefireBooter
             // The test classloader must be constructed first to avoid issues with commons-logging until we properly
             // separate the TestNG classloader
             ClassLoader testsClassLoader;
-            String testClassPath = getTestClassPathAsString();
+            String testClassPath = getClasspathConfiguration().getTestClassPathAsString();
             System.setProperty( "surefire.test.class.path", testClassPath );
-            if ( useManifestOnlyJar() )
+            if ( booterConfiguration.getForkConfiguration().isManifestOnlyJarRequestedAndUsable() )
             {
                 testsClassLoader = getClass().getClassLoader(); // ClassLoader.getSystemClassLoader()
                 // SUREFIRE-459, trick the app under test into thinking its classpath was conventional
@@ -202,35 +153,18 @@ public class SurefireBooter
             }
             else
             {
-                testsClassLoader = createClassLoader( booterConfiguration.getClassPathUrls(), null,
-                                                      booterConfiguration.isChildDelegation() );
+                testsClassLoader = getClasspathConfiguration().createTestClassLoader(  );
             }
 
-            ClassLoader surefireClassLoader =
-                createClassLoader( booterConfiguration.getSurefireClassPathUrls(), testsClassLoader );
+            ClassLoader surefireClassLoader = getClasspathConfiguration().createSurefireClassLoader( testsClassLoader );
 
-            Class surefireClass = surefireClassLoader.loadClass( Surefire.class.getName() );
-
-            Object surefire = surefireClass.newInstance();
-
-            Method run = surefireClass.getMethod( "run", new Class[]{ List.class, List.class, ClassLoader.class,
-                ClassLoader.class, Boolean.class } );
+            SurefireReflector reflector = new SurefireReflector( surefireClassLoader );
 
             Thread.currentThread().setContextClassLoader( testsClassLoader );
 
-            Integer result = (Integer) run.invoke( surefire, new Object[]{ booterConfiguration.getReports(),
-                booterConfiguration.getTestSuites(), surefireClassLoader, testsClassLoader,
-                booterConfiguration.isFailIfNoTests() } );
+            return reflector.run( booterConfiguration.getReports(), booterConfiguration.getTestSuites(),
+                                  surefireClassLoader, testsClassLoader, booterConfiguration.isFailIfNoTests() );
 
-            return result.intValue();
-        }
-        catch ( InvocationTargetException e )
-        {
-            throw new SurefireExecutionException( e.getTargetException().getMessage(), e.getTargetException() );
-        }
-        catch ( Exception e )
-        {
-            throw new SurefireExecutionException( "Unable to instantiate and execute Surefire", e );
         }
         finally
         {
@@ -239,16 +173,6 @@ public class SurefireBooter
     }
 
 
-    private String getTestClassPathAsString()
-    {
-        StringBuffer sb = new StringBuffer();
-        for ( int i = 0; i < booterConfiguration.getClassPathUrls().size(); i++ )
-        {
-            sb.append( booterConfiguration.getClassPathUrls().get( i ) ).append( File.pathSeparatorChar );
-        }
-        return sb.toString();
-    }
-
     private int runSuitesForkOnce()
         throws SurefireBooterForkException
     {
@@ -262,12 +186,11 @@ public class SurefireBooter
         ClassLoader surefireClassLoader;
         try
         {
-            testsClassLoader = createClassLoader( booterConfiguration.getClassPathUrls(), null, false );
+            testsClassLoader = getClasspathConfiguration().createTestClassLoader( false );
             // TODO: assertions = true shouldn't be required if we had proper separation (see TestNG)
-            surefireClassLoader =
-                createClassLoader( booterConfiguration.getSurefireClassPathUrls(), testsClassLoader, false );
+            surefireClassLoader = getClasspathConfiguration().createSurefireClassLoader( testsClassLoader );
         }
-        catch ( MalformedURLException e )
+        catch ( SurefireExecutionException e )
         {
             throw new SurefireBooterForkException( "Unable to create classloader to find test suites", e );
         }
@@ -298,6 +221,11 @@ public class SurefireBooter
         return globalResult;
     }
 
+    private ClasspathConfiguration getClasspathConfiguration()
+    {
+        return booterConfiguration.getClasspathConfiguration();
+    }
+
     private Map getTestSets( Object[] testSuite, ClassLoader testsClassLoader, ClassLoader surefireClassLoader )
         throws SurefireBooterForkException
     {
@@ -370,18 +298,6 @@ public class SurefireBooter
         return fork( properties, showHeading, showFooter );
     }
 
-    private boolean useSystemClassLoader()
-    {
-        return booterConfiguration.getForkConfiguration().isUseSystemClassLoader() &&
-            ( booterConfiguration.isForked() || booterConfiguration.getForkConfiguration().isForking() );
-    }
-
-    private boolean useManifestOnlyJar()
-    {
-        return booterConfiguration.getForkConfiguration().isUseSystemClassLoader() &&
-            booterConfiguration.getForkConfiguration().isUseManifestOnlyJar();
-    }
-
     private int fork( Properties properties, boolean showHeading, boolean showFooter )
         throws SurefireBooterForkException
     {
@@ -401,18 +317,9 @@ public class SurefireBooter
             throw new SurefireBooterForkException( "Error creating properties files for forking", e );
         }
 
-        List bootClasspath = new ArrayList(
-            booterConfiguration.getSurefireBootClassPathUrls().size() + booterConfiguration.getClassPathUrls().size() );
-
-        bootClasspath.addAll( booterConfiguration.getSurefireBootClassPathUrls() );
+        List bootClasspath = getClasspathConfiguration().getBootClasspath( booterConfiguration.useSystemClassLoader() );
 
-        if ( useSystemClassLoader() )
-        {
-            bootClasspath.addAll( booterConfiguration.getClassPathUrls() );
-        }
-
-        Commandline cli =
-            booterConfiguration.getForkConfiguration().createCommandLine( bootClasspath, useManifestOnlyJar() );
+        Commandline cli = booterConfiguration.getForkConfiguration().createCommandLine( bootClasspath );
 
         cli.createArg().setFile( surefireProperties );
 
@@ -490,57 +397,6 @@ public class SurefireBooter
         return returnCode;
     }
 
-    private ClassLoader createClassLoader( List classPathUrls, ClassLoader parent )
-        throws MalformedURLException
-    {
-        return createClassLoader( classPathUrls, parent, false );
-    }
-
-    private ClassLoader createClassLoader( List classPathUrls, ClassLoader parent, boolean childDelegation )
-        throws MalformedURLException
-    {
-        List urls = new ArrayList();
-
-        for ( Iterator i = classPathUrls.iterator(); i.hasNext(); )
-        {
-            String url = (String) i.next();
-
-            if ( url != null )
-            {
-                File f = new File( url );
-                urls.add( UrlUtils.getURL( f ) );
-            }
-        }
-
-        IsolatedClassLoader classLoader = new IsolatedClassLoader( parent, childDelegation );
-        if ( assertionStatusMethod != null )
-        {
-            try
-            {
-                Object[] args = new Object[]{ booterConfiguration.isEnableAssertions() ? Boolean.TRUE : Boolean.FALSE };
-                if ( parent != null )
-                {
-                    assertionStatusMethod.invoke( parent, args );
-                }
-                assertionStatusMethod.invoke( classLoader, args );
-            }
-            catch ( IllegalAccessException e )
-            {
-                throw new NestedRuntimeException( "Unable to access the assertion enablement method", e );
-            }
-            catch ( InvocationTargetException e )
-            {
-                throw new NestedRuntimeException( "Unable to invoke the assertion enablement method", e );
-            }
-        }
-        for ( Iterator iter = urls.iterator(); iter.hasNext(); )
-        {
-            URL url = (URL) iter.next();
-            classLoader.addURL( url );
-        }
-        return classLoader;
-    }
-
     private static Properties loadProperties( File file )
         throws IOException
     {
@@ -585,7 +441,6 @@ public class SurefireBooter
     public static void main( String[] args )
         throws Throwable
     {
-        // noinspection CatchGenericClass,OverlyBroadCatchBlock
         try
         {
             if ( args.length > 1 )

Added: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java?rev=1033250&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java (added)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java Tue Nov  9 21:50:28 2010
@@ -0,0 +1,187 @@
+package org.apache.maven.surefire.booter;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.surefire.Surefire;
+import org.apache.maven.surefire.testset.TestSetFailedException;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * Does reflection based invocation of the surefire methods.
+ * <p/>
+ * This is to avoid compilications with linkage issues
+ *
+ * @author Kristian Rosenvold
+ */
+public class SurefireReflector
+{
+
+    private final Class surefireClass;
+
+    public SurefireReflector( ClassLoader surefirClassLoader )
+        throws SurefireExecutionException
+    {
+        try
+        {
+            surefireClass = surefirClassLoader.loadClass( Surefire.class.getName() );
+        }
+        catch ( ClassNotFoundException e )
+        {
+            throw new SurefireExecutionException( "When loading class", e );
+        }
+    }
+
+
+    public int run( List reportDefinitions, Object[] testSuiteDefinition, String testSetName,
+                    ClassLoader surefireClassLoader, ClassLoader testsClassLoader, Properties results,
+                    Boolean failIfNoTests )
+        throws SurefireExecutionException
+    {
+        Object surefire = instantiateSurefire();
+        Method run = getRunMethod(
+            new Class[]{ List.class, Object[].class, String.class, ClassLoader.class, ClassLoader.class,
+                Properties.class, Boolean.class } );
+
+        return invokeRunMethod( surefire, run,
+                                new Object[]{ reportDefinitions, testSuiteDefinition, testSetName, surefireClassLoader,
+                                    testsClassLoader, results, failIfNoTests } );
+    }
+
+    public int run( List reportDefinitions, List testSuiteDefinitions, ClassLoader surefireClassLoader,
+                    ClassLoader testsClassLoader, Boolean failIfNoTests )
+        throws SurefireExecutionException
+    {
+        Object surefire = instantiateSurefire();
+
+        Method run =
+            getRunMethod( new Class[]{ List.class, List.class, ClassLoader.class, ClassLoader.class, Boolean.class } );
+
+        Thread.currentThread().setContextClassLoader( testsClassLoader );
+
+        return invokeRunMethod( surefire, run,
+                                new Object[]{ reportDefinitions, testSuiteDefinitions, surefireClassLoader,
+                                    testsClassLoader, failIfNoTests } );
+    }
+
+    public static Object instantiateObject( String className, Object[] params, ClassLoader classLoader )
+        throws TestSetFailedException, ClassNotFoundException, NoSuchMethodException
+    {
+        Class clazz = classLoader.loadClass( className );
+
+        Object object;
+        try
+        {
+            if ( params != null )
+            {
+                Class[] paramTypes = new Class[params.length];
+
+                for ( int j = 0; j < params.length; j++ )
+                {
+                    if ( params[j] == null )
+                    {
+                        paramTypes[j] = String.class;
+                    }
+                    else
+                    {
+                        paramTypes[j] = params[j].getClass();
+                    }
+                }
+
+                Constructor constructor = clazz.getConstructor( paramTypes );
+
+                object = constructor.newInstance( params );
+            }
+            else
+            {
+                object = clazz.newInstance();
+            }
+        }
+        catch ( IllegalAccessException e )
+        {
+            throw new TestSetFailedException( "Unable to instantiate object: " + e.getMessage(), e );
+        }
+        catch ( InvocationTargetException e )
+        {
+            throw new TestSetFailedException( e.getTargetException().getMessage(), e.getTargetException() );
+        }
+        catch ( InstantiationException e )
+        {
+            throw new TestSetFailedException( "Unable to instantiate object: " + e.getMessage(), e );
+        }
+        return object;
+    }
+
+
+    private int invokeRunMethod( Object surefire, Method run, Object[] args )
+        throws SurefireExecutionException
+
+    {
+        try
+        {
+            final Integer invoke = (Integer) run.invoke( surefire, args );
+            return invoke.intValue();
+        }
+        catch ( IllegalAccessException e )
+        {
+            throw new SurefireExecutionException( "When instantiating surefire", e );
+        }
+        catch ( InvocationTargetException e )
+        {
+            throw new SurefireExecutionException( e.getTargetException().getMessage(), e.getTargetException() );
+        }
+
+    }
+
+    private Object instantiateSurefire()
+        throws SurefireExecutionException
+    {
+        try
+        {
+            return surefireClass.newInstance();
+        }
+        catch ( InstantiationException e )
+        {
+            throw new SurefireExecutionException( "When instanitating surefire", e );
+        }
+        catch ( IllegalAccessException e )
+        {
+            throw new SurefireExecutionException( "When instanitating surefire", e );
+        }
+    }
+
+    private Method getRunMethod( Class[] parameters )
+        throws SurefireExecutionException
+    {
+        try
+        {
+            return surefireClass.getMethod( "run", parameters );
+        }
+        catch ( NoSuchMethodException e )
+        {
+            throw new SurefireExecutionException( "When finding run method", e );
+        }
+    }
+
+
+}

Propchange: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message