Author: carlos Date: Sun Feb 10 21:04:20 2008 New Revision: 620411 URL: http://svn.apache.org/viewvc?rev=620411&view=rev Log: [MNG-3396] Managed versions don't affect over constrained ranges
Modified: maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java maven/artifact/trunk/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java Modified: maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java?rev=620411&r1=620410&r2=620411&view=diff ============================================================================== --- maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java (original) +++ maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java Sun Feb 10 21:04:20 2008 @@ -378,6 +378,38 @@ Artifact artifact = child.getArtifact(); try { + Object childKey = child.getKey(); + if ( managedVersions.containsKey( childKey ) ) + { + // If this child node is a managed dependency, ensure + // we are using the dependency management version + // of this child if applicable b/c we want to use the + // managed version's POM, *not* any other version's POM. + // We retrieve the POM below in the retrieval step. + manageArtifact( child, managedVersions, listeners ); + + // Also, we need to ensure that any exclusions it presents are + // added to the artifact before we retrive the metadata + // for the artifact; otherwise we may end up with unwanted + // dependencies. + Artifact ma = (Artifact) managedVersions.get( childKey ); + ArtifactFilter managedExclusionFilter = ma.getDependencyFilter(); + if ( null != managedExclusionFilter ) + { + if ( null != artifact.getDependencyFilter() ) + { + AndArtifactFilter aaf = new AndArtifactFilter(); + aaf.add( artifact.getDependencyFilter() ); + aaf.add( managedExclusionFilter ); + artifact.setDependencyFilter( aaf ); + } + else + { + artifact.setDependencyFilter( managedExclusionFilter ); + } + } + } + if ( artifact.getVersion() == null ) { // set the recommended version @@ -422,43 +454,11 @@ fireEvent( ResolutionListener.SELECT_VERSION_FROM_RANGE, listeners, child ); } - Object childKey = child.getKey(); - if ( managedVersions.containsKey( childKey ) ) - { - // If this child node is a managed dependency, ensure - // we are using the dependency management version - // of this child if applicable b/c we want to use the - // managed version's POM, *not* any other version's POM. - // We retrieve the POM below in the retrieval step. - manageArtifact( child, managedVersions, listeners ); - - // Also, we need to ensure that any exclusions it presents are - // added to the artifact before we retrive the metadata - // for the artifact; otherwise we may end up with unwanted - // dependencies. - Artifact ma = (Artifact) managedVersions.get( childKey ); - ArtifactFilter managedExclusionFilter = ma.getDependencyFilter(); - if ( null != managedExclusionFilter ) - { - if ( null != artifact.getDependencyFilter() ) - { - AndArtifactFilter aaf = new AndArtifactFilter(); - aaf.add( artifact.getDependencyFilter() ); - aaf.add( managedExclusionFilter ); - artifact.setDependencyFilter( aaf ); - } - else - { - artifact.setDependencyFilter( managedExclusionFilter ); - } - } - } - artifact.setDependencyTrail( node.getDependencyTrail() ); ResolutionGroup rGroup = source.retrieve( artifact, localRepository, remoteRepositories ); - //TODO might be better to have source.retreive() throw a specific exception for this situation + //TODO might be better to have source.retrieve() throw a specific exception for this situation //and catch here rather than have it return null if ( rGroup == null ) { Modified: maven/artifact/trunk/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java?rev=620411&r1=620410&r2=620411&view=diff ============================================================================== --- maven/artifact/trunk/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java (original) +++ maven/artifact/trunk/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java Sun Feb 10 21:04:20 2008 @@ -285,6 +285,20 @@ assertEquals( "Check version", "2.0", getArtifact( "c", res.getArtifacts() ).getVersion() ); } + public void testResolveRangeWithManagedVersion() + throws ArtifactResolutionException, InvalidVersionSpecificationException + { + ArtifactSpec a = createArtifactSpec( "a", "1.0" ); + ArtifactSpec b = a.addDependency( "b", "[1.0,3.0]" ); + + ArtifactSpec managedB = createArtifactSpec( "b", "5.0" ); + + ArtifactResolutionResult res = collect( a, managedB.artifact ); + assertEquals( "Check artifact list", createSet( new Object[] { a.artifact, managedB.artifact } ), + res.getArtifacts() ); + assertEquals( "Check version", "5.0", getArtifact( "b", res.getArtifacts() ).getVersion() ); + } + public void testCompatibleRanges() throws ArtifactResolutionException, InvalidVersionSpecificationException {