Resolving: MNG-1008...DependencyManagement can now inject exclusions.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@291806 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-09-27 02:31:33 +00:00
parent 78e74cd7fe
commit e41222abd0
2 changed files with 63 additions and 0 deletions

View File

@ -90,6 +90,22 @@ public class DefaultModelDefaultsInjector
{ {
dep.setVersion( def.getVersion() ); dep.setVersion( def.getVersion() );
} }
if ( dep.getClassifier() == null && def.getClassifier() != null )
{
dep.setClassifier( def.getClassifier() );
}
if ( dep.getType() == null && def.getType() != null )
{
dep.setType( def.getType() );
}
List exclusions = dep.getExclusions();
if ( exclusions == null || exclusions.isEmpty() )
{
dep.setExclusions( def.getExclusions() );
}
} }
} }

View File

@ -19,8 +19,10 @@ package org.apache.maven.project.injection;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.maven.model.Dependency; import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement; import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Exclusion;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -65,6 +67,51 @@ public class DefaultModelDefaultsInjectorTest
assertEquals( def.getVersion(), result.getVersion() ); assertEquals( def.getVersion(), result.getVersion() );
} }
public void testShouldMergeDependencyExclusionsFromDefaultsToDependency()
{
Model model = new Model();
Dependency dep = new Dependency();
dep.setGroupId( "myGroup" );
dep.setArtifactId( "myArtifact" );
model.addDependency( dep );
Dependency def = new Dependency();
def.setGroupId( dep.getGroupId() );
def.setArtifactId( dep.getArtifactId() );
def.setVersion( "1.0.1" );
def.setScope( "scope" );
Exclusion exc = new Exclusion();
exc.setArtifactId( "mydep" );
exc.setGroupId( "mygrp" );
def.addExclusion( exc );
DependencyManagement depMgmt = new DependencyManagement();
depMgmt.addDependency( def );
model.setDependencyManagement( depMgmt );
new DefaultModelDefaultsInjector().injectDefaults( model );
List deps = model.getDependencies();
assertEquals( 1, deps.size() );
Dependency result = (Dependency) deps.get( 0 );
assertEquals( def.getVersion(), result.getVersion() );
List resultExclusions = result.getExclusions();
assertNotNull( resultExclusions );
assertEquals( 1, resultExclusions.size() );
Exclusion resultExclusion = (Exclusion) resultExclusions.get( 0 );
assertEquals( "mydep", resultExclusion.getArtifactId() );
assertEquals( "mygrp", resultExclusion.getGroupId() );
}
public void testShouldMergeDefaultUrlAndArtifactWhenDependencyDoesntSupplyVersion() public void testShouldMergeDefaultUrlAndArtifactWhenDependencyDoesntSupplyVersion()
{ {
Model model = new Model(); Model model = new Model();