maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bentm...@apache.org
Subject svn commit: r809751 - in /maven/components/trunk: maven-core/src/main/java/org/apache/maven/model/plugin/ maven-core/src/test/java/org/apache/maven/project/ maven-core/src/test/resources-project-builder/plugin-exec-order-and-default-exec/ maven-model-b...
Date Mon, 31 Aug 2009 21:31:02 GMT
Author: bentmann
Date: Mon Aug 31 21:31:01 2009
New Revision: 809751

URL: http://svn.apache.org/viewvc?rev=809751&view=rev
Log:
[MNG-4332] [regression] Default plugin executions contributed by packaging execute after executions
from plugin management

Added:
    maven/components/trunk/maven-core/src/test/resources-project-builder/plugin-exec-order-and-default-exec/
  (with props)
    maven/components/trunk/maven-core/src/test/resources-project-builder/plugin-exec-order-and-default-exec/pom.xml
  (with props)
Modified:
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/model/plugin/DefaultLifecycleBindingsInjector.java
    maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java
    maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/management/DefaultPluginManagementInjector.java
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/management/DependencyManagementInjector.java
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/management/PluginManagementInjector.java
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/plugin/LifecycleBindingsInjector.java

Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/model/plugin/DefaultLifecycleBindingsInjector.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/model/plugin/DefaultLifecycleBindingsInjector.java?rev=809751&r1=809750&r2=809751&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/model/plugin/DefaultLifecycleBindingsInjector.java
(original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/model/plugin/DefaultLifecycleBindingsInjector.java
Mon Aug 31 21:31:01 2009
@@ -32,6 +32,8 @@
 import org.apache.maven.model.Model;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.model.PluginContainer;
+import org.apache.maven.model.PluginManagement;
+import org.apache.maven.model.building.ModelBuildingRequest;
 import org.apache.maven.model.building.ModelProblemCollector;
 import org.apache.maven.model.merge.MavenModelMerger;
 import org.codehaus.plexus.component.annotations.Component;
@@ -52,7 +54,7 @@
     @Requirement
     private LifecycleExecutor lifecycle;
 
-    public void injectLifecycleBindings( Model model, ModelProblemCollector problems )
+    public void injectLifecycleBindings( Model model, ModelBuildingRequest request, ModelProblemCollector
problems )
     {
         String packaging = model.getPackaging();
 
@@ -76,13 +78,19 @@
         extends MavenModelMerger
     {
 
+        private static final String PLUGIN_MANAGEMENT = "plugin-management";
+
         public void merge( Model target, Model source )
         {
             if ( target.getBuild() == null )
             {
                 target.setBuild( new Build() );
             }
-            mergePluginContainer_Plugins( target.getBuild(), source.getBuild(), false, Collections.emptyMap()
);
+
+            Map<Object, Object> context =
+                Collections.<Object, Object> singletonMap( PLUGIN_MANAGEMENT, target.getBuild().getPluginManagement()
);
+
+            mergePluginContainer_Plugins( target.getBuild(), source.getBuild(), false, context
);
         }
 
         @Override
@@ -103,6 +111,8 @@
                     merged.put( key, element );
                 }
 
+                Map<Object, Plugin> unmanaged = new LinkedHashMap<Object, Plugin>(
merged );
+
                 for ( Iterator<Plugin> it = tgt.iterator(); it.hasNext(); )
                 {
                     Plugin element = it.next();
@@ -111,10 +121,31 @@
                     if ( existing != null )
                     {
                         mergePlugin( element, existing, sourceDominant, context );
+                        unmanaged.remove( key );
                     }
                     merged.put( key, element );
                 }
 
+                if ( !unmanaged.isEmpty() )
+                {
+                    PluginManagement pluginMgmt = (PluginManagement) context.get( PLUGIN_MANAGEMENT
);
+                    if ( pluginMgmt != null )
+                    {
+                        for ( Iterator<Plugin> it = pluginMgmt.getPlugins().iterator();
it.hasNext(); )
+                        {
+                            Plugin managedPlugin = it.next();
+                            Object key = getPluginKey( managedPlugin );
+                            Plugin unmanagedPlugin = unmanaged.get( key );
+                            if ( unmanagedPlugin != null )
+                            {
+                                Plugin plugin = managedPlugin.clone();
+                                mergePlugin( plugin, unmanagedPlugin, sourceDominant, Collections.emptyMap()
);
+                                merged.put( key, plugin );
+                            }
+                        }
+                    }
+                }
+
                 target.setPlugins( new ArrayList<Plugin>( merged.values() ) );
             }
         }

