mirror of https://github.com/apache/maven.git
[MNG-4695] Missing Error during pom validation: "You cannot have two plugin executions with the same (or missing) <id/> elements."
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@949720 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d499ca59c1
commit
bb39b48044
|
@ -28,6 +28,7 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.maven.model.Build;
|
import org.apache.maven.model.Build;
|
||||||
|
import org.apache.maven.model.BuildBase;
|
||||||
import org.apache.maven.model.Dependency;
|
import org.apache.maven.model.Dependency;
|
||||||
import org.apache.maven.model.DependencyManagement;
|
import org.apache.maven.model.DependencyManagement;
|
||||||
import org.apache.maven.model.DistributionManagement;
|
import org.apache.maven.model.DistributionManagement;
|
||||||
|
@ -103,12 +104,12 @@ public class DefaultModelValidator
|
||||||
Build build = model.getBuild();
|
Build build = model.getBuild();
|
||||||
if ( build != null )
|
if ( build != null )
|
||||||
{
|
{
|
||||||
validateRawPlugins( problems, build.getPlugins(), false, request );
|
validateRawPlugins( problems, build.getPlugins(), "build.plugins.plugin", request );
|
||||||
|
|
||||||
PluginManagement mngt = build.getPluginManagement();
|
PluginManagement mngt = build.getPluginManagement();
|
||||||
if ( mngt != null )
|
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() )
|
for ( Profile profile : model.getProfiles() )
|
||||||
{
|
{
|
||||||
|
String prefix = "profiles.profile[" + profile.getId() + "]";
|
||||||
|
|
||||||
if ( !profileIds.add( profile.getId() ) )
|
if ( !profileIds.add( profile.getId() ) )
|
||||||
{
|
{
|
||||||
addViolation( problems, errOn30, "profiles.profile.id", null,
|
addViolation( problems, errOn30, "profiles.profile.id", null,
|
||||||
"must be unique but found duplicate profile with id " + profile.getId(), profile );
|
"must be unique but found duplicate profile with id " + profile.getId(), profile );
|
||||||
}
|
}
|
||||||
|
|
||||||
validateRawDependencies( problems, profile.getDependencies(), "profiles.profile[" + profile.getId()
|
validateRawDependencies( problems, profile.getDependencies(), prefix + ".dependencies.dependency",
|
||||||
+ "].dependencies.dependency", request );
|
request );
|
||||||
|
|
||||||
if ( profile.getDependencyManagement() != null )
|
if ( profile.getDependencyManagement() != null )
|
||||||
{
|
{
|
||||||
validateRawDependencies( problems, profile.getDependencyManagement().getDependencies(),
|
validateRawDependencies( problems, profile.getDependencyManagement().getDependencies(), prefix
|
||||||
"profiles.profile[" + profile.getId()
|
+ ".dependencyManagement.dependencies.dependency", request );
|
||||||
+ "].dependencyManagement.dependencies.dependency", request );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
validateRepositories( problems, profile.getRepositories(), "profiles.profile[" + profile.getId()
|
validateRepositories( problems, profile.getRepositories(), prefix + ".repositories.repository", request );
|
||||||
+ "].repositories.repository", request );
|
|
||||||
|
|
||||||
validateRepositories( problems, profile.getPluginRepositories(), "profiles.profile[" + profile.getId()
|
validateRepositories( problems, profile.getPluginRepositories(), prefix
|
||||||
+ "].pluginRepositories.pluginRepository", request );
|
+ ".pluginRepositories.pluginRepository", request );
|
||||||
|
|
||||||
|
BuildBase buildBase = profile.getBuild();
|
||||||
|
if ( buildBase != null )
|
||||||
|
{
|
||||||
|
validateRawPlugins( problems, buildBase.getPlugins(), prefix + ".plugins.plugin", 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 )
|
ModelBuildingRequest request )
|
||||||
{
|
{
|
||||||
Severity errOn31 = getSeverity( request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 );
|
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>();
|
Map<String, Plugin> index = new HashMap<String, Plugin>();
|
||||||
|
|
||||||
for ( Plugin plugin : plugins )
|
for ( Plugin plugin : plugins )
|
||||||
|
@ -158,7 +170,7 @@ public class DefaultModelValidator
|
||||||
|
|
||||||
if ( existing != null )
|
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 );
|
"must be unique but found duplicate declaration of plugin " + key, plugin );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -172,7 +184,7 @@ public class DefaultModelValidator
|
||||||
{
|
{
|
||||||
if ( !executionIds.add( exec.getId() ) )
|
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 "
|
+ "].executions.execution.id", null, "must be unique but found duplicate execution with id "
|
||||||
+ exec.getId(), exec );
|
+ exec.getId(), exec );
|
||||||
}
|
}
|
||||||
|
|
|
@ -433,10 +433,25 @@ public class DefaultModelValidatorTest
|
||||||
{
|
{
|
||||||
SimpleProblemCollector result = validateRaw( "duplicate-plugin.xml" );
|
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( 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( 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()
|
public void testReservedRepositoryId()
|
||||||
|
|
|
@ -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>
|
|
@ -48,4 +48,34 @@ under the License.
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</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>
|
</project>
|
||||||
|
|
Loading…
Reference in New Issue