You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2010/03/28 17:05:40 UTC
svn commit: r928426 - in /maven/maven-3/trunk/maven-model-builder/src:
main/java/org/apache/maven/model/validation/
test/java/org/apache/maven/model/validation/ test/resources/poms/validation/
Author: bentmann
Date: Sun Mar 28 15:05:40 2010
New Revision: 928426
URL: http://svn.apache.org/viewvc?rev=928426&view=rev
Log:
[MNG-1701] Validate that a plugin is not configured twice in the pom
Added:
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/duplicate-plugin.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
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=928426&r1=928425&r2=928426&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 Sun Mar 28 15:05:40 2010
@@ -34,6 +34,7 @@ import org.apache.maven.model.Distributi
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.model.Plugin;
+import org.apache.maven.model.PluginManagement;
import org.apache.maven.model.Profile;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.Reporting;
@@ -95,6 +96,18 @@ public class DefaultModelValidator
validateRepositories( problems, model.getPluginRepositories(), "pluginRepositories.pluginRepository", request );
+ Build build = model.getBuild();
+ if ( build != null )
+ {
+ validateRawPlugins( problems, build.getPlugins(), false, request );
+
+ PluginManagement mngt = build.getPluginManagement();
+ if ( mngt != null )
+ {
+ validateRawPlugins( problems, mngt.getPlugins(), true, request );
+ }
+ }
+
Set<String> profileIds = new HashSet<String>();
for ( Profile profile : model.getProfiles() )
@@ -124,6 +137,33 @@ public class DefaultModelValidator
}
}
+ private void validateRawPlugins( ModelProblemCollector problems, List<Plugin> plugins, boolean managed,
+ 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 )
+ {
+ String key = plugin.getKey();
+
+ Plugin existing = index.get( key );
+
+ if ( existing != null )
+ {
+ addViolation( problems, errOn31, prefix + "(groupId:artifactId)", null,
+ "must be unique but found duplicate declaration of plugin " + key );
+ }
+ else
+ {
+ index.put( key, plugin );
+ }
+ }
+ }
+
public void validateEffectiveModel( Model model, ModelBuildingRequest request, ModelProblemCollector problems )
{
validateStringNotEmpty( "modelVersion", problems, Severity.ERROR, model.getModelVersion() );
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=928426&r1=928425&r2=928426&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 Sun Mar 28 15:05:40 2010
@@ -439,4 +439,15 @@ public class DefaultModelValidatorTest
assertTrue( result.getWarnings().get( 0 ).contains( "'modules.module' has been specified without a path" ) );
}
+ public void testDuplicatePlugin()
+ throws Exception
+ {
+ SimpleProblemCollector result = validateRaw( "duplicate-plugin.xml" );
+
+ assertViolations( result, 0, 0, 2 );
+
+ 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" ) );
+ }
+
}
Added: 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=928426&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/duplicate-plugin.xml (added)
+++ maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/duplicate-plugin.xml Sun Mar 28 15:05:40 2010
@@ -0,0 +1,51 @@
+<!--
+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>test</groupId>
+ <artifactId>managed-duplicate</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>test</groupId>
+ <artifactId>managed-duplicate</artifactId>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>test</groupId>
+ <artifactId>duplicate</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>test</groupId>
+ <artifactId>duplicate</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange: maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/duplicate-plugin.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/duplicate-plugin.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision