mirror of https://github.com/apache/maven.git
[MNG-1701] Validate that a plugin is not configured twice in the pom
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@928426 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e472d8f539
commit
fbaa48e658
|
@ -34,6 +34,7 @@ import org.apache.maven.model.DistributionManagement;
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.Parent;
|
import org.apache.maven.model.Parent;
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
|
import org.apache.maven.model.PluginManagement;
|
||||||
import org.apache.maven.model.Profile;
|
import org.apache.maven.model.Profile;
|
||||||
import org.apache.maven.model.ReportPlugin;
|
import org.apache.maven.model.ReportPlugin;
|
||||||
import org.apache.maven.model.Reporting;
|
import org.apache.maven.model.Reporting;
|
||||||
|
@ -95,6 +96,18 @@ public class DefaultModelValidator
|
||||||
|
|
||||||
validateRepositories( problems, model.getPluginRepositories(), "pluginRepositories.pluginRepository", request );
|
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>();
|
Set<String> profileIds = new HashSet<String>();
|
||||||
|
|
||||||
for ( Profile profile : model.getProfiles() )
|
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 )
|
public void validateEffectiveModel( Model model, ModelBuildingRequest request, ModelProblemCollector problems )
|
||||||
{
|
{
|
||||||
validateStringNotEmpty( "modelVersion", problems, Severity.ERROR, model.getModelVersion() );
|
validateStringNotEmpty( "modelVersion", problems, Severity.ERROR, model.getModelVersion() );
|
||||||
|
|
|
@ -439,4 +439,15 @@ public class DefaultModelValidatorTest
|
||||||
assertTrue( result.getWarnings().get( 0 ).contains( "'modules.module' has been specified without a path" ) );
|
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" ) );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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>
|
Loading…
Reference in New Issue