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 2009/06/08 23:38:46 UTC

svn commit: r782796 - in /maven/components/trunk: maven-core/src/test/java/org/apache/maven/project/ maven-core/src/test/java/org/apache/maven/project/harness/ maven-core/src/test/resources-project-builder/unique-repo-id/ maven-core/src/test/resources-...

Author: bentmann
Date: Mon Jun  8 21:38:45 2009
New Revision: 782796

URL: http://svn.apache.org/viewvc?rev=782796&view=rev
Log:
[MNG-4193] Throw validation error upon multiple repository declarations with the same id

Added:
    maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/   (with props)
    maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo/   (with props)
    maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo-in-profile/   (with props)
    maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo-in-profile/pom.xml   (with props)
    maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo/pom.xml   (with props)
    maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo/   (with props)
    maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo-in-profile/   (with props)
    maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo-in-profile/pom.xml   (with props)
    maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo/pom.xml   (with props)
Modified:
    maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java
    maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java
    maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
    maven/components/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java

Modified: maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java?rev=782796&r1=782795&r2=782796&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java (original)
+++ maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java Mon Jun  8 21:38:45 2009
@@ -1450,6 +1450,67 @@
         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 @@
     }
 
     private PomTestWrapper buildPom( String pomPath, Properties executionProperties, String... profileIds )
-        throws Exception
+        throws ProjectBuildingException
     {
         File pomFile = new File( testDirectory, pomPath );
         if ( pomFile.isDirectory() )

Modified: maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java?rev=782796&r1=782795&r2=782796&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java (original)
+++ maven/components/trunk/maven-core/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java Mon Jun  8 21:38:45 2009
@@ -20,7 +20,6 @@
  */
 
 import java.io.File;
-import java.io.IOException;
 import java.util.Iterator;
 
 import org.apache.commons.jxpath.JXPathContext;
@@ -43,7 +42,6 @@
     }
 
     public PomTestWrapper( File pomFile, MavenProject mavenProject )
