o Revised the defaults section to <dependencyManagement>, all builds and is happy.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163325 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-02-02 02:23:12 +00:00
parent 58ead792af
commit da47c49f4f
6 changed files with 132 additions and 189 deletions

View File

@ -1,30 +1,30 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>maven</groupId>
<artifactId>maven-core-it0011</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>maven</groupId>
<artifactId>maven-plugin</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
<dependencyDefaults>
<dependencyDefault>
<groupId>maven</groupId>
<artifactId>maven-plugin</artifactId>
<version>2.0-SNAPSHOT</version>
</dependencyDefault>
<dependencyDefault>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependencyDefault>
</dependencyDefaults>
</project>
<modelVersion>4.0.0</modelVersion>
<groupId>maven</groupId>
<artifactId>maven-core-it0011</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>maven</groupId>
<artifactId>maven-plugin</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>maven</groupId>
<artifactId>maven-plugin</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>

View File

@ -8,7 +8,7 @@ import java.util.Properties;
import java.util.TreeMap;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyDefault;
import org.apache.maven.model.DependencyManagement;
import org.codehaus.plexus.util.StringUtils;
/**
@ -21,61 +21,53 @@ public class DefaultProjectDefaultsInjector implements ProjectDefaultsInjector
public void injectDefaults(MavenProject project)
{
injectDependencyDefaults(project.getDependencies(), project.getDependencyDefaults());
injectDependencyDefaults(project.getDependencies(), project.getDependencyManagement());
}
/** Added: Feb 1, 2005 by jdcasey
*/
private void injectDependencyDefaults( List dependencies, List dependencyDefaults )
private void injectDependencyDefaults( List dependencies, DependencyManagement dependencyManagement )
{
// a given project's dependencies should be smaller than the group-defined defaults set...
// in other words, the project's deps will probably be a subset of those specified in defaults.
Map depsMap = new TreeMap();
for ( Iterator it = dependencies.iterator(); it.hasNext(); )
if(dependencyManagement != null)
{
Dependency dep = (Dependency) it.next();
depsMap.put(dep.getGroupId() + ":" + dep.getArtifactId() + ":" + dep.getType(), dep);
}
for ( Iterator it = dependencyDefaults.iterator(); it.hasNext(); )
{
DependencyDefault depdef = (DependencyDefault) it.next();
String key = depdef.getGroupId() + ":" + depdef.getArtifactId() + ":" + depdef.getType();
Dependency dep = (Dependency) depsMap.get(key);
if(dep != null)
// a given project's dependencies should be smaller than the group-defined defaults set...
// in other words, the project's deps will probably be a subset of those specified in defaults.
Map depsMap = new TreeMap();
for ( Iterator it = dependencies.iterator(); it.hasNext(); )
{
mergeWithDefaults(dep, depdef);
validateDependency(dep);
Dependency dep = (Dependency) it.next();
depsMap.put(dep.getManagementKey(), dep);
}
List dependencyDefaults = dependencyManagement.getDependencies();
for ( Iterator it = dependencyDefaults.iterator(); it.hasNext(); )
{
Dependency def = (Dependency) it.next();
String key = def.getManagementKey();
Dependency dep = (Dependency) depsMap.get(key);
if(dep != null)
{
mergeWithDefaults(dep, def);
validateDependency(dep);
}
}
}
}
/** Added: Feb 1, 2005 by jdcasey
*/
private void mergeWithDefaults( Dependency dep, DependencyDefault depdef )
private void mergeWithDefaults( Dependency dep, Dependency def )
{
if(dep.getVersion() == null && depdef.getVersion() != null)
if(dep.getVersion() == null && def.getVersion() != null)
{
dep.setVersion(depdef.getVersion());
if(dep.getArtifact() == null && depdef.getArtifact() != null)
{
dep.setArtifact(depdef.getArtifact());
}
if(dep.getUrl() == null && depdef.getUrl() != null)
{
dep.setUrl(depdef.getUrl());
}
dep.setVersion(def.getVersion());
}
Properties depProps = dep.getProperties();
Properties depdefProps = depdef.getProperties();
if(depProps == null && depdefProps != null)
{
dep.setProperties(depdefProps);
}
Properties props = new Properties(def.getProperties());
props.putAll(dep.getProperties());
dep.setProperties(props);
}
/** Added: Feb 1, 2005 by jdcasey

View File

@ -22,6 +22,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Build;
import org.apache.maven.model.CiManagement;
import org.apache.maven.model.Contributor;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Developer;
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.IssueManagement;
@ -119,9 +120,9 @@ public class MavenProject
return model.getDependencies();
}
public List getDependencyDefaults()
public DependencyManagement getDependencyManagement()
{
return model.getDependencyDefaults();
return model.getDependencyManagement();
}
// ----------------------------------------------------------------------

View File

@ -5,7 +5,7 @@ import java.util.List;
import java.util.Properties;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyDefault;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Model;
import junit.framework.TestCase;
@ -24,7 +24,7 @@ public class DefaultProjectDefaultsInjectorTest
new DefaultProjectDefaultsInjector();
}
public void testShouldSucceedInMergingDependencyWithDependencyDefault()
public void testShouldSucceedInMergingDependencyWithDependency()
{
Model model = new Model();
@ -34,12 +34,16 @@ public class DefaultProjectDefaultsInjectorTest
model.addDependency(dep);
DependencyDefault def = new DependencyDefault();
Dependency def = new Dependency();
def.setGroupId(dep.getGroupId());
def.setArtifactId(dep.getArtifactId());
def.setVersion("1.0.1");
model.addDependencyDefault(def);
DependencyManagement depMgmt = new DependencyManagement();
depMgmt.addDependency(def);
model.setDependencyManagement(depMgmt);
MavenProject project = new MavenProject(model);
@ -62,14 +66,16 @@ public class DefaultProjectDefaultsInjectorTest
model.addDependency(dep);
DependencyDefault def = new DependencyDefault();
Dependency def = new Dependency();
def.setGroupId(dep.getGroupId());
def.setArtifactId(dep.getArtifactId());
def.setArtifact("myArtifact");
def.setUrl("http://www.google.com");
def.setVersion("1.0.1");
model.addDependencyDefault(def);
DependencyManagement depMgmt = new DependencyManagement();
depMgmt.addDependency(def);
model.setDependencyManagement(depMgmt);
MavenProject project = new MavenProject(model);
@ -80,8 +86,6 @@ public class DefaultProjectDefaultsInjectorTest
Dependency result = (Dependency)deps.get(0);
assertEquals(def.getVersion(), result.getVersion());
assertEquals(def.getArtifact(), result.getArtifact());
assertEquals(def.getUrl(), result.getUrl());
}
public void testShouldNotMergeDefaultUrlOrArtifactWhenDependencySuppliesVersion()
@ -95,13 +99,15 @@ public class DefaultProjectDefaultsInjectorTest
model.addDependency(dep);
DependencyDefault def = new DependencyDefault();
Dependency def = new Dependency();
def.setGroupId(dep.getGroupId());
def.setArtifactId(dep.getArtifactId());
def.setArtifact("myArtifact");
def.setUrl("http://www.google.com");
model.addDependencyDefault(def);
DependencyManagement depMgmt = new DependencyManagement();
depMgmt.addDependency(def);
model.setDependencyManagement(depMgmt);
MavenProject project = new MavenProject(model);
@ -112,8 +118,6 @@ public class DefaultProjectDefaultsInjectorTest
Dependency result = (Dependency)deps.get(0);
assertEquals(dep.getVersion(), result.getVersion());
assertNull(result.getArtifact());
assertNull(result.getUrl());
}
public void testShouldMergeDefaultPropertiesWhenDependencyDoesntSupplyProperties()
@ -127,7 +131,7 @@ public class DefaultProjectDefaultsInjectorTest
model.addDependency(dep);
DependencyDefault def = new DependencyDefault();
Dependency def = new Dependency();
def.setGroupId(dep.getGroupId());
def.setArtifactId(dep.getArtifactId());
@ -136,7 +140,11 @@ public class DefaultProjectDefaultsInjectorTest
def.setProperties(props);
model.addDependencyDefault(def);
DependencyManagement depMgmt = new DependencyManagement();
depMgmt.addDependency(def);
model.setDependencyManagement(depMgmt);
MavenProject project = new MavenProject(model);
@ -146,6 +154,7 @@ public class DefaultProjectDefaultsInjectorTest
assertEquals(1, deps.size());
Dependency result = (Dependency)deps.get(0);
assertEquals("value", result.getProperties().getProperty("test"));
}
@ -165,7 +174,7 @@ public class DefaultProjectDefaultsInjectorTest
model.addDependency(dep);
DependencyDefault def = new DependencyDefault();
Dependency def = new Dependency();
def.setGroupId(dep.getGroupId());
def.setArtifactId(dep.getArtifactId());
@ -174,7 +183,11 @@ public class DefaultProjectDefaultsInjectorTest
def.setProperties(props2);
model.addDependencyDefault(def);
DependencyManagement depMgmt = new DependencyManagement();
depMgmt.addDependency(def);
model.setDependencyManagement(depMgmt);
MavenProject project = new MavenProject(model);
@ -197,11 +210,15 @@ public class DefaultProjectDefaultsInjectorTest
model.addDependency(dep);
DependencyDefault def = new DependencyDefault();
Dependency def = new Dependency();
def.setGroupId(dep.getGroupId());
def.setArtifactId(dep.getArtifactId());
model.addDependencyDefault(def);
DependencyManagement depMgmt = new DependencyManagement();
depMgmt.addDependency(def);
model.setDependencyManagement(depMgmt);
MavenProject project = new MavenProject(model);

View File

@ -151,8 +151,6 @@ public class ProjectTestHelper
assertEquals( "1.0", dep.getVersion() );
assertEquals( "d1-url", dep.getUrl() );
Dependency dep2 = (Dependency) project.getDependencies().get( 1 );
assertEquals( "g2", dep2.getGroupId() );
@ -161,8 +159,6 @@ public class ProjectTestHelper
assertEquals( "2.0", dep2.getVersion() );
assertEquals( "d2-url", dep2.getUrl() );
// ----------------------------------------------------------------------
// Build
// ----------------------------------------------------------------------

View File

@ -411,13 +411,12 @@
<!-- [ jdcasey:01-Feb-2005 ] Added to handle version management for
| dependencies to be used in sub-projects. -->
<field>
<name>dependencyDefaults</name>
<name>dependencyManagement</name>
<version>4.0.0</version>
<required>false</required>
<description><![CDATA[Default dependency information for grouped projects inheriting from this one.]]></description>
<association>
<type>DependencyDefault</type>
<multiplicity>*</multiplicity>
<type>DependencyManagement</type>
</association>
</field>
<field>
@ -826,7 +825,7 @@
</field>
<field>
<name>url</name>
<version>3.0.0+</version>
<version>3.0.0</version>
<description><![CDATA[
This url will be provided to the user if the jar file cannot be downloaded
from the central repository.
@ -840,12 +839,6 @@
<description><![CDATA[Literal name of the artifact.]]></description>
<type>String</type>
</field>
<field>
<name>artifact</name>
<version>4.0.0+</version>
<description><![CDATA[Literal name of the artifact]]></description>
<type>String</type>
</field>
<field>
<name>type</name>
<version>3.0.0+</version>
@ -892,6 +885,11 @@
{
return groupId + ":" + artifactId + ":" + type + ":" + version;
}
public String getManagementKey()
{
return groupId + ":" + artifactId + ":" + type;
}
</code>
</codeSegment>
<codeSegment>
@ -1767,90 +1765,29 @@
</field>
</fields>
</class>
<!-- [ jdcasey:01-Feb-2005 ] Added to handle version management for
| dependencies to be used in sub-projects. -->
<class>
<name>DependencyDefault</name>
<version>4.0.0</version>
<description><![CDATA[
Default information for a dependency to be used in a sub-project. The
required fields here will be used to match dependency references.
]]></description>
<fields>
<field>
<name>groupId</name>
<version>4.0.0</version>
<required>true</required>
<description><![CDATA[
The project group that produced the dependency, e.g.
<code>geronimo</code>.
]]></description>
<type>String</type>
</field>
<field>
<name>artifactId</name>
<version>4.0.0</version>
<required>true</required>
<description><![CDATA[
The unique id for an artifact produced by the project group, e.g.
<code>germonimo-jms</code>
]]></description>
<type>String</type>
</field>
<field>
<name>version</name>
<version>4.0.0</version>
<description><![CDATA[
The version of the dependency., e.g.
<code>3.2.1</code>
]]></description>
<type>String</type>
</field>
<field>
<name>url</name>
<version>4.0.0</version>
<description><![CDATA[
This url will be provided to the user if the jar file cannot be downloaded
from the central repository.
]]></description>
<type>String</type>
<comment>The URL should really be gleaned from a shared database of dependency information.</comment>
</field>
<field>
<name>artifact</name>
<version>4.0.0</version>
<description><![CDATA[Literal name of the artifact]]></description>
<type>String</type>
</field>
<field>
<name>type</name>
<version>4.0.0</version>
<description><![CDATA[
Other known recognised dependency types are:
<code>ejb</code> and
<code>plugin</code>.
]]></description>
<type>String</type>
<defaultValue>jar</defaultValue>
</field>
<field>
<name>properties</name>
<version>4.0.0</version>
<description><![CDATA[
Properties about the dependency. Various plugins allow you to
<code>mark</code> dependencies with properties. For example the
<a href="plugins/war/index.html">war</a> plugin looks for a
<code>war.bundle</code> property, and if found will include the dependency
in
<code>WEB-INF/lib</code>. For example syntax, check the war plugin docs.
]]></description>
<type>Properties</type>
<association xml.mapStyle="inline">
<type>String</type>
<multiplicity>*</multiplicity>
</association>
</field>
</fields>
<name>DependencyManagement</name>
<version>4.0.0</version>
<description><![CDATA[
Section for management of default dependency information for use in
a group of POMs.
]]></description>
<fields>
<field>
<name>dependencies</name>
<version>4.0.0</version>
<description><![CDATA[
The dependencies specified here are not validated until they
are referenced in a POM within the group. This allows the
specification of a "standard" version for a particular
dependency.
]]></description>
<association>
<type>Dependency</type>
<multiplicity>*</multiplicity>
</association>
</field>
</fields>
</class>
</classes>
</model>