mirror of https://github.com/apache/maven.git
PR: MNG-505
use comparable versions in ranges git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@219630 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4fcc1e1074
commit
27cdfc3cd1
|
@ -23,7 +23,9 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
||||||
|
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||||
import org.apache.maven.model.Dependency;
|
import org.apache.maven.model.Dependency;
|
||||||
|
import org.apache.maven.model.Repository;
|
||||||
import org.apache.maven.project.MavenProjectBuilder;
|
import org.apache.maven.project.MavenProjectBuilder;
|
||||||
import org.apache.maven.project.artifact.MavenMetadataSource;
|
import org.apache.maven.project.artifact.MavenMetadataSource;
|
||||||
import org.apache.tools.ant.BuildException;
|
import org.apache.tools.ant.BuildException;
|
||||||
|
@ -56,6 +58,9 @@ public class DependenciesTask
|
||||||
|
|
||||||
private boolean verbose;
|
private boolean verbose;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @noinspection RefusedBequest
|
||||||
|
*/
|
||||||
public void execute()
|
public void execute()
|
||||||
{
|
{
|
||||||
ArtifactRepository localRepo = createLocalArtifactRepository();
|
ArtifactRepository localRepo = createLocalArtifactRepository();
|
||||||
|
@ -79,7 +84,7 @@ public class DependenciesTask
|
||||||
|
|
||||||
for ( Iterator i = pom.getRepositories().iterator(); i.hasNext(); )
|
for ( Iterator i = pom.getRepositories().iterator(); i.hasNext(); )
|
||||||
{
|
{
|
||||||
org.apache.maven.model.Repository pomRepository = (org.apache.maven.model.Repository) i.next();
|
Repository pomRepository = (Repository) i.next();
|
||||||
|
|
||||||
remoteRepositories.add( createAntRemoteRepository( pomRepository ) );
|
remoteRepositories.add( createAntRemoteRepository( pomRepository ) );
|
||||||
}
|
}
|
||||||
|
@ -91,7 +96,15 @@ public class DependenciesTask
|
||||||
pom = createDummyPom();
|
pom = createDummyPom();
|
||||||
}
|
}
|
||||||
|
|
||||||
Set artifacts = MavenMetadataSource.createArtifacts( artifactFactory, dependencies, null, null );
|
Set artifacts;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
artifacts = MavenMetadataSource.createArtifacts( artifactFactory, dependencies, null, null );
|
||||||
|
}
|
||||||
|
catch ( InvalidVersionSpecificationException e )
|
||||||
|
{
|
||||||
|
throw new BuildException( "Invalid version specification", e );
|
||||||
|
}
|
||||||
|
|
||||||
log( "Resolving dependencies..." );
|
log( "Resolving dependencies..." );
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class DefaultArtifact
|
||||||
this.artifactId = artifactId;
|
this.artifactId = artifactId;
|
||||||
|
|
||||||
// TODO: this would be where we might have a min/max instead
|
// TODO: this would be where we might have a min/max instead
|
||||||
this.version = versionRange != null ? versionRange.getRecommendedVersion() : null;
|
this.version = versionRange != null ? versionRange.getRecommendedVersion().toString() : null;
|
||||||
|
|
||||||
this.artifactHandler = artifactHandler;
|
this.artifactHandler = artifactHandler;
|
||||||
|
|
||||||
|
|
|
@ -142,11 +142,11 @@ public class DefaultArtifactVersion
|
||||||
return qualifier;
|
return qualifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void parseVersion( String version )
|
public final void parseVersion( String version )
|
||||||
{
|
{
|
||||||
int index = version.indexOf( "-" );
|
int index = version.indexOf( "-" );
|
||||||
|
|
||||||
String part1 = null;
|
String part1;
|
||||||
String part2 = null;
|
String part2 = null;
|
||||||
|
|
||||||
if ( index < 0 )
|
if ( index < 0 )
|
||||||
|
@ -171,22 +171,40 @@ public class DefaultArtifactVersion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StringTokenizer tok = new StringTokenizer( part1, "." );
|
if ( part1.indexOf( "." ) < 0 )
|
||||||
majorVersion = Integer.valueOf( tok.nextToken() );
|
|
||||||
if ( tok.hasMoreTokens() )
|
|
||||||
{
|
{
|
||||||
minorVersion = Integer.valueOf( tok.nextToken() );
|
try
|
||||||
|
{
|
||||||
|
majorVersion = Integer.valueOf( part1 );
|
||||||
|
}
|
||||||
|
catch ( NumberFormatException e )
|
||||||
|
{
|
||||||
|
// qualifier is the whole version, including "-"
|
||||||
|
qualifier = version;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ( tok.hasMoreTokens() )
|
else
|
||||||
{
|
{
|
||||||
incrementalVersion = Integer.valueOf( tok.nextToken() );
|
StringTokenizer tok = new StringTokenizer( part1, "." );
|
||||||
|
majorVersion = Integer.valueOf( tok.nextToken() );
|
||||||
|
if ( tok.hasMoreTokens() )
|
||||||
|
{
|
||||||
|
minorVersion = Integer.valueOf( tok.nextToken() );
|
||||||
|
}
|
||||||
|
if ( tok.hasMoreTokens() )
|
||||||
|
{
|
||||||
|
incrementalVersion = Integer.valueOf( tok.nextToken() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuffer buf = new StringBuffer();
|
||||||
buf.append( majorVersion );
|
if ( majorVersion != null )
|
||||||
|
{
|
||||||
|
buf.append( majorVersion );
|
||||||
|
}
|
||||||
if ( minorVersion != null )
|
if ( minorVersion != null )
|
||||||
{
|
{
|
||||||
buf.append( "." );
|
buf.append( "." );
|
||||||
|
@ -204,7 +222,10 @@ public class DefaultArtifactVersion
|
||||||
}
|
}
|
||||||
else if ( qualifier != null )
|
else if ( qualifier != null )
|
||||||
{
|
{
|
||||||
buf.append( "-" );
|
if ( buf.length() > 0 )
|
||||||
|
{
|
||||||
|
buf.append( "-" );
|
||||||
|
}
|
||||||
buf.append( qualifier );
|
buf.append( qualifier );
|
||||||
}
|
}
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
|
|
|
@ -24,15 +24,16 @@ package org.apache.maven.artifact.versioning;
|
||||||
*/
|
*/
|
||||||
public class Restriction
|
public class Restriction
|
||||||
{
|
{
|
||||||
private final String lowerBound;
|
private final ArtifactVersion lowerBound;
|
||||||
|
|
||||||
private final boolean lowerBoundInclusive;
|
private final boolean lowerBoundInclusive;
|
||||||
|
|
||||||
private final String upperBound;
|
private final ArtifactVersion upperBound;
|
||||||
|
|
||||||
private final boolean upperBoundInclusive;
|
private final boolean upperBoundInclusive;
|
||||||
|
|
||||||
public Restriction( String lowerBound, boolean lowerBoundInclusive, String upperBound, boolean upperBoundInclusive )
|
public Restriction( ArtifactVersion lowerBound, boolean lowerBoundInclusive, ArtifactVersion upperBound,
|
||||||
|
boolean upperBoundInclusive )
|
||||||
{
|
{
|
||||||
this.lowerBound = lowerBound;
|
this.lowerBound = lowerBound;
|
||||||
this.lowerBoundInclusive = lowerBoundInclusive;
|
this.lowerBoundInclusive = lowerBoundInclusive;
|
||||||
|
@ -40,7 +41,7 @@ public class Restriction
|
||||||
this.upperBoundInclusive = upperBoundInclusive;
|
this.upperBoundInclusive = upperBoundInclusive;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLowerBound()
|
public ArtifactVersion getLowerBound()
|
||||||
{
|
{
|
||||||
return lowerBound;
|
return lowerBound;
|
||||||
}
|
}
|
||||||
|
@ -50,7 +51,7 @@ public class Restriction
|
||||||
return lowerBoundInclusive;
|
return lowerBoundInclusive;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUpperBound()
|
public ArtifactVersion getUpperBound()
|
||||||
{
|
{
|
||||||
return upperBound;
|
return upperBound;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,17 +28,17 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class VersionRange
|
public class VersionRange
|
||||||
{
|
{
|
||||||
private final String recommendedVersion;
|
private final ArtifactVersion recommendedVersion;
|
||||||
|
|
||||||
private final List restrictions;
|
private final List restrictions;
|
||||||
|
|
||||||
private VersionRange( String recommendedVersion, List restrictions )
|
private VersionRange( ArtifactVersion recommendedVersion, List restrictions )
|
||||||
{
|
{
|
||||||
this.recommendedVersion = recommendedVersion;
|
this.recommendedVersion = recommendedVersion;
|
||||||
this.restrictions = restrictions;
|
this.restrictions = restrictions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRecommendedVersion()
|
public ArtifactVersion getRecommendedVersion()
|
||||||
{
|
{
|
||||||
return recommendedVersion;
|
return recommendedVersion;
|
||||||
}
|
}
|
||||||
|
@ -51,9 +51,9 @@ public class VersionRange
|
||||||
public static VersionRange createFromVersionSpec( String spec )
|
public static VersionRange createFromVersionSpec( String spec )
|
||||||
throws InvalidVersionSpecificationException
|
throws InvalidVersionSpecificationException
|
||||||
{
|
{
|
||||||
List exclusions = new ArrayList();
|
List restrictions = new ArrayList();
|
||||||
String process = spec;
|
String process = spec;
|
||||||
String version = null;
|
ArtifactVersion version = null;
|
||||||
|
|
||||||
while ( process.startsWith( "[" ) || process.startsWith( "(" ) )
|
while ( process.startsWith( "[" ) || process.startsWith( "(" ) )
|
||||||
{
|
{
|
||||||
|
@ -74,7 +74,7 @@ public class VersionRange
|
||||||
throw new InvalidVersionSpecificationException( "Unbounded range: " + spec );
|
throw new InvalidVersionSpecificationException( "Unbounded range: " + spec );
|
||||||
}
|
}
|
||||||
|
|
||||||
exclusions.add( parseRestriction( process.substring( 0, index + 1 ) ) );
|
restrictions.add( parseRestriction( process.substring( 0, index + 1 ) ) );
|
||||||
|
|
||||||
process = process.substring( index + 1 ).trim();
|
process = process.substring( index + 1 ).trim();
|
||||||
|
|
||||||
|
@ -86,18 +86,18 @@ public class VersionRange
|
||||||
|
|
||||||
if ( process.length() > 0 )
|
if ( process.length() > 0 )
|
||||||
{
|
{
|
||||||
if ( exclusions.size() > 0 )
|
if ( restrictions.size() > 0 )
|
||||||
{
|
{
|
||||||
throw new InvalidVersionSpecificationException(
|
throw new InvalidVersionSpecificationException(
|
||||||
"Only fully-qualified sets allowed in multiple set scenario: " + spec );
|
"Only fully-qualified sets allowed in multiple set scenario: " + spec );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
version = process;
|
version = new DefaultArtifactVersion( process );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new VersionRange( version, exclusions );
|
return new VersionRange( version, restrictions );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Restriction parseRestriction( String spec )
|
private static Restriction parseRestriction( String spec )
|
||||||
|
@ -118,7 +118,10 @@ public class VersionRange
|
||||||
{
|
{
|
||||||
throw new InvalidVersionSpecificationException( "Single version must be surrounded by []: " + spec );
|
throw new InvalidVersionSpecificationException( "Single version must be surrounded by []: " + spec );
|
||||||
}
|
}
|
||||||
restriction = new Restriction( process, lowerBoundInclusive, process, upperBoundInclusive );
|
|
||||||
|
ArtifactVersion version = new DefaultArtifactVersion( process );
|
||||||
|
|
||||||
|
restriction = new Restriction( version, lowerBoundInclusive, version, upperBoundInclusive );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -129,16 +132,18 @@ public class VersionRange
|
||||||
throw new InvalidVersionSpecificationException( "Range cannot have identical boundaries: " + spec );
|
throw new InvalidVersionSpecificationException( "Range cannot have identical boundaries: " + spec );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( lowerBound.length() == 0 )
|
ArtifactVersion lowerVersion = null;
|
||||||
|
if ( lowerBound.length() > 0 )
|
||||||
{
|
{
|
||||||
lowerBound = null;
|
lowerVersion = new DefaultArtifactVersion( lowerBound );
|
||||||
}
|
}
|
||||||
if ( upperBound.length() == 0 )
|
ArtifactVersion upperVersion = null;
|
||||||
|
if ( upperBound.length() > 0 )
|
||||||
{
|
{
|
||||||
upperBound = null;
|
upperVersion = new DefaultArtifactVersion( upperBound );
|
||||||
}
|
}
|
||||||
|
|
||||||
restriction = new Restriction( lowerBound, lowerBoundInclusive, upperBound, upperBoundInclusive );
|
restriction = new Restriction( lowerVersion, lowerBoundInclusive, upperVersion, upperBoundInclusive );
|
||||||
}
|
}
|
||||||
|
|
||||||
return restriction;
|
return restriction;
|
||||||
|
@ -146,6 +151,27 @@ public class VersionRange
|
||||||
|
|
||||||
public static VersionRange createFromVersion( String version )
|
public static VersionRange createFromVersion( String version )
|
||||||
{
|
{
|
||||||
|
return new VersionRange( new DefaultArtifactVersion( version ), Collections.EMPTY_LIST );
|
||||||
|
}
|
||||||
|
|
||||||
|
public VersionRange restrict( VersionRange restriction )
|
||||||
|
{
|
||||||
|
ArtifactVersion version = max( recommendedVersion, restriction.getRecommendedVersion() );
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
|
||||||
return new VersionRange( version, Collections.EMPTY_LIST );
|
return new VersionRange( version, Collections.EMPTY_LIST );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ArtifactVersion max( ArtifactVersion v1, ArtifactVersion v2 )
|
||||||
|
{
|
||||||
|
if ( v1.compareTo( v2 ) > 0 )
|
||||||
|
{
|
||||||
|
return v1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return v2;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,15 @@ public class DefaultArtifactVersionTest
|
||||||
assertEquals( "check major version", 1, version.getMajorVersion() );
|
assertEquals( "check major version", 1, version.getMajorVersion() );
|
||||||
assertEquals( "check minor version", 2, version.getMinorVersion() );
|
assertEquals( "check minor version", 2, version.getMinorVersion() );
|
||||||
assertEquals( "check incremental version", 0, version.getIncrementalVersion() );
|
assertEquals( "check incremental version", 0, version.getIncrementalVersion() );
|
||||||
|
assertEquals( "check build number", 0, version.getBuildNumber() );
|
||||||
assertEquals( "check qualifier", "alpha-1-20050205.060708-1", version.getQualifier() );
|
assertEquals( "check qualifier", "alpha-1-20050205.060708-1", version.getQualifier() );
|
||||||
|
|
||||||
|
version = new DefaultArtifactVersion( "RELEASE" );
|
||||||
|
assertEquals( "check major version", 0, version.getMajorVersion() );
|
||||||
|
assertEquals( "check minor version", 0, version.getMinorVersion() );
|
||||||
|
assertEquals( "check incremental version", 0, version.getIncrementalVersion() );
|
||||||
|
assertEquals( "check build number", 0, version.getBuildNumber() );
|
||||||
|
assertEquals( "check qualifier", "RELEASE", version.getQualifier() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testVersionComparing()
|
public void testVersionComparing()
|
||||||
|
|
|
@ -50,22 +50,22 @@ public class VersionRangeTest
|
||||||
Restriction restriction = (Restriction) restrictions.get( 0 );
|
Restriction restriction = (Restriction) restrictions.get( 0 );
|
||||||
assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() );
|
assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() );
|
||||||
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
|
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
|
||||||
assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound() );
|
assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() );
|
||||||
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
|
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
|
||||||
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
|
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
|
||||||
|
|
||||||
range = VersionRange.createFromVersionSpec( "1.0" );
|
range = VersionRange.createFromVersionSpec( "1.0" );
|
||||||
restrictions = range.getRestrictions();
|
restrictions = range.getRestrictions();
|
||||||
assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() );
|
assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() );
|
||||||
assertEquals( CHECK_VERSION_RECOMMENDATION, "1.0", range.getRecommendedVersion() );
|
assertEquals( CHECK_VERSION_RECOMMENDATION, "1.0", range.getRecommendedVersion().toString() );
|
||||||
|
|
||||||
range = VersionRange.createFromVersionSpec( "[1.0]" );
|
range = VersionRange.createFromVersionSpec( "[1.0]" );
|
||||||
restrictions = range.getRestrictions();
|
restrictions = range.getRestrictions();
|
||||||
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
|
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
|
||||||
restriction = (Restriction) restrictions.get( 0 );
|
restriction = (Restriction) restrictions.get( 0 );
|
||||||
assertEquals( CHECK_LOWER_BOUND, "1.0", restriction.getLowerBound() );
|
assertEquals( CHECK_LOWER_BOUND, "1.0", restriction.getLowerBound().toString() );
|
||||||
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
|
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
|
||||||
assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound() );
|
assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() );
|
||||||
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
|
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
|
||||||
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
|
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
|
||||||
|
|
||||||
|
@ -73,9 +73,9 @@ public class VersionRangeTest
|
||||||
restrictions = range.getRestrictions();
|
restrictions = range.getRestrictions();
|
||||||
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
|
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
|
||||||
restriction = (Restriction) restrictions.get( 0 );
|
restriction = (Restriction) restrictions.get( 0 );
|
||||||
assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound() );
|
assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() );
|
||||||
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
|
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
|
||||||
assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound() );
|
assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() );
|
||||||
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
|
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
|
||||||
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
|
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
|
||||||
|
|
||||||
|
@ -83,9 +83,9 @@ public class VersionRangeTest
|
||||||
restrictions = range.getRestrictions();
|
restrictions = range.getRestrictions();
|
||||||
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
|
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
|
||||||
restriction = (Restriction) restrictions.get( 0 );
|
restriction = (Restriction) restrictions.get( 0 );
|
||||||
assertEquals( CHECK_LOWER_BOUND, "1.0", restriction.getLowerBound() );
|
assertEquals( CHECK_LOWER_BOUND, "1.0", restriction.getLowerBound().toString() );
|
||||||
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
|
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
|
||||||
assertEquals( CHECK_UPPER_BOUND, "2.0", restriction.getUpperBound() );
|
assertEquals( CHECK_UPPER_BOUND, "2.0", restriction.getUpperBound().toString() );
|
||||||
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
|
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
|
||||||
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
|
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ public class VersionRangeTest
|
||||||
restrictions = range.getRestrictions();
|
restrictions = range.getRestrictions();
|
||||||
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
|
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
|
||||||
restriction = (Restriction) restrictions.get( 0 );
|
restriction = (Restriction) restrictions.get( 0 );
|
||||||
assertEquals( CHECK_LOWER_BOUND, "1.5", restriction.getLowerBound() );
|
assertEquals( CHECK_LOWER_BOUND, "1.5", restriction.getLowerBound().toString() );
|
||||||
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
|
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
|
||||||
assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() );
|
assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() );
|
||||||
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
|
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
|
||||||
|
@ -105,11 +105,11 @@ public class VersionRangeTest
|
||||||
restriction = (Restriction) restrictions.get( 0 );
|
restriction = (Restriction) restrictions.get( 0 );
|
||||||
assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() );
|
assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() );
|
||||||
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
|
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
|
||||||
assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound() );
|
assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() );
|
||||||
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
|
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
|
||||||
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
|
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
|
||||||
restriction = (Restriction) restrictions.get( 1 );
|
restriction = (Restriction) restrictions.get( 1 );
|
||||||
assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound() );
|
assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() );
|
||||||
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
|
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
|
||||||
assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() );
|
assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() );
|
||||||
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
|
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
|
||||||
|
@ -130,9 +130,22 @@ public class VersionRangeTest
|
||||||
checkInvalidRange( "[1.0,1.2),(1.1,1.3]" );
|
checkInvalidRange( "[1.0,1.2),(1.1,1.3]" );
|
||||||
// overlap
|
// overlap
|
||||||
checkInvalidRange( "[1.1,1.3),(1.0,1.2]" );
|
checkInvalidRange( "[1.1,1.3),(1.0,1.2]" );
|
||||||
|
// ordering
|
||||||
|
checkInvalidRange( "(1.1,1.2],[1.0,1.1)" );
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testIntersections()
|
||||||
|
{
|
||||||
|
VersionRange range1 = VersionRange.createFromVersion( "1.0" );
|
||||||
|
VersionRange range2 = VersionRange.createFromVersion( "1.1" );
|
||||||
|
VersionRange mergedRange = range1.restrict( range2 );
|
||||||
|
assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() );
|
||||||
|
|
||||||
|
mergedRange = range2.restrict( range1 );
|
||||||
|
assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() );
|
||||||
|
}
|
||||||
|
|
||||||
private void checkInvalidRange( String version )
|
private void checkInvalidRange( String version )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||||
import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
|
import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
|
||||||
import org.apache.maven.artifact.resolver.filter.InversionArtifactFilter;
|
import org.apache.maven.artifact.resolver.filter.InversionArtifactFilter;
|
||||||
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
|
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
|
||||||
|
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||||
import org.apache.maven.artifact.versioning.VersionRange;
|
import org.apache.maven.artifact.versioning.VersionRange;
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
|
@ -105,7 +106,7 @@ public class DefaultPluginManager
|
||||||
protected ArtifactResolver artifactResolver;
|
protected ArtifactResolver artifactResolver;
|
||||||
|
|
||||||
protected MavenProjectBuilder mavenProjectBuilder;
|
protected MavenProjectBuilder mavenProjectBuilder;
|
||||||
|
|
||||||
protected MavenPluginMappingBuilder pluginMappingBuilder;
|
protected MavenPluginMappingBuilder pluginMappingBuilder;
|
||||||
// END component requirements
|
// END component requirements
|
||||||
|
|
||||||
|
@ -123,17 +124,19 @@ public class DefaultPluginManager
|
||||||
{
|
{
|
||||||
return pluginCollector.getPluginDescriptorForPrefix( prefix );
|
return pluginCollector.getPluginDescriptorForPrefix( prefix );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Plugin getPluginDefinitionForPrefix( String prefix, MavenSession session, MavenProject project ) throws PluginManagerException
|
public Plugin getPluginDefinitionForPrefix( String prefix, MavenSession session, MavenProject project )
|
||||||
|
throws PluginManagerException
|
||||||
{
|
{
|
||||||
PluginMappingManager mappingManager = getPluginMappingManager( session, project );
|
PluginMappingManager mappingManager = getPluginMappingManager( session, project );
|
||||||
|
|
||||||
Plugin plugin = mappingManager.getByPrefix( prefix );
|
Plugin plugin = mappingManager.getByPrefix( prefix );
|
||||||
|
|
||||||
if ( plugin == null && !mappingManager.isRefreshed() )
|
if ( plugin == null && !mappingManager.isRefreshed() )
|
||||||
{
|
{
|
||||||
getLogger().info( "Refreshing plugin mapping metadata; looking for plugin with prefix: \'" + prefix + "\'." );
|
getLogger().info(
|
||||||
|
"Refreshing plugin mapping metadata; looking for plugin with prefix: \'" + prefix + "\'." );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mappingManager = pluginMappingBuilder.refreshPluginMappingManager( session
|
mappingManager = pluginMappingBuilder.refreshPluginMappingManager( session
|
||||||
|
@ -148,10 +151,10 @@ public class DefaultPluginManager
|
||||||
{
|
{
|
||||||
throw new PluginManagerException( "Error refreshing plugin mappings.", e );
|
throw new PluginManagerException( "Error refreshing plugin mappings.", e );
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin = mappingManager.getByPrefix( prefix );
|
plugin = mappingManager.getByPrefix( prefix );
|
||||||
}
|
}
|
||||||
|
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +178,7 @@ public class DefaultPluginManager
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
VersionRange versionRange = new VersionRange( plugin.getVersion() );
|
VersionRange versionRange = VersionRange.createFromVersionSpec( plugin.getVersion() );
|
||||||
Artifact pluginArtifact = artifactFactory.createPluginArtifact( plugin.getGroupId(),
|
Artifact pluginArtifact = artifactFactory.createPluginArtifact( plugin.getGroupId(),
|
||||||
plugin.getArtifactId(), versionRange );
|
plugin.getArtifactId(), versionRange );
|
||||||
|
|
||||||
|
@ -198,9 +201,12 @@ public class DefaultPluginManager
|
||||||
String artifactId = plugin.getArtifactId();
|
String artifactId = plugin.getArtifactId();
|
||||||
String version = plugin.getVersion();
|
String version = plugin.getVersion();
|
||||||
|
|
||||||
if ( ( groupId == null || artifactId == null || version == null || ( groupId.equals( e.getGroupId() ) &&
|
if ( groupId == null || artifactId == null || version == null )
|
||||||
artifactId.equals( e.getArtifactId() ) && version.equals( e.getVersion() ) ) ) &&
|
{
|
||||||
"maven-plugin".equals( e.getType() ) )
|
throw new PluginNotFoundException( e );
|
||||||
|
}
|
||||||
|
else if ( groupId.equals( e.getGroupId() ) && artifactId.equals( e.getArtifactId() ) &&
|
||||||
|
version.equals( e.getVersion() ) && "maven-plugin".equals( e.getType() ) )
|
||||||
{
|
{
|
||||||
throw new PluginNotFoundException( e );
|
throw new PluginNotFoundException( e );
|
||||||
}
|
}
|
||||||
|
@ -209,6 +215,11 @@ public class DefaultPluginManager
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch ( InvalidVersionSpecificationException e )
|
||||||
|
{
|
||||||
|
throw new PluginVersionResolutionException( plugin.getGroupId(), plugin.getArtifactId(),
|
||||||
|
"Invalid version specification", e );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return pluginCollector.getPluginDescriptor( plugin );
|
return pluginCollector.getPluginDescriptor( plugin );
|
||||||
|
@ -256,7 +267,7 @@ public class DefaultPluginManager
|
||||||
|
|
||||||
String goalName = mojoDescriptor.getFullGoalName();
|
String goalName = mojoDescriptor.getFullGoalName();
|
||||||
|
|
||||||
Mojo plugin = null;
|
Mojo plugin;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -477,7 +488,7 @@ public class DefaultPluginManager
|
||||||
{
|
{
|
||||||
Artifact artifact = (Artifact) it.next();
|
Artifact artifact = (Artifact) it.next();
|
||||||
|
|
||||||
if ( artifact != pluginArtifact )
|
if ( !artifact.equals( pluginArtifact ) )
|
||||||
{
|
{
|
||||||
pluginContainer.addJarResource( artifact.getFile() );
|
pluginContainer.addJarResource( artifact.getFile() );
|
||||||
}
|
}
|
||||||
|
@ -534,7 +545,7 @@ public class DefaultPluginManager
|
||||||
|
|
||||||
if ( parameterMap.containsKey( child.getName() ) )
|
if ( parameterMap.containsKey( child.getName() ) )
|
||||||
{
|
{
|
||||||
extractedConfiguration.addChild( DefaultPluginManager.copyConfiguration( child ) );
|
extractedConfiguration.addChild( copyConfiguration( child ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -711,7 +722,7 @@ public class DefaultPluginManager
|
||||||
for ( int i = 0; i < children.length; i++ )
|
for ( int i = 0; i < children.length; i++ )
|
||||||
{
|
{
|
||||||
PlexusConfiguration child = children[i];
|
PlexusConfiguration child = children[i];
|
||||||
PlexusConfiguration childDom = (XmlPlexusConfiguration) dominant.getChild( child.getName(), false );
|
PlexusConfiguration childDom = dominant.getChild( child.getName(), false );
|
||||||
if ( childDom != null )
|
if ( childDom != null )
|
||||||
{
|
{
|
||||||
mergeConfiguration( childDom, child );
|
mergeConfiguration( childDom, child );
|
||||||
|
@ -803,22 +814,24 @@ public class DefaultPluginManager
|
||||||
private Field findPluginField( Class clazz, String key )
|
private Field findPluginField( Class clazz, String key )
|
||||||
throws NoSuchFieldException
|
throws NoSuchFieldException
|
||||||
{
|
{
|
||||||
try
|
Field field = null;
|
||||||
|
|
||||||
|
while ( field == null )
|
||||||
{
|
{
|
||||||
return clazz.getDeclaredField( key );
|
try
|
||||||
}
|
|
||||||
catch ( NoSuchFieldException e )
|
|
||||||
{
|
|
||||||
Class superclass = clazz.getSuperclass();
|
|
||||||
if ( superclass != Object.class )
|
|
||||||
{
|
{
|
||||||
return findPluginField( superclass, key );
|
field = clazz.getDeclaredField( key );
|
||||||
}
|
}
|
||||||
else
|
catch ( NoSuchFieldException e )
|
||||||
{
|
{
|
||||||
throw e;
|
clazz = clazz.getSuperclass();
|
||||||
|
if ( clazz.equals( Object.class ) )
|
||||||
|
{
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return field;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String createPluginParameterRequiredMessage( MojoDescriptor mojo, Parameter parameter,
|
public static String createPluginParameterRequiredMessage( MojoDescriptor mojo, Parameter parameter,
|
||||||
|
@ -963,36 +976,36 @@ public class DefaultPluginManager
|
||||||
return pluginContainer.lookup( role, roleHint );
|
return pluginContainer.lookup( role, roleHint );
|
||||||
}
|
}
|
||||||
|
|
||||||
private PluginMappingManager getPluginMappingManager( MavenSession session, MavenProject project )
|
private PluginMappingManager getPluginMappingManager( MavenSession session, MavenProject project )
|
||||||
throws PluginManagerException
|
throws PluginManagerException
|
||||||
{
|
|
||||||
PluginMappingManager mappingManager = session.getPluginMappingManager();
|
|
||||||
|
|
||||||
// don't reassemble the plugin mappings if the session has already been configured with them.
|
|
||||||
if ( mappingManager == null )
|
|
||||||
{
|
{
|
||||||
try
|
PluginMappingManager mappingManager = session.getPluginMappingManager();
|
||||||
{
|
|
||||||
List pluginGroupIds = session.getSettings().getPluginGroups();
|
|
||||||
List pluginRepositories = project.getPluginArtifactRepositories();
|
|
||||||
ArtifactRepository localRepository = session.getLocalRepository();
|
|
||||||
|
|
||||||
mappingManager = pluginMappingBuilder.loadPluginMappings( pluginGroupIds, pluginRepositories,
|
// don't reassemble the plugin mappings if the session has already been configured with them.
|
||||||
localRepository );
|
if ( mappingManager == null )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List pluginGroupIds = session.getSettings().getPluginGroups();
|
||||||
|
List pluginRepositories = project.getPluginArtifactRepositories();
|
||||||
|
ArtifactRepository localRepository = session.getLocalRepository();
|
||||||
|
|
||||||
// lazily configure this on the session.
|
mappingManager = pluginMappingBuilder.loadPluginMappings( pluginGroupIds, pluginRepositories,
|
||||||
session.setPluginMappingManager( mappingManager );
|
localRepository );
|
||||||
}
|
|
||||||
catch ( RepositoryMetadataManagementException e )
|
// lazily configure this on the session.
|
||||||
{
|
session.setPluginMappingManager( mappingManager );
|
||||||
throw new PluginManagerException( "Cannot load plugin mappings.", e );
|
}
|
||||||
}
|
catch ( RepositoryMetadataManagementException e )
|
||||||
catch ( PluginMappingManagementException e )
|
{
|
||||||
{
|
throw new PluginManagerException( "Cannot load plugin mappings.", e );
|
||||||
throw new PluginManagerException( "Cannot load plugin mappings.", e );
|
}
|
||||||
|
catch ( PluginMappingManagementException e )
|
||||||
|
{
|
||||||
|
throw new PluginManagerException( "Cannot load plugin mappings.", e );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return mappingManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mappingManager;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
||||||
|
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||||
import org.apache.maven.artifact.versioning.VersionRange;
|
import org.apache.maven.artifact.versioning.VersionRange;
|
||||||
import org.apache.maven.model.Build;
|
import org.apache.maven.model.Build;
|
||||||
import org.apache.maven.model.Dependency;
|
import org.apache.maven.model.Dependency;
|
||||||
|
@ -158,6 +159,7 @@ public class DefaultMavenProjectBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map createManagedVersionMap( DependencyManagement dependencyManagement )
|
private Map createManagedVersionMap( DependencyManagement dependencyManagement )
|
||||||
|
throws ProjectBuildingException
|
||||||
{
|
{
|
||||||
Map map;
|
Map map;
|
||||||
if ( dependencyManagement != null && dependencyManagement.getDependencies() != null )
|
if ( dependencyManagement != null && dependencyManagement.getDependencies() != null )
|
||||||
|
@ -167,11 +169,18 @@ public class DefaultMavenProjectBuilder
|
||||||
{
|
{
|
||||||
Dependency d = (Dependency) i.next();
|
Dependency d = (Dependency) i.next();
|
||||||
|
|
||||||
Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(),
|
try
|
||||||
new VersionRange( d.getVersion() ),
|
{
|
||||||
d.getType(), d.getScope() );
|
VersionRange versionRange = VersionRange.createFromVersionSpec( d.getVersion() );
|
||||||
|
Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(),
|
||||||
map.put( d.getManagementKey(), artifact );
|
versionRange, d.getType(),
|
||||||
|
d.getScope() );
|
||||||
|
map.put( d.getManagementKey(), artifact );
|
||||||
|
}
|
||||||
|
catch ( InvalidVersionSpecificationException e )
|
||||||
|
{
|
||||||
|
throw new ProjectBuildingException( "Unable to parse dependency version", e );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -499,8 +508,7 @@ public class DefaultMavenProjectBuilder
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
reader = new FileReader( file );
|
reader = new FileReader( file );
|
||||||
Model model = modelReader.read( reader );
|
return modelReader.read( reader );
|
||||||
return model;
|
|
||||||
}
|
}
|
||||||
catch ( FileNotFoundException e )
|
catch ( FileNotFoundException e )
|
||||||
{
|
{
|
||||||
|
@ -558,11 +566,20 @@ public class DefaultMavenProjectBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Set createArtifacts( List dependencies )
|
protected Set createArtifacts( List dependencies )
|
||||||
|
throws ProjectBuildingException
|
||||||
{
|
{
|
||||||
return MavenMetadataSource.createArtifacts( artifactFactory, dependencies, null, null );
|
try
|
||||||
|
{
|
||||||
|
return MavenMetadataSource.createArtifacts( artifactFactory, dependencies, null, null );
|
||||||
|
}
|
||||||
|
catch ( InvalidVersionSpecificationException e )
|
||||||
|
{
|
||||||
|
throw new ProjectBuildingException( "Unable to parse dependency version", e );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Set createPluginArtifacts( List plugins )
|
protected Set createPluginArtifacts( List plugins )
|
||||||
|
throws ProjectBuildingException
|
||||||
{
|
{
|
||||||
Set pluginArtifacts = new HashSet();
|
Set pluginArtifacts = new HashSet();
|
||||||
|
|
||||||
|
@ -580,8 +597,17 @@ public class DefaultMavenProjectBuilder
|
||||||
version = p.getVersion();
|
version = p.getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
Artifact artifact = artifactFactory.createPluginArtifact( p.getGroupId(), p.getArtifactId(),
|
Artifact artifact = null;
|
||||||
new VersionRange( version ) );
|
try
|
||||||
|
{
|
||||||
|
artifact = artifactFactory.createPluginArtifact( p.getGroupId(), p.getArtifactId(),
|
||||||
|
VersionRange.createFromVersionSpec( version ) );
|
||||||
|
}
|
||||||
|
catch ( InvalidVersionSpecificationException e )
|
||||||
|
{
|
||||||
|
throw new ProjectBuildingException( "Unable to parse plugin version", e );
|
||||||
|
}
|
||||||
|
|
||||||
if ( artifact != null )
|
if ( artifact != null )
|
||||||
{
|
{
|
||||||
pluginArtifacts.add( artifact );
|
pluginArtifacts.add( artifact );
|
||||||
|
@ -630,9 +656,7 @@ public class DefaultMavenProjectBuilder
|
||||||
{
|
{
|
||||||
URL url = DefaultMavenProjectBuilder.class.getResource( "pom-" + MAVEN_MODEL_VERSION + ".xml" );
|
URL url = DefaultMavenProjectBuilder.class.getResource( "pom-" + MAVEN_MODEL_VERSION + ".xml" );
|
||||||
|
|
||||||
Model superModel = readModel( url );
|
return readModel( url );
|
||||||
|
|
||||||
return superModel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void contextualize( Context context )
|
public void contextualize( Context context )
|
||||||
|
|
|
@ -22,10 +22,10 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||||
import org.apache.maven.artifact.metadata.ResolutionGroup;
|
import org.apache.maven.artifact.metadata.ResolutionGroup;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
|
||||||
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
|
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
|
||||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||||
import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
|
import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
|
||||||
|
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||||
import org.apache.maven.artifact.versioning.VersionRange;
|
import org.apache.maven.artifact.versioning.VersionRange;
|
||||||
import org.apache.maven.model.Dependency;
|
import org.apache.maven.model.Dependency;
|
||||||
import org.apache.maven.model.Exclusion;
|
import org.apache.maven.model.Exclusion;
|
||||||
|
@ -62,7 +62,7 @@ public class MavenMetadataSource
|
||||||
{
|
{
|
||||||
// TODO: only metadata is really needed - resolve as metadata
|
// TODO: only metadata is really needed - resolve as metadata
|
||||||
Artifact pomArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(),
|
Artifact pomArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(),
|
||||||
artifact.getVersion(), artifact.getScope() );
|
artifact.getVersion(), artifact.getScope() );
|
||||||
|
|
||||||
// TODO: this a very thin wrapper around a project builder - is it needed?
|
// TODO: this a very thin wrapper around a project builder - is it needed?
|
||||||
List dependencies = null;
|
List dependencies = null;
|
||||||
|
@ -85,10 +85,15 @@ public class MavenMetadataSource
|
||||||
{
|
{
|
||||||
throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e );
|
throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e );
|
||||||
}
|
}
|
||||||
|
catch ( InvalidVersionSpecificationException e )
|
||||||
|
{
|
||||||
|
throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set createArtifacts( ArtifactFactory artifactFactory, List dependencies, String inheritedScope,
|
public static Set createArtifacts( ArtifactFactory artifactFactory, List dependencies, String inheritedScope,
|
||||||
ArtifactFilter dependencyFilter )
|
ArtifactFilter dependencyFilter )
|
||||||
|
throws InvalidVersionSpecificationException
|
||||||
{
|
{
|
||||||
Set projectArtifacts = new HashSet();
|
Set projectArtifacts = new HashSet();
|
||||||
|
|
||||||
|
@ -97,8 +102,10 @@ public class MavenMetadataSource
|
||||||
Dependency d = (Dependency) i.next();
|
Dependency d = (Dependency) i.next();
|
||||||
|
|
||||||
Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(),
|
Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(),
|
||||||
new VersionRange( d.getVersion() ),
|
VersionRange.createFromVersionSpec(
|
||||||
d.getType(), d.getScope(), inheritedScope );
|
d.getVersion() ), d.getType(),
|
||||||
|
d.getScope(),
|
||||||
|
inheritedScope );
|
||||||
|
|
||||||
if ( artifact != null && ( dependencyFilter == null || dependencyFilter.include( artifact ) ) )
|
if ( artifact != null && ( dependencyFilter == null || dependencyFilter.include( artifact ) ) )
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||||
import org.apache.maven.artifact.resolver.DefaultArtifactResolver;
|
import org.apache.maven.artifact.resolver.DefaultArtifactResolver;
|
||||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||||
|
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||||
import org.apache.maven.artifact.versioning.VersionRange;
|
import org.apache.maven.artifact.versioning.VersionRange;
|
||||||
import org.apache.maven.model.Dependency;
|
import org.apache.maven.model.Dependency;
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
|
@ -81,7 +82,7 @@ public class ProjectClasspathArtifactResolver
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String scope = artifact.getArtifactId().substring( "scope-".length() );
|
String scope = artifact.getArtifactId().substring( "scope-".length() );
|
||||||
if ( artifact.getGroupId().equals( "maven-test" ) )
|
if ( "maven-test".equals( artifact.getGroupId() ) )
|
||||||
{
|
{
|
||||||
String name = "/projects/scope/transitive-" + scope + "-dep.xml";
|
String name = "/projects/scope/transitive-" + scope + "-dep.xml";
|
||||||
r = new InputStreamReader( getClass().getResourceAsStream( name ) );
|
r = new InputStreamReader( getClass().getResourceAsStream( name ) );
|
||||||
|
@ -108,7 +109,15 @@ public class ProjectClasspathArtifactResolver
|
||||||
IOUtil.close( r );
|
IOUtil.close( r );
|
||||||
}
|
}
|
||||||
|
|
||||||
Set artifacts = createArtifacts( model.getDependencies(), artifact.getScope() );
|
Set artifacts = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
artifacts = createArtifacts( model.getDependencies(), artifact.getScope() );
|
||||||
|
}
|
||||||
|
catch ( InvalidVersionSpecificationException e )
|
||||||
|
{
|
||||||
|
throw new ArtifactMetadataRetrievalException( e );
|
||||||
|
}
|
||||||
|
|
||||||
List artifactRepositories;
|
List artifactRepositories;
|
||||||
try
|
try
|
||||||
|
@ -125,6 +134,7 @@ public class ProjectClasspathArtifactResolver
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Set createArtifacts( List dependencies, String inheritedScope )
|
protected Set createArtifacts( List dependencies, String inheritedScope )
|
||||||
|
throws InvalidVersionSpecificationException
|
||||||
{
|
{
|
||||||
Set projectArtifacts = new HashSet();
|
Set projectArtifacts = new HashSet();
|
||||||
|
|
||||||
|
@ -132,9 +142,9 @@ public class ProjectClasspathArtifactResolver
|
||||||
{
|
{
|
||||||
Dependency d = (Dependency) i.next();
|
Dependency d = (Dependency) i.next();
|
||||||
|
|
||||||
|
VersionRange versionRange = VersionRange.createFromVersionSpec( d.getVersion() );
|
||||||
Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(),
|
Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(),
|
||||||
new VersionRange( d.getVersion() ),
|
versionRange, d.getType(), d.getScope(),
|
||||||
d.getType(), d.getScope(),
|
|
||||||
inheritedScope );
|
inheritedScope );
|
||||||
if ( artifact != null )
|
if ( artifact != null )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue