add file to dependency, and handle in injection

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163399 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-02-24 04:16:18 +00:00
parent 4b7ab94e31
commit 87b3e49afd
3 changed files with 76 additions and 2 deletions

View File

@ -82,6 +82,11 @@ public class DefaultModelDefaultsInjector
dep.setVersion( def.getVersion() );
}
if ( dep.getFile() == null && def.getFile() != null )
{
dep.setFile( def.getFile() );
}
Properties props = new Properties( def.getProperties() );
props.putAll( dep.getProperties() );
dep.setProperties( props );

View File

@ -27,8 +27,6 @@ import java.util.Properties;
/**
* @author jdcasey
* <p/>
* Created on Feb 1, 2005
*/
public class DefaultProjectDefaultsInjectorTest
extends TestCase
@ -53,6 +51,7 @@ extends TestCase
def.setGroupId( dep.getGroupId() );
def.setArtifactId( dep.getArtifactId() );
def.setVersion( "1.0.1" );
def.setFile( "file" );
DependencyManagement depMgmt = new DependencyManagement();
@ -205,6 +204,70 @@ extends TestCase
assertEquals( "value", result.getProperties().getProperty( "test" ) );
}
public void testShouldMergeDefaultFileWhenDependencyDoesntSupplyFile()
{
Model model = new Model();
Dependency dep = new Dependency();
dep.setGroupId( "myGroup" );
dep.setArtifactId( "myArtifact" );
dep.setVersion( "1.0.1" );
dep.setFile( "file" );
model.addDependency( dep );
Dependency def = new Dependency();
def.setGroupId( dep.getGroupId() );
def.setArtifactId( dep.getArtifactId() );
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( "file", result.getFile() );
}
public void testShouldNotMergeDefaultFileWhenDependencySuppliesFile()
{
Model model = new Model();
Dependency dep = new Dependency();
dep.setGroupId( "myGroup" );
dep.setArtifactId( "myArtifact" );
dep.setVersion( "1.0.1" );
dep.setFile( "file" );
model.addDependency( dep );
Dependency def = new Dependency();
def.setGroupId( dep.getGroupId() );
def.setArtifactId( dep.getArtifactId() );
def.setFile( "default" );
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( "file", result.getFile() );
}
public void testShouldRejectDependencyWhereNoVersionIsFoundAfterDefaultsInjection()
{
Model model = new Model();

View File

@ -807,6 +807,12 @@
<multiplicity>*</multiplicity>
</association>
</field>
<field>
<name>file</name>
<version>4.0.0</version>
<description>Override the use of a repository - retrieve it from this file</description>
<type>String</type>
</field>
</fields>
<codeSegments>
<codeSegment>