o Restored backward-compat with regard to handling of duplicate dependencies during metadata retrieval

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@784227 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-06-12 18:45:37 +00:00
parent 60496472c7
commit 425f632772
2 changed files with 34 additions and 2 deletions

View File

@ -176,6 +176,14 @@ public class PomConstructionTest
}
*/
public void testDuplicateDependenciesCauseLastDeclarationToBePickedInLenientMode()
throws Exception
{
PomTestWrapper pom = buildPom( "dependencies-different-versions", true, null );
assertEquals( 1, ( (List<?>) pom.getValue( "dependencies" ) ).size() );
assertEquals( "1.1", pom.getValue( "dependencies[1]/version" ) );
}
/* MNG-3567*/
public void testParentInterpolation()
throws Exception
@ -1573,6 +1581,13 @@ public class PomConstructionTest
private PomTestWrapper buildPom( String pomPath, Properties executionProperties, String... profileIds )
throws ProjectBuildingException
{
return buildPom( pomPath, false, executionProperties, profileIds );
}
private PomTestWrapper buildPom( String pomPath, boolean lenientValidation, Properties executionProperties,
String... profileIds )
throws ProjectBuildingException
{
File pomFile = new File( testDirectory, pomPath );
if ( pomFile.isDirectory() )
@ -1582,12 +1597,14 @@ public class PomConstructionTest
ProjectBuildingRequest config = new DefaultProjectBuildingRequest();
String localRepoUrl = System.getProperty( "maven.repo.local", System.getProperty( "user.home" ) + "/.m2/repository" );
String localRepoUrl =
System.getProperty( "maven.repo.local", System.getProperty( "user.home" ) + "/.m2/repository" );
localRepoUrl = "file://" + localRepoUrl;
config.setLocalRepository( new DefaultArtifactRepository( "local", localRepoUrl, new DefaultRepositoryLayout() ) );
config.setActiveProfileIds( Arrays.asList( profileIds ) );
config.setExecutionProperties( executionProperties );
config.setLenientValidation( lenientValidation );
return new PomTestWrapper( pomFile, projectBuilder.build( pomFile, config ) );
}

View File

@ -67,6 +67,21 @@ public class DefaultModelNormalizer
build.setPlugins( new ArrayList<Plugin>( normalized.values() ) );
}
if ( request.istLenientValidation() )
{
/*
* NOTE: This is to keep backward-compat with Maven 2.x which did not validate that dependencies are unique
* within a single POM. Upon multiple declarations, 2.x just kept the last one. So when we're in lenient
* mode for metadata retrieval, we have to deal with such broken POMs and mimic the way 2.x works.
*/
Map<String, Dependency> dependencies = new LinkedHashMap<String, Dependency>();
for ( Dependency dependency : model.getDependencies() )
{
dependencies.put( dependency.getManagementKey(), dependency );
}
model.setDependencies( new ArrayList<Dependency>( dependencies.values() ) );
}
}
private static class DuplicateMerger