-        throws IOException
     {
         if ( mavenProject == null )
         {
@@ -55,7 +53,6 @@
     }
 
     public PomTestWrapper( MavenProject mavenProject )
-        throws IOException
     {
         if ( mavenProject == null )
         {

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/
------------------------------------------------------------------------------
    bugtraq:label = Enter issue ID:

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/
------------------------------------------------------------------------------
    bugtraq:message = Issue id: %BUGID%

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/
------------------------------------------------------------------------------
    bugtraq:number = false

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/
------------------------------------------------------------------------------
    bugtraq:url = http://jira.codehaus.org/browse/%BUGID%

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo/
------------------------------------------------------------------------------
    bugtraq:label = Enter issue ID:

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo/
------------------------------------------------------------------------------
    bugtraq:message = Issue id: %BUGID%

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo/
------------------------------------------------------------------------------
    bugtraq:number = false

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo/
------------------------------------------------------------------------------
    bugtraq:url = http://jira.codehaus.org/browse/%BUGID%

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo-in-profile/
------------------------------------------------------------------------------
    bugtraq:label = Enter issue ID:

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo-in-profile/
------------------------------------------------------------------------------
    bugtraq:message = Issue id: %BUGID%

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo-in-profile/
------------------------------------------------------------------------------
    bugtraq:number = false

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo-in-profile/
------------------------------------------------------------------------------
    bugtraq:url = http://jira.codehaus.org/browse/%BUGID%

Added: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo-in-profile/pom.xml
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo-in-profile/pom.xml?rev=782796&view=auto
==============================================================================
--- maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo-in-profile/pom.xml (added)
+++ maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo-in-profile/pom.xml Mon Jun  8 21:38:45 2009
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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>
+
+  <groupId>org.apache.maven.its.mng4193</groupId>
+  <artifactId>test</artifactId>
+  <version>0.1</version>
+  <packaging>jar</packaging>
+
+  <name>Maven Integration Test :: MNG-4193</name>
+  <description>
+    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.
+  </description>
+
+  <profiles>
+    <profile>
+      <id>test</id>
+      <repositories>
+        <repository>
+          <id>one</id>
+          <url>http://repo1.maven.org/maven2</url>
+        </repository>
+        <repository>
+          <id>one</id>
+          <url>http://repository.codehaus.org/</url>
+        </repository>
+      </repositories>
+    </profile>
+  </profiles>
+</project>

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo-in-profile/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo-in-profile/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo/pom.xml
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo/pom.xml?rev=782796&view=auto
==============================================================================
--- maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo/pom.xml (added)
+++ maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo/pom.xml Mon Jun  8 21:38:45 2009
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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>
+
+  <groupId>org.apache.maven.its.mng4193</groupId>
+  <artifactId>test</artifactId>
+  <version>0.1</version>
+  <packaging>jar</packaging>
+
+  <name>Maven Integration Test :: MNG-4193</name>
+  <description>
+    Test that multiple artifact repository declarations with the same id cause a validation error.
+  </description>
+
+  <repositories>
+    <repository>
+      <id>one</id>
+      <url>http://repo1.maven.org/maven2</url>
+    </repository>
+    <repository>
+      <id>one</id>
+      <url>http://repository.codehaus.org/</url>
+    </repository>
+  </repositories>
+</project>

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/artifact-repo/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo/
------------------------------------------------------------------------------
    bugtraq:label = Enter issue ID:

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo/
------------------------------------------------------------------------------
    bugtraq:message = Issue id: %BUGID%

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo/
------------------------------------------------------------------------------
    bugtraq:number = false

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo/
------------------------------------------------------------------------------
    bugtraq:url = http://jira.codehaus.org/browse/%BUGID%

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo-in-profile/
------------------------------------------------------------------------------
    bugtraq:label = Enter issue ID:

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo-in-profile/
------------------------------------------------------------------------------
    bugtraq:message = Issue id: %BUGID%

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo-in-profile/
------------------------------------------------------------------------------
    bugtraq:number = false

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo-in-profile/
------------------------------------------------------------------------------
    bugtraq:url = http://jira.codehaus.org/browse/%BUGID%

Added: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo-in-profile/pom.xml
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo-in-profile/pom.xml?rev=782796&view=auto
==============================================================================
--- maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo-in-profile/pom.xml (added)
+++ maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo-in-profile/pom.xml Mon Jun  8 21:38:45 2009
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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>
+
+  <groupId>org.apache.maven.its.mng4193</groupId>
+  <artifactId>test</artifactId>
+  <version>0.1</version>
+  <packaging>jar</packaging>
+
+  <name>Maven Integration Test :: MNG-4193</name>
+  <description>
+    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.
+  </description>
+
+  <profiles>
+    <profile>
+      <id>test</id>
+      <pluginRepositories>
+        <pluginRepository>
+          <id>one</id>
+          <url>http://repo1.maven.org/maven2</url>
+        </pluginRepository>
+        <pluginRepository>
+          <id>one</id>
+          <url>http://repository.codehaus.org/</url>
+        </pluginRepository>
+      </pluginRepositories>
+    </profile>
+  </profiles>
+</project>

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo-in-profile/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo-in-profile/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo/pom.xml
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo/pom.xml?rev=782796&view=auto
==============================================================================
--- maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo/pom.xml (added)
+++ maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo/pom.xml Mon Jun  8 21:38:45 2009
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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>
+
+  <groupId>org.apache.maven.its.mng4193</groupId>
+  <artifactId>test</artifactId>
+  <version>0.1</version>
+  <packaging>jar</packaging>
+
+  <name>Maven Integration Test :: MNG-4193</name>
+  <description>
+    Test that multiple plugin repository declarations with the same id cause a validation error.
+  </description>
+
+  <pluginRepositories>
+    <pluginRepository>
+      <id>one</id>
+      <url>http://repo1.maven.org/maven2</url>
+    </pluginRepository>
+    <pluginRepository>
+      <id>one</id>
+      <url>http://repository.codehaus.org/</url>
+    </pluginRepository>
+  </pluginRepositories>
+</project>

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-core/src/test/resources-project-builder/unique-repo-id/plugin-repo/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java?rev=782796&r1=782795&r2=782796&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java (original)
+++ maven/components/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java Mon Jun  8 21:38:45 2009
@@ -20,6 +20,8 @@
  */
 
 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.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 @@
             }
         }
 
-        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 @@
 
     private void validateRepositories( ModelValidationResult result, List<Repository> repositories, String prefix )
     {
+        Collection<String> ids = new HashSet<String>();
+
         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() );
+            }
         }
     }
 

Modified: maven/components/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java?rev=782796&r1=782795&r2=782796&view=diff
==============================================================================
--- maven/components/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java (original)
+++ maven/components/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java Mon Jun  8 21:38:45 2009
@@ -251,11 +251,15 @@
     {
         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()