o Tuned code

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@833044 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-11-05 13:15:54 +00:00
parent c980cfb28d
commit ed43cef785
1 changed files with 17 additions and 8 deletions

View File

@ -52,10 +52,10 @@ public class DefaultModelNormalizer
Build build = model.getBuild(); Build build = model.getBuild();
if ( build != null ) if ( build != null )
{ {
List<Plugin> original = build.getPlugins(); List<Plugin> plugins = build.getPlugins();
Map<Object, Plugin> normalized = new LinkedHashMap<Object, Plugin>(); Map<Object, Plugin> normalized = new LinkedHashMap<Object, Plugin>( plugins.size() * 2 );
for ( Plugin plugin : original ) for ( Plugin plugin : plugins )
{ {
Object key = plugin.getKey(); Object key = plugin.getKey();
Plugin first = normalized.get( key ); Plugin first = normalized.get( key );
@ -66,8 +66,11 @@ public class DefaultModelNormalizer
normalized.put( key, plugin ); normalized.put( key, plugin );
} }
if ( plugins.size() != normalized.size() )
{
build.setPlugins( new ArrayList<Plugin>( normalized.values() ) ); build.setPlugins( new ArrayList<Plugin>( normalized.values() ) );
} }
}
/* /*
* NOTE: This is primarily to keep backward-compat with Maven 2.x which did not validate that dependencies are * NOTE: This is primarily to keep backward-compat with Maven 2.x which did not validate that dependencies are
@ -76,12 +79,18 @@ public class DefaultModelNormalizer
* the way 2.x works. When we're in strict mode, the removal of duplicates just saves other merging steps from * the way 2.x works. When we're in strict mode, the removal of duplicates just saves other merging steps from
* aftereffects and bogus error messages. * aftereffects and bogus error messages.
*/ */
Map<String, Dependency> dependencies = new LinkedHashMap<String, Dependency>(); List<Dependency> dependencies = model.getDependencies();
for ( Dependency dependency : model.getDependencies() ) Map<String, Dependency> normalized = new LinkedHashMap<String, Dependency>( dependencies.size() * 2 );
for ( Dependency dependency : dependencies )
{ {
dependencies.put( dependency.getManagementKey(), dependency ); normalized.put( dependency.getManagementKey(), dependency );
}
if ( dependencies.size() != normalized.size() )
{
model.setDependencies( new ArrayList<Dependency>( normalized.values() ) );
} }
model.setDependencies( new ArrayList<Dependency>( dependencies.values() ) );
} }
private static class DuplicateMerger private static class DuplicateMerger