Author: pgier
Date: Fri May 14 21:16:57 2010
New Revision: 944475
URL: http://svn.apache.org/viewvc?rev=944475&view=rev
Log:
[SUREFIRE-619] Move test classpath generation inside surefire plugin.
Modified:
maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
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=944475&r1=944474&r2=944475&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
Fri May 14 21:16:57 2010
@@ -145,14 +145,6 @@ public class SurefirePlugin
protected MavenProject project;
/**
- * The classpath elements of the project being tested.
- *
- * @parameter default-value="${project.testClasspathElements}"
- * @readonly
- */
- private List classpathElements;
-
- /**
* the classpath elements to be excluded from classpath
* while executing tests. Permitted values are none, runtime
* and all. Meaning of values is:
@@ -991,59 +983,14 @@ public class SurefirePlugin
}
}
- // Check if we need to add configured classes/test classes directories
here.
- // If they are configured, we should remove the default to avoid
conflicts.
- File projectClassesDirectory = new File(
project.getBuild().getOutputDirectory() );
- if ( !projectClassesDirectory.equals( classesDirectory ) )
- {
- int indexToReplace = classpathElements.indexOf(
project.getBuild().getOutputDirectory() );
- if ( indexToReplace != -1 )
- {
- classpathElements.remove( indexToReplace );
- classpathElements.add( indexToReplace,
classesDirectory.getAbsolutePath() );
- }
- else
- {
- classpathElements.add( 1, classesDirectory.getAbsolutePath() );
- }
- }
-
- File projectTestClassesDirectory = new File(
project.getBuild().getTestOutputDirectory() );
- if ( !projectTestClassesDirectory.equals( testClassesDirectory ) )
- {
- int indexToReplace = classpathElements.indexOf(
project.getBuild().getTestOutputDirectory() );
- if ( indexToReplace != -1 )
- {
- classpathElements.remove( indexToReplace );
- classpathElements.add( indexToReplace,
testClassesDirectory.getAbsolutePath() );
- }
- else
- {
- classpathElements.add( 0,
testClassesDirectory.getAbsolutePath() );
- }
- }
-
- //
----------------------------------------------------------------------
- // Remove elements from the classpath according to configuration
- if ( ignoreClasspathElements.equals( "all" ) )
- {
- classpathElements.clear();
- }
- else if ( ignoreClasspathElements.equals( "runtime" ) )
+ List classpathElements = null;
+ try
{
- try
- {
- classpathElements.removeAll(
project.getRuntimeClasspathElements() );
- }
- catch ( DependencyResolutionRequiredException e )
- {
- throw new MojoExecutionException ( "Unable to resolve runtime
classpath elements: " + e, e );
- }
+ classpathElements = generateTestClasspath();
}
- else if ( ! ignoreClasspathElements.equals( "none" ) )
+ catch ( DependencyResolutionRequiredException e )
{
- throw new MojoExecutionException( "Unsupported value for
ignoreClasspathElements parameter: " +
- ignoreClasspathElements );
+ throw new MojoExecutionException( "Unable to generate test
classpath: " + e, e );
}
getLog().debug( "Test Classpath :" );
@@ -1076,18 +1023,6 @@ public class SurefirePlugin
}
}
- if ( additionalClasspathElements != null )
- {
- for ( Iterator i = additionalClasspathElements.iterator();
i.hasNext(); )
- {
- String classpathElement = (String) i.next();
-
- getLog().debug( " " + classpathElement );
-
- surefireBooter.addClassPathUrl( classpathElement );
- }
- }
-
//
----------------------------------------------------------------------
// Forking
//
----------------------------------------------------------------------
@@ -1176,6 +1111,61 @@ public class SurefirePlugin
return surefireBooter;
}
+
+ /**
+ * Generate the test classpath.
+ * @return List containing the classpath elements
+ * @throws DependencyResolutionRequiredException
+ */
+ public List generateTestClasspath()
+ throws DependencyResolutionRequiredException, MojoExecutionException
+ {
+ List classpath = new ArrayList( 2 + project.getArtifacts().size() );
+
+ classpath.add( testClassesDirectory.getAbsolutePath() );
+
+ classpath.add( classesDirectory.getAbsolutePath() );
+
+ for ( Iterator iter = project.getArtifacts().iterator();
iter.hasNext(); )
+ {
+ Artifact artifact = (Artifact) iter.next();
+ if ( artifact.getArtifactHandler().isAddedToClasspath() )
+ {
+ File file = artifact.getFile();
+ if ( file != null )
+ {
+ classpath.add( file.getPath() );
+ }
+ }
+ }
+
+ // Remove elements from the classpath according to configuration
+ if ( ignoreClasspathElements.equals( "all" ) )
+ {
+ classpath.clear();
+ }
+ else if ( ignoreClasspathElements.equals( "runtime" ) )
+ {
+ classpath.removeAll( project.getRuntimeClasspathElements() );
+ }
+ else if ( ! ignoreClasspathElements.equals( "none" ) )
+ {
+ throw new MojoExecutionException( "Unsupported value for
ignoreClasspathElements parameter: " +
+ ignoreClasspathElements );
+ }
+
+ // Add additional configured elements to the classpath
+ if ( additionalClasspathElements != null )
+ {
+ for ( Iterator iter = additionalClasspathElements.iterator();
iter.hasNext(); )
+ {
+ String classpathElement = (String) iter.next();
+ classpath.add( classpathElement );
+ }
+ }
+
+ return classpath;
+ }
private void showMap( Map map, String setting )
{