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 )
|
private void injectHandlerPluginConfiguration( MavenProject project, String groupId, String artifactId )
|
||||||
{
|
{
|
||||||
// TODO: use the model injector, or just lookup the versions from the project?
|
String key = Plugin.constructKey( groupId, artifactId );
|
||||||
// They need to be injected, but we should track the required plugins first, then just sweep through.
|
Plugin plugin = (Plugin) project.getBuild().getPluginsAsMap().get( key );
|
||||||
|
|
||||||
// TODO: this is a bit of a hack to get the version from plugin management - please fix
|
|
||||||
|
|
||||||
Plugin plugin = findPlugin( project.getPlugins(), groupId, artifactId );
|
|
||||||
|
|
||||||
if ( plugin == null )
|
if ( plugin == null )
|
||||||
{
|
{
|
||||||
plugin = new Plugin();
|
plugin = new Plugin();
|
||||||
plugin.setGroupId( groupId );
|
plugin.setGroupId( groupId );
|
||||||
plugin.setArtifactId( artifactId );
|
plugin.setArtifactId( artifactId );
|
||||||
|
|
||||||
|
Plugin def = (Plugin) project.getPluginManagement().getPluginsAsMap().get( key );
|
||||||
|
if ( def != null )
|
||||||
|
{
|
||||||
|
modelDefaultsInjector.mergePluginWithDefaults( plugin, def );
|
||||||
|
}
|
||||||
|
|
||||||
project.addPlugin( plugin );
|
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 )
|
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 )
|
public void verifyPlugin( String groupId, String artifactId, MavenSession session )
|
||||||
throws ArtifactResolutionException, PluginManagerException
|
throws ArtifactResolutionException, PluginManagerException
|
||||||
{
|
{
|
||||||
|
// TODO: we should we support concurrent versions
|
||||||
if ( !isPluginInstalled( groupId, artifactId ) )
|
if ( !isPluginInstalled( groupId, artifactId ) )
|
||||||
{
|
{
|
||||||
MavenProject project = session.getProject();
|
MavenProject project = session.getProject();
|
||||||
|
@ -217,10 +218,8 @@ public class DefaultPluginManager
|
||||||
{
|
{
|
||||||
if ( StringUtils.isEmpty( pluginConfig.getVersion() ) )
|
if ( StringUtils.isEmpty( pluginConfig.getVersion() ) )
|
||||||
{
|
{
|
||||||
// The model/project builder should have validated this already
|
// TODO: this is where we go searching the repo for more information
|
||||||
String message = "The maven plugin with groupId: '" + groupId + "' and artifactId: '" + artifactId +
|
version = PluginDescriptor.getDefaultPluginVersion();
|
||||||
"' which was configured for use in this project does not have a version associated with it.";
|
|
||||||
throw new IllegalStateException( message );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -656,9 +656,55 @@
|
||||||
</field>
|
</field>
|
||||||
</fields>
|
</fields>
|
||||||
</class>
|
</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>
|
<class>
|
||||||
<name>Build</name>
|
<name>Build</name>
|
||||||
<version>3.0.0+</version>
|
<version>3.0.0+</version>
|
||||||
|
<superClass>PluginContainer</superClass>
|
||||||
<fields>
|
<fields>
|
||||||
<field>
|
<field>
|
||||||
<name>nagEmailAddress</name>
|
<name>nagEmailAddress</name>
|
||||||
|
@ -841,17 +887,6 @@
|
||||||
]]></description>
|
]]></description>
|
||||||
<type>String</type>
|
<type>String</type>
|
||||||
</field>
|
</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
|
<!-- [ jdcasey:06-Mar-2005 ] Added to handle version management, etc. for
|
||||||
| plugins to be used in sub-projects. -->
|
| plugins to be used in sub-projects. -->
|
||||||
<field>
|
<field>
|
||||||
|
@ -2015,6 +2050,16 @@
|
||||||
}
|
}
|
||||||
return goalMap;
|
return goalMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getKey()
|
||||||
|
{
|
||||||
|
return constructKey( groupId, artifactId );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String constructKey( String groupId, String artifactId )
|
||||||
|
{
|
||||||
|
return groupId + ":" + artifactId;
|
||||||
|
}
|
||||||
]]></code>
|
]]></code>
|
||||||
</codeSegment>
|
</codeSegment>
|
||||||
</codeSegments>
|
</codeSegments>
|
||||||
|
@ -2060,25 +2105,10 @@
|
||||||
<class>
|
<class>
|
||||||
<name>PluginManagement</name>
|
<name>PluginManagement</name>
|
||||||
<version>4.0.0</version>
|
<version>4.0.0</version>
|
||||||
|
<superClass>PluginContainer</superClass>
|
||||||
<description>
|
<description>
|
||||||
Section for management of default plugin information for use in a group of POMs.
|
Section for management of default plugin information for use in a group of POMs.
|
||||||
</description>
|
</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>
|
||||||
<class>
|
<class>
|
||||||
<name>Reports</name>
|
<name>Reports</name>
|
||||||
|
|
|
@ -206,40 +206,26 @@ public class DefaultModelInheritanceAssembler
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
List childPlugins = childPluginMgmt.getPlugins();
|
Map mappedChildPlugins = childPluginMgmt.getPluginsAsMap();
|
||||||
|
|
||||||
Map mappedChildPlugins = new TreeMap();
|
|
||||||
for ( Iterator it = childPlugins.iterator(); it.hasNext(); )
|
|
||||||
{
|
|
||||||
Plugin plugin = (Plugin) it.next();
|
|
||||||
mappedChildPlugins.put( constructPluginKey( plugin ), plugin );
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( Iterator it = parentPluginMgmt.getPlugins().iterator(); it.hasNext(); )
|
for ( Iterator it = parentPluginMgmt.getPlugins().iterator(); it.hasNext(); )
|
||||||
{
|
{
|
||||||
Plugin plugin = (Plugin) it.next();
|
Plugin plugin = (Plugin) it.next();
|
||||||
|
|
||||||
String pluginKey = constructPluginKey( plugin );
|
if ( !mappedChildPlugins.containsKey( plugin.getKey() ) )
|
||||||
|
|
||||||
if ( !mappedChildPlugins.containsKey( pluginKey ) )
|
|
||||||
{
|
{
|
||||||
childPluginMgmt.addPlugin( plugin );
|
childPluginMgmt.addPlugin( plugin );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Plugin childPlugin = (Plugin) mappedChildPlugins.get( pluginKey );
|
Plugin childPlugin = (Plugin) mappedChildPlugins.get( plugin.getKey() );
|
||||||
|
|
||||||
if ( childPlugin.getVersion() == null )
|
if ( childPlugin.getVersion() == null )
|
||||||
{
|
{
|
||||||
childPlugin.setVersion( childPlugin.getVersion() );
|
childPlugin.setVersion( childPlugin.getVersion() );
|
||||||
}
|
}
|
||||||
|
|
||||||
Map mappedChildGoals = new TreeMap();
|
Map mappedChildGoals = childPlugin.getGoalsAsMap();
|
||||||
for ( Iterator itGoals = childPlugin.getGoals().iterator(); itGoals.hasNext(); )
|
|
||||||
{
|
|
||||||
Goal goal = (Goal) itGoals.next();
|
|
||||||
mappedChildGoals.put( goal.getId(), goal );
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( Iterator itGoals = plugin.getGoals().iterator(); itGoals.hasNext(); )
|
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 )
|
private void assembleDependencyManagementInheritance( Model child, Model parent )
|
||||||
{
|
{
|
||||||
DependencyManagement parentDepMgmt = parent.getDependencyManagement();
|
DependencyManagement parentDepMgmt = parent.getDependencyManagement();
|
||||||
|
|
|
@ -41,11 +41,11 @@ public class DefaultModelDefaultsInjector
|
||||||
injectDependencyDefaults( model.getDependencies(), model.getDependencyManagement() );
|
injectDependencyDefaults( model.getDependencies(), model.getDependencyManagement() );
|
||||||
if ( model.getBuild() != null )
|
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 )
|
if ( pluginManagement != null )
|
||||||
{
|
{
|
||||||
|
@ -55,22 +55,13 @@ public class DefaultModelDefaultsInjector
|
||||||
// of
|
// of
|
||||||
// those specified in defaults.
|
// 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();
|
List managedPlugins = pluginManagement.getPlugins();
|
||||||
|
|
||||||
for ( Iterator it = managedPlugins.iterator(); it.hasNext(); )
|
for ( Iterator it = managedPlugins.iterator(); it.hasNext(); )
|
||||||
{
|
{
|
||||||
Plugin def = (Plugin) it.next();
|
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 )
|
if ( plugin != null )
|
||||||
{
|
{
|
||||||
mergePluginWithDefaults( plugin, def );
|
mergePluginWithDefaults( plugin, def );
|
||||||
|
@ -79,31 +70,14 @@ public class DefaultModelDefaultsInjector
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String constructPluginKey( Plugin plugin )
|
public void mergePluginWithDefaults( Plugin plugin, Plugin def )
|
||||||
{
|
|
||||||
return plugin.getGroupId() + ":" + plugin.getArtifactId();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void mergePluginWithDefaults( Plugin plugin, Plugin def )
|
|
||||||
{
|
{
|
||||||
if ( plugin.getVersion() == null && def.getVersion() != null )
|
if ( plugin.getVersion() == null && def.getVersion() != null )
|
||||||
{
|
{
|
||||||
plugin.setVersion( def.getVersion() );
|
plugin.setVersion( def.getVersion() );
|
||||||
}
|
}
|
||||||
|
|
||||||
Map defaultGoals = new TreeMap();
|
Map defaultGoals = def.getGoalsAsMap();
|
||||||
|
|
||||||
List defGoalList = def.getGoals();
|
|
||||||
|
|
||||||
if ( defGoalList != null )
|
|
||||||
{
|
|
||||||
for ( Iterator it = defGoalList.iterator(); it.hasNext(); )
|
|
||||||
{
|
|
||||||
Goal defaultGoal = (Goal) it.next();
|
|
||||||
|
|
||||||
defaultGoals.put( defaultGoal.getId(), defaultGoal );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List pluginGoals = plugin.getGoals();
|
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.Model;
|
||||||
|
import org.apache.maven.model.Plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jdcasey Created on Feb 1, 2005
|
* @author jdcasey Created on Feb 1, 2005
|
||||||
|
@ -26,4 +27,6 @@ public interface ModelDefaultsInjector
|
||||||
String ROLE = ModelDefaultsInjector.class.getName();
|
String ROLE = ModelDefaultsInjector.class.getName();
|
||||||
|
|
||||||
void injectDefaults( Model model );
|
void injectDefaults( Model model );
|
||||||
|
|
||||||
|
void mergePluginWithDefaults( Plugin plugin, Plugin def );
|
||||||
}
|
}
|
Loading…
Reference in New Issue