diff --git a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java
index f3c8bd0c47..73e08ab741 100644
--- a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java
+++ b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java
@@ -1450,6 +1450,67 @@ public class PomConstructionTest
assertEquals( 1, executions.size() );
assertEquals( "inherited-execution", executions.get( 0 ).getId() );
}
+
+ /* MNG-4193 */
+ public void testValidationErrorUponNonUniqueArtifactRepositoryId()
+ throws Exception
+ {
+ try
+ {
+ buildPom( "unique-repo-id/artifact-repo" );
+ fail( "Non-unique repository ids did not cause validation error" );
+ }
+ catch ( ProjectBuildingException e )
+ {
+ // expected
+ }
+ }
+
+ /* MNG-4193 */
+ public void testValidationErrorUponNonUniquePluginRepositoryId()
+ throws Exception
+ {
+ try
+ {
+ buildPom( "unique-repo-id/plugin-repo" );
+ fail( "Non-unique repository ids did not cause validation error" );
+ }
+ catch ( ProjectBuildingException e )
+ {
+ // expected
+ }
+ }
+
+ /* MNG-4193 */
+ public void testValidationErrorUponNonUniqueArtifactRepositoryIdInProfile()
+ throws Exception
+ {
+ try
+ {
+ buildPom( "unique-repo-id/artifact-repo-in-profile" );
+ fail( "Non-unique repository ids did not cause validation error" );
+ }
+ catch ( ProjectBuildingException e )
+ {
+ // expected
+ e.printStackTrace();
+ }
+ }
+
+ /* MNG-4193 */
+ public void testValidationErrorUponNonUniquePluginRepositoryIdInProfile()
+ throws Exception
+ {
+ try
+ {
+ buildPom( "unique-repo-id/plugin-repo-in-profile" );
+ fail( "Non-unique repository ids did not cause validation error" );
+ }
+ catch ( ProjectBuildingException e )
+ {
+ // expected
+ }
+ }
private void assertPathSuffixEquals( String expected, Object actual )
{
@@ -1470,7 +1531,7 @@ public class PomConstructionTest
}
private PomTestWrapper buildPom( String pomPath, Properties executionProperties, String... profileIds )
- throws Exception
+ throws ProjectBuildingException
{
File pomFile = new File( testDirectory, pomPath );
if ( pomFile.isDirectory() )
diff --git a/maven-core/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java b/maven-core/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java
index 72c95e0b52..c204140a1f 100644
--- a/maven-core/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java
+++ b/maven-core/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java
@@ -20,7 +20,6 @@ package org.apache.maven.project.harness;
*/
import java.io.File;
-import java.io.IOException;
import java.util.Iterator;
import org.apache.commons.jxpath.JXPathContext;
@@ -43,7 +42,6 @@ public class PomTestWrapper
}
public PomTestWrapper( File pomFile, MavenProject mavenProject )
- throws IOException
{
if ( mavenProject == null )
{
@@ -55,7 +53,6 @@ public class PomTestWrapper
}
public PomTestWrapper( MavenProject mavenProject )
- throws IOException
{
if ( mavenProject == null )
{
diff --git a/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo-in-profile/pom.xml b/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo-in-profile/pom.xml
new file mode 100644
index 0000000000..eb73c4e23d
--- /dev/null
+++ b/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo-in-profile/pom.xml
@@ -0,0 +1,51 @@
+
+
+
+
+
+ 4.0.0
+
+ org.apache.maven.its.mng4193
+ test
+ 0.1
+ jar
+
+ Maven Integration Test :: MNG-4193
+
+ Test that multiple artifact repository declarations with the same id cause a validation error even if the
+ repositories are defined within a (non-active) profile.
+
+
+
+
+ test
+
+
+ one
+ http://repo1.maven.org/maven2
+
+
+ one
+ http://repository.codehaus.org/
+
+
+
+
+
diff --git a/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo/pom.xml b/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo/pom.xml
new file mode 100644
index 0000000000..76d4f74aff
--- /dev/null
+++ b/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo/pom.xml
@@ -0,0 +1,45 @@
+
+
+
+
+
+ 4.0.0
+
+ org.apache.maven.its.mng4193
+ test
+ 0.1
+ jar
+
+ Maven Integration Test :: MNG-4193
+
+ Test that multiple artifact repository declarations with the same id cause a validation error.
+
+
+
+
+ one
+ http://repo1.maven.org/maven2
+
+
+ one
+ http://repository.codehaus.org/
+
+
+
diff --git a/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo-in-profile/pom.xml b/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo-in-profile/pom.xml
new file mode 100644
index 0000000000..ac1fada558
--- /dev/null
+++ b/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo-in-profile/pom.xml
@@ -0,0 +1,51 @@
+
+
+
+
+
+ 4.0.0
+
+ org.apache.maven.its.mng4193
+ test
+ 0.1
+ jar
+
+ Maven Integration Test :: MNG-4193
+
+ Test that multiple plugin repository declarations with the same id cause a validation error even if the
+ repositories are defined within a (non-active) profile.
+
+
+
+
+ test
+
+
+ one
+ http://repo1.maven.org/maven2
+
+
+ one
+ http://repository.codehaus.org/
+
+
+
+
+
diff --git a/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo/pom.xml b/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo/pom.xml
new file mode 100644
index 0000000000..92fd1264d4
--- /dev/null
+++ b/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo/pom.xml
@@ -0,0 +1,45 @@
+
+
+
+
+
+ 4.0.0
+
+ org.apache.maven.its.mng4193
+ test
+ 0.1
+ jar
+
+ Maven Integration Test :: MNG-4193
+
+ Test that multiple plugin repository declarations with the same id cause a validation error.
+
+
+
+
+ one
+ http://repo1.maven.org/maven2
+
+
+ one
+ http://repository.codehaus.org/
+
+
+
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
index a2cb3cc002..dcfcb96aec 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
@@ -20,6 +20,8 @@ package org.apache.maven.model.validation;
*/
import java.io.File;
+import java.util.Collection;
+import java.util.HashSet;
import java.util.List;
import org.apache.maven.model.Build;
@@ -29,6 +31,7 @@ import org.apache.maven.model.Model;
import org.apache.maven.model.ModelBuildingRequest;
import org.apache.maven.model.Parent;
import org.apache.maven.model.Plugin;
+import org.apache.maven.model.Profile;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.Reporting;
import org.apache.maven.model.Repository;
@@ -67,7 +70,21 @@ public class DefaultModelValidator
}
}
- validateRepositories( result, model.getRepositories(), "repositories.repository" );
+ if ( !request.istLenientValidation() )
+ {
+ validateRepositories( result, model.getRepositories(), "repositories.repository" );
+
+ validateRepositories( result, model.getPluginRepositories(), "pluginRepositories.pluginRepository" );
+
+ for ( Profile profile : model.getProfiles() )
+ {
+ validateRepositories( result, profile.getRepositories(), "profiles.profile[" + profile.getId()
+ + "].repositories.repository" );
+
+ validateRepositories( result, profile.getPluginRepositories(), "profiles.profile[" + profile.getId()
+ + "].pluginRepositories.pluginRepository" );
+ }
+ }
return result;
}
@@ -231,11 +248,19 @@ public class DefaultModelValidator
private void validateRepositories( ModelValidationResult result, List repositories, String prefix )
{
+ Collection ids = new HashSet();
+
for ( Repository repository : repositories )
{
validateStringNotEmpty( prefix + ".id", result, repository.getId() );
validateStringNotEmpty( prefix + ".url", result, repository.getUrl() );
+
+ if ( !ids.add( repository.getId() ) )
+ {
+ result.addMessage( "'" + prefix + ".id' must be unique: " + repository.getId() + " -> "
+ + repository.getUrl() );
+ }
}
}
diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
index 441efc487c..a704bd36aa 100644
--- a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
+++ b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
@@ -251,11 +251,15 @@ public class DefaultModelValidatorTest
{
ModelValidationResult result = validate( "missing-repository-id-pom.xml", true, false );
- assertEquals( 2, result.getMessageCount() );
+ assertEquals( 4, result.getMessageCount() );
assertEquals( "'repositories.repository.id' is missing.", result.getMessage( 0 ) );
assertEquals( "'repositories.repository.url' is missing.", result.getMessage( 1 ) );
+
+ assertEquals( "'pluginRepositories.pluginRepository.id' is missing.", result.getMessage( 2 ) );
+
+ assertEquals( "'pluginRepositories.pluginRepository.url' is missing.", result.getMessage( 3 ) );
}
public void testMissingResourceDirectory()