Author: bentmann Date: Tue May 12 12:40:57 2009 New Revision: 773869 URL: http://svn.apache.org/viewvc?rev=773869&view=rev Log: o Added model normalizer for things like merging duplicate plugin declarations
Added: maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/normalization/ (with props) maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/normalization/DefaultNormalizer.java (with props) maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/normalization/Normalizer.java (with props) Modified: maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java maven/components/branches/MNG-2766/maven-core/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml Modified: maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java?rev=773869&r1=773868&r2=773869&view=diff ============================================================================== --- maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java (original) +++ maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java Tue May 12 12:40:57 2009 @@ -42,6 +42,7 @@ import org.apache.maven.model.interpolator.Interpolator; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.model.lifecycle.LifecycleBindingsInjector; +import org.apache.maven.model.normalization.Normalizer; import org.apache.maven.model.plugin.PluginConfigurationExpander; import org.apache.maven.profiles.DefaultProfileManager; import org.apache.maven.profiles.ProfileActivationException; @@ -77,7 +78,10 @@ private RepositorySystem repositorySystem; @Requirement - List<ModelEventListener> listeners; + private List<ModelEventListener> listeners; + + @Requirement + private Normalizer normalizer; @Requirement private Interpolator interpolator; @@ -390,6 +394,11 @@ domainModels.addAll( mavenParents ); } + for ( DomainModel domain : domainModels ) + { + normalizer.mergeDuplicates( domain.getModel() ); + } + domainModels.add( new DomainModel( getSuperModel(), false ) ); List<DomainModel> profileModels = new ArrayList<DomainModel>(); //Process Profiles Modified: maven/components/branches/MNG-2766/maven-core/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml?rev=773869&r1=773868&r2=773869&view=diff ============================================================================== --- maven/components/branches/MNG-2766/maven-core/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml (original) +++ maven/components/branches/MNG-2766/maven-core/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml Tue May 12 12:40:57 2009 @@ -37,6 +37,11 @@ <field-name>interpolator</field-name> </requirement> <requirement> + <role>org.apache.maven.model.normalization.Normalizer</role> + <role-hint>default</role-hint> + <field-name>normalizer</field-name> + </requirement> + <requirement> <role>org.apache.maven.model.lifecycle.LifecycleBindingsInjector</role> <role-hint>default</role-hint> <field-name>lifecycleBindingsInjector</field-name> Propchange: maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/normalization/ ------------------------------------------------------------------------------ bugtraq:label = Enter issue ID: Propchange: maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/normalization/ ------------------------------------------------------------------------------ bugtraq:message = Issue id: %BUGID% Propchange: maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/normalization/ ------------------------------------------------------------------------------ bugtraq:number = false Propchange: maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/normalization/ ------------------------------------------------------------------------------ bugtraq:url = http://jira.codehaus.org/browse/%BUGID% Added: maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/normalization/DefaultNormalizer.java URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/normalization/DefaultNormalizer.java?rev=773869&view=auto ============================================================================== --- maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/normalization/DefaultNormalizer.java (added) +++ maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/normalization/DefaultNormalizer.java Tue May 12 12:40:57 2009 @@ -0,0 +1,80 @@ +package org.apache.maven.model.normalization; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.apache.maven.model.Build; +import org.apache.maven.model.Model; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.merge.MavenModelMerger; +import org.codehaus.plexus.component.annotations.Component; + +/** + * Handles normalization of a model. + * + * @author Benjamin Bentmann + */ +...@component( role = Normalizer.class ) +public class DefaultNormalizer + implements Normalizer +{ + + private DuplicateMerger merger = new DuplicateMerger(); + + public void mergeDuplicates( Model model ) + { + Build build = model.getBuild(); + if ( build != null ) + { + List<Plugin> original = build.getPlugins(); + Map<Object, Plugin> normalized = new LinkedHashMap<Object, Plugin>(); + + for ( Plugin plugin : original ) + { + Object key = plugin.getKey(); + Plugin first = normalized.get( key ); + if ( first != null ) + { + merger.mergePlugin( plugin, first ); + } + normalized.put( key, plugin ); + } + + build.setPlugins( new ArrayList<Plugin>( normalized.values() ) ); + } + } + + private static class DuplicateMerger + extends MavenModelMerger + { + + public void mergePlugin( Plugin target, Plugin source ) + { + super.mergePlugin( target, source, false, Collections.emptyMap() ); + } + + } + +} Propchange: maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/normalization/DefaultNormalizer.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/normalization/DefaultNormalizer.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/normalization/Normalizer.java URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/normalization/Normalizer.java?rev=773869&view=auto ============================================================================== --- maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/normalization/Normalizer.java (added) +++ maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/normalization/Normalizer.java Tue May 12 12:40:57 2009 @@ -0,0 +1,39 @@ +package org.apache.maven.model.normalization; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.model.Model; + +/** + * Handles normalization of a model. + * + * @author Benjamin Bentmann + */ +public interface Normalizer +{ + + /** + * Merges duplicate elements like multiple declarations of the same build plugin in the specified model. + * + * @param model The model whose duplicate elements should be merged, must not be <code>null</code>. + */ + void mergeDuplicates( Model model ); + +} Propchange: maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/normalization/Normalizer.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/normalization/Normalizer.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision