mirror of https://github.com/apache/maven.git
add basic test dependency handling
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163466 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
17b616537e
commit
6c36fe6f71
|
@ -26,6 +26,8 @@ public interface Artifact
|
|||
|
||||
String getVersion();
|
||||
|
||||
String getScope();
|
||||
|
||||
String getType();
|
||||
|
||||
String getExtension();
|
||||
|
|
|
@ -37,28 +37,39 @@ public class DefaultArtifact
|
|||
|
||||
private String type;
|
||||
|
||||
private String scope;
|
||||
|
||||
private String extension;
|
||||
|
||||
private String path;
|
||||
|
||||
public DefaultArtifact( String groupId, String artifactId, String version, String type, String extension )
|
||||
public DefaultArtifact( String groupId, String artifactId, String version, String scope, String type,
|
||||
String extension )
|
||||
{
|
||||
this.groupId = groupId;
|
||||
|
||||
this.artifactId = artifactId;
|
||||
|
||||
this.version = version;
|
||||
|
||||
this.type = type;
|
||||
|
||||
this.scope = scope;
|
||||
this.extension = extension;
|
||||
}
|
||||
|
||||
/** @todo this should be replaced by type handler */
|
||||
public DefaultArtifact( String groupId, String artifactId, String version, String type, String extension )
|
||||
{
|
||||
this( groupId, artifactId, version, null, type, extension );
|
||||
}
|
||||
|
||||
public DefaultArtifact( String groupId, String artifactId, String version, String type )
|
||||
{
|
||||
this( groupId, artifactId, version, type, type );
|
||||
}
|
||||
|
||||
public String getScope()
|
||||
{
|
||||
return scope;
|
||||
}
|
||||
|
||||
public String getGroupId()
|
||||
{
|
||||
return groupId;
|
||||
|
|
|
@ -2,13 +2,13 @@ package org.apache.maven.artifact.resolver;
|
|||
|
||||
import org.apache.maven.artifact.AbstractArtifactComponent;
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.resolver.transform.ArtifactRequestTransformation;
|
||||
import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException;
|
||||
import org.apache.maven.artifact.manager.WagonManager;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||
import org.apache.maven.artifact.resolver.transform.ArtifactRequestTransformation;
|
||||
import org.apache.maven.wagon.TransferFailedException;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -187,11 +187,11 @@ public class DefaultArtifactResolver
|
|||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
protected ArtifactResolutionResult collect( Set artifacts,
|
||||
ArtifactRepository localRepository,
|
||||
Set remoteRepositories,
|
||||
ArtifactMetadataSource source,
|
||||
ArtifactFilter filter )
|
||||
private ArtifactResolutionResult collect( Set artifacts,
|
||||
ArtifactRepository localRepository,
|
||||
Set remoteRepositories,
|
||||
ArtifactMetadataSource source,
|
||||
ArtifactFilter filter )
|
||||
throws TransitiveArtifactResolutionException
|
||||
{
|
||||
ArtifactResolutionResult result = new ArtifactResolutionResult();
|
||||
|
@ -242,6 +242,7 @@ public class DefaultArtifactResolver
|
|||
|
||||
try
|
||||
{
|
||||
// TODO: need to convert scope compile -> runtime using scope handler
|
||||
referencedDependencies = source.retrieve( newArtifact, localRepository, remoteRepositories );
|
||||
}
|
||||
catch ( ArtifactMetadataRetrievalException e )
|
||||
|
|
|
@ -117,6 +117,8 @@ public class MavenMetadataSource
|
|||
Artifact artifact = new DefaultArtifact( dependency.getGroupId(),
|
||||
dependency.getArtifactId(),
|
||||
dependency.getVersion(),
|
||||
dependency.getScope(),
|
||||
dependency.getType(),
|
||||
dependency.getType() );
|
||||
return artifact;
|
||||
}
|
||||
|
|
|
@ -51,6 +51,8 @@ public class DefaultArtifactFactory
|
|||
Artifact artifact = new DefaultArtifact( dependency.getGroupId(),
|
||||
dependency.getArtifactId(),
|
||||
dependency.getVersion(),
|
||||
dependency.getScope(),
|
||||
dependency.getType(),
|
||||
dependency.getType() );
|
||||
|
||||
return artifact;
|
||||
|
|
|
@ -209,35 +209,51 @@ public class MavenProject
|
|||
return list;
|
||||
}
|
||||
|
||||
/* TODO: remove - should be using a type handler - is being used by introspection in plugins. */
|
||||
public String[] getClasspathElements()
|
||||
public List getCompileClasspathElements()
|
||||
{
|
||||
int size = getArtifacts().size();
|
||||
List list = new ArrayList( getArtifacts().size() );
|
||||
|
||||
String[] classpathElements = new String[size + 1];
|
||||
|
||||
int i = 0;
|
||||
|
||||
for ( Iterator it = getArtifacts().iterator(); it.hasNext(); )
|
||||
for ( Iterator i = getArtifacts().iterator(); i.hasNext(); )
|
||||
{
|
||||
Artifact artifact = (Artifact) it.next();
|
||||
Artifact a = (Artifact) i.next();
|
||||
|
||||
if ( isAddedToClasspath( artifact ) )
|
||||
// TODO: let the scope handler deal with this
|
||||
if ( a.getScope() == null || "compile".equals( a.getScope() ) )
|
||||
{
|
||||
classpathElements[i++] = artifact.getPath();
|
||||
list.add( a.getPath() );
|
||||
}
|
||||
}
|
||||
|
||||
classpathElements[i] = getBuild().getOutput();
|
||||
|
||||
return classpathElements;
|
||||
return list;
|
||||
}
|
||||
|
||||
public boolean isAddedToClasspath( Artifact artifact )
|
||||
public List getTestClasspathElements()
|
||||
{
|
||||
String type = artifact.getType().trim();
|
||||
List list = new ArrayList( getArtifacts().size() + 1 );
|
||||
|
||||
if ( type.equals( "jar" ) || type.equals( "ejb" ) || type.equals( "test" ) )
|
||||
list.add( getBuild().getOutput() );
|
||||
|
||||
for ( Iterator i = getArtifacts().iterator(); i.hasNext(); )
|
||||
{
|
||||
Artifact a = (Artifact) i.next();
|
||||
|
||||
if ( isAddedToClasspath( a ) )
|
||||
{
|
||||
// TODO: let the scope handler deal with this
|
||||
if ( a.getScope() == null || "test".equals( a.getScope() ) || "compile".equals( a.getScope() ) || "runtime".equals( a.getScope() ) )
|
||||
{
|
||||
list.add( a.getPath() );
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private static boolean isAddedToClasspath( Artifact artifact )
|
||||
{
|
||||
String type = artifact.getType();
|
||||
|
||||
// TODO: utilise type handler
|
||||
if ( "jar".equals( type ) || "ejb".equals( type ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import org.codehaus.plexus.compiler.javac.JavacCompiler;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -36,10 +35,10 @@ import java.util.List;
|
|||
*
|
||||
* @parameter
|
||||
* name="classpathElements"
|
||||
* type="String[]"
|
||||
* type="List"
|
||||
* required="true"
|
||||
* validator=""
|
||||
* expression="#project.classpathElements"
|
||||
* expression="#project.compileClasspathElements"
|
||||
* description=""
|
||||
*
|
||||
* @parameter
|
||||
|
@ -73,7 +72,7 @@ public class CompilerMojo
|
|||
|
||||
String outputDirectory = (String) request.getParameter( "outputDirectory" );
|
||||
|
||||
String[] classpathElements = (String[]) request.getParameter( "classpathElements" );
|
||||
List classpathElements = (List) request.getParameter( "classpathElements" );
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
|
@ -88,7 +87,7 @@ public class CompilerMojo
|
|||
CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
|
||||
|
||||
compilerConfiguration.setOutputLocation(outputDirectory);
|
||||
compilerConfiguration.setClasspathEntries(Arrays.asList(classpathElements));
|
||||
compilerConfiguration.setClasspathEntries( classpathElements );
|
||||
compilerConfiguration.setSourceLocations( compileSourceRootsList );
|
||||
|
||||
/* Compile with debugging info */
|
||||
|
@ -106,11 +105,12 @@ public class CompilerMojo
|
|||
|
||||
if ( debug )
|
||||
{
|
||||
for ( int i = 0; i < classpathElements.length; i++ )
|
||||
for ( Iterator i = classpathElements.iterator(); i.hasNext(); )
|
||||
{
|
||||
String message;
|
||||
|
||||
if ( new File( classpathElements[i] ).exists() )
|
||||
String classpathElement = (String) i.next();
|
||||
if ( new File( classpathElement ).exists() )
|
||||
{
|
||||
message = "present in repository.";
|
||||
}
|
||||
|
@ -119,8 +119,7 @@ public class CompilerMojo
|
|||
message = "Warning! not present in repository!";
|
||||
}
|
||||
|
||||
// System.out.println( "classpathElements[ "+ i +" ] = " + classpathElements[i] + ": " + message );
|
||||
request.getLog().debug( "classpathElements[ "+ i +" ] = " + classpathElements[i] + ": " + message );
|
||||
request.getLog().debug( "classpathElements[ "+ i +" ] = " + classpathElement + ": " + message );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ package org.apache.maven.plugin;
|
|||
*
|
||||
* @description Compiles test sources
|
||||
*
|
||||
* @requiresDependencyResolution
|
||||
*
|
||||
* @parameter
|
||||
* name="compileSourceRootsList"
|
||||
* type="java.util.List"
|
||||
|
@ -24,10 +26,10 @@ package org.apache.maven.plugin;
|
|||
* description=""
|
||||
* @parameter
|
||||
* name="classpathElements"
|
||||
* type="String[]"
|
||||
* type="List"
|
||||
* required="true"
|
||||
* validator=""
|
||||
* expression="#project.classpathElements"
|
||||
* expression="#project.testClasspathElements"
|
||||
* description=""
|
||||
* @parameter
|
||||
* name="debug"
|
||||
|
|
|
@ -1,18 +1,15 @@
|
|||
package org.apache.maven.test;
|
||||
|
||||
import org.codehaus.surefire.SurefireBooter;
|
||||
import org.apache.maven.plugin.AbstractPlugin;
|
||||
import org.apache.maven.plugin.PluginExecutionRequest;
|
||||
import org.apache.maven.plugin.PluginExecutionResponse;
|
||||
import org.codehaus.surefire.SurefireBooter;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
/**
|
||||
* @goal test
|
||||
|
@ -71,7 +68,7 @@ import java.lang.reflect.Array;
|
|||
* type="String[]"
|
||||
* required="true"
|
||||
* validator=""
|
||||
* expression="#project.classpathElements"
|
||||
* expression="#project.testClasspathElements"
|
||||
* description=""
|
||||
* @parameter
|
||||
* name="reportsDirectory"
|
||||
|
@ -112,7 +109,7 @@ public class SurefirePlugin
|
|||
|
||||
String testClassesDirectory = (String) request.getParameter( "testClassesDirectory" );
|
||||
|
||||
String[] classpathElements = (String[]) request.getParameter( "classpathElements" );
|
||||
List testClasspathElements = (List) request.getParameter( "classpathElements" );
|
||||
|
||||
String reportsDirectory = (String) request.getParameter( "reportsDirectory" );
|
||||
|
||||
|
@ -171,12 +168,9 @@ public class SurefirePlugin
|
|||
|
||||
surefireBooter.addClassPathUrl( new File( testClassesDirectory ).getPath() );
|
||||
|
||||
for ( int i = 0; i < classpathElements.length; i++ )
|
||||
for ( Iterator i = testClasspathElements.iterator(); i.hasNext(); )
|
||||
{
|
||||
if(classpathElements[i] != null)
|
||||
{
|
||||
surefireBooter.addClassPathUrl( classpathElements[i] );
|
||||
}
|
||||
surefireBooter.addClassPathUrl( (String) i.next() );
|
||||
}
|
||||
|
||||
surefireBooter.addReport( "org.codehaus.surefire.report.ConsoleReporter" );
|
||||
|
|
Loading…
Reference in New Issue