[MNG-4418] Dependency resolution appears to misbehave if a remote repository uses the id "local"

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@929329 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2010-03-30 22:53:01 +00:00
parent 1b157097df
commit e45fa790c7
5 changed files with 116 additions and 13 deletions

View File

@ -88,6 +88,11 @@ public class DefaultSettingsValidator
{
validateStringNotEmpty( problems, "mirrors.mirror.id", mirror.getId(), mirror.getUrl() );
if ( "local".equals( mirror.getId() ) )
{
addError( problems, "'mirrors.mirror.id' must not be 'local', this identifier is reserved." );
}
validateStringNotEmpty( problems, "mirrors.mirror.url", mirror.getUrl(), mirror.getId() );
validateStringNotEmpty( problems, "mirrors.mirror.mirrorOf", mirror.getMirrorOf(), mirror.getId() );
@ -112,6 +117,11 @@ public class DefaultSettingsValidator
{
validateStringNotEmpty( problems, prefix + ".id", repository.getId(), repository.getUrl() );
if ( "local".equals( repository.getId() ) )
{
addError( problems, "'" + prefix + ".id' must not be 'local', this identifier is reserved." );
}
validateStringNotEmpty( problems, prefix + ".url", repository.getUrl(), repository.getId() );
if ( "legacy".equals( repository.getLayout() ) )

View File

@ -87,15 +87,36 @@ public class DefaultSettingsValidatorTest
throws Exception
{
Mirror mirror = new Mirror();
mirror.setId( "local" );
Settings settings = new Settings();
settings.addMirror( mirror );
SimpleProblemCollector problems = new SimpleProblemCollector();
validator.validate( settings, problems );
assertEquals( 3, problems.messages.size() );
assertTrue( problems.messages.get( 0 ), problems.messages.get( 0 ).contains( "'mirrors.mirror.id' must not be 'local'" ) );
assertTrue( problems.messages.get( 1 ), problems.messages.get( 1 ).contains( "'mirrors.mirror.url' is missing" ) );
assertTrue( problems.messages.get( 2 ),
problems.messages.get( 2 ).contains( "'mirrors.mirror.mirrorOf' is missing" ) );
}
public void testValidateRepository()
throws Exception
{
Repository repo = new Repository();
repo.setId( "local" );
Profile profile = new Profile();
profile.addRepository( repo );
Settings settings = new Settings();
settings.addProfile( profile );
SimpleProblemCollector problems = new SimpleProblemCollector();
validator.validate( settings, problems );
assertEquals( 2, problems.messages.size() );
assertTrue( problems.messages.get( 0 ), problems.messages.get( 0 ).contains( "'mirrors.mirror.url' is missing" ) );
assertTrue( problems.messages.get( 0 ),
problems.messages.get( 0 ).contains( "'repositories.repository.id' must not be 'local'" ) );
assertTrue( problems.messages.get( 1 ),
problems.messages.get( 1 ).contains( "'mirrors.mirror.mirrorOf' is missing" ) );
problems.messages.get( 1 ).contains( "'repositories.repository.url' is missing" ) );
}
private static class SimpleProblemCollector

View File

@ -270,12 +270,12 @@ public class DefaultModelValidator
for ( Repository repository : model.getRepositories() )
{
validateRepositoryLayout( problems, repository, "repositories.repository", request );
validateRepository( problems, repository, "repositories.repository", request );
}
for ( Repository repository : model.getPluginRepositories() )
{
validateRepositoryLayout( problems, repository, "pluginRepositories.pluginRepository", request );
validateRepository( problems, repository, "pluginRepositories.pluginRepository", request );
}
DistributionManagement distMgmt = model.getDistributionManagement();
@ -287,10 +287,9 @@ public class DefaultModelValidator
"must not be specified." );
}
validateRepositoryLayout( problems, distMgmt.getRepository(), "distributionManagement.repository",
request );
validateRepositoryLayout( problems, distMgmt.getSnapshotRepository(),
"distributionManagement.snapshotRepository", request );
validateRepository( problems, distMgmt.getRepository(), "distributionManagement.repository", request );
validateRepository( problems, distMgmt.getSnapshotRepository(),
"distributionManagement.snapshotRepository", request );
}
}
}
@ -457,13 +456,21 @@ public class DefaultModelValidator
}
}
private void validateRepositoryLayout( ModelProblemCollector problems, Repository repository, String prefix,
ModelBuildingRequest request )
private void validateRepository( ModelProblemCollector problems, Repository repository, String prefix,
ModelBuildingRequest request )
{
if ( repository != null && "legacy".equals( repository.getLayout() ) )
if ( repository != null )
{
addViolation( problems, Severity.WARNING, prefix + ".layout", repository.getId(),
"uses the deprecated value 'legacy'." );
if ( "local".equals( repository.getId() ) )
{
addViolation( problems, Severity.ERROR, prefix + ".id", null,
"must not be 'local', this identifier is reserved." );
}
if ( "legacy".equals( repository.getLayout() ) )
{
addViolation( problems, Severity.WARNING, prefix + ".layout", repository.getId(),
"uses the deprecated value 'legacy'." );
}
}
}

View File

@ -450,4 +450,19 @@ public class DefaultModelValidatorTest
assertTrue( result.getWarnings().get( 1 ).contains( "duplicate declaration of plugin test:managed-duplicate" ) );
}
public void testReservedRepositoryId()
throws Exception
{
SimpleProblemCollector result = validate( "reserved-repository-id.xml" );
assertViolations( result, 0, 4, 0 );
assertTrue( result.getErrors().get( 0 ).contains( "'repositories.repository.id' must not be 'local'" ) );
assertTrue( result.getErrors().get( 1 ).contains(
"'pluginRepositories.pluginRepository.id' must not be 'local'" ) );
assertTrue( result.getErrors().get( 2 ).contains( "'distributionManagement.repository.id' must not be 'local'" ) );
assertTrue( result.getErrors().get( 3 ).contains(
"'distributionManagement.snapshotRepository.id' must not be 'local'" ) );
}
}

View File

@ -0,0 +1,50 @@
<!--
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>gid</groupId>
<artifactId>aid</artifactId>
<version>99.44</version>
<repositories>
<repository>
<id>local</id>
<url>http://localhost</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>local</id>
<url>http://localhost</url>
</pluginRepository>
</pluginRepositories>
<distributionManagement>
<repository>
<id>local</id>
<url>http://localhost</url>
</repository>
<snapshotRepository>
<id>local</id>
<url>http://localhost</url>
</snapshotRepository>
</distributionManagement>
</project>