Author: krosenvold
Date: Thu Nov 18 21:25:00 2010
New Revision: 1036640
URL: http://svn.apache.org/viewvc?rev=1036640&view=rev
Log:
o Extracted a few methods to make method fit in 5 printed pages ;)
No functional changes
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/test/java/org/apache/maven/surefire/booter/BooterSerializerTest.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=1036640&r1=1036639&r2=1036640&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 Nov 18 21:25:00 2010
@@ -223,7 +223,8 @@ public abstract class AbstractSurefireMo
new ClasspathConfiguration( isEnableAssertions(),
isChildDelegation() );
BooterConfiguration booterConfiguration =
- new BooterConfiguration(
forkConfiguration.getBooterForkConfiguration(), classpathConfiguration );
+ new BooterConfiguration(
forkConfiguration.getBooterForkConfiguration(), classpathConfiguration,
+ isRedirectTestOutputToFile() );
Artifact surefireArtifact =
(Artifact) getPluginArtifactMap().get(
"org.apache.maven.surefire:surefire-booter" );
@@ -240,58 +241,11 @@ public abstract class AbstractSurefireMo
{
addArtifact( classpathConfiguration, surefireArtifact );
- junitArtifact = (Artifact) getProjectArtifactMap().get(
getJunitArtifactName() );
- // SUREFIRE-378, junit can have an alternate artifact name
- if ( junitArtifact == null && "junit:junit".equals(
getJunitArtifactName() ) )
- {
- junitArtifact = (Artifact) getProjectArtifactMap().get(
"junit:junit-dep" );
- }
-
- // TODO: this is pretty manual, but I'd rather not require the
plugin > dependencies section right now
- testNgArtifact = (Artifact) getProjectArtifactMap().get(
getTestNGArtifactName() );
-
- if ( testNgArtifact != null )
- {
- VersionRange range = VersionRange.createFromVersionSpec(
"[4.7,)" );
- if ( !range.containsVersion( new DefaultArtifactVersion(
testNgArtifact.getVersion() ) ) )
- {
- throw new MojoFailureException(
- "TestNG support requires version 4.7 or above. You
have declared version " +
- testNgArtifact.getVersion() );
- }
+ junitArtifact = getJunitArtifact();
- convertTestNGParameters();
+ testNgArtifact = getTestNgArtifact();
- if ( this.getTestClassesDirectory() != null )
- {
- getProperties().setProperty( "testng.test.classpath",
getTestClassesDirectory().getAbsolutePath() );
- }
-
- 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( classpathConfiguration, "surefire-testng",
surefireArtifact.getBaseVersion(),
- testNgArtifact );
- }
- else if ( junitArtifact != null && isAnyJunit4( junitArtifact ) )
- {
- if ( isAnyConcurrencySelected() && isJunit47Compatible(
junitArtifact ) )
- {
- convertJunitCoreParameters();
- addProvider( classpathConfiguration, "surefire-junit47",
surefireArtifact.getBaseVersion(), null );
- }
- else
- {
- 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( classpathConfiguration, "surefire-junit",
surefireArtifact.getBaseVersion(), null );
- }
+ setCorrectProvider( classpathConfiguration, surefireArtifact,
junitArtifact, testNgArtifact );
}
catch ( ArtifactNotFoundException e )
{
@@ -307,10 +261,11 @@ public abstract class AbstractSurefireMo
throw new MojoExecutionException( "Error to resolving surefire
provider dependency: " + e.getMessage(), e );
}
+ final boolean isTestNg = testNgArtifact != null;
String providerName;
if ( getSuiteXmlFiles() != null && getSuiteXmlFiles().length > 0 &&
getTest() == null )
{
- if ( testNgArtifact == null )
+ if ( !isTestNg )
{
throw new MojoExecutionException( "suiteXmlFiles is
configured, but there is no TestNG dependency" );
}
@@ -324,55 +279,15 @@ public abstract class AbstractSurefireMo
}
else
{
- List includes;
- List excludes;
+ List includes = getIncludeList();
+ List excludes = getExcludeList();
if ( getTest() != null )
{
- // Check to see if we are running a single test. The raw
parameter will
- // come through if it has not been set.
-
- // FooTest -> **/FooTest.java
-
- includes = new ArrayList();
-
- excludes = new ArrayList();
-
if ( getFailIfNoTests() == null )
{
setFailIfNoTests( Boolean.TRUE );
}
-
- String[] testRegexes = StringUtils.split( getTest(), "," );
-
- for ( int i = 0; i < testRegexes.length; i++ )
- {
- String testRegex = testRegexes[i];
- if ( testRegex.endsWith( ".java" ) )
- {
- testRegex = testRegex.substring( 0, testRegex.length()
- 5 );
- }
- // Allow paths delimited by '.' or '/'
- testRegex = testRegex.replace( '.', '/' );
- includes.add( "**/" + testRegex + ".java" );
- }
- }
- else
- {
- includes = this.getIncludes();
-
- excludes = this.getExcludes();
-
- // defaults here, qdox doesn't like the end javadoc value
- // Have to wrap in an ArrayList as surefire expects an
ArrayList instead of a List for some reason
- if ( includes == null || includes.size() == 0 )
- {
- includes = new ArrayList( Arrays.asList(
getDefaultIncludes() ) );
- }
- if ( excludes == null || excludes.size() == 0 )
- {
- excludes = new ArrayList( Arrays.asList( new String[]{
"**/*$*" } ) );
- }
}
if ( testNgArtifact != null )
@@ -457,13 +372,155 @@ public abstract class AbstractSurefireMo
booterConfiguration.setFailIfNoTests( getFailIfNoTests() != null &&
getFailIfNoTests().booleanValue() );
- booterConfiguration.setRedirectTestOutputToFile(
isRedirectTestOutputToFile() );
-
addReporters( booterConfiguration, forkConfiguration.isForking() );
return booterConfiguration;
}
+ private List getExcludeList()
+ {
+ List excludes;
+ if ( getTest() != null )
+ {
+ // Check to see if we are running a single test. The raw parameter
will
+ // come through if it has not been set.
+ // FooTest -> **/FooTest.java
+
+ excludes = new ArrayList();
+ }
+ else
+ {
+
+ excludes = this.getExcludes();
+
+ // defaults here, qdox doesn't like the end javadoc value
+ // Have to wrap in an ArrayList as surefire expects an ArrayList
instead of a List for some reason
+ if ( excludes == null || excludes.size() == 0 )
+ {
+ excludes = new ArrayList( Arrays.asList( new String[]{
"**/*$*" } ) );
+ }
+ }
+ return excludes;
+ }
+
+ private List getIncludeList()
+ {
+ List includes;
+ if ( getTest() != null )
+ {
+ // Check to see if we are running a single test. The raw parameter
will
+ // come through if it has not been set.
+
+ // FooTest -> **/FooTest.java
+
+ includes = new ArrayList();
+
+ String[] testRegexes = StringUtils.split( getTest(), "," );
+
+ for ( int i = 0; i < testRegexes.length; i++ )
+ {
+ String testRegex = testRegexes[i];
+ if ( testRegex.endsWith( ".java" ) )
+ {
+ testRegex = testRegex.substring( 0, testRegex.length() - 5
);
+ }
+ // Allow paths delimited by '.' or '/'
+ testRegex = testRegex.replace( '.', '/' );
+ includes.add( "**/" + testRegex + ".java" );
+ }
+ }
+ else
+ {
+ includes = this.getIncludes();
+
+ // defaults here, qdox doesn't like the end javadoc value
+ // Have to wrap in an ArrayList as surefire expects an ArrayList
instead of a List for some reason
+ if ( includes == null || includes.size() == 0 )
+ {
+ includes = new ArrayList( Arrays.asList( getDefaultIncludes()
) );
+ }
+ }
+ return includes;
+ }
+
+ private void setCorrectProvider( ClasspathConfiguration
classpathConfiguration, Artifact surefireArtifact,
+ Artifact junitArtifact, Artifact
testNgArtifact )
+ throws ArtifactNotFoundException, ArtifactResolutionException,
MojoExecutionException
+ {
+ if ( testNgArtifact != null )
+ {
+ setTestNgProvider( classpathConfiguration, surefireArtifact,
testNgArtifact );
+ }
+ else if ( junitArtifact != null && isAnyJunit4( junitArtifact ) )
+ {
+ if ( isAnyConcurrencySelected() && isJunit47Compatible(
junitArtifact ) )
+ {
+ convertJunitCoreParameters();
+ setProvider( classpathConfiguration, "surefire-junit47",
surefireArtifact.getBaseVersion(), null );
+ }
+ else
+ {
+ setProvider( 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.
+ setProvider( classpathConfiguration, "surefire-junit",
surefireArtifact.getBaseVersion(), null );
+ }
+ }
+
+ private void setTestNgProvider( ClasspathConfiguration
classpathConfiguration, Artifact surefireArtifact,
+ Artifact testNgArtifact )
+ throws ArtifactNotFoundException, ArtifactResolutionException
+ {
+ convertTestNGParameters();
+
+ if ( this.getTestClassesDirectory() != null )
+ {
+ getProperties().setProperty( "testng.test.classpath",
getTestClassesDirectory().getAbsolutePath() );
+ }
+
+ 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.
+ setProvider( classpathConfiguration, "surefire-testng",
surefireArtifact.getBaseVersion(), testNgArtifact );
+ }
+
+ private Artifact getTestNgArtifact()
+ throws MojoFailureException, InvalidVersionSpecificationException
+ {
+ // TODO: this is pretty manual, but I'd rather not require the plugin
> dependencies section right now
+ Artifact artifact = (Artifact) getProjectArtifactMap().get(
getTestNGArtifactName() );
+
+ if ( artifact != null )
+ {
+ VersionRange range = VersionRange.createFromVersionSpec( "[4.7,)"
);
+ if ( !range.containsVersion( new DefaultArtifactVersion(
artifact.getVersion() ) ) )
+ {
+ throw new MojoFailureException(
+ "TestNG support requires version 4.7 or above. You have
declared version " +
+ artifact.getVersion() );
+ }
+ }
+ return artifact;
+
+ }
+
+ private Artifact getJunitArtifact()
+ {
+ Artifact junitArtifact;
+ junitArtifact = (Artifact) getProjectArtifactMap().get(
getJunitArtifactName() );
+ // SUREFIRE-378, junit can have an alternate artifact name
+ if ( junitArtifact == null && "junit:junit".equals(
getJunitArtifactName() ) )
+ {
+ junitArtifact = (Artifact) getProjectArtifactMap().get(
"junit:junit-dep" );
+ }
+ return junitArtifact;
+ }
+
protected PluginsideForkConfiguration getForkConfiguration()
{
PluginsideForkConfiguration fork = new PluginsideForkConfiguration();
@@ -632,7 +689,8 @@ public abstract class AbstractSurefireMo
}
}
- private void addProvider( ClasspathConfiguration classpathConfiguration,
String provider, String version,
+
+ private void setProvider( ClasspathConfiguration classpathConfiguration,
String provider, String version,
Artifact filteredArtifact )
throws ArtifactNotFoundException, ArtifactResolutionException
{
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=1036640&r1=1036639&r2=1036640&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
Thu Nov 18 21:25:00 2010
@@ -56,21 +56,21 @@ public class BooterConfiguration
private boolean failIfNoTests = false;
- private boolean redirectTestOutputToFile = false;
+ private final boolean redirectTestOutputToFile;
private Properties properties; // todo: Zap out of here !
Object[] dirScannerParams;
- /**
- * This field is set to true if it's running from main. It's used to help
decide what classloader to use.
- */
- private boolean forked;
+ private final boolean isInForkedVm;
- public BooterConfiguration( ForkConfiguration forkConfiguration,
ClasspathConfiguration classpathConfiguration )
+ public BooterConfiguration( ForkConfiguration forkConfiguration,
ClasspathConfiguration classpathConfiguration,
+ boolean redirectTestOutputToFile)
{
this.forkConfiguration = forkConfiguration;
this.classpathConfiguration = classpathConfiguration;
+ this.isInForkedVm = false;
+ this.redirectTestOutputToFile = redirectTestOutputToFile;
}
public BooterConfiguration( ForkConfiguration forkConfiguration,
ClasspathConfiguration classpathConfiguration,
@@ -81,10 +81,11 @@ public class BooterConfiguration
this.classpathConfiguration = classpathConfiguration;
this.suiteDefinition = suiteDefinition;
this.reports.addAll( reports );
- this.forked = forked;
+ this.isInForkedVm = forked;
this.dirScannerParams = dirScannerParams;
this.failIfNoTests = failIfNoTests;
- this.properties = properties; // Hack hack. This must go
+ this.redirectTestOutputToFile = false;
+ this.properties = properties; // Todo: Hack hack. This must go
}
@@ -95,7 +96,7 @@ public class BooterConfiguration
public boolean useSystemClassLoader()
{
- return forkConfiguration.isUseSystemClassLoader() && ( forked ||
forkConfiguration.isForking() );
+ return forkConfiguration.isUseSystemClassLoader() && ( isInForkedVm ||
forkConfiguration.isForking() );
}
@@ -140,17 +141,6 @@ public class BooterConfiguration
this.failIfNoTests = failIfNoTests;
}
- /**
- * When forking, setting this to true will make the test output to be
saved in a file instead of showing it on the
- * standard output
- *
- * @param redirectTestOutputToFile to redirect test output to file
- */
- public void setRedirectTestOutputToFile( boolean redirectTestOutputToFile )
- {
- this.redirectTestOutputToFile = redirectTestOutputToFile;
- }
-
public void setDirectoryScannerOptions( File testClassesDirectory, List
includes, List excludes )
{
dirScannerParams = new Object[]{ testClassesDirectory, includes,
excludes };
Modified:
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/BooterSerializerTest.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/BooterSerializerTest.java?rev=1036640&r1=1036639&r2=1036640&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/BooterSerializerTest.java
(original)
+++
maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/booter/BooterSerializerTest.java
Thu Nov 18 21:25:00 2010
@@ -75,6 +75,6 @@ public class BooterSerializerTest
{
ClasspathConfiguration classpathConfiguration = new
ClasspathConfiguration( true, true );
- return new BooterConfiguration( forkConfiguration,
classpathConfiguration );
+ return new BooterConfiguration( forkConfiguration,
classpathConfiguration, false );
}
}