Modified: maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java?rev=809751&r1=809750&r2=809751&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java
(original)
+++ maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java
Mon Aug 31 21:31:01 2009
@@ -34,6 +34,7 @@
 import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
 import org.apache.maven.lifecycle.MavenExecutionPlan;
 import org.apache.maven.model.Plugin;
+import org.apache.maven.model.PluginExecution;
 import org.apache.maven.plugin.InvalidPluginDescriptorException;
 import org.apache.maven.plugin.MojoExecution;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -90,12 +91,12 @@
         {
             plugins = new LinkedHashSet<Plugin>();
 
-            plugins.add( newPlugin( "maven-compiler-plugin" ) );
-            plugins.add( newPlugin( "maven-resources-plugin" ) );
-            plugins.add( newPlugin( "maven-surefire-plugin" ) );
-            plugins.add( newPlugin( "maven-jar-plugin" ) );
-            plugins.add( newPlugin( "maven-install-plugin" ) );
-            plugins.add( newPlugin( "maven-deploy-plugin" ) );
+            plugins.add( newPlugin( "maven-compiler-plugin", "compile", "testCompile" ) );
+            plugins.add( newPlugin( "maven-resources-plugin", "resources", "testResources"
) );
+            plugins.add( newPlugin( "maven-surefire-plugin", "test" ) );
+            plugins.add( newPlugin( "maven-jar-plugin", "jar" ) );
+            plugins.add( newPlugin( "maven-install-plugin", "install" ) );
+            plugins.add( newPlugin( "maven-deploy-plugin", "deploy" ) );
         }
         else
         {
@@ -105,13 +106,21 @@
         return plugins;
     }
 
-    private Plugin newPlugin( String artifactId )
+    private Plugin newPlugin( String artifactId, String... goals )
     {
         Plugin plugin = new Plugin();
 
         plugin.setGroupId( "org.apache.maven.plugins" );
         plugin.setArtifactId( artifactId );
 
+        for ( String goal : goals )
+        {
+            PluginExecution pluginExecution = new PluginExecution();
+            pluginExecution.setId( "default-" + goal );
+            pluginExecution.addGoal( goal );
+            plugin.addExecution( pluginExecution );
+        }
+
         return plugin;
     }
 

Modified: maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java?rev=809751&r1=809750&r2=809751&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java
(original)
+++ maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java
Mon Aug 31 21:31:01 2009
@@ -1661,6 +1661,20 @@
                       pom.getValue( "build/plugins[@artifactId='maven-it-plugin-log-file']/configuration/logFile"
) );
     }
 
+    public void testDefaultPluginsExecutionContributedByPackagingExecuteBeforeUserDefinedExecutions()
+        throws Exception
+    {
+        PomTestWrapper pom = buildPom( "plugin-exec-order-and-default-exec" );
+        List<PluginExecution> executions =
+            (List<PluginExecution>) pom.getValue( "build/plugins[@artifactId='maven-resources-plugin']/executions"
);
+        assertNotNull( executions );
+        assertEquals( 4, executions.size() );
+        assertEquals( "default-resources", executions.get( 0 ).getId() );
+        assertEquals( "default-testResources", executions.get( 1 ).getId() );
+        assertEquals( "test-1", executions.get( 2 ).getId() );
+        assertEquals( "test-2", executions.get( 3 ).getId() );
+    }
+
     private void assertPathSuffixEquals( String expected, Object actual )
     {
         String a = actual.toString();

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/plugin-exec-order-and-default-exec/
------------------------------------------------------------------------------
    bugtraq:label = Enter issue ID:

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/plugin-exec-order-and-default-exec/
------------------------------------------------------------------------------
    bugtraq:message = Issue id: %BUGID%

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/plugin-exec-order-and-default-exec/
------------------------------------------------------------------------------
    bugtraq:number = false

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/plugin-exec-order-and-default-exec/
------------------------------------------------------------------------------
    bugtraq:url = http://jira.codehaus.org/browse/%BUGID%

Added: maven/components/trunk/maven-core/src/test/resources-project-builder/plugin-exec-order-and-default-exec/pom.xml
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/test/resources-project-builder/plugin-exec-order-and-default-exec/pom.xml?rev=809751&view=auto
==============================================================================
--- maven/components/trunk/maven-core/src/test/resources-project-builder/plugin-exec-order-and-default-exec/pom.xml
(added)
+++ maven/components/trunk/maven-core/src/test/resources-project-builder/plugin-exec-order-and-default-exec/pom.xml
Mon Aug 31 21:31:01 2009
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<project>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.mng4332</groupId>
+  <artifactId>test</artifactId>
+  <version>0.1</version>
+  <!-- NOTE: The upper-case packaging name is intentional and triggers a special mode
in the EmptyLifecycleExecutor -->
+  <packaging>JAR</packaging>
+
+  <name>Maven Integration Test :: MNG-4332</name>
+  <description>
+    Verify that default plugin executions contributed by the packaging are executed before
user-defined
+    executions from the POM's build section, regardless whether the executions are defined
in the regular
+    plugins section or the plugin management section.
+  </description>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <artifactId>maven-resources-plugin</artifactId>
+          <version>2.2</version>
+          <executions>
+            <execution>
+              <id>test-1</id>
+              <goals>
+                <goal>resources</goal>
+              </goals>
+            </execution>
+          </executions>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+    <plugins>
+      <plugin>
+        <artifactId>maven-resources-plugin</artifactId>
+        <version>2.2</version>
+        <executions>
+          <execution>
+            <id>test-2</id>
+            <goals>
+              <goal>resources</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/plugin-exec-order-and-default-exec/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/plugin-exec-order-and-default-exec/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java?rev=809751&r1=809750&r2=809751&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
(original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
Mon Aug 31 21:31:01 2009
@@ -215,17 +215,15 @@
 
         modelPathTranslator.alignToBaseDirectory( resultModel, resultModel.getProjectDirectory(),
request );
 
-        pluginManagementInjector.injectBasicManagement( resultModel, request, problems );
+        pluginManagementInjector.injectManagement( resultModel, request, problems );
 
         fireEvent( resultModel, request, problems, ModelBuildingEventCatapult.BUILD_EXTENSIONS_ASSEMBLED
);
 
         if ( request.isProcessPlugins() )
         {
-            lifecycleBindingsInjector.injectLifecycleBindings( resultModel, problems );
+            lifecycleBindingsInjector.injectLifecycleBindings( resultModel, request, problems
);
         }
 
-        pluginManagementInjector.injectManagement( resultModel, request, problems );
-
         importDependencyManagement( resultModel, request, problems );
 
         dependencyManagementInjector.injectManagement( resultModel, request, problems );

Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/management/DefaultPluginManagementInjector.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/management/DefaultPluginManagementInjector.java?rev=809751&r1=809750&r2=809751&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/management/DefaultPluginManagementInjector.java
(original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/management/DefaultPluginManagementInjector.java
Mon Aug 31 21:31:01 2009
@@ -51,19 +51,14 @@
 
     public void injectManagement( Model model, ModelBuildingRequest request, ModelProblemCollector
problems )
     {
-        merger.mergeManagedBuildPlugins( model, false );
-    }
-
-    public void injectBasicManagement( Model model, ModelBuildingRequest request, ModelProblemCollector
problems )
-    {
-        merger.mergeManagedBuildPlugins( model, true );
+        merger.mergeManagedBuildPlugins( model );
     }
 
     private static class ManagementModelMerger
         extends MavenModelMerger
     {
 
-        public void mergeManagedBuildPlugins( Model model, boolean basic )
+        public void mergeManagedBuildPlugins( Model model )
         {
             Build build = model.getBuild();
             if ( build != null )
@@ -71,12 +66,12 @@
                 PluginManagement pluginManagement = build.getPluginManagement();
                 if ( pluginManagement != null )
                 {
-                    mergePluginContainer_Plugins( build, pluginManagement, basic );
+                    mergePluginContainer_Plugins( build, pluginManagement );
                 }
             }
         }
 
-        private void mergePluginContainer_Plugins( PluginContainer target, PluginContainer
source, boolean basic )
+        private void mergePluginContainer_Plugins( PluginContainer target, PluginContainer
source )
         {
             List<Plugin> src = source.getPlugins();
             if ( !src.isEmpty() )
@@ -101,19 +96,7 @@
                     Plugin managedPlugin = managedPlugins.get( key );
                     if ( managedPlugin != null )
                     {
-                        if ( basic )
-                        {
-                            mergePlugin_Version( element, managedPlugin, false, context );
-                            mergePlugin_Extensions( element, managedPlugin, false, context
);
-                            if ( element.isExtensions() )
-                            {
-                                mergePlugin_Dependencies( element, managedPlugin, false,
context );
-                            }
-                        }
-                        else
-                        {
-                            mergePlugin( element, managedPlugin, false, context );
-                        }
+                        mergePlugin( element, managedPlugin, false, context );
                     }
                 }
             }

Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/management/DependencyManagementInjector.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/management/DependencyManagementInjector.java?rev=809751&r1=809750&r2=809751&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/management/DependencyManagementInjector.java
(original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/management/DependencyManagementInjector.java
Mon Aug 31 21:31:01 2009
@@ -34,11 +34,11 @@
     /**
      * Merges default values from the dependency management section of the given model into
itself.
      * 
-     * @param child The model into which to merge the values specified by its dependency
management sections, must not
+     * @param model The model into which to merge the values specified by its dependency
management sections, must not
      *            be <code>null</code>.
      * @param request The model building request that holds further settings, must not be
{@code null}.
      * @param problems The container used to collect problems that were encountered, must
not be {@code null}.
      */
-    void injectManagement( Model child, ModelBuildingRequest request, ModelProblemCollector
problems );
+    void injectManagement( Model model, ModelBuildingRequest request, ModelProblemCollector
problems );
 
 }

Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/management/PluginManagementInjector.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/management/PluginManagementInjector.java?rev=809751&r1=809750&r2=809751&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/management/PluginManagementInjector.java
(original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/management/PluginManagementInjector.java
Mon Aug 31 21:31:01 2009
@@ -34,23 +34,11 @@
     /**
      * Merges default values from the plugin management section of the given model into itself.
      * 
-     * @param child The model into which to merge the values specified by its plugin management
section, must not be
+     * @param model The model into which to merge the values specified by its plugin management
section, must not be
      *            <code>null</code>.
      * @param request The model building request that holds further settings, must not be
{@code null}.
      * @param problems The container used to collect problems that were encountered, must
not be {@code null}.
      */
-    void injectManagement( Model child, ModelBuildingRequest request, ModelProblemCollector
problems );
-
-    /**
-     * Merges important default values from the plugin management section of the given model
into itself. In detail,
-     * only the plugin version and the extensions flag are merged. These fields are critical
in order to be able to load
-     * extensions from plugins.
-     * 
-     * @param child The model into which to merge the values specified by its plugin management
section, must not be
-     *            <code>null</code>.
-     * @param request The model building request that holds further settings, must not be
{@code null}.
-     * @param problems The container used to collect problems that were encountered, must
not be {@code null}.
-     */
-    void injectBasicManagement( Model child, ModelBuildingRequest request, ModelProblemCollector
problems );
+    void injectManagement( Model model, ModelBuildingRequest request, ModelProblemCollector
problems );
 
 }

Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/plugin/LifecycleBindingsInjector.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/plugin/LifecycleBindingsInjector.java?rev=809751&r1=809750&r2=809751&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/plugin/LifecycleBindingsInjector.java
(original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/plugin/LifecycleBindingsInjector.java
Mon Aug 31 21:31:01 2009
@@ -20,6 +20,7 @@
  */
 
 import org.apache.maven.model.Model;
+import org.apache.maven.model.building.ModelBuildingRequest;
 import org.apache.maven.model.building.ModelProblemCollector;
 
 /**
@@ -31,12 +32,15 @@
 {
 
     /**
-     * Injects plugin executions induced by lifecycle bindings into the specified model.
+     * Injects plugin executions induced by lifecycle bindings into the specified model.
The model has already undergone
+     * injection of plugin management so any plugins that are injected by lifecycle bindings
and are not already present
+     * in the model's plugin section need to be subjected to the model's plugin management.
      * 
      * @param model The model into which to inject the default plugin executions for its
packaging, must not be
      *            <code>null</code>.
+     * @param request The model building request that holds further settings, must not be
{@code null}.
      * @param problems The container used to collect problems that were encountered, must
not be {@code null}.
      */
-    void injectLifecycleBindings( Model model, ModelProblemCollector problems );
+    void injectLifecycleBindings( Model model, ModelBuildingRequest request, ModelProblemCollector
problems );
 
 }



Mime
View raw message