Author: krosenvold
Date: Sun Nov 28 22:46:53 2010
New Revision: 1039969
URL: http://svn.apache.org/viewvc?rev=1039969&view=rev
Log:
o Extracted distinct class to represent classpath.
Also removed the booter classpath from the serialization since it was not being
used
Added:
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
(with props)
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ClasspathTest.java
(with props)
Modified:
maven/surefire/trunk/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java
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/booterclient/ForkConfiguration.java
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java
maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.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/ClasspathConfiguration.java
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireStarter.java
Modified:
maven/surefire/trunk/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java?rev=1039969&r1=1039968&r2=1039969&view=diff
==============================================================================
---
maven/surefire/trunk/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java
(original)
+++
maven/surefire/trunk/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java
Sun Nov 28 22:46:53 2010
@@ -19,17 +19,6 @@ package org.apache.maven.plugin.failsafe
* under the License.
*/
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -38,11 +27,12 @@ import org.apache.maven.execution.MavenS
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.surefire.AbstractSurefireMojo;
+import org.apache.maven.plugin.surefire.SurefireExecutionParameters;
import org.apache.maven.plugin.surefire.booterclient.ForkConfiguration;
import org.apache.maven.plugin.surefire.booterclient.ForkStarter;
-import org.apache.maven.plugin.surefire.SurefireExecutionParameters;
import org.apache.maven.project.MavenProject;
import org.apache.maven.surefire.booter.BooterConfiguration;
+import org.apache.maven.surefire.booter.Classpath;
import org.apache.maven.surefire.booter.SurefireBooterForkException;
import org.apache.maven.surefire.booter.SurefireExecutionException;
import org.apache.maven.surefire.failsafe.model.FailsafeSummary;
@@ -51,6 +41,17 @@ import org.apache.maven.toolchain.Toolch
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
/**
* Run integration tests using Surefire.
*
@@ -602,7 +603,9 @@ public class IntegrationTestMojo
{
if ( verifyParameters() )
{
- ForkConfiguration forkConfiguration = getForkConfiguration();
+ final Classpath bootClasspathConfiguration = new Classpath();
+ ForkConfiguration forkConfiguration = getForkConfiguration(
bootClasspathConfiguration );
+
BooterConfiguration booterConfiguration =
createBooterConfiguration( forkConfiguration );
ForkStarter booter = new ForkStarter( booterConfiguration,
reportsDirectory, forkConfiguration );
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=1039969&r1=1039968&r2=1039969&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
Sun Nov 28 22:46:53 2010
@@ -37,6 +37,7 @@ import org.apache.maven.plugin.MojoFailu
import org.apache.maven.plugin.surefire.booterclient.ForkConfiguration;
import org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter;
import org.apache.maven.surefire.booter.BooterConfiguration;
+import org.apache.maven.surefire.booter.Classpath;
import org.apache.maven.surefire.booter.ClasspathConfiguration;
import org.apache.maven.surefire.providerapi.ProviderConfiguration;
import org.apache.maven.surefire.report.BriefConsoleReporter;
@@ -48,8 +49,8 @@ import org.apache.maven.surefire.report.
import org.apache.maven.surefire.report.ReporterConfiguration;
import org.apache.maven.surefire.report.XMLReporter;
import org.apache.maven.surefire.testset.DirectoryScannerParameters;
-import org.apache.maven.surefire.testset.TestSuiteDefinition;
import org.apache.maven.surefire.testset.TestArtifactInfo;
+import org.apache.maven.surefire.testset.TestSuiteDefinition;
import org.apache.maven.toolchain.Toolchain;
import org.codehaus.plexus.util.StringUtils;
@@ -229,7 +230,6 @@ public abstract class AbstractSurefireMo
ReporterConfiguration reporterConfiguration =
new ReporterConfiguration( getReportsDirectory(), Boolean.valueOf(
isTrimStackTrace() ) );
-
Artifact surefireArtifact =
(Artifact) getPluginArtifactMap().get(
"org.apache.maven.surefire:surefire-booter" );
if ( surefireArtifact == null )
@@ -244,13 +244,15 @@ public abstract class AbstractSurefireMo
String providerName;
try
{
- addArtifact( classpathConfiguration, surefireArtifact );
+ addArtifact( forkConfiguration.getBootClasspathConfiguration(),
surefireArtifact );
junitArtifact = getJunitArtifact();
testNgArtifact = getTestNgArtifact();
- providerName = setCorrectProvider( classpathConfiguration,
surefireArtifact, junitArtifact, testNgArtifact );
+ providerName =
+ setCorrectProvider(
forkConfiguration.getBootClasspathConfiguration(), classpathConfiguration,
+ surefireArtifact, junitArtifact,
testNgArtifact );
}
catch ( ArtifactNotFoundException e )
{
@@ -268,8 +270,10 @@ public abstract class AbstractSurefireMo
DirectoryScannerParameters directoryScannerParameters = null;
final boolean isTestNg = testNgArtifact != null;
- TestArtifactInfo testNg = isTestNg ? new TestArtifactInfo(
testNgArtifact.getVersion(), testNgArtifact.getClassifier()) : null;
- TestSuiteDefinition testSuiteDefinition = new
TestSuiteDefinition(getSuiteXmlFiles(), null, getTestSourceDirectory(),
getTest());
+ TestArtifactInfo testNg =
+ isTestNg ? new TestArtifactInfo( testNgArtifact.getVersion(),
testNgArtifact.getClassifier() ) : null;
+ TestSuiteDefinition testSuiteDefinition =
+ new TestSuiteDefinition( getSuiteXmlFiles(), null,
getTestSourceDirectory(), getTest() );
final boolean failIfNoTests;
if ( isValidSuiteXmlFileConfig() && getTest() == null )
@@ -280,7 +284,8 @@ public abstract class AbstractSurefireMo
throw new MojoExecutionException( "suiteXmlFiles is
configured, but there is no TestNG dependency" );
}
- testSuiteDefinition = new TestSuiteDefinition(getSuiteXmlFiles(),
getTest(), getTestSourceDirectory(), getTest());
+ testSuiteDefinition =
+ new TestSuiteDefinition( getSuiteXmlFiles(), getTest(),
getTestSourceDirectory(), getTest() );
}
else
{
@@ -298,21 +303,22 @@ public abstract class AbstractSurefireMo
List includes = getIncludeList();
List excludes = getExcludeList();
- directoryScannerParameters =
- new DirectoryScannerParameters( getTestClassesDirectory(),
includes, excludes, Boolean.valueOf( failIfNoTests) );
+ directoryScannerParameters = new DirectoryScannerParameters(
getTestClassesDirectory(), includes, excludes,
+
Boolean.valueOf( failIfNoTests ) );
}
-
ProviderConfiguration providerConfiguration = new
ProviderConfiguration( providerName );
List reports = getReporters( forkConfiguration.isForking() );
Properties providerProperties = getProperties();
- if (providerProperties == null) {
- providerProperties = new Properties( );
+ if ( providerProperties == null )
+ {
+ providerProperties = new Properties();
}
BooterConfiguration booterConfiguration =
- new BooterConfiguration( providerProperties,
forkConfiguration.isForking(), forkConfiguration.getClassLoaderConfiguration(),
- classpathConfiguration,
isRedirectTestOutputToFile(), reporterConfiguration, testNg,
testSuiteDefinition, directoryScannerParameters, failIfNoTests, reports,
providerConfiguration);
-
+ new BooterConfiguration( providerProperties,
forkConfiguration.isForking(),
+
forkConfiguration.getClassLoaderConfiguration(), classpathConfiguration,
+ isRedirectTestOutputToFile(),
reporterConfiguration, testNg, testSuiteDefinition,
+ directoryScannerParameters,
failIfNoTests, reports, providerConfiguration );
List classpathElements;
try
@@ -332,7 +338,7 @@ public abstract class AbstractSurefireMo
getLog().debug( " " + classpathElement );
- classpathConfiguration.addClassPathUrl( classpathElement );
+ classpathConfiguration.addClasspathUrl( classpathElement );
}
Toolchain tc = getToolchain();
@@ -354,7 +360,6 @@ public abstract class AbstractSurefireMo
}
}
-
return booterConfiguration;
}
@@ -434,13 +439,14 @@ public abstract class AbstractSurefireMo
return includes;
}
- private String setCorrectProvider( ClasspathConfiguration
classpathConfiguration, Artifact surefireArtifact,
- Artifact junitArtifact, Artifact
testNgArtifact )
+ private String setCorrectProvider( Classpath bootClasspathConfiguration,
+ ClasspathConfiguration
classpathConfiguration, Artifact surefireArtifact,
+ Artifact junitArtifact, Artifact
testNgArtifact )
throws ArtifactNotFoundException, ArtifactResolutionException,
MojoExecutionException
{
if ( testNgArtifact != null )
{
- setTestNgProvider( classpathConfiguration, surefireArtifact,
testNgArtifact );
+ setTestNgProvider( bootClasspathConfiguration,
classpathConfiguration, surefireArtifact, testNgArtifact );
return "org.apache.maven.surefire.testng.TestNGProvider";
}
@@ -467,8 +473,8 @@ public abstract class AbstractSurefireMo
}
}
- private void setTestNgProvider( ClasspathConfiguration
classpathConfiguration, Artifact surefireArtifact,
- Artifact testNgArtifact )
+ private void setTestNgProvider( Classpath bootClasspathConfiguration,
ClasspathConfiguration classpathConfiguration,
+ Artifact surefireArtifact, Artifact
testNgArtifact )
throws ArtifactNotFoundException, ArtifactResolutionException
{
convertTestNGParameters();
@@ -478,7 +484,7 @@ public abstract class AbstractSurefireMo
getProperties().setProperty( "testng.test.classpath",
getTestClassesDirectory().getAbsolutePath() );
}
- addArtifact( classpathConfiguration, testNgArtifact );
+ addArtifact( bootClasspathConfiguration, 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.
@@ -517,9 +523,9 @@ public abstract class AbstractSurefireMo
return junitArtifact;
}
- protected ForkConfiguration getForkConfiguration()
+ protected ForkConfiguration getForkConfiguration( Classpath
bootClasspathConfiguration )
{
- ForkConfiguration fork = new ForkConfiguration();
+ ForkConfiguration fork = new ForkConfiguration(
bootClasspathConfiguration );
fork.setForkMode( getForkMode() );
@@ -704,7 +710,7 @@ public abstract class AbstractSurefireMo
"Adding to " + getPluginName() + " test classpath: " +
artifact.getFile().getAbsolutePath() +
" Scope: " + artifact.getScope() );
- classpathConfiguration.addSurefireClassPathUrl(
artifact.getFile().getAbsolutePath() );
+ classpathConfiguration.addSurefireClasspathUrl(
artifact.getFile().getAbsolutePath() );
}
}
@@ -725,7 +731,7 @@ public abstract class AbstractSurefireMo
getRemoteRepositories(), getMetadataSource(), filter );
}
- private void addArtifact( ClasspathConfiguration classpathConfiguration,
Artifact surefireArtifact )
+ private void addArtifact( Classpath bootClasspath, Artifact
surefireArtifact )
throws ArtifactNotFoundException, ArtifactResolutionException
{
ArtifactResolutionResult result = resolveArtifact( null,
surefireArtifact );
@@ -738,7 +744,7 @@ public abstract class AbstractSurefireMo
"Adding to " + getPluginName() + " booter test classpath: " +
artifact.getFile().getAbsolutePath() +
" Scope: " + artifact.getScope() );
- classpathConfiguration.addSurefireBootClassPathUrl(
artifact.getFile().getAbsolutePath() );
+ bootClasspath.addClassPathElementUrl(
artifact.getFile().getAbsolutePath() );
}
}
@@ -840,12 +846,12 @@ public abstract class AbstractSurefireMo
* The Reporter that will be added will be based on the value of the
parameter useFile, reportFormat, and
* printSummary.
*
- * @param forking forking
+ * @param forking forking
* @return a list of reporters
*/
private List getReporters( boolean forking )
{
- List reports = new ArrayList( );
+ List reports = new ArrayList();
if ( isUseFile() )
{
if ( isPrintSummary() )
Modified:
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java?rev=1039969&r1=1039968&r2=1039969&view=diff
==============================================================================
---
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java
(original)
+++
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java
Sun Nov 28 22:46:53 2010
@@ -20,6 +20,7 @@ package org.apache.maven.plugin.surefire
*/
import org.apache.maven.surefire.booter.ClassLoaderConfiguration;
+import org.apache.maven.surefire.booter.Classpath;
import org.apache.maven.surefire.booter.ForkedBooter;
import org.apache.maven.surefire.booter.SurefireBooterForkException;
import org.apache.maven.surefire.util.UrlUtils;
@@ -53,6 +54,8 @@ public class ForkConfiguration
public static final String FORK_NEVER = "never";
+ private final Classpath bootClasspathConfiguration;
+
private String forkMode;
private boolean useSystemClassLoader;
@@ -75,9 +78,19 @@ public class ForkConfiguration
private String debugLine;
+ public ForkConfiguration( Classpath bootClasspathConfiguration )
+ {
+ this.bootClasspathConfiguration = bootClasspathConfiguration;
+ }
+
+ public Classpath getBootClasspathConfiguration()
+ {
+ return bootClasspathConfiguration;
+ }
+
public ClassLoaderConfiguration getClassLoaderConfiguration()
{
- return new ClassLoaderConfiguration(isUseSystemClassLoader() ,
isUseManifestOnlyJar() );
+ return new ClassLoaderConfiguration( isUseSystemClassLoader(),
isUseManifestOnlyJar() );
}
public void setForkMode( String forkMode )
Modified:
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java?rev=1039969&r1=1039968&r2=1039969&view=diff
==============================================================================
---
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
(original)
+++
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
Sun Nov 28 22:46:53 2010
@@ -19,18 +19,19 @@ package org.apache.maven.plugin.surefire
* under the License.
*/
+import
org.apache.maven.plugin.surefire.booterclient.output.FileOutputConsumerProxy;
+import org.apache.maven.plugin.surefire.booterclient.output.OutputConsumer;
+import
org.apache.maven.plugin.surefire.booterclient.output.StandardOutputConsumer;
+import
org.apache.maven.plugin.surefire.booterclient.output.SupressFooterOutputConsumerProxy;
+import
org.apache.maven.plugin.surefire.booterclient.output.SupressHeaderOutputConsumerProxy;
import org.apache.maven.surefire.booter.BooterConfiguration;
+import org.apache.maven.surefire.booter.Classpath;
import org.apache.maven.surefire.booter.ClasspathConfiguration;
+import org.apache.maven.surefire.booter.ProviderFactory;
import org.apache.maven.surefire.booter.SurefireBooterForkException;
import org.apache.maven.surefire.booter.SurefireExecutionException;
import org.apache.maven.surefire.booter.SurefireReflector;
import org.apache.maven.surefire.booter.SurefireStarter;
-import
org.apache.maven.plugin.surefire.booterclient.output.FileOutputConsumerProxy;
-import org.apache.maven.plugin.surefire.booterclient.output.OutputConsumer;
-import
org.apache.maven.plugin.surefire.booterclient.output.StandardOutputConsumer;
-import
org.apache.maven.plugin.surefire.booterclient.output.SupressFooterOutputConsumerProxy;
-import
org.apache.maven.plugin.surefire.booterclient.output.SupressHeaderOutputConsumerProxy;
-import org.apache.maven.surefire.booter.*;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.cli.CommandLineException;
import org.codehaus.plexus.util.cli.CommandLineUtils;
@@ -42,7 +43,6 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;
-import java.util.List;
import java.util.Properties;
@@ -86,7 +86,7 @@ public class ForkStarter
if ( ForkConfiguration.FORK_NEVER.equals( requestedForkMode ) )
{
SurefireStarter testVmBooter = new SurefireStarter(
booterConfiguration );
- result =
testVmBooter.runSuitesInProcess(booterConfiguration.getProviderProperties());
+ result = testVmBooter.runSuitesInProcess(
booterConfiguration.getProviderProperties() );
}
else if ( ForkConfiguration.FORK_ONCE.equals( requestedForkMode ) )
{
@@ -127,14 +127,13 @@ public class ForkStarter
throw new SurefireBooterForkException( "Unable to create
classloader to find test suites", e );
}
-
boolean showHeading = true;
- final ProviderFactory providerFactory = new ProviderFactory(
booterConfiguration, surefireClassLoader);
- Object surefireProvider =
providerFactory.createProvider(testsClassLoader);
+ final ProviderFactory providerFactory = new ProviderFactory(
booterConfiguration, surefireClassLoader );
+ Object surefireProvider = providerFactory.createProvider(
testsClassLoader );
Properties properties = new Properties();
- final Iterator suites = (Iterator)
SurefireReflector.getSuites(surefireProvider);
+ final Iterator suites = (Iterator) SurefireReflector.getSuites(
surefireProvider );
while ( suites.hasNext() )
{
Object testSet = suites.next();
@@ -206,9 +205,14 @@ public class ForkStarter
throw new SurefireBooterForkException( "Error creating properties
files for forking", e );
}
- List bootClasspath = getClasspathConfiguration().getBootClasspath(
booterConfiguration.useSystemClassLoader() );
+ final Classpath bootClasspathConfiguration =
forkConfiguration.getBootClasspathConfiguration();
+ final Classpath additionlClassPathUrls =
booterConfiguration.useSystemClassLoader()
+ ?
booterConfiguration.getClasspathConfiguration().getTestClasspath()
+ : null;
+
+ Classpath bootClasspath = bootClasspathConfiguration.append(
additionlClassPathUrls );
- Commandline cli = forkConfiguration.createCommandLine( bootClasspath );
+ Commandline cli = forkConfiguration.createCommandLine(
bootClasspath.getClassPath() );
cli.createArg().setFile( surefireProperties );
Modified:
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java?rev=1039969&r1=1039968&r2=1039969&view=diff
==============================================================================
---
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java
(original)
+++
maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java
Sun Nov 28 22:46:53 2010
@@ -20,7 +20,7 @@ package org.apache.maven.plugin.surefire
*/
import junit.framework.TestCase;
-import org.apache.maven.plugin.surefire.booterclient.ForkConfiguration;
+import org.apache.maven.surefire.booter.Classpath;
import org.apache.maven.surefire.booter.SurefireBooterForkException;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.cli.Commandline;
@@ -75,7 +75,7 @@ public class ForkConfigurationTest
public static ForkConfiguration getForkConfiguration()
throws IOException
{
- ForkConfiguration forkConfiguration = new ForkConfiguration();
+ ForkConfiguration forkConfiguration = new ForkConfiguration( new
Classpath() );
forkConfiguration.setWorkingDirectory( new File( "."
).getCanonicalFile() );
return forkConfiguration;
}
Modified:
maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java?rev=1039969&r1=1039968&r2=1039969&view=diff
==============================================================================
---
maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
(original)
+++
maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
Sun Nov 28 22:46:53 2010
@@ -30,6 +30,7 @@ import org.apache.maven.plugin.surefire.
import org.apache.maven.plugin.surefire.booterclient.ForkStarter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.surefire.booter.BooterConfiguration;
+import org.apache.maven.surefire.booter.Classpath;
import org.apache.maven.surefire.booter.SurefireBooterForkException;
import org.apache.maven.surefire.booter.SurefireExecutionException;
import org.apache.maven.toolchain.ToolchainManager;
@@ -569,7 +570,9 @@ public class SurefirePlugin
{
if ( verifyParameters() )
{
- ForkConfiguration forkConfiguration = getForkConfiguration();
+ final Classpath bootClasspathConfiguration = new Classpath();
+ ForkConfiguration forkConfiguration =
getForkConfiguration(bootClasspathConfiguration);
+
BooterConfiguration booterConfiguration =
createBooterConfiguration( forkConfiguration );
getLog().info(
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=1039969&r1=1039968&r2=1039969&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
Sun Nov 28 22:46:53 2010
@@ -31,7 +31,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
@@ -55,6 +54,7 @@ import java.util.TreeMap;
public class BooterDeserializer
{
public static final String INCLUDES_PROPERTY_PREFIX = "includes";
+
public static final String EXCLUDES_PROPERTY_PREFIX = "excludes";
public static final String DIRSCANNER_PROPERTY_PREFIX = "dirscanner.";
@@ -82,7 +82,6 @@ public class BooterDeserializer
SortedMap surefireClassPathUrls = new TreeMap();
SortedMap reportsMap = new TreeMap();
- Collection booterClassPathUrl = new ArrayList();
boolean isTrimStackTrace = false;
File reportsDirectory = null;
@@ -126,10 +125,6 @@ public class BooterDeserializer
surefireClassPathUrls.put( Integer.valueOf( name.substring(
name.indexOf( '.' ) + 1 ) ),
properties.getProperty( name ) );
}
- else if ( name.startsWith( "surefireBootClassPathUrl." ) )
- {
- booterClassPathUrl.add( properties.getProperty( name ) );
- }
else if ( "childDelegation".equals( name ) )
{
childDelegation = Boolean.valueOf( properties.getProperty(
"childDelegation" ) ).booleanValue();
@@ -188,8 +183,7 @@ public class BooterDeserializer
}
else if ( "testSuiteXmlFiles".equals( name ) )
{
- testSuiteXmlFiles =
- constructParamObjects( properties.getProperty(
"testSuiteXmlFiles" ), File.class );
+ testSuiteXmlFiles = constructParamObjects(
properties.getProperty( "testSuiteXmlFiles" ), File.class );
}
else if ( "providerConfiguration".equals( name ) )
{
@@ -197,30 +191,29 @@ public class BooterDeserializer
}
}
-
- dirScannerParams =
- new DirectoryScannerParameters( testClassesDirectory, new
ArrayList( includes.values() ),
- new ArrayList( excludes.values()
), Boolean.valueOf( failIfNotests ) );
+ dirScannerParams = new DirectoryScannerParameters(
testClassesDirectory, new ArrayList( includes.values() ),
+ new ArrayList(
excludes.values() ),
+ Boolean.valueOf(
failIfNotests ) );
TestArtifactInfo testNg = new TestArtifactInfo( testNgVersion,
testNgClassifier );
- TestSuiteDefinition testSuiteDefinition = new TestSuiteDefinition(
testSuiteXmlFiles, testForFork,
-
testSuiteDefinitionTestSourceDirectory, requestedTest );
+ TestSuiteDefinition testSuiteDefinition =
+ new TestSuiteDefinition( testSuiteXmlFiles, testForFork,
testSuiteDefinitionTestSourceDirectory,
+ requestedTest );
ClassLoaderConfiguration forkConfiguration =
new ClassLoaderConfiguration( useSystemClassLoader,
useManifestOnlyJar );
ClasspathConfiguration classpathConfiguration =
- new ClasspathConfiguration( classPathUrls, surefireClassPathUrls,
booterClassPathUrl, enableAssertions,
- childDelegation );
+ new ClasspathConfiguration( classPathUrls, surefireClassPathUrls,
enableAssertions, childDelegation );
ReporterConfiguration reporterConfiguration =
new ReporterConfiguration( reportsDirectory, Boolean.valueOf(
isTrimStackTrace ) );
ProviderConfiguration providerConfigurationObj = new
ProviderConfiguration( providerConfiguration );
List reports = new ArrayList( reportsMap.values() );
- return new BooterConfiguration( forkConfiguration,
classpathConfiguration, reports,
- dirScannerParams, failIfNotests,
properties, reporterConfiguration, testNg,
- testSuiteDefinition,
providerConfigurationObj );
+ return new BooterConfiguration( forkConfiguration,
classpathConfiguration, reports, dirScannerParams,
+ failIfNotests, properties,
reporterConfiguration, testNg, testSuiteDefinition,
+ providerConfigurationObj );
}
private boolean isTypeHolderProperty( String name )
Added:
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=1039969&view=auto
==============================================================================
---
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
(added)
+++
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
Sun Nov 28 22:46:53 2010
@@ -0,0 +1,143 @@
+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.UrlUtils;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+/**
+ * An ordered set of classpath elements
+ *
+ * @author Kristian Rosenvold
+ */
+public class Classpath
+{
+ private final List elements;
+
+ private final Set elementSet;
+
+ public Classpath()
+ {
+ this( new ArrayList() );
+ }
+
+ private Classpath( List elements )
+ {
+ this.elements = elements;
+ this.elementSet = new HashSet( elements );
+ if ( elements.size() != elementSet.size() )
+ {
+ throw new IllegalStateException( "This is not permitted and is a
violation of contract" );
+ }
+ }
+
+ public List getClassPath()
+ {
+ return elements;
+ }
+
+ public Classpath append( Classpath otherClassPathToAppend )
+ {
+ int additionalLength = otherClassPathToAppend != null ?
otherClassPathToAppend.size() : 0;
+ List combinedClassPath = new ArrayList( elements.size() +
additionalLength );
+
+ combinedClassPath.addAll( elements );
+
+ if ( otherClassPathToAppend != null )
+ {
+ Iterator iterator =
otherClassPathToAppend.getClassPath().iterator();
+ while ( iterator.hasNext() )
+ {
+ String element = (String) iterator.next();
+ if ( !elementSet.contains( element ) )
+ {
+ combinedClassPath.add( element );
+ }
+ }
+ }
+ return new Classpath( combinedClassPath );
+ }
+
+
+ public void addClassPathElementUrl( String path )
+ {
+ if ( !elementSet.contains( path ) )
+ {
+ elements.add( path );
+ elementSet.add( path );
+ }
+ }
+
+ public Object get( int index )
+ {
+ return elements.get( index );
+ }
+
+ public int size()
+ {
+ return elements.size();
+ }
+
+ public String getClassPathAsString()
+ {
+ StringBuffer sb = new StringBuffer();
+ for ( int i = 0; i < elements.size(); i++ )
+ {
+ sb.append( elements.get( i ) ).append( File.pathSeparatorChar );
+ }
+ return sb.toString();
+ }
+
+ public List getAsUrlList()
+ throws MalformedURLException
+ {
+ List urls = new ArrayList();
+
+ for ( Iterator i = elements.iterator(); i.hasNext(); )
+ {
+ String url = (String) i.next();
+
+ if ( url != null )
+ {
+ File f = new File( url );
+ urls.add( UrlUtils.getURL( f ) );
+ }
+ }
+ return urls;
+ }
+
+ public void setForkProperties( Properties properties, String prefix )
+ {
+ for ( int i = 0; i < elements.size(); i++ )
+ {
+ String url = (String) elements.get( i );
+ properties.setProperty( prefix + i, url );
+ }
+ }
+
+}
Propchange:
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/Classpath.java
------------------------------------------------------------------------------
svn:eol-style = native
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=1039969&r1=1039968&r2=1039969&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
Sun Nov 28 22:46:53 2010
@@ -20,16 +20,12 @@ package org.apache.maven.surefire.booter
*/
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;
@@ -47,11 +43,9 @@ import java.util.SortedMap;
public class ClasspathConfiguration
{
- private final List classPathUrls = new ArrayList();
+ private final Classpath classpathUrls = new Classpath();
- private final List surefireClassPathUrls = new ArrayList();
-
- private final List surefireBootClassPathUrls = new ArrayList();
+ private final Classpath surefireClasspathUrls = new Classpath();
/**
* Whether to enable assertions or not (can be affected by the fork
arguments, and the ability to do so based on the
@@ -63,7 +57,6 @@ public class ClasspathConfiguration
private final boolean childDelegation;
-
public ClasspathConfiguration( boolean enableAssertions, boolean
childDelegation )
{
this.enableAssertions = enableAssertions;
@@ -73,8 +66,8 @@ public class ClasspathConfiguration
/*
* Reads the config from the supplied stream. Closes the stream.
*/
- public ClasspathConfiguration( SortedMap classPathUrls, SortedMap
surefireClassPathUrls, Collection booterClassPath,
- boolean enableAssertions, boolean
childDelegation )
+ public ClasspathConfiguration( SortedMap classPathUrls, SortedMap
surefireClassPathUrls, boolean enableAssertions,
+ boolean childDelegation )
throws IOException
{
@@ -83,37 +76,21 @@ public class ClasspathConfiguration
for ( Iterator cpi = classPathUrls.keySet().iterator(); cpi.hasNext();
)
{
String url = (String) classPathUrls.get( cpi.next() );
- this.classPathUrls.add( url );
+ this.classpathUrls.addClassPathElementUrl( 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 );
+ this.surefireClasspathUrls.addClassPathElementUrl( 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 );
- }
-
+ classpathUrls.setForkProperties( properties, "classPathUrl." );
+ surefireClasspathUrls.setForkProperties( properties,
"surefireClassPathUrl." );
properties.setProperty( "enableAssertions", String.valueOf(
enableAssertions ) );
properties.setProperty( "childDelegation", String.valueOf(
childDelegation ) );
}
@@ -134,54 +111,33 @@ public class ClasspathConfiguration
}
}
- 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 );
+ return useSystemClassLoader
+ ? ClassLoader.getSystemClassLoader()
+ : createTestClassLoader( this.childDelegation );
}
public ClassLoader createTestClassLoader( boolean childDelegation )
throws SurefireExecutionException
{
- return createClassLoaderSEE( getClassPathUrls(), null, childDelegation
);
+ return createClassLoaderSEE( classpathUrls, null, childDelegation );
}
- public ClassLoader createTestClassLoader( )
+ public ClassLoader createTestClassLoader()
throws SurefireExecutionException
{
- return createClassLoaderSEE( getClassPathUrls(), null,
this.childDelegation );
+ return createClassLoaderSEE( classpathUrls, null, this.childDelegation
);
}
public ClassLoader createSurefireClassLoader( ClassLoader parent )
throws SurefireExecutionException
{
- return createClassLoaderSEE( getSurefireClassPathUrls(), parent, false
);
+ return createClassLoaderSEE( surefireClasspathUrls, parent, false );
}
- private ClassLoader createClassLoaderSEE( List classPathUrls, ClassLoader
parent, boolean childDelegation )
+ private ClassLoader createClassLoaderSEE( Classpath classPathUrls,
ClassLoader parent, boolean childDelegation )
throws SurefireExecutionException
{
try
@@ -195,22 +151,10 @@ public class ClasspathConfiguration
}
- private ClassLoader createClassLoader( List classPathUrls, ClassLoader
parent, boolean childDelegation )
+ private ClassLoader createClassLoader( Classpath 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 ) );
- }
- }
-
+ List urls = classPathUrls.getAsUrlList();
IsolatedClassLoader classLoader = new IsolatedClassLoader( parent,
childDelegation );
if ( assertionStatusMethod != null )
{
@@ -240,42 +184,18 @@ public class ClasspathConfiguration
return classLoader;
}
- public List getSurefireClassPathUrls()
- {
- return surefireClassPathUrls;
- }
-
- public List getSurefireBootClassPathUrls()
+ public Classpath getTestClasspath()
{
- return surefireBootClassPathUrls;
+ return classpathUrls;
}
- public void addClassPathUrl( String path )
+ 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 );
- }
+ classpathUrls.addClassPathElementUrl( path );
}
- public List getClassPathUrls()
+ public void addSurefireClasspathUrl( String path )
{
- return classPathUrls;
+ surefireClasspathUrls.addClassPathElementUrl( path );
}
}
Modified:
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireStarter.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireStarter.java?rev=1039969&r1=1039968&r2=1039969&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireStarter.java
(original)
+++
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireStarter.java
Sun Nov 28 22:46:53 2010
@@ -84,7 +84,7 @@ public class SurefireStarter
// The test classloader must be constructed first to avoid issues
with commons-logging until we properly
// separate the TestNG classloader
ClassLoader testsClassLoader;
- String testClassPath =
getClasspathConfiguration().getTestClassPathAsString();
+ String testClassPath =
getClasspathConfiguration().getTestClasspath().getClassPathAsString();
System.setProperty( "surefire.test.class.path", testClassPath );
if ( booterConfiguration.isManifestOnlyJarRequestedAndUsable() )
{
Added:
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ClasspathTest.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ClasspathTest.java?rev=1039969&view=auto
==============================================================================
---
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ClasspathTest.java
(added)
+++
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ClasspathTest.java
Sun Nov 28 22:46:53 2010
@@ -0,0 +1,87 @@
+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 junit.framework.TestCase;
+
+import java.io.File;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class ClasspathTest
+ extends TestCase
+{
+ public void testGetClassPath()
+ throws Exception
+ {
+ Classpath classpath = new Classpath();
+ classpath.addClassPathElementUrl( "foo.jar" );
+ classpath.addClassPathElementUrl( "bar.jar" );
+ assertEquals( expected, classpath.getClassPathAsString() );
+ }
+
+ public void testGetClassPathNoDupes()
+ throws Exception
+ {
+ Classpath classPath = getWith2DistinctElements();
+ assertEquals( expected, classPath.getClassPathAsString() );
+ }
+
+ public void testGetClassPathNoDupes2()
+ throws Exception
+ {
+ Classpath classpath = getWith2DistinctElements();
+ assertEquals( expected, classpath.append( getWith2DistinctElements()
).getClassPathAsString() );
+ }
+
+ final String expected = "foo.jar" + File.pathSeparatorChar + "bar.jar" +
File.pathSeparatorChar;
+
+ private Classpath getWith2DistinctElements()
+ {
+ Classpath classpath = new Classpath();
+ classpath.addClassPathElementUrl( "foo.jar" );
+ classpath.addClassPathElementUrl( "bar.jar" );
+ classpath.addClassPathElementUrl( "foo.jar" );
+ return classpath;
+ }
+
+ public void testGetAsUrlList()
+ throws Exception
+ {
+ final List asUrlList = getWith2DistinctElements().getAsUrlList();
+ assertEquals( 2, asUrlList.size() );
+ assertTrue( asUrlList.get( 0 ).toString().endsWith( "foo.jar" ) );
+ assertTrue( asUrlList.get( 1 ).toString().endsWith( "bar.jar" ) );
+ }
+
+ public void testSetForkProperties()
+ throws Exception
+ {
+ Properties properties = new Properties();
+ getWith2DistinctElements().setForkProperties( properties, "test" );
+ assertEquals( "foo.jar", properties.get( "test0" ) );
+ assertEquals( "bar.jar", properties.get( "test1" ) );
+ }
+
+}
Propchange:
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/ClasspathTest.java
------------------------------------------------------------------------------
svn:eol-style = native