o Fixed legacy artifact creation by metadata source

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@807836 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-08-25 22:16:19 +00:00
parent 3dd5ffbcaf
commit e8f81a7d36
1 changed files with 35 additions and 22 deletions

View File

@ -223,30 +223,40 @@ public class MavenMetadataSource
private Artifact createDependencyArtifact( Dependency dependency, Artifact owner, Artifact pom )
throws ArtifactMetadataRetrievalException
{
String effectiveScope = getEffectiveScope( dependency.getScope(), ( owner != null ) ? owner.getScope() : null );
if ( effectiveScope == null )
{
return null;
}
VersionRange versionRange;
try
{
versionRange = VersionRange.createFromVersionSpec( dependency.getVersion() );
String inheritedScope = ( owner != null ) ? owner.getScope() : null;
ArtifactFilter inheritedFilter = ( owner != null ) ? owner.getDependencyFilter() : null;
return createDependencyArtifact( repositorySystem, dependency, inheritedScope, inheritedFilter );
}
catch ( InvalidVersionSpecificationException e )
{
throw new ArtifactMetadataRetrievalException( "Invalid version for dependency "
+ dependency.getManagementKey() + ": " + e.getMessage(), e, pom );
}
}
private static Artifact createDependencyArtifact( ArtifactFactory factory, Dependency dependency, String inheritedScope,
ArtifactFilter inheritedFilter )
throws InvalidVersionSpecificationException
{
String effectiveScope = getEffectiveScope( dependency.getScope(), inheritedScope );
if ( effectiveScope == null )
{
return null;
}
VersionRange versionRange = VersionRange.createFromVersionSpec( dependency.getVersion() );
Artifact dependencyArtifact =
repositorySystem.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(),
versionRange, dependency.getType(), dependency.getClassifier(),
effectiveScope, dependency.isOptional() );
factory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(), versionRange,
dependency.getType(), dependency.getClassifier(), effectiveScope,
dependency.isOptional() );
ArtifactFilter dependencyFilter = ( owner != null ) ? owner.getDependencyFilter() : null;
ArtifactFilter dependencyFilter = inheritedFilter;
if ( dependencyFilter != null && !dependencyFilter.include( dependencyArtifact ) )
{
@ -263,7 +273,7 @@ public class MavenMetadataSource
return dependencyArtifact;
}
private String getEffectiveScope( String originalScope, String inheritedScope )
private static String getEffectiveScope( String originalScope, String inheritedScope )
{
String effectiveScope = Artifact.SCOPE_RUNTIME;
@ -304,7 +314,7 @@ public class MavenMetadataSource
return effectiveScope;
}
private ArtifactFilter createDependencyFilter( Dependency dependency, ArtifactFilter inheritedFilter )
private static ArtifactFilter createDependencyFilter( Dependency dependency, ArtifactFilter inheritedFilter )
{
ArtifactFilter effectiveFilter = inheritedFilter;
@ -398,19 +408,22 @@ public class MavenMetadataSource
@Deprecated
public static Set<Artifact> createArtifacts( ArtifactFactory artifactFactory, List<Dependency> dependencies, String inheritedScope, ArtifactFilter dependencyFilter, MavenProject project )
throws InvalidDependencyVersionException
{
return createArtifacts( artifactFactory, dependencies, dependencyFilter );
}
private static Set<Artifact> createArtifacts( ArtifactFactory factory, List<Dependency> dependencies, ArtifactFilter filter )
{
Set<Artifact> artifacts = new LinkedHashSet<Artifact>();
for ( Dependency d : dependencies )
{
Artifact dependencyArtifact = factory.createArtifact( d.getGroupId(), d.getArtifactId(), d.getVersion(), d.getScope(), d.getType() );
Artifact dependencyArtifact;
try
{
dependencyArtifact = createDependencyArtifact( artifactFactory, d, inheritedScope, dependencyFilter );
}
catch ( InvalidVersionSpecificationException e )
{
throw new InvalidDependencyVersionException( project.getId(), d, project.getFile(), e );
}
if ( filter.include( dependencyArtifact ) )
if ( dependencyArtifact != null )
{
artifacts.add( dependencyArtifact );
}