o Fixed merging of lifecycle plugins that contribute more than one execution

o Fixed conversion of default value for plugin configuration

git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@771154 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-05-04 01:08:40 +00:00
parent 4279de6540
commit c3c878fa94
2 changed files with 46 additions and 27 deletions

View File

@ -18,10 +18,10 @@ package org.apache.maven.lifecycle;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -508,7 +508,7 @@ public class DefaultLifecycleExecutor
// //
public Set<Plugin> getPluginsBoundByDefaultToAllLifecycles( String packaging ) public Set<Plugin> getPluginsBoundByDefaultToAllLifecycles( String packaging )
{ {
Set<Plugin> plugins = new LinkedHashSet<Plugin>(); Map<Plugin, Plugin> plugins = new LinkedHashMap<Plugin, Plugin>();
for ( Lifecycle lifecycle : lifecycles ) for ( Lifecycle lifecycle : lifecycles )
{ {
@ -524,21 +524,33 @@ public class DefaultLifecycleExecutor
// //
// org.apache.maven.plugins:maven-compiler-plugin:compile // org.apache.maven.plugins:maven-compiler-plugin:compile
// //
for ( String s : lifecyclePhasesForPackaging.values() ) parseLifecyclePhaseDefinitions( plugins, lifecyclePhasesForPackaging.values() );
{
plugins.add( populatePluginWithInformationSpecifiedInLifecyclePhaseDefinition( s ) );
}
} }
else if ( lifecycle.getDefaultPhases() != null ) else if ( lifecycle.getDefaultPhases() != null )
{ {
for ( String s : lifecycle.getDefaultPhases() ) parseLifecyclePhaseDefinitions( plugins, lifecycle.getDefaultPhases() );
{
plugins.add( populatePluginWithInformationSpecifiedInLifecyclePhaseDefinition( s ) );
}
} }
} }
return plugins; return plugins.keySet();
}
private void parseLifecyclePhaseDefinitions( Map<Plugin, Plugin> plugins,
Collection<String> lifecyclePhaseDefinitions )
{
for ( String lifecyclePhaseDefinition : lifecyclePhaseDefinitions )
{
Plugin plugin = populatePluginWithInformationSpecifiedInLifecyclePhaseDefinition( lifecyclePhaseDefinition );
Plugin existing = plugins.get( plugin );
if ( existing != null )
{
existing.getExecutions().addAll( plugin.getExecutions() );
}
else
{
plugins.put( plugin, plugin );
}
}
} }
private Plugin populatePluginWithInformationSpecifiedInLifecyclePhaseDefinition( String lifecyclePhaseDefinition ) private Plugin populatePluginWithInformationSpecifiedInLifecyclePhaseDefinition( String lifecyclePhaseDefinition )
@ -548,8 +560,10 @@ public class DefaultLifecycleExecutor
plugin.setGroupId( p[0] ); plugin.setGroupId( p[0] );
plugin.setArtifactId( p[1] ); plugin.setArtifactId( p[1] );
PluginExecution execution = new PluginExecution(); PluginExecution execution = new PluginExecution();
execution.setGoals( Arrays.asList( new String[]{ p[2] } ) ); // FIXME: Find a better execution id
plugin.setExecutions( Arrays.asList( new PluginExecution[]{ execution } ) ); execution.setId( "default-" + p[2] );
execution.setGoals( new ArrayList<String>( Arrays.asList( new String[] { p[2] } ) ) );
plugin.setExecutions( new ArrayList<PluginExecution>( Arrays.asList( new PluginExecution[] { execution } ) ) );
return plugin; return plugin;
} }
@ -563,7 +577,7 @@ public class DefaultLifecycleExecutor
for( String g : e.getGoals() ) for( String g : e.getGoals() )
{ {
Xpp3Dom dom = getDefaultPluginConfiguration( p.getGroupId(), p.getArtifactId(), p.getVersion(), g, project, localRepository ); Xpp3Dom dom = getDefaultPluginConfiguration( p.getGroupId(), p.getArtifactId(), p.getVersion(), g, project, localRepository );
e.setConfiguration( dom ); e.setConfiguration( Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) e.getConfiguration(), dom, Boolean.TRUE ) );
} }
} }
} }
@ -594,11 +608,11 @@ public class DefaultLifecycleExecutor
for( PlexusConfiguration ce : ces ) for( PlexusConfiguration ce : ces )
{ {
if ( ce.getValue( null ) != null ) String defaultValue = ce.getAttribute( "default-value", null );
if ( ce.getValue( null ) != null || defaultValue != null )
{ {
Xpp3Dom e = new Xpp3Dom( ce.getName() ); Xpp3Dom e = new Xpp3Dom( ce.getName() );
e.setValue( ce.getValue( null ) ); e.setValue( ce.getValue( null ) );
String defaultValue = ce.getAttribute( "default-value", null );
if ( defaultValue != null ) if ( defaultValue != null )
{ {
e.setAttribute( "default-value", defaultValue ); e.setAttribute( "default-value", defaultValue );

View File

@ -280,7 +280,7 @@ public class DefaultMavenProjectBuilder
return null; return null;
} }
public static void addPluginsToModel(Model target, Set<Plugin> plugins) public static void addPluginsToModel( Model target, Set<Plugin> plugins )
{ {
List<Plugin> mngPlugins = (target.getBuild().getPluginManagement() != null) List<Plugin> mngPlugins = (target.getBuild().getPluginManagement() != null)
? target.getBuild().getPluginManagement().getPlugins() : new ArrayList<Plugin>(); ? target.getBuild().getPluginManagement().getPlugins() : new ArrayList<Plugin>();
@ -300,13 +300,18 @@ public class DefaultMavenProjectBuilder
} }
Plugin pomPlugin = containsPlugin( p, pomPlugins); Plugin pomPlugin = containsPlugin( p, pomPlugins);
if( pomPlugin == null) if ( pomPlugin == null )
{ {
lifecyclePlugins.add(p); lifecyclePlugins.add( p );
} }
else if(p.getConfiguration() != null) else
{ {
System.out.println(Xpp3Dom.mergeXpp3Dom((Xpp3Dom) p.getConfiguration(), (Xpp3Dom) pomPlugin.getConfiguration())); PluginProcessor.copy2( p, pomPlugin, true );
if ( p.getConfiguration() != null )
{
System.out.println( Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) p.getConfiguration(),
(Xpp3Dom) pomPlugin.getConfiguration() ) );
}
} }
} }
pomPlugins.addAll(lifecyclePlugins); pomPlugins.addAll(lifecyclePlugins);