transitive test dependencies should be ignored

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163488 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-03-08 06:01:43 +00:00
parent f35b9869af
commit b5f8943edf
2 changed files with 30 additions and 28 deletions

View File

@ -38,13 +38,14 @@
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class MavenMetadataSource
implements ArtifactMetadataSource
public class MavenMetadataSource implements ArtifactMetadataSource
{
private MavenProjectBuilder mavenProjectBuilder;
private ArtifactResolver artifactResolver;
/** @todo remove. */
/**
* @todo remove.
*/
private MavenXpp3Reader reader = new MavenXpp3Reader();
public MavenMetadataSource( ArtifactResolver artifactResolver )
@ -65,10 +66,8 @@ public Set retrieve( Artifact artifact, ArtifactRepository localRepository, Set
throws ArtifactMetadataRetrievalException
{
Set artifacts;
Artifact metadataArtifact = new DefaultArtifact( artifact.getGroupId(),
artifact.getArtifactId(),
artifact.getVersion(),
"pom" );
Artifact metadataArtifact = new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(),
artifact.getVersion(), "pom" );
try
{
artifactResolver.resolve( metadataArtifact, remoteRepositories, localRepository );
@ -106,33 +105,30 @@ protected Set createArtifacts( List dependencies, String scope, ArtifactReposito
{
Dependency d = (Dependency) i.next();
Artifact artifact = createArtifact( d, scope, localRepository );
projectArtifacts.add( artifact );
if ( artifact != null )
{
projectArtifacts.add( artifact );
}
}
return projectArtifacts;
}
protected Artifact createArtifact( Dependency dependency, String scope, ArtifactRepository localRepository )
{
// TODO: duplicated with the ArtifactFactory, localRepository not used (should be used here to resolve path?
Artifact artifact = new DefaultArtifact( dependency.getGroupId(),
dependency.getArtifactId(),
dependency.getVersion(),
transitiveScope( dependency.getScope(), scope ),
dependency.getType(),
dependency.getType() );
return artifact;
}
// TODO: can refactor
if ( Artifact.SCOPE_TEST.equals( scope ) )
{
return null;
}
private String transitiveScope( String desiredScope, String artifactScope )
{
// TODO: duplicated with the ArtifactFactory, localRepository not used (should be used here to resolve path?
// TODO: scope handler
if ( Artifact.SCOPE_TEST.equals( artifactScope ) || Artifact.SCOPE_TEST.equals( desiredScope ) )
String desiredScope = Artifact.SCOPE_RUNTIME;
if ( Artifact.SCOPE_TEST.equals( dependency.getScope() ) )
{
return Artifact.SCOPE_TEST;
}
else
{
return Artifact.SCOPE_RUNTIME;
desiredScope = Artifact.SCOPE_TEST;
}
return new DefaultArtifact( dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(),
desiredScope, dependency.getType(), dependency.getType() );
}
}

View File

@ -57,8 +57,15 @@ public void testProjectClasspath()
checkArtifactIdScope( project, "runtime", "runtime" );
checkArtifactIdScope( project, "default", "compile" );
// check all transitive deps of a test dependency are test scope
checkGroupIdScope( project, "test", "test" );
// check all transitive deps of a test dependency are skipped
artifact = getArtifact( project, "maven-test-test", "scope-compile" );
assertNull( "Check no test dependencies are transitive", artifact );
artifact = getArtifact( project, "maven-test-test", "scope-test" );
assertNull( "Check no test dependencies are transitive", artifact );
artifact = getArtifact( project, "maven-test-test", "scope-default" );
assertNull( "Check no test dependencies are transitive", artifact );
artifact = getArtifact( project, "maven-test-test", "scope-runtime" );
assertNull( "Check no test dependencies are transitive", artifact );
// check all transitive deps of a runtime dependency are runtime scope, except for test
checkGroupIdScope( project, "runtime", "runtime" );
@ -101,7 +108,6 @@ private Artifact getArtifact( MavenProject project, String groupId, String artif
return a;
}
}
fail( "Dependency " + artifactId + " not found" );
return null;
}
}