It's fine to fix this temporarily like this, but ultimately here I'm just trying to give the project/model builder all the information it needs and the merging of any bits should only be in the model builder. Merging of any configuration should also definitely not happen in the plugin manager. I realize there is some interplay between the model/ project builder and the lifecycle executor right now because we need to deal with giving the model builder the correct default lifecycle plugin information but this stuff all needs to find it's way back to to the model/project builder.

It can go in the project builder for now and we'll figure out the exact boundaries of the model versus project. For most consumers of POMs they probably don't care about plugins, they want the dependency information. So the model builder could be told to turn off the plugin processor and therefore not require a component (whether that be the lifecycle executor as it is now or something else).

We could also just go simple and spit out an XML document with all the plugins in the default lifcycle with versions and configurations. Include a copy of it with Maven for its use, and publish it to central for use by the model builder if we wanted to provide a model builder which truly could be any POM without requiring Maven's runtime. We could just remove that configuration from the default lifecycle executor component, which we really should do, and then this would become an order of magnitude easier. I'm sure you can see the lack of symmetry in having to synthesize execution elements for the model builder to consume. They should just be there in full form.

- the model builder should stand-alone to build fully inherited/ interpolated models - the project builder should bring in any runtime information in the form of properties, and really should be a very thin layer over the model builder - the lifecycle executor should calculate the build plan, and by this point every bit of configuration for each mojo should be calculated - the plugin manager does nothing except build up the class loader and execute the mojo with the already built up and fully validated configurations (i still don't like the expression evaluator which mixes composition and configuration but i'm still thinking about that one). you should not execute 4 of N plugins in your build plan and then find out a required parameter is missing. Every last bit needs to be know and made available to external tooling so that we could have real POM validation in m2eclipse and provide real help to correct the problems. only knowing while the plugins is executing is not good enough.

On 3-May-09, at 6:08 PM, [email protected] wrote:

Author: bentmann
Date: Mon May  4 01:08:40 2009
New Revision: 771154

URL: http://svn.apache.org/viewvc?rev=771154&view=rev
Log:
o Fixed merging of lifecycle plugins that contribute more than one execution
o Fixed conversion of default value for plugin configuration

Modified:
maven/components/branches/MNG-2766/maven-core/src/main/java/org/ apache/maven/lifecycle/DefaultLifecycleExecutor.java maven/components/branches/MNG-2766/maven-core/src/main/java/org/ apache/maven/project/DefaultMavenProjectBuilder.java

Modified: maven/components/branches/MNG-2766/maven-core/src/main/ java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java?rev=771154&r1=771153&r2=771154&view=diff
= = = = = = = = ====================================================================== --- maven/components/branches/MNG-2766/maven-core/src/main/java/org/ apache/maven/lifecycle/DefaultLifecycleExecutor.java (original) +++ maven/components/branches/MNG-2766/maven-core/src/main/java/org/ apache/maven/lifecycle/DefaultLifecycleExecutor.java Mon May 4 01:08:40 2009
@@ -18,10 +18,10 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -508,7 +508,7 @@
    //
public Set<Plugin> getPluginsBoundByDefaultToAllLifecycles( String packaging )
    {
-        Set<Plugin> plugins = new LinkedHashSet<Plugin>();
+ Map<Plugin, Plugin> plugins = new LinkedHashMap<Plugin, Plugin>();

        for ( Lifecycle lifecycle : lifecycles )
        {
@@ -524,23 +524,35 @@
                //
// org.apache.maven.plugins:maven-compiler- plugin:compile
                //
- for ( String s : lifecyclePhasesForPackaging.values() )
-                {
- plugins .add ( populatePluginWithInformationSpecifiedInLifecyclePhaseDefinition ( s ) );
-                }
+ parseLifecyclePhaseDefinitions( plugins, lifecyclePhasesForPackaging.values() );
            }
            else if ( lifecycle.getDefaultPhases() != null )
            {
-                for ( String s : lifecycle.getDefaultPhases() )
-                {
- plugins .add ( populatePluginWithInformationSpecifiedInLifecyclePhaseDefinition ( s ) );
-                }
+ parseLifecyclePhaseDefinitions( plugins, lifecycle.getDefaultPhases() );
            }
        }

-        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 )
    {
String[] p = StringUtils.split( lifecyclePhaseDefinition, ":" );
@@ -548,8 +560,10 @@
        plugin.setGroupId( p[0] );
        plugin.setArtifactId( p[1] );
        PluginExecution execution = new PluginExecution();
-        execution.setGoals( Arrays.asList( new String[]{ p[2] } ) );
- plugin.setExecutions( Arrays.asList( new PluginExecution[] { execution } ) );
+        // FIXME: Find a better execution id
+        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;
    }

@@ -563,7 +577,7 @@
                for( String g : e.getGoals() )
                {
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 @@

        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() );
                e.setValue( ce.getValue( null ) );
- String defaultValue = ce.getAttribute( "default- value", null );
                if ( defaultValue != null )
                {
                    e.setAttribute( "default-value", defaultValue );

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=771154&r1=771153&r2=771154&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 Mon May 4 01:08:40 2009
@@ -191,7 +191,7 @@
                                pln.add(copy);
                        }
                
-                       // Merge the various sources for mojo configuration:
+            // Merge the various sources for mojo configuration:
            // 1. default values from mojo descriptor
            // 2. POM values from per-plugin configuration
            // 3. POM values from per-execution configuration
@@ -280,7 +280,7 @@
        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) ? target.getBuild().getPluginManagement().getPlugins() : new ArrayList<Plugin>();
@@ -300,14 +300,19 @@
                }
                
                Plugin pomPlugin = containsPlugin( p, pomPlugins);
-               if( pomPlugin == null)
-               {
-                       lifecyclePlugins.add(p);
-               }
-               else if(p.getConfiguration() != null)
-               {
- System.out.println(Xpp3Dom.mergeXpp3Dom((Xpp3Dom) p.getConfiguration(), (Xpp3Dom) pomPlugin.getConfiguration()));
-               }
+               if ( pomPlugin == null )
+            {
+                lifecyclePlugins.add( p );
+            }
+            else
+            {
+                PluginProcessor.copy2( p, pomPlugin, true );
+                if ( p.getConfiguration() != null )
+                {
+ System.out.println( Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) p.getConfiguration(), + (Xpp3Dom) pomPlugin.getConfiguration() ) );
+                }
+            }
        }
        pomPlugins.addAll(lifecyclePlugins);
        target.getBuild().setPlugins(pomPlugins);



Thanks,

Jason

----------------------------------------------------------
Jason van Zyl
Founder,  Apache Maven
http://twitter.com/jvanzyl
http://twitter.com/SonatypeNexus
http://twitter.com/SonatypeM2E
----------------------------------------------------------

A party which is not afraid of letting culture,
business, and welfare go to ruin completely can
be omnipotent for a while.

  -- Jakob Burckhardt


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to