mirror of https://github.com/apache/maven.git
o Added model normalizer for things like merging duplicate plugin declarations
git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@773869 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ea67631690
commit
cff6ab0d02
|
@ -42,6 +42,7 @@ import org.apache.maven.model.Profile;
|
||||||
import org.apache.maven.model.interpolator.Interpolator;
|
import org.apache.maven.model.interpolator.Interpolator;
|
||||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||||
import org.apache.maven.model.lifecycle.LifecycleBindingsInjector;
|
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.model.plugin.PluginConfigurationExpander;
|
||||||
import org.apache.maven.profiles.DefaultProfileManager;
|
import org.apache.maven.profiles.DefaultProfileManager;
|
||||||
import org.apache.maven.profiles.ProfileActivationException;
|
import org.apache.maven.profiles.ProfileActivationException;
|
||||||
|
@ -77,7 +78,10 @@ public class DefaultMavenProjectBuilder
|
||||||
private RepositorySystem repositorySystem;
|
private RepositorySystem repositorySystem;
|
||||||
|
|
||||||
@Requirement
|
@Requirement
|
||||||
List<ModelEventListener> listeners;
|
private List<ModelEventListener> listeners;
|
||||||
|
|
||||||
|
@Requirement
|
||||||
|
private Normalizer normalizer;
|
||||||
|
|
||||||
@Requirement
|
@Requirement
|
||||||
private Interpolator interpolator;
|
private Interpolator interpolator;
|
||||||
|
@ -390,6 +394,11 @@ public class DefaultMavenProjectBuilder
|
||||||
domainModels.addAll( mavenParents );
|
domainModels.addAll( mavenParents );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for ( DomainModel domain : domainModels )
|
||||||
|
{
|
||||||
|
normalizer.mergeDuplicates( domain.getModel() );
|
||||||
|
}
|
||||||
|
|
||||||
domainModels.add( new DomainModel( getSuperModel(), false ) );
|
domainModels.add( new DomainModel( getSuperModel(), false ) );
|
||||||
List<DomainModel> profileModels = new ArrayList<DomainModel>();
|
List<DomainModel> profileModels = new ArrayList<DomainModel>();
|
||||||
//Process Profiles
|
//Process Profiles
|
||||||
|
|
|
@ -36,6 +36,11 @@
|
||||||
<role-hint>default</role-hint>
|
<role-hint>default</role-hint>
|
||||||
<field-name>interpolator</field-name>
|
<field-name>interpolator</field-name>
|
||||||
</requirement>
|
</requirement>
|
||||||
|
<requirement>
|
||||||
|
<role>org.apache.maven.model.normalization.Normalizer</role>
|
||||||
|
<role-hint>default</role-hint>
|
||||||
|
<field-name>normalizer</field-name>
|
||||||
|
</requirement>
|
||||||
<requirement>
|
<requirement>
|
||||||
<role>org.apache.maven.model.lifecycle.LifecycleBindingsInjector</role>
|
<role>org.apache.maven.model.lifecycle.LifecycleBindingsInjector</role>
|
||||||
<role-hint>default</role-hint>
|
<role-hint>default</role-hint>
|
||||||
|
|
|
@ -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() );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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 );
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue