Author: bentmann
Date: Mon May 31 11:27:00 2010
New Revision: 949720

URL: http://svn.apache.org/viewvc?rev=949720&view=rev
Log:
[MNG-4695] Missing Error during pom validation: "You cannot have two plugin 
executions with the same (or missing) <id/> elements."

Added:
    
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/duplicate-plugin-execution.xml
   (with props)
Modified:
    
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
    
maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
    
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/duplicate-plugin.xml

Modified: 
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
URL: 
http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java?rev=949720&r1=949719&r2=949720&view=diff
==============================================================================
--- 
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
 (original)
+++ 
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
 Mon May 31 11:27:00 2010
@@ -28,6 +28,7 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.maven.model.Build;
+import org.apache.maven.model.BuildBase;
 import org.apache.maven.model.Dependency;
 import org.apache.maven.model.DependencyManagement;
 import org.apache.maven.model.DistributionManagement;
@@ -103,12 +104,12 @@ public class DefaultModelValidator
             Build build = model.getBuild();
             if ( build != null )
             {
-                validateRawPlugins( problems, build.getPlugins(), false, 
request );
+                validateRawPlugins( problems, build.getPlugins(), 
"build.plugins.plugin", request );
 
                 PluginManagement mngt = build.getPluginManagement();
                 if ( mngt != null )
                 {
-                    validateRawPlugins( problems, mngt.getPlugins(), true, 
request );
+                    validateRawPlugins( problems, mngt.getPlugins(), 
"build.pluginManagement.plugins.plugin", request );
                 }
             }
 
@@ -116,38 +117,49 @@ public class DefaultModelValidator
 
             for ( Profile profile : model.getProfiles() )
             {
+                String prefix = "profiles.profile[" + profile.getId() + "]";
+
                 if ( !profileIds.add( profile.getId() ) )
                 {
                     addViolation( problems, errOn30, "profiles.profile.id", 
null,
                                   "must be unique but found duplicate profile 
with id " + profile.getId(), profile );
                 }
 
-                validateRawDependencies( problems, profile.getDependencies(), 
"profiles.profile[" + profile.getId()
-                    + "].dependencies.dependency", request );
+                validateRawDependencies( problems, profile.getDependencies(), 
prefix + ".dependencies.dependency",
+                                         request );
 
                 if ( profile.getDependencyManagement() != null )
                 {
-                    validateRawDependencies( problems, 
profile.getDependencyManagement().getDependencies(),
-                                          "profiles.profile[" + profile.getId()
-                                              + 
"].dependencyManagement.dependencies.dependency", request );
+                    validateRawDependencies( problems, 
profile.getDependencyManagement().getDependencies(), prefix
+                        + ".dependencyManagement.dependencies.dependency", 
request );
                 }
 
-                validateRepositories( problems, profile.getRepositories(), 
"profiles.profile[" + profile.getId()
-                    + "].repositories.repository", request );
+                validateRepositories( problems, profile.getRepositories(), 
prefix + ".repositories.repository", request );
+
+                validateRepositories( problems, 
profile.getPluginRepositories(), prefix
+                    + ".pluginRepositories.pluginRepository", request );
+
+                BuildBase buildBase = profile.getBuild();
+                if ( buildBase != null )
+                {
+                    validateRawPlugins( problems, buildBase.getPlugins(), 
prefix + ".plugins.plugin", request );
 
-                validateRepositories( problems, 
profile.getPluginRepositories(), "profiles.profile[" + profile.getId()
-                    + "].pluginRepositories.pluginRepository", request );
+                    PluginManagement mngt = buildBase.getPluginManagement();
+                    if ( mngt != null )
+                    {
+                        validateRawPlugins( problems, mngt.getPlugins(), 
prefix + ".pluginManagement.plugins.plugin",
+                                            request );
+                    }
+                }
             }
         }
     }
 
