Author: krosenvold Date: Thu Feb 17 21:56:09 2011 New Revision: 1071808 URL: http://svn.apache.org/viewvc?rev=1071808&view=rev Log: Revert "[SUREFIRE-700] Isolate surefire from itself"
It broke the windows build and I won't have time to fix it before going off on more vacation. Someone's got to try to beat Julia in # vacation days ;) Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ProviderInfo.java maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireDependencyResolver.java maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterConstants.java maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterDeserializer.java maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/IsolatedClassLoader.java maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreRunListener.java maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestSet.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=1071808&r1=1071807&r2=1071808&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 Thu Feb 17 21:56:09 2011 @@ -99,45 +99,47 @@ public abstract class AbstractSurefireMo if ( verifyParameters() && !hasExecutedBefore() ) { logReportsDirectory(); - executeAfterPreconditionsChecked(); + executeAfterPreconditionsChecked(); } } protected boolean verifyParameters() throws MojoFailureException - { - if ( isSkipExecution() ) - { - getLog().info( "Tests are skipped." ); - return false; - } - - if ( !getTestClassesDirectory().exists() ) - { - if ( Boolean.TRUE.equals( getFailIfNoTests() ) ) - { - throw new MojoFailureException( "No tests to run!" ); - } - getLog().info( "No tests to run." ); - } - else - { - ensureWorkingDirectoryExists(); - ensureParallelRunningCompatibility(); - warnIfUselessUseSystemClassLoaderParameter(); - } - - return true; - } - + { + if ( isSkipExecution() ) + { + getLog().info( "Tests are skipped." ); + return false; + } + + if ( !getTestClassesDirectory().exists() ) + { + if ( Boolean.TRUE.equals(getFailIfNoTests()) ) + { + throw new MojoFailureException( "No tests to run!" ); + } + getLog().info( "No tests to run." ); + } + else + { + ensureWorkingDirectoryExists(); + ensureParallelRunningCompatibility(); + warnIfUselessUseSystemClassLoaderParameter(); + } + + return true; + } + protected abstract boolean isSkipExecution(); - + protected abstract void executeAfterPreconditionsChecked() throws MojoExecutionException, MojoFailureException; private Artifact surefireArtifact; + private ProviderList wellKnownProviders; + protected List initialize() throws MojoFailureException { @@ -148,12 +150,10 @@ public abstract class AbstractSurefireMo try { final Artifact junitDepArtifact = getJunitDepArtifact(); - - ProviderList wellKnownProviders = new ProviderList( - new ProviderInfo[]{ new TestNgProviderInfo( getTestNgArtifact() ), - new JUnitCoreProviderInfo( getJunitArtifact(), junitDepArtifact ), - new JUnit4ProviderInfo( getJunitArtifact(), junitDepArtifact ), - new JUnit3ProviderInfo( getJunitArtifact() ) }, new DynamicProviderInfo( null ) ); + wellKnownProviders = new ProviderList( new ProviderInfo[]{ new TestNgProviderInfo( getTestNgArtifact() ), + new JUnitCoreProviderInfo( getJunitArtifact(), junitDepArtifact ), + new JUnit4ProviderInfo( getJunitArtifact(), junitDepArtifact ), new JUnit3ProviderInfo() }, + new DynamicProviderInfo( null ) ); return wellKnownProviders.resolve( getLog() ); } @@ -276,16 +276,34 @@ public abstract class AbstractSurefireMo new ReporterConfiguration( reports, getReportsDirectory(), Boolean.valueOf( isTrimStackTrace() ), timeoutSet ); + 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" ); + } + + surefireArtifact.isSnapshot(); // MNG-2961: before Maven 2.0.8, fixes getBaseVersion to be -SNAPSHOT if needed + Artifact testNgArtifact; try { + addArtifact( forkConfiguration.getBootClasspath(), surefireArtifact ); testNgArtifact = getTestNgArtifact(); } + catch ( ArtifactNotFoundException e ) + { + throw new MojoExecutionException( + "Unable to locate required surefire provider dependency: " + e.getMessage(), e ); + } catch ( InvalidVersionSpecificationException e ) { throw new MojoExecutionException( "Error determining the TestNG version requested: " + e.getMessage(), e ); } + catch ( ArtifactResolutionException e ) + { + throw new MojoExecutionException( "Error to resolving surefire provider dependency: " + e.getMessage(), e ); + } DirectoryScannerParameters directoryScannerParameters = null; final boolean isTestNg = testNgArtifact != null; @@ -356,21 +374,25 @@ public abstract class AbstractSurefireMo ClassLoaderConfiguration classLoaderConfiguration ) throws MojoExecutionException, MojoFailureException { + final ClasspathConfiguration classpathConfiguration = + new ClasspathConfiguration( isEnableAssertions(), isChildDelegation() ); + + 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" ); + } + + surefireArtifact.isSnapshot(); // MNG-2961: before Maven 2.0.8, fixes getBaseVersion to be -SNAPSHOT if needed + + String providerName; try { - provider.addProviderProperties(); + addArtifact( forkConfiguration.getBootClasspath(), surefireArtifact ); - String providerName = provider.getProviderName(); - Classpath providerClasspath = provider.getProviderClasspath(); - Classpath testClasspath = generateTestClasspath(); - - final ClasspathConfiguration classpathConfiguration = - new ClasspathConfiguration( testClasspath, providerClasspath, provider.getTestframeworkClasspath(), - isEnableAssertions(), isChildDelegation() ); - - logClasspath( testClasspath, "Test" ); - return new StartupConfiguration( providerName, classpathConfiguration, classLoaderConfiguration, - forkConfiguration.isForking(), false, isRedirectTestOutputToFile() ); + provider.addProviderProperties(); + provider.addProviderArtifactToSurefireClasspath( classpathConfiguration ); + providerName = provider.getProviderName(); } catch ( ArtifactNotFoundException e ) { @@ -381,30 +403,40 @@ public abstract class AbstractSurefireMo { throw new MojoExecutionException( "Error to resolving surefire provider dependency: " + e.getMessage(), e ); } + + List classpathElements; + try + { + classpathElements = generateTestClasspath(); + } catch ( DependencyResolutionRequiredException e ) { throw new MojoExecutionException( "Unable to generate test classpath: " + e, e ); } + + addClasspathElementsToClasspathConfiguration(classpathElements, classpathConfiguration); + return new StartupConfiguration( providerName, classpathConfiguration, classLoaderConfiguration, + forkConfiguration.isForking(), false, isRedirectTestOutputToFile() ); } - public void logClasspath( Classpath classpath, String descriptor ) + private void addClasspathElementsToClasspathConfiguration(List classpathElements, ClasspathConfiguration classpathConfiguration) { - getLog().debug( descriptor + " classpath:" ); - for ( Iterator i = classpath.getClassPath().iterator(); i.hasNext(); ) + getLog().debug( "Test classpath:" ); + for ( Iterator i = classpathElements.iterator(); i.hasNext(); ) { String classpathElement = (String) i.next(); if ( classpathElement == null ) { - getLog().warn( "The test classpath contains a null element." ); + getLog().warn("The test classpath contains a null element."); } else { getLog().debug( " " + classpathElement ); + classpathConfiguration.addClasspathUrl( classpathElement ); } } } - private boolean isSpecificTestSpecified() { return getTest() != null; @@ -493,8 +525,8 @@ public abstract class AbstractSurefireMo if ( !range.containsVersion( new DefaultArtifactVersion( artifact.getVersion() ) ) ) { throw new MojoFailureException( - "TestNG support requires version 4.7 or above. You have declared version " - + artifact.getVersion() ); + "TestNG support requires version 4.7 or above. You have declared version " + + artifact.getVersion() ); } } return artifact; @@ -523,35 +555,12 @@ public abstract class AbstractSurefireMo } protected ForkConfiguration getForkConfiguration() - throws MojoExecutionException { File tmpDir = getSurefireTempDir(); //noinspection ResultOfMethodCallIgnored tmpDir.mkdirs(); - final Classpath bootClasspathConfiguration; - try - { - 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" ); - } - - surefireArtifact.isSnapshot(); // MNG-2961: before Maven 2.0.8, fixes getBaseVersion to be -SNAPSHOT if needed - - bootClasspathConfiguration = dependencyResolver.getResolvedArtifactClasspath( surefireArtifact ); - - } - catch ( ArtifactNotFoundException e ) - { - throw new MojoExecutionException( - "Unable to locate required surefire provider dependency: " + e.getMessage(), e ); - } - catch ( ArtifactResolutionException e ) - { - throw new MojoExecutionException( "Error to resolving surefire provider dependency: " + e.getMessage(), e ); - } + final Classpath bootClasspathConfiguration = new Classpath(); ForkConfiguration fork = new ForkConfiguration( bootClasspathConfiguration, getForkMode(), tmpDir ); @@ -619,12 +628,12 @@ public abstract class AbstractSurefireMo return fork; } + /** * Where surefire stores its own temp files * * @return A file pointing to the location of surefire's own temp files */ - private File getSurefireTempDir() { return new File( getReportsDirectory().getParentFile(), "surefire" ); @@ -721,7 +730,7 @@ public abstract class AbstractSurefireMo * @throws org.apache.maven.plugin.MojoExecutionException * upon other problems */ - public Classpath generateTestClasspath() + public List generateTestClasspath() throws DependencyResolutionRequiredException, MojoExecutionException { List classpath = new ArrayList( 2 + getProject().getArtifacts().size() ); @@ -763,14 +772,11 @@ public abstract class AbstractSurefireMo for ( Iterator iter = getAdditionalClasspathElements().iterator(); iter.hasNext(); ) { String classpathElement = (String) iter.next(); - if ( classpathElement != null ) - { - classpath.add( classpathElement ); - } + classpath.add( classpathElement ); } } - return new Classpath( classpath ); + return classpath; } /** @@ -824,6 +830,23 @@ public abstract class AbstractSurefireMo getRemoteRepositories(), getMetadataSource(), filter ); } + private void addArtifact( Classpath bootClasspath, Artifact surefireArtifact ) + throws ArtifactNotFoundException, ArtifactResolutionException + { + ArtifactResolutionResult result = resolveArtifact( null, surefireArtifact ); + + for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); ) + { + Artifact artifact = (Artifact) i.next(); + + getLog().debug( + "Adding to " + getPluginName() + " booter test classpath: " + artifact.getFile().getAbsolutePath() + + " Scope: " + artifact.getScope() ); + + bootClasspath.addClassPathElementUrl( artifact.getFile().getAbsolutePath() ); + } + } + protected void processSystemProperties( boolean setInSystem ) { copyPropertiesToInternalSystemProperties( getSystemProperties() ); @@ -895,8 +918,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 ); @@ -1037,67 +1060,24 @@ public abstract class AbstractSurefireMo return testNgArtifact != null; } - public Classpath getTestframeworkClasspath() - { - return new Classpath( testNgArtifact.getFile() ); - } - public void addProviderProperties() { convertTestNGParameters(); } - public Classpath getProviderClasspath() + public void addProviderArtifactToSurefireClasspath( ClasspathConfiguration bootclasspath ) throws ArtifactResolutionException, ArtifactNotFoundException { Artifact surefireArtifact = (Artifact) getPluginArtifactMap().get( "org.apache.maven.surefire:surefire-booter" ); - return dependencyResolver.getProviderClasspath( "surefire-testng", surefireArtifact.getBaseVersion(), - testNgArtifact ); - } - } - - private static abstract class JUnitProvider - implements ProviderInfo - { - protected final Artifact junitArtifact; - - JUnitProvider( Artifact junitArtifact ) - { - this.junitArtifact = junitArtifact; - } - } - - private static abstract class JUnit4Provider - extends JUnitProvider - { - protected final Artifact junitDepArtifact; - - JUnit4Provider( Artifact junitArtifact, Artifact junitDepArtifact ) - { - super( junitArtifact ); - this.junitDepArtifact = junitDepArtifact; - } - - protected Artifact getArtifactToUse() - { - return junitDepArtifact != null ? junitDepArtifact : junitArtifact; - } - - public Classpath getTestframeworkClasspath() - { - return new Classpath( getArtifactToUse().getFile() ); + dependencyResolver.addProviderToClasspath( bootclasspath, "surefire-testng", + surefireArtifact.getBaseVersion(), testNgArtifact ); } } class JUnit3ProviderInfo - extends JUnitProvider + implements ProviderInfo { - JUnit3ProviderInfo( Artifact junitArtifact ) - { - super( junitArtifact ); - } - public String getProviderName() { return "org.apache.maven.surefire.junit.JUnit3Provider"; @@ -1112,31 +1092,29 @@ public abstract class AbstractSurefireMo { } - public Classpath getProviderClasspath() + public void addProviderArtifactToSurefireClasspath( ClasspathConfiguration classpathConfiguration ) throws ArtifactResolutionException, ArtifactNotFoundException { // add the JUnit provider as default - it doesn't require JUnit to be present, // since it supports POJO tests. - return dependencyResolver.getProviderClasspath( "surefire-junit3", surefireArtifact.getBaseVersion(), - null ); - - } + dependencyResolver.addProviderToClasspath( classpathConfiguration, "surefire-junit3", + surefireArtifact.getBaseVersion(), null ); - public Classpath getTestframeworkClasspath() - { - return junitArtifact != null ? new Classpath( junitArtifact.getFile() ) : new Classpath(); } - } - class JUnit4ProviderInfo - extends JUnit4Provider + implements ProviderInfo { + private final Artifact junitArtifact; + + private final Artifact junitDepArtifact; + JUnit4ProviderInfo( Artifact junitArtifact, Artifact junitDepArtifact ) { - super( junitArtifact, junitDepArtifact ); + this.junitArtifact = junitArtifact; + this.junitDepArtifact = junitDepArtifact; } public String getProviderName() @@ -1153,22 +1131,27 @@ public abstract class AbstractSurefireMo { } - public Classpath getProviderClasspath() + public void addProviderArtifactToSurefireClasspath( ClasspathConfiguration classpathConfiguration ) throws ArtifactResolutionException, ArtifactNotFoundException { - return dependencyResolver.getProviderClasspath( "surefire-junit4", surefireArtifact.getBaseVersion(), - null ); + dependencyResolver.addProviderToClasspath( classpathConfiguration, "surefire-junit4", + surefireArtifact.getBaseVersion(), null ); } } class JUnitCoreProviderInfo - extends JUnit4Provider + implements ProviderInfo { + private final Artifact junitArtifact; + + private final Artifact junitDepArtifact; + JUnitCoreProviderInfo( Artifact junitArtifact, Artifact junitDepArtifact ) { - super( junitArtifact, junitDepArtifact ); + this.junitArtifact = junitArtifact; + this.junitDepArtifact = junitDepArtifact; } public String getProviderName() @@ -1192,14 +1175,13 @@ public abstract class AbstractSurefireMo convertJunitCoreParameters(); } - public Classpath getProviderClasspath() + public void addProviderArtifactToSurefireClasspath( ClasspathConfiguration classpathConfiguration ) throws ArtifactResolutionException, ArtifactNotFoundException { - return dependencyResolver.getProviderClasspath( "surefire-junit47", surefireArtifact.getBaseVersion(), - null ); + dependencyResolver.addProviderToClasspath( classpathConfiguration, "surefire-junit47", + surefireArtifact.getBaseVersion(), null ); } - } public class DynamicProviderInfo @@ -1234,17 +1216,14 @@ public abstract class AbstractSurefireMo convertTestNGParameters(); } - public Classpath getTestframeworkClasspath() - { - return new Classpath(); - } - - public Classpath getProviderClasspath() + public void addProviderArtifactToSurefireClasspath( ClasspathConfiguration classpathConfiguration ) throws ArtifactResolutionException, ArtifactNotFoundException { final Map pluginArtifactMap = getPluginArtifactMap(); Artifact plugin = (Artifact) pluginArtifactMap.get( "org.apache.maven.plugins:maven-surefire-plugin" ); - return dependencyResolver.addProviderToClasspath( pluginArtifactMap, plugin ); + dependencyResolver.addProviderToClasspath( classpathConfiguration, pluginArtifactMap, plugin ); } + } + } Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ProviderInfo.java URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ProviderInfo.java?rev=1071808&r1=1071807&r2=1071808&view=diff ============================================================================== --- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ProviderInfo.java (original) +++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ProviderInfo.java Thu Feb 17 21:56:09 2011 @@ -21,20 +21,18 @@ package org.apache.maven.plugin.surefire import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; -import org.apache.maven.surefire.booter.Classpath; +import org.apache.maven.surefire.booter.ClasspathConfiguration; /** - * @author Kristian Rosenvold - */ +* @author Kristian Rosenvold +*/ public interface ProviderInfo { String getProviderName(); boolean isApplicable(); - Classpath getTestframeworkClasspath(); - - Classpath getProviderClasspath() + void addProviderArtifactToSurefireClasspath( ClasspathConfiguration bootclasspath ) throws ArtifactResolutionException, ArtifactNotFoundException; void addProviderProperties(); Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireDependencyResolver.java URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireDependencyResolver.java?rev=1071808&r1=1071807&r2=1071808&view=diff ============================================================================== --- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireDependencyResolver.java (original) +++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireDependencyResolver.java Thu Feb 17 21:56:09 2011 @@ -35,8 +35,8 @@ import org.apache.maven.artifact.version import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.plugin.logging.Log; import org.apache.maven.surefire.booter.Classpath; +import org.apache.maven.surefire.booter.ClasspathConfiguration; -import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashSet; @@ -151,14 +151,14 @@ public class SurefireDependencyResolver filter ); } - public Classpath getProviderClasspath( String provider, String version, Artifact filteredArtifact ) + public void addProviderToClasspath( ClasspathConfiguration classpathConfiguration, String provider, String version, + Artifact filteredArtifact ) throws ArtifactNotFoundException, ArtifactResolutionException { Artifact providerArtifact = artifactFactory.createDependencyArtifact( "org.apache.maven.surefire", provider, VersionRange.createFromVersion( version ), "jar", null, Artifact.SCOPE_TEST ); ArtifactResolutionResult result = resolveArtifact( filteredArtifact, providerArtifact ); - List files = new ArrayList(); for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); ) { @@ -168,15 +168,30 @@ public class SurefireDependencyResolver "Adding to " + pluginName + " test classpath: " + artifact.getFile().getAbsolutePath() + " Scope: " + artifact.getScope() ); - files.add( artifact.getFile().getAbsolutePath() ); + classpathConfiguration.addSurefireClasspathUrl( artifact.getFile().getAbsolutePath() ); } - return new Classpath( files ); } - public Classpath addProviderToClasspath( Map pluginArtifactMap, Artifact surefireArtifact ) + public void addResolvedArtifactToClasspath( Classpath bootClasspath, Artifact surefireArtifact ) + throws ArtifactNotFoundException, ArtifactResolutionException + { + ArtifactResolutionResult result = resolveArtifact( null, surefireArtifact ); + + for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); ) + { + Artifact artifact = (Artifact) i.next(); + + log.debug( "Adding to " + pluginName + " booter test classpath: " + artifact.getFile().getAbsolutePath() + + " Scope: " + artifact.getScope() ); + + bootClasspath.addClassPathElementUrl( artifact.getFile().getAbsolutePath() ); + } + } + + public void addProviderToClasspath( ClasspathConfiguration classpathConfiguration, Map pluginArtifactMap, + Artifact surefireArtifact ) throws ArtifactResolutionException, ArtifactNotFoundException { - List files = new ArrayList(); if ( surefireArtifact != null ) { final ArtifactResolutionResult artifactResolutionResult = resolveArtifact( null, surefireArtifact ); @@ -185,7 +200,7 @@ public class SurefireDependencyResolver Artifact artifact = (Artifact) iterator.next(); if ( !artifactResolutionResult.getArtifacts().contains( artifact ) ) { - files.add( artifact.getFile().getAbsolutePath() ); + classpathConfiguration.addClasspathUrl( artifact.getFile().getPath() ); } } } @@ -195,25 +210,8 @@ public class SurefireDependencyResolver for ( Iterator iterator = pluginArtifactMap.values().iterator(); iterator.hasNext(); ) { Artifact artifact = (Artifact) iterator.next(); - files.add( artifact.getFile().getPath() ); + classpathConfiguration.addClasspathUrl( artifact.getFile().getPath() ); } } - return new Classpath( files ); } - - public Classpath getResolvedArtifactClasspath( Artifact surefireArtifact ) - throws ArtifactNotFoundException, ArtifactResolutionException - { - ArtifactResolutionResult result = resolveArtifact( null, surefireArtifact ); - List classpath = new ArrayList(); - - for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); ) - { - Artifact artifact = (Artifact) i.next(); - - classpath.add( artifact.getFile().getAbsolutePath() ); - } - return new Classpath( classpath); - } - } Modified: maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java?rev=1071808&r1=1071807&r2=1071808&view=diff ============================================================================== --- maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java (original) +++ maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java Thu Feb 17 21:56:09 2011 @@ -19,10 +19,19 @@ package org.apache.maven.plugin.surefire * under the License. */ +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Properties; + +import junit.framework.TestCase; + import org.apache.maven.surefire.booter.BooterConstants; import org.apache.maven.surefire.booter.BooterDeserializer; import org.apache.maven.surefire.booter.ClassLoaderConfiguration; -import org.apache.maven.surefire.booter.Classpath; import org.apache.maven.surefire.booter.ClasspathConfiguration; import org.apache.maven.surefire.booter.ProviderConfiguration; import org.apache.maven.surefire.booter.StartupConfiguration; @@ -32,16 +41,6 @@ import org.apache.maven.surefire.testset import org.apache.maven.surefire.testset.TestArtifactInfo; import org.apache.maven.surefire.testset.TestRequest; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Properties; - -import junit.framework.TestCase; - /** * Performs roundtrip testing of serialization/deserialization of The StartupConfiguration * @@ -72,10 +71,10 @@ public class BooterDeserializerStartupCo assertEquals( "true", props.get( BooterConstants.ENABLE_ASSERTIONS ) ); assertEquals( "true", props.get( BooterConstants.CHILD_DELEGATION ) ); assertEquals( 2, testClassPathUrls.size() ); - assertEquals( "T1", testClassPathUrls.get( 0 ) ); - assertEquals( "T2", testClassPathUrls.get( 1 ) ); - assertEquals( "P1", props.get( BooterConstants.SUREFIRE_CLASSPATHURL + "0" ) ); - assertEquals( "P2", props.get( BooterConstants.SUREFIRE_CLASSPATHURL + "1" ) ); + assertEquals( "CP1", testClassPathUrls.get( 0 ) ); + assertEquals( "CP2", testClassPathUrls.get( 1 ) ); + assertEquals( "SP1", props.get( BooterConstants.SUREFIRE_CLASSPATHURL + "0" ) ); + assertEquals( "SP2", props.get( BooterConstants.SUREFIRE_CLASSPATHURL + "1" ) ); } public void testClassLoaderConfiguration() @@ -145,11 +144,11 @@ public class BooterDeserializerStartupCo private StartupConfiguration getTestStartupConfiguration( ClassLoaderConfiguration classLoaderConfiguration ) { - Classpath testClasspath = new Classpath( Arrays.asList( new String[]{ "T1", "T2" } ) ); - Classpath providerClasspath = new Classpath( Arrays.asList( new String[]{ "P1", "P2" } ) ); - Classpath testFrameworkClasspath = new Classpath(); - ClasspathConfiguration classpathConfiguration = - new ClasspathConfiguration( testClasspath, providerClasspath, testFrameworkClasspath, true, true ); + ClasspathConfiguration classpathConfiguration = new ClasspathConfiguration( true, true ); + classpathConfiguration.addClasspathUrl( "CP1" ); + classpathConfiguration.addClasspathUrl( "CP2" ); + classpathConfiguration.addSurefireClasspathUrl( "SP1" ); + classpathConfiguration.addSurefireClasspathUrl( "SP2" ); return new StartupConfiguration( "com.provider", classpathConfiguration, classLoaderConfiguration, false, false, false ); } Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterConstants.java URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterConstants.java?rev=1071808&r1=1071807&r2=1071808&view=diff ============================================================================== --- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterConstants.java (original) +++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterConstants.java Thu Feb 17 21:56:09 2011 @@ -36,7 +36,6 @@ public interface BooterConstants String TYPES_SUFIX = ".types"; String CLASSPATH_URL = "classPathUrl."; String SUREFIRE_CLASSPATHURL = "surefireClassPathUrl."; - String TEST_FRAMEWORK_CLASSPATHURL = "testFwClassPathUrl."; String CHILD_DELEGATION = "childDelegation"; String ENABLE_ASSERTIONS = "enableAssertions"; String USESYSTEMCLASSLOADER = "useSystemClassLoader"; Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterDeserializer.java URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterDeserializer.java?rev=1071808&r1=1071807&r2=1071808&view=diff ============================================================================== --- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterDeserializer.java (original) +++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/BooterDeserializer.java Thu Feb 17 21:56:09 2011 @@ -103,13 +103,12 @@ public class BooterDeserializer Classpath classpath = Classpath.readFromForkProperties( properties, CLASSPATH_URL ); Classpath sureFireClasspath = Classpath.readFromForkProperties( properties, SUREFIRE_CLASSPATHURL ); - Classpath testFrameworkClasspath = Classpath.readFromForkProperties( properties, TEST_FRAMEWORK_CLASSPATHURL ); ClassLoaderConfiguration classLoaderConfiguration = new ClassLoaderConfiguration( useSystemClassLoader, useManifestOnlyJar ); ClasspathConfiguration classpathConfiguration = - new ClasspathConfiguration( classpath, sureFireClasspath, testFrameworkClasspath, enableAssertions, childDelegation ); + new ClasspathConfiguration( classpath, sureFireClasspath, enableAssertions, childDelegation ); return StartupConfiguration.inForkedVm( providerConfiguration, classpathConfiguration, classLoaderConfiguration ); Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java?rev=1071808&r1=1071807&r2=1071808&view=diff ============================================================================== --- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java (original) +++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java Thu Feb 17 21:56:09 2011 @@ -25,7 +25,6 @@ import java.io.File; import java.net.MalformedURLException; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Properties; @@ -37,14 +36,6 @@ import java.util.Properties; */ public class Classpath { - public Classpath( List files ) - { - for ( Iterator iter = files.iterator(); iter.hasNext(); ) - { - addClassPathElementUrl( (String) iter.next() ); - } - } - static Classpath readFromForkProperties( PropertiesWrapper properties, String prefix ) { List elements = properties.getStringList( prefix ); @@ -53,13 +44,10 @@ public class Classpath public static Classpath join( Classpath firstClasspath, Classpath secondClasspath ) { - - List result = new ArrayList( firstClasspath != null ? firstClasspath.elements : new ArrayList() ); - if ( secondClasspath != null ) - { - result.addAll( secondClasspath.elements ); - } - return new Classpath( result ); + Classpath joinedClasspath = new Classpath(); + joinedClasspath.addElementsOfClasspath( firstClasspath ); + joinedClasspath.addElementsOfClasspath( secondClasspath ); + return joinedClasspath; } private final List elements = new ArrayList(); @@ -68,12 +56,13 @@ public class Classpath { } - public Classpath( File file ) + private Classpath( Collection elements ) { - this( Collections.singletonList( file.getAbsolutePath() ) ); + this(); + addElements( elements ); } - void addClassPathElementUrl( String path ) + public void addClassPathElementUrl( String path ) { if ( path == null ) { @@ -138,9 +127,4 @@ public class Classpath } System.setProperty( propertyName, sb.toString() ); } - - public int size() - { - return elements.size(); - } } Modified: 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=1071808&r1=1071807&r2=1071808&view=diff ============================================================================== --- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java (original) +++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java Thu Feb 17 21:56:09 2011 @@ -32,7 +32,7 @@ import java.util.Properties; /** * Represents the classpaths for the BooterConfiguration. * <p/> - * + * * @author Jason van Zyl * @author Emmanuel Venisse * @author Kristian Rosenvold @@ -41,11 +41,9 @@ import java.util.Properties; public class ClasspathConfiguration { - private final Classpath testFrameworkClasspath; + private final Classpath classpathUrls; - private final Classpath testClasspath; - - private final Classpath providerClasspath; + private final Classpath surefireClasspathUrls; /** * Whether to enable assertions or not (can be affected by the fork arguments, and the ability to do so based on the @@ -58,24 +56,25 @@ public class ClasspathConfiguration public ClasspathConfiguration( boolean enableAssertions, boolean childDelegation ) { - this( new Classpath(), new Classpath(), new Classpath(), enableAssertions, childDelegation ); + this( new Classpath(), new Classpath(), enableAssertions, childDelegation ); } - public ClasspathConfiguration( Classpath testClasspath, Classpath providerClasspath, - Classpath testFrameworkClasspath, boolean enableAssertions, boolean childDelegation ) + /* + * Reads the config from the supplied stream. Closes the stream. + */ + public ClasspathConfiguration( Classpath classPathUrls, Classpath surefireClassPathUrls, boolean enableAssertions, + boolean childDelegation ) { - this.testFrameworkClasspath = testFrameworkClasspath; - this.testClasspath = testClasspath; - this.providerClasspath = providerClasspath; this.enableAssertions = enableAssertions; this.childDelegation = childDelegation; + this.classpathUrls = classPathUrls; + this.surefireClasspathUrls = surefireClassPathUrls; } public void setForkProperties( Properties properties ) { - testClasspath.writeToForkProperties( properties, BooterConstants.CLASSPATH_URL ); - providerClasspath.writeToForkProperties( properties, BooterConstants.SUREFIRE_CLASSPATHURL ); - testFrameworkClasspath.writeToForkProperties( properties, BooterConstants.TEST_FRAMEWORK_CLASSPATHURL ); + classpathUrls.writeToForkProperties( properties, BooterConstants.CLASSPATH_URL ); + surefireClasspathUrls.writeToForkProperties( properties, BooterConstants.SUREFIRE_CLASSPATHURL ); properties.setProperty( BooterConstants.ENABLE_ASSERTIONS, String.valueOf( enableAssertions ) ); properties.setProperty( BooterConstants.CHILD_DELEGATION, String.valueOf( childDelegation ) ); } @@ -106,112 +105,80 @@ public class ClasspathConfiguration public ClassLoader createTestClassLoader( boolean childDelegation ) throws SurefireExecutionException { - ClassLoader testFrameWorkClassLoader = createTestFrameworkClassLoader( childDelegation ); - return createClassLoader( testClasspath, testFrameWorkClassLoader, childDelegation, "Test" ); - } - - private ClassLoader createTestFrameworkClassLoader( boolean childDelegation ) - throws SurefireExecutionException - { - return hasTestFrameworkClasspath() ? createClassLoader( testFrameworkClasspath, null, childDelegation, - "TestFramework" ) : null; + return createClassLoaderSEE( classpathUrls, null, childDelegation ); } public ClassLoader createTestClassLoader() throws SurefireExecutionException { - final ClassLoader testFrameworkClassLoader = createTestFrameworkClassLoader( this.childDelegation ); - return createClassLoader( testClasspath, testFrameworkClassLoader, this.childDelegation, "Test" ); + return createClassLoaderSEE( classpathUrls, null, this.childDelegation ); } - public ClassLoader createTestframeworkClassLoader() + public ClassLoader createSurefireClassLoader( ClassLoader parent ) throws SurefireExecutionException { - return createClassLoader( testFrameworkClasspath, null, this.childDelegation, "Test" ); + return createClassLoaderSEE( surefireClasspathUrls, parent, false ); } - public ClassLoader createSurefireClassLoader( ClassLoader parent ) + private ClassLoader createClassLoaderSEE( Classpath classPathUrls, ClassLoader parent, boolean childDelegation ) throws SurefireExecutionException { - boolean useTestClassLoaderAsParent = - parent.equals( ClassLoader.getSystemClassLoader() ) || !hasTestFrameworkClasspath(); - - ClassLoader parentToUse = useTestClassLoaderAsParent ? parent : parent.getParent(); + try + { + return createClassLoader( classPathUrls, parent, childDelegation ); + } + catch ( MalformedURLException e ) + { + throw new SurefireExecutionException( "When creating classloader", e ); + } - return createClassLoader( providerClasspath, parentToUse, false, "Provider" ); } - private ClassLoader createClassLoader( Classpath classPathUrls, ClassLoader parent, boolean childDelegation, - String description ) - throws SurefireExecutionException + private ClassLoader createClassLoader( Classpath classPathUrls, ClassLoader parent, boolean childDelegation ) + throws MalformedURLException { - try + List urls = classPathUrls.getAsUrlList(); + IsolatedClassLoader classLoader = new IsolatedClassLoader( parent, childDelegation ); + if ( assertionStatusMethod != null ) { - List urls = classPathUrls.getAsUrlList(); - IsolatedClassLoader classLoader = new IsolatedClassLoader( parent, childDelegation, description ); - if ( assertionStatusMethod != null ) + try { - try + Object[] args = new Object[]{ enableAssertions ? Boolean.TRUE : Boolean.FALSE }; + if ( parent != null ) { - 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 ); + assertionStatusMethod.invoke( parent, args ); } + assertionStatusMethod.invoke( classLoader, args ); + } + catch ( IllegalAccessException e ) + { + throw new NestedRuntimeException( "Unable to access the assertion enablement method", e ); } - for ( Iterator iter = urls.iterator(); iter.hasNext(); ) + catch ( InvocationTargetException e ) { - URL url = (URL) iter.next(); - classLoader.addURL( url ); + throw new NestedRuntimeException( "Unable to invoke the assertion enablement method", e ); } - return classLoader; } - catch ( MalformedURLException e ) + for ( Iterator iter = urls.iterator(); iter.hasNext(); ) { - throw new SurefireExecutionException( "When creating classloader", e ); + URL url = (URL) iter.next(); + classLoader.addURL( url ); } + return classLoader; } public Classpath getTestClasspath() { - return testClasspath; + return classpathUrls; } public void addClasspathUrl( String path ) { - testClasspath.addClassPathElementUrl( path ); + classpathUrls.addClassPathElementUrl( path ); } public void addSurefireClasspathUrl( String path ) { - providerClasspath.addClassPathElementUrl( path ); + surefireClasspathUrls.addClassPathElementUrl( path ); } - - private Classpath getTestFrameworkClasspath() - { - return testFrameworkClasspath; - } - - /** - * Indicates if there is a test framework classpath present, which triggers - * the pitchfork classloader configuration. - * - * @return True if there is a test framework classpath available - */ - private boolean hasTestFrameworkClasspath() - { - return testFrameworkClasspath.size() > 0; - } - - } Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java?rev=1071808&r1=1071807&r2=1071808&view=diff ============================================================================== --- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java (original) +++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java Thu Feb 17 21:56:09 2011 @@ -29,6 +29,7 @@ import java.util.Properties; * <p/> * Deals with deserialization of the booter wire-level protocol * <p/> + * Todo: Look at relationship between this class and BooterSerializer (BooterDeserializer?) * * @author Jason van Zyl * @author Emmanuel Venisse Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/IsolatedClassLoader.java URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/IsolatedClassLoader.java?rev=1071808&r1=1071807&r2=1071808&view=diff ============================================================================== --- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/IsolatedClassLoader.java (original) +++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/IsolatedClassLoader.java Thu Feb 17 21:56:09 2011 @@ -30,9 +30,6 @@ import java.util.Set; public class IsolatedClassLoader extends URLClassLoader { - - private final String description; - private final ClassLoader parent = ClassLoader.getSystemClassLoader(); private final Set urls = new HashSet(); @@ -41,13 +38,11 @@ public class IsolatedClassLoader private static final URL[] EMPTY_URL_ARRAY = new URL[0]; - public IsolatedClassLoader( ClassLoader parent, boolean childDelegation, String description ) + public IsolatedClassLoader( ClassLoader parent, boolean childDelegation ) { super( EMPTY_URL_ARRAY, parent ); this.childDelegation = childDelegation; - - this.description = description; } public void addURL( URL url ) @@ -100,10 +95,4 @@ public class IsolatedClassLoader return c; } - - - public String toString() - { - return description; - } } Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreRunListener.java URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreRunListener.java?rev=1071808&r1=1071807&r2=1071808&view=diff ============================================================================== --- maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreRunListener.java (original) +++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreRunListener.java Thu Feb 17 21:56:09 2011 @@ -21,7 +21,6 @@ package org.apache.maven.surefire.junitc import org.apache.maven.surefire.common.junit4.JUnit4RunListener; import org.apache.maven.surefire.report.Reporter; -import org.apache.maven.surefire.util.NestedRuntimeException; import java.util.ArrayList; import java.util.Map; @@ -76,16 +75,7 @@ public class JUnitCoreRunListener testSet.incrementTestMethodCount(); if ( itemTestClass == null ) { - String className = item.getClassName(); - try - { - itemTestClass = Class.forName( className); - } - catch ( ClassNotFoundException ignore ) - { - throw new NestedRuntimeException( "Should not have trouble with this" , ignore ); - } - + itemTestClass = item.getTestClass(); } } else if ( item.getChildren().size() > 0 ) Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestSet.java URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestSet.java?rev=1071808&r1=1071807&r2=1071808&view=diff ============================================================================== --- maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestSet.java (original) +++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestSet.java Thu Feb 17 21:56:09 2011 @@ -23,7 +23,6 @@ import org.apache.maven.surefire.report. import org.apache.maven.surefire.report.ReportWriter; import org.apache.maven.surefire.report.Reporter; import org.apache.maven.surefire.report.SimpleReportEntry; -import org.apache.maven.surefire.util.NestedRuntimeException; import java.util.ArrayList; import java.util.Collections; @@ -31,6 +30,7 @@ import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; +import org.apache.maven.surefire.util.NestedRuntimeException; import org.junit.runner.Description; /** @@ -102,7 +102,7 @@ public class TestSet private ReportEntry createReportEntry( Integer elapsed ) { - boolean isJunit3 = testSetDescription.getClassName() == null; + boolean isJunit3 = testSetDescription.getTestClass() == null; String classNameToUse = isJunit3 ? testSetDescription.getChildren().get( 0 ).getClassName() : testSetDescription.getClassName(); return new SimpleReportEntry( classNameToUse, classNameToUse, elapsed );