[MNG-0479] unable to override the default central repository.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@759383 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Britton Isbell 2009-03-27 23:03:38 +00:00
parent 334c95d85e
commit e81caca85f
3 changed files with 104 additions and 8 deletions

View File

@ -32,21 +32,30 @@ public class RepositoriesProcessor extends BaseProcessor
super.process( parent, child, target, isChildMostSpecialized );
Model t = (Model) target, c = (Model) child, p = (Model) parent;
copy(c.getPluginRepositories(), t.getPluginRepositories());
copy( c.getRepositories(), t.getRepositories() );
if(p != null)
{
copy( p.getRepositories(), t.getRepositories() );
copy( p.getPluginRepositories(), t.getPluginRepositories() );
}
}
copy(c.getPluginRepositories(), t.getPluginRepositories());
copy( c.getRepositories(), t.getRepositories() );
}
private static void copy(List<Repository> sources, List<Repository> targets)
{
for(Repository repository : sources)
{
Repository r = new Repository();
Repository match = matches(repository, targets);
Repository r = null;
if(match != null)
{
r = match;
}
else
{
r = new Repository();
}
r.setId( repository.getId() );
r.setLayout( repository.getLayout() );
r.setName( repository.getName() );
@ -59,11 +68,25 @@ public class RepositoriesProcessor extends BaseProcessor
{
r.setSnapshots( copy(repository.getSnapshots()) );
}
targets.add( r );
if (match == null)
{
targets.add( r );
}
}
}
private static Repository matches(Repository repository, List<Repository> targets)
{
for(Repository r : targets)
{
if(r.getId() != null && r.getId().equals(repository.getId()))
{
return r;
}
}
return null;
}
private static RepositoryPolicy copy(RepositoryPolicy policy)
{
RepositoryPolicy p = new RepositoryPolicy();

View File

@ -935,7 +935,16 @@ public class PomConstructionTest
{
PomTestWrapper pom = this.buildPom( "percent-encoded-url" );
assertEquals("@baseurl@/target/repo", pom.getValue( "distributionManagement/repository/url" ));
}
}
/** MNG-0479 */
public void testRepoInheritance()
throws Exception
{
PomTestWrapper pom = this.buildPom( "repo-inheritance" );
assertEquals(1, ( (List<?>) pom.getValue( "repositories" ) ).size());
assertEquals( "it0043", pom.getValue( "repositories[1]/name" ) );
}
public void testPluginConfigurationUsingAttributesWithoutPluginManagement()
throws Exception

View File

@ -0,0 +1,64 @@
<?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.it0043</groupId>
<artifactId>maven-it-it0043</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Maven Integration Test :: it0043</name>
<description>Test for repository inheritence - ensure using the same id overrides the defaults</description>
<repositories>
<repository>
<id>central</id>
<name>it0043</name>
<url>file:///${basedir}/target/maven-core-it0043-repo</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>it0043</name>
<url>file:///${basedir}/target/maven-core-it0043-repo</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-expression</artifactId>
<version>2.1-SNAPSHOT</version>
<configuration>
<outputFile>target/expression.properties</outputFile>
<expressions>
<expression>project/repositories</expression>
<expression>project/pluginRepositories</expression>
</expressions>
</configuration>
</plugin>
</plugins>
</build>
</project>