[MNG-1856] fix inheritance of the distribution management section and add tests

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@379324 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2006-02-21 03:57:23 +00:00
parent fa34c36025
commit faa5cf27cb
2 changed files with 105 additions and 69 deletions

View File

@ -107,10 +107,6 @@ public class DefaultModelInheritanceAssembler
}
}
// ----------------------------------------------------------------------
// Distribution
// ----------------------------------------------------------------------
assembleDistributionInheritence( child, parent, childPathAdjustment, appendPaths );
// issueManagement
@ -177,8 +173,6 @@ public class DefaultModelInheritanceAssembler
assembleDependencyManagementInheritance( child, parent );
assembleDistributionManagementInheritance( child, parent );
Properties props = new Properties();
props.putAll( parent.getProperties() );
props.putAll( child.getProperties() );
@ -186,46 +180,6 @@ public class DefaultModelInheritanceAssembler
child.setProperties( props );
}
private void assembleDistributionManagementInheritance( Model child, Model parent )
{
DistributionManagement cDistMgmt = child.getDistributionManagement();
DistributionManagement pDistMgmt = parent.getDistributionManagement();
if ( cDistMgmt == null )
{
child.setDistributionManagement( pDistMgmt );
}
else if ( pDistMgmt != null )
{
if ( cDistMgmt.getRepository() == null )
{
cDistMgmt.setRepository( pDistMgmt.getRepository() );
}
if ( cDistMgmt.getSnapshotRepository() == null )
{
cDistMgmt.setSnapshotRepository( pDistMgmt.getSnapshotRepository() );
}
if ( StringUtils.isEmpty( cDistMgmt.getDownloadUrl() ) )
{
cDistMgmt.setDownloadUrl( pDistMgmt.getDownloadUrl() );
}
if ( cDistMgmt.getRelocation() == null )
{
cDistMgmt.setRelocation( pDistMgmt.getRelocation() );
}
if ( cDistMgmt.getSite() == null )
{
cDistMgmt.setSite( pDistMgmt.getSite() );
}
// NOTE: We SHOULD NOT be inheriting status, since this is an assessment of the POM quality.
}
}
private void assembleDependencyManagementInheritance( Model child, Model parent )
{
DependencyManagement parentDepMgmt = parent.getDependencyManagement();
@ -486,17 +440,8 @@ public class DefaultModelInheritanceAssembler
{
if ( parentDistMgmt.getRepository() != null )
{
DeploymentRepository repository = new DeploymentRepository();
DeploymentRepository repository = copyDistributionRepository( parentDistMgmt.getRepository() );
childDistMgmt.setRepository( repository );
repository.setId( parentDistMgmt.getRepository().getId() );
repository.setName( parentDistMgmt.getRepository().getName() );
repository.setUrl( parentDistMgmt.getRepository().getUrl() );
repository.setUniqueVersion( parentDistMgmt.getRepository().isUniqueVersion() );
}
}
@ -504,22 +449,39 @@ public class DefaultModelInheritanceAssembler
{
if ( parentDistMgmt.getSnapshotRepository() != null )
{
DeploymentRepository repository = new DeploymentRepository();
DeploymentRepository repository =
copyDistributionRepository( parentDistMgmt.getSnapshotRepository() );
childDistMgmt.setSnapshotRepository( repository );
repository.setId( parentDistMgmt.getSnapshotRepository().getId() );
repository.setName( parentDistMgmt.getSnapshotRepository().getName() );
repository.setUrl( parentDistMgmt.getSnapshotRepository().getUrl() );
repository.setUniqueVersion( parentDistMgmt.getSnapshotRepository().isUniqueVersion() );
}
}
if ( StringUtils.isEmpty( childDistMgmt.getDownloadUrl() ) )
{
childDistMgmt.setDownloadUrl( parentDistMgmt.getDownloadUrl() );
}
// NOTE: We SHOULD NOT be inheriting status, since this is an assessment of the POM quality.
// NOTE: We SHOULD NOT be inheriting relocation, since this relates to a single POM
}
}
private static DeploymentRepository copyDistributionRepository( DeploymentRepository parentRepository )
{
DeploymentRepository repository = new DeploymentRepository();
repository.setId( parentRepository.getId() );
repository.setName( parentRepository.getName() );
repository.setUrl( parentRepository.getUrl() );
repository.setLayout( parentRepository.getLayout() );
repository.setUniqueVersion( parentRepository.isUniqueVersion() );
return repository;
}
protected String appendPath( String parentPath, String childPath, String pathAdjustment, boolean appendPaths )
{
List pathFragments = new ArrayList();

View File

@ -18,16 +18,21 @@ package org.apache.maven.project.inheritance;
import junit.framework.TestCase;
import org.apache.maven.model.Build;
import org.apache.maven.model.DeploymentRepository;
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.Relocation;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.ReportSet;
import org.apache.maven.model.Reporting;
import org.apache.maven.model.Repository;
import org.apache.maven.model.RepositoryBase;
import org.apache.maven.model.Resource;
import org.apache.maven.model.Scm;
import org.apache.maven.model.Site;
import java.util.ArrayList;
import java.util.Collections;
@ -57,6 +62,69 @@ public class DefaultModelInheritanceAssemblerTest
assertEquals( "Append with path adjustment failed.", "http://maven.apache.org/shared/file-management", result );
}
public void testDistributionManagementInheritance()
{
Model parent = makeBaseModel( "parent" );
Model child = makeBaseModel( "child" );
DistributionManagement distributionManagement = new DistributionManagement();
distributionManagement.setDownloadUrl( "downloadUrl" );
distributionManagement.setRelocation( new Relocation() );
distributionManagement.setStatus( "deployed" );
DeploymentRepository repository = new DeploymentRepository();
repository.setId( "apache.releases" );
repository.setUrl( "scp://minotaur.apache.org/www/www.apache.org/dist/java-repository" );
repository.setName( "name" );
repository.setLayout( "legacy" );
distributionManagement.setRepository( repository );
DeploymentRepository snapshotRepository = new DeploymentRepository();
snapshotRepository.setId( "apache.snapshots" );
snapshotRepository.setUrl( "scp://minotaur.apache.org/www/cvs.apache.org/repository" );
snapshotRepository.setName( "name" );
snapshotRepository.setLayout( "legacy" );
snapshotRepository.setUniqueVersion( false );
distributionManagement.setSnapshotRepository( snapshotRepository );
Site site = new Site();
site.setId( "apache.website" );
site.setUrl( "scp://minotaur.apache.org/www/maven.apache.org/" );
site.setName( "name3" );
distributionManagement.setSite( site );
parent.setDistributionManagement( distributionManagement );
assembler.assembleModelInheritance( child, parent );
DistributionManagement childDistMgmt = child.getDistributionManagement();
assertNotNull( "Check distMgmt inherited", childDistMgmt );
assertNull( "Check status NOT inherited", childDistMgmt.getStatus() );
assertNull( "Check relocation NOT inherited", childDistMgmt.getRelocation() );
assertEquals( "Check downloadUrl inherited", distributionManagement.getDownloadUrl(),
childDistMgmt.getDownloadUrl() );
Site childSite = childDistMgmt.getSite();
assertNotNull( "Check site inherited", childSite );
assertEquals( "Check id matches", site.getId(), childSite.getId() );
assertEquals( "Check name matches", site.getName(), childSite.getName() );
assertEquals( "Check url matches with appended path", site.getUrl() + "child", childSite.getUrl() );
assertRepositoryBase( childDistMgmt.getRepository(), repository );
assertRepositoryBase( childDistMgmt.getSnapshotRepository(), snapshotRepository );
assertEquals( "Check uniqueVersion is inherited", snapshotRepository.isUniqueVersion(),
childDistMgmt.getSnapshotRepository().isUniqueVersion() );
}
private static void assertRepositoryBase( RepositoryBase childRepository, RepositoryBase repository )
{
assertNotNull( "Check repository inherited", childRepository );
assertEquals( "Check id matches", repository.getId(), childRepository.getId() );
assertEquals( "Check name matches", repository.getName(), childRepository.getName() );
assertEquals( "Check url matches", repository.getUrl(), childRepository.getUrl() );
assertEquals( "Check layout matches", repository.getLayout(), childRepository.getLayout() );
}
public void testShouldOverrideUnitTestExcludesOnly()
{
Model parent = new Model();
@ -659,15 +727,21 @@ public class DefaultModelInheritanceAssemblerTest
{
Model model = makeBaseModel( artifactId );
Repository repository = new Repository();
repository.setId( id );
repository.setUrl( url );
Repository repository = makeRepository( id, url );
model.setRepositories( new ArrayList( Collections.singletonList( repository ) ) );
return model;
}
private static Repository makeRepository( String id, String url )
{
Repository repository = new Repository();
repository.setId( id );
repository.setUrl( url );
return repository;
}
private void assertRepositories( List expected, List actual )
{
assertEquals( "Repository list sizes don't match", expected.size(), actual.size() );