-    private void validateRawPlugins( ModelProblemCollector problems, 
List<Plugin> plugins, boolean managed,
+    private void validateRawPlugins( ModelProblemCollector problems, 
List<Plugin> plugins, String prefix,
                                      ModelBuildingRequest request )
     {
         Severity errOn31 = getSeverity( request, 
ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 );
 
-        String prefix = ( managed ? "build.pluginManagement." : "build." ) + 
"plugins.plugin.";
-
         Map<String, Plugin> index = new HashMap<String, Plugin>();
 
         for ( Plugin plugin : plugins )
@@ -158,7 +170,7 @@ public class DefaultModelValidator
 
             if ( existing != null )
             {
-                addViolation( problems, errOn31, prefix + 
"(groupId:artifactId)", null,
+                addViolation( problems, errOn31, prefix + 
".(groupId:artifactId)", null,
                               "must be unique but found duplicate declaration 
of plugin " + key, plugin );
             }
             else
@@ -172,7 +184,7 @@ public class DefaultModelValidator
             {
                 if ( !executionIds.add( exec.getId() ) )
                 {
-                    addViolation( problems, Severity.ERROR, 
"build.plugins.plugin[" + plugin.getKey()
+                    addViolation( problems, Severity.ERROR, prefix + "[" + 
plugin.getKey()
                         + "].executions.execution.id", null, "must be unique 
but found duplicate execution with id "
                         + exec.getId(), exec );
                 }

Modified: 
maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
URL: 
http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java?rev=949720&r1=949719&r2=949720&view=diff
==============================================================================
--- 
maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
 (original)
+++ 
maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
 Mon May 31 11:27:00 2010
@@ -433,10 +433,25 @@ public class DefaultModelValidatorTest
     {
         SimpleProblemCollector result = validateRaw( "duplicate-plugin.xml" );
 
-        assertViolations( result, 0, 0, 2 );
+        assertViolations( result, 0, 0, 4 );
 
         assertTrue( result.getWarnings().get( 0 ).contains( "duplicate 
declaration of plugin test:duplicate" ) );
         assertTrue( result.getWarnings().get( 1 ).contains( "duplicate 
declaration of plugin test:managed-duplicate" ) );
+        assertTrue( result.getWarnings().get( 2 ).contains( "duplicate 
declaration of plugin profile:duplicate" ) );
+        assertTrue( result.getWarnings().get( 3 ).contains( "duplicate 
declaration of plugin profile:managed-duplicate" ) );
+    }
+
+    public void testDuplicatePluginExecution()
+        throws Exception
+    {
+        SimpleProblemCollector result = validateRaw( 
"duplicate-plugin-execution.xml" );
+
+        assertViolations( result, 0, 4, 0 );
+
+        assertContains( result.getErrors().get( 0 ), "duplicate execution with 
id a" );
+        assertContains( result.getErrors().get( 1 ), "duplicate execution with 
id default" );
+        assertContains( result.getErrors().get( 2 ), "duplicate execution with 
id c" );
+        assertContains( result.getErrors().get( 3 ), "duplicate execution with 
id b" );
     }
 
     public void testReservedRepositoryId()

Added: 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/duplicate-plugin-execution.xml
URL: 
http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/duplicate-plugin-execution.xml?rev=949720&view=auto
==============================================================================
--- 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/duplicate-plugin-execution.xml
 (added)
+++ 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/duplicate-plugin-execution.xml
 Mon May 31 11:27:00 2010
@@ -0,0 +1,103 @@
+<!--
+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>
+  <artifactId>aid</artifactId>
+  <groupId>gid</groupId>
+  <version>0.1</version>
+  <packaging>pom</packaging>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>build</groupId>
+          <artifactId>managed-plugin</artifactId>
+          <executions>
+            <execution>
+              <phase>test</phase>
+            </execution>
+            <execution>
+              <phase>test</phase>
+            </execution>
+          </executions>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+    <plugins>
+      <plugin>
+        <groupId>build</groupId>
+        <artifactId>plugin</artifactId>
+        <executions>
+          <execution>
+            <id>a</id>
+            <phase>test</phase>
+          </execution>
+          <execution>
+            <id>a</id>
+            <phase>test</phase>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <profiles>
+    <profile>
+      <id>test</id>
+      <build>
+        <pluginManagement>
+          <plugins>
+            <plugin>
+              <groupId>profile</groupId>
+              <artifactId>managed-plugin</artifactId>
+              <executions>
+                <execution>
+                  <id>b</id>
+                  <phase>test</phase>
+                </execution>
+                <execution>
+                  <id>b</id>
+                  <phase>test</phase>
+                </execution>
+              </executions>
+            </plugin>
+          </plugins>
+        </pluginManagement>
+        <plugins>
+          <plugin>
+            <groupId>profile</groupId>
+            <artifactId>plugin</artifactId>
+            <executions>
+              <execution>
+                <id>c</id>
+                <phase>test</phase>
+              </execution>
+              <execution>
+                <id>c</id>
+                <phase>test</phase>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
+</project>

Propchange: 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/duplicate-plugin-execution.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/duplicate-plugin-execution.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/duplicate-plugin.xml
URL: 
http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/duplicate-plugin.xml?rev=949720&r1=949719&r2=949720&view=diff
==============================================================================
--- 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/duplicate-plugin.xml
 (original)
+++ 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/duplicate-plugin.xml
 Mon May 31 11:27:00 2010
@@ -48,4 +48,34 @@ under the License.
       </plugin>
     </plugins>
   </build>
+
+  <profiles>
+    <profile>
+      <id>test</id>
+      <build>
+        <pluginManagement>
+          <plugins>
+            <plugin>
+              <groupId>profile</groupId>
+              <artifactId>managed-duplicate</artifactId>
+            </plugin>
+            <plugin>
+              <groupId>profile</groupId>
+              <artifactId>managed-duplicate</artifactId>
+            </plugin>
+          </plugins>
+        </pluginManagement>
+        <plugins>
+          <plugin>
+            <groupId>profile</groupId>
+            <artifactId>duplicate</artifactId>
+          </plugin>
+          <plugin>
+            <groupId>profile</groupId>
+            <artifactId>duplicate</artifactId>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
 </project>


Reply via email to