[MNG-4193] Throw validation error upon multiple repository declarations with the same id

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@782796 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-06-08 21:38:45 +00:00
parent 2ec6f400be
commit 5cde8bfe4b
8 changed files with 285 additions and 6 deletions

View File

@ -1450,6 +1450,67 @@ public void testPluginExecutionInheritanceWhenChildDoesDeclarePluginAsWell()
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, String... profileIds )
}
private PomTestWrapper buildPom( String pomPath, Properties executionProperties, String... profileIds )
throws Exception
throws ProjectBuildingException
{
File pomFile = new File( testDirectory, pomPath );
if ( pomFile.isDirectory() )

View File

@ -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 class PomTestWrapper
}
public PomTestWrapper( File pomFile, MavenProject mavenProject )
throws IOException
{
if ( mavenProject == null )
{
@ -55,7 +53,6 @@ public PomTestWrapper( File pomFile, MavenProject mavenProject )
}
public PomTestWrapper( MavenProject mavenProject )
throws IOException
{
if ( mavenProject == null )
{

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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 @@ public ModelValidationResult validateRawModel( Model model, ModelBuildingRequest
}
}
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 boolean validateId( String fieldName, ModelValidationResult result, Stri
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() );
}
}
}

View File

@ -251,11 +251,15 @@ public void testMissingRepositoryId()
{
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()