mirror of https://github.com/apache/maven.git
consolidate defaults injection
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@168152 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5a40c40754
commit
acfba80edc
|
@ -174,45 +174,23 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
private void injectHandlerPluginConfiguration( MavenProject project, String groupId, String artifactId )
|
||||
{
|
||||
// TODO: use the model injector, or just lookup the versions from the project?
|
||||
// They need to be injected, but we should track the required plugins first, then just sweep through.
|
||||
|
||||
// TODO: this is a bit of a hack to get the version from plugin management - please fix
|
||||
|
||||
Plugin plugin = findPlugin( project.getPlugins(), groupId, artifactId );
|
||||
String key = Plugin.constructKey( groupId, artifactId );
|
||||
Plugin plugin = (Plugin) project.getBuild().getPluginsAsMap().get( key );
|
||||
|
||||
if ( plugin == null )
|
||||
{
|
||||
plugin = new Plugin();
|
||||
plugin.setGroupId( groupId );
|
||||
plugin.setArtifactId( artifactId );
|
||||
|
||||
Plugin def = (Plugin) project.getPluginManagement().getPluginsAsMap().get( key );
|
||||
if ( def != null )
|
||||
{
|
||||
modelDefaultsInjector.mergePluginWithDefaults( plugin, def );
|
||||
}
|
||||
|
||||
project.addPlugin( plugin );
|
||||
}
|
||||
|
||||
// TODO: shouldn't have to call all the time
|
||||
modelDefaultsInjector.injectDefaults( project.getModel() );
|
||||
|
||||
// TODO: remove - should discover the version
|
||||
plugin = findPlugin( project.getPlugins(), groupId, artifactId );
|
||||
if ( plugin.getVersion() == null )
|
||||
{
|
||||
plugin.setVersion( PluginDescriptor.getDefaultPluginVersion() );
|
||||
}
|
||||
}
|
||||
|
||||
private static Plugin findPlugin( List plugins, String groupId, String artifactId )
|
||||
{
|
||||
Plugin plugin = null;
|
||||
|
||||
for ( Iterator i = plugins.iterator(); i.hasNext() && plugin == null; )
|
||||
{
|
||||
Plugin p = (Plugin) i.next();
|
||||
if ( groupId.equals( p.getGroupId() ) && artifactId.equals( p.getArtifactId() ) )
|
||||
{
|
||||
plugin = p;
|
||||
}
|
||||
}
|
||||
return plugin;
|
||||
}
|
||||
|
||||
private void processPluginConfiguration( MavenProject project, MavenSession mavenSession, Map phaseMap )
|
||||
|
|
|
@ -178,6 +178,7 @@ public class DefaultPluginManager
|
|||
public void verifyPlugin( String groupId, String artifactId, MavenSession session )
|
||||
throws ArtifactResolutionException, PluginManagerException
|
||||
{
|
||||
// TODO: we should we support concurrent versions
|
||||
if ( !isPluginInstalled( groupId, artifactId ) )
|
||||
{
|
||||
MavenProject project = session.getProject();
|
||||
|
@ -217,10 +218,8 @@ public class DefaultPluginManager
|
|||
{
|
||||
if ( StringUtils.isEmpty( pluginConfig.getVersion() ) )
|
||||
{
|
||||
// The model/project builder should have validated this already
|
||||
String message = "The maven plugin with groupId: '" + groupId + "' and artifactId: '" + artifactId +
|
||||
"' which was configured for use in this project does not have a version associated with it.";
|
||||
throw new IllegalStateException( message );
|
||||
// TODO: this is where we go searching the repo for more information
|
||||
version = PluginDescriptor.getDefaultPluginVersion();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -656,9 +656,55 @@
|
|||
</field>
|
||||
</fields>
|
||||
</class>
|
||||
<class>
|
||||
<name>PluginContainer</name>
|
||||
<version>3.0.0+</version>
|
||||
<fields>
|
||||
<field>
|
||||
<name>plugins</name>
|
||||
<version>4.0.0</version>
|
||||
<description>
|
||||
The plugins specified here are not validated until they
|
||||
are referenced in a POM within the group. This allows the
|
||||
specification of a "standard" version for a particular
|
||||
plugin.
|
||||
</description>
|
||||
<association>
|
||||
<type>Plugin</type>
|
||||
<multiplicity>*</multiplicity>
|
||||
</association>
|
||||
</field>
|
||||
</fields>
|
||||
<codeSegments>
|
||||
<codeSegment>
|
||||
<version>4.0.0</version>
|
||||
<code><![CDATA[
|
||||
Map pluginMap;
|
||||
|
||||
public Map getPluginsAsMap()
|
||||
{
|
||||
if ( pluginMap == null )
|
||||
{
|
||||
pluginMap = new HashMap();
|
||||
if ( plugins != null )
|
||||
{
|
||||
for ( Iterator it = plugins.iterator(); it.hasNext(); )
|
||||
{
|
||||
Plugin plugin = (Plugin) it.next();
|
||||
pluginMap.put( plugin.getKey(), plugin );
|
||||
}
|
||||
}
|
||||
}
|
||||
return pluginMap;
|
||||
}
|
||||
]]></code>
|
||||
</codeSegment>
|
||||
</codeSegments>
|
||||
</class>
|
||||
<class>
|
||||
<name>Build</name>
|
||||
<version>3.0.0+</version>
|
||||
<superClass>PluginContainer</superClass>
|
||||
<fields>
|
||||
<field>
|
||||
<name>nagEmailAddress</name>
|
||||
|
@ -841,17 +887,6 @@
|
|||
]]></description>
|
||||
<type>String</type>
|
||||
</field>
|
||||
<field>
|
||||
<name>plugins</name>
|
||||
<version>4.0.0</version>
|
||||
<description><![CDATA[
|
||||
Configuration for plugins to be used to build this project.
|
||||
]]></description>
|
||||
<association>
|
||||
<type>Plugin</type>
|
||||
<multiplicity>*</multiplicity>
|
||||
</association>
|
||||
</field>
|
||||
<!-- [ jdcasey:06-Mar-2005 ] Added to handle version management, etc. for
|
||||
| plugins to be used in sub-projects. -->
|
||||
<field>
|
||||
|
@ -2015,6 +2050,16 @@
|
|||
}
|
||||
return goalMap;
|
||||
}
|
||||
|
||||
public String getKey()
|
||||
{
|
||||
return constructKey( groupId, artifactId );
|
||||
}
|
||||
|
||||
public static String constructKey( String groupId, String artifactId )
|
||||
{
|
||||
return groupId + ":" + artifactId;
|
||||
}
|
||||
]]></code>
|
||||
</codeSegment>
|
||||
</codeSegments>
|
||||
|
@ -2060,25 +2105,10 @@
|
|||
<class>
|
||||
<name>PluginManagement</name>
|
||||
<version>4.0.0</version>
|
||||
<superClass>PluginContainer</superClass>
|
||||
<description>
|
||||
Section for management of default plugin information for use in a group of POMs.
|
||||
</description>
|
||||
<fields>
|
||||
<field>
|
||||
<name>plugins</name>
|
||||
<version>4.0.0</version>
|
||||
<description>
|
||||
The dependencies specified here are not validated until they
|
||||
are referenced in a POM within the group. This allows the
|
||||
specification of a "standard" version for a particular
|
||||
dependency.
|
||||
</description>
|
||||
<association>
|
||||
<type>Plugin</type>
|
||||
<multiplicity>*</multiplicity>
|
||||
</association>
|
||||
</field>
|
||||
</fields>
|
||||
</class>
|
||||
<class>
|
||||
<name>Reports</name>
|
||||
|
|
|
@ -206,40 +206,26 @@ public class DefaultModelInheritanceAssembler
|
|||
}
|
||||
else
|
||||
{
|
||||
List childPlugins = childPluginMgmt.getPlugins();
|
||||
|
||||
Map mappedChildPlugins = new TreeMap();
|
||||
for ( Iterator it = childPlugins.iterator(); it.hasNext(); )
|
||||
{
|
||||
Plugin plugin = (Plugin) it.next();
|
||||
mappedChildPlugins.put( constructPluginKey( plugin ), plugin );
|
||||
}
|
||||
Map mappedChildPlugins = childPluginMgmt.getPluginsAsMap();
|
||||
|
||||
for ( Iterator it = parentPluginMgmt.getPlugins().iterator(); it.hasNext(); )
|
||||
{
|
||||
Plugin plugin = (Plugin) it.next();
|
||||
|
||||
String pluginKey = constructPluginKey( plugin );
|
||||
|
||||
if ( !mappedChildPlugins.containsKey( pluginKey ) )
|
||||
if ( !mappedChildPlugins.containsKey( plugin.getKey() ) )
|
||||
{
|
||||
childPluginMgmt.addPlugin( plugin );
|
||||
}
|
||||
else
|
||||
{
|
||||
Plugin childPlugin = (Plugin) mappedChildPlugins.get( pluginKey );
|
||||
Plugin childPlugin = (Plugin) mappedChildPlugins.get( plugin.getKey() );
|
||||
|
||||
if ( childPlugin.getVersion() == null )
|
||||
{
|
||||
childPlugin.setVersion( childPlugin.getVersion() );
|
||||
}
|
||||
|
||||
Map mappedChildGoals = new TreeMap();
|
||||
for ( Iterator itGoals = childPlugin.getGoals().iterator(); itGoals.hasNext(); )
|
||||
{
|
||||
Goal goal = (Goal) itGoals.next();
|
||||
mappedChildGoals.put( goal.getId(), goal );
|
||||
}
|
||||
Map mappedChildGoals = childPlugin.getGoalsAsMap();
|
||||
|
||||
for ( Iterator itGoals = plugin.getGoals().iterator(); itGoals.hasNext(); )
|
||||
{
|
||||
|
@ -267,11 +253,6 @@ public class DefaultModelInheritanceAssembler
|
|||
}
|
||||
}
|
||||
|
||||
private String constructPluginKey( Plugin plugin )
|
||||
{
|
||||
return plugin.getGroupId() + ":" + plugin.getArtifactId();
|
||||
}
|
||||
|
||||
private void assembleDependencyManagementInheritance( Model child, Model parent )
|
||||
{
|
||||
DependencyManagement parentDepMgmt = parent.getDependencyManagement();
|
||||
|
|
|
@ -41,11 +41,11 @@ public class DefaultModelDefaultsInjector
|
|||
injectDependencyDefaults( model.getDependencies(), model.getDependencyManagement() );
|
||||
if ( model.getBuild() != null )
|
||||
{
|
||||
injectPluginDefaults( model.getBuild().getPlugins(), model.getBuild().getPluginManagement() );
|
||||
injectPluginDefaults( model.getBuild().getPluginsAsMap(), model.getBuild().getPluginManagement() );
|
||||
}
|
||||
}
|
||||
|
||||
private void injectPluginDefaults( List plugins, PluginManagement pluginManagement )
|
||||
private void injectPluginDefaults( Map pluginMap, PluginManagement pluginManagement )
|
||||
{
|
||||
if ( pluginManagement != null )
|
||||
{
|
||||
|
@ -55,22 +55,13 @@ public class DefaultModelDefaultsInjector
|
|||
// of
|
||||
// those specified in defaults.
|
||||
|
||||
// TODO: share with inheritence assembler
|
||||
Map pluginMap = new TreeMap();
|
||||
for ( Iterator it = plugins.iterator(); it.hasNext(); )
|
||||
{
|
||||
Plugin plugin = (Plugin) it.next();
|
||||
pluginMap.put( constructPluginKey( plugin ), plugin );
|
||||
}
|
||||
|
||||
List managedPlugins = pluginManagement.getPlugins();
|
||||
|
||||
for ( Iterator it = managedPlugins.iterator(); it.hasNext(); )
|
||||
{
|
||||
Plugin def = (Plugin) it.next();
|
||||
String key = constructPluginKey( def );
|
||||
|
||||
Plugin plugin = (Plugin) pluginMap.get( key );
|
||||
Plugin plugin = (Plugin) pluginMap.get( def.getKey() );
|
||||
if ( plugin != null )
|
||||
{
|
||||
mergePluginWithDefaults( plugin, def );
|
||||
|
@ -79,31 +70,14 @@ public class DefaultModelDefaultsInjector
|
|||
}
|
||||
}
|
||||
|
||||
private static String constructPluginKey( Plugin plugin )
|
||||
{
|
||||
return plugin.getGroupId() + ":" + plugin.getArtifactId();
|
||||
}
|
||||
|
||||
private void mergePluginWithDefaults( Plugin plugin, Plugin def )
|
||||
public void mergePluginWithDefaults( Plugin plugin, Plugin def )
|
||||
{
|
||||
if ( plugin.getVersion() == null && def.getVersion() != null )
|
||||
{
|
||||
plugin.setVersion( def.getVersion() );
|
||||
}
|
||||
|
||||
Map defaultGoals = new TreeMap();
|
||||
|
||||
List defGoalList = def.getGoals();
|
||||
|
||||
if ( defGoalList != null )
|
||||
{
|
||||
for ( Iterator it = defGoalList.iterator(); it.hasNext(); )
|
||||
{
|
||||
Goal defaultGoal = (Goal) it.next();
|
||||
|
||||
defaultGoals.put( defaultGoal.getId(), defaultGoal );
|
||||
}
|
||||
}
|
||||
Map defaultGoals = def.getGoalsAsMap();
|
||||
|
||||
List pluginGoals = plugin.getGoals();
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ package org.apache.maven.project.injection;
|
|||
*/
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Plugin;
|
||||
|
||||
/**
|
||||
* @author jdcasey Created on Feb 1, 2005
|
||||
|
@ -26,4 +27,6 @@ public interface ModelDefaultsInjector
|
|||
String ROLE = ModelDefaultsInjector.class.getName();
|
||||
|
||||
void injectDefaults( Model model );
|
||||
|
||||
void mergePluginWithDefaults( Plugin plugin, Plugin def );
|
||||
}
|
Loading…
Reference in New Issue