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> <project>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>maven</groupId> <groupId>maven</groupId>
<artifactId>maven-core-it0011</artifactId> <artifactId>maven-core-it0011</artifactId>
<version>1.0</version> <version>1.0</version>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>maven</groupId> <groupId>maven</groupId>
<artifactId>maven-plugin</artifactId> <artifactId>maven-plugin</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
<dependencyManagement>
<dependencyDefaults> <dependencies>
<dependencyDefault> <dependency>
<groupId>maven</groupId> <groupId>maven</groupId>
<artifactId>maven-plugin</artifactId> <artifactId>maven-plugin</artifactId>
<version>2.0-SNAPSHOT</version> <version>2.0-SNAPSHOT</version>
</dependencyDefault> </dependency>
<dependencyDefault> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>3.8.1</version> <version>3.8.1</version>
</dependencyDefault> </dependency>
</dependencyDefaults> </dependencies>
</dependencyManagement>
</project> </project>

View File

@ -8,7 +8,7 @@ import java.util.Properties;
import java.util.TreeMap; import java.util.TreeMap;
import org.apache.maven.model.Dependency; import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyDefault; import org.apache.maven.model.DependencyManagement;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
/** /**
@ -21,61 +21,53 @@ public class DefaultProjectDefaultsInjector implements ProjectDefaultsInjector
public void injectDefaults(MavenProject project) public void injectDefaults(MavenProject project)
{ {
injectDependencyDefaults(project.getDependencies(), project.getDependencyDefaults()); injectDependencyDefaults(project.getDependencies(), project.getDependencyManagement());
} }
/** Added: Feb 1, 2005 by jdcasey /** 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... if(dependencyManagement != null)
// 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(); )
{ {
Dependency dep = (Dependency) it.next(); // a given project's dependencies should be smaller than the group-defined defaults set...
depsMap.put(dep.getGroupId() + ":" + dep.getArtifactId() + ":" + dep.getType(), dep); // 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(); )
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)
{ {
mergeWithDefaults(dep, depdef); Dependency dep = (Dependency) it.next();
validateDependency(dep); 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 /** 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()); dep.setVersion(def.getVersion());
if(dep.getArtifact() == null && depdef.getArtifact() != null)
{
dep.setArtifact(depdef.getArtifact());
}
if(dep.getUrl() == null && depdef.getUrl() != null)
{
dep.setUrl(depdef.getUrl());
}
} }
Properties depProps = dep.getProperties(); Properties props = new Properties(def.getProperties());
Properties depdefProps = depdef.getProperties(); props.putAll(dep.getProperties());
if(depProps == null && depdefProps != null) dep.setProperties(props);
{
dep.setProperties(depdefProps);
}
} }
/** Added: Feb 1, 2005 by jdcasey /** 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.Build;
import org.apache.maven.model.CiManagement; import org.apache.maven.model.CiManagement;
import org.apache.maven.model.Contributor; import org.apache.maven.model.Contributor;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Developer; import org.apache.maven.model.Developer;
import org.apache.maven.model.DistributionManagement; import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.IssueManagement; import org.apache.maven.model.IssueManagement;
@ -119,9 +120,9 @@ public class MavenProject
return model.getDependencies(); 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 java.util.Properties;
import org.apache.maven.model.Dependency; 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 org.apache.maven.model.Model;
import junit.framework.TestCase; import junit.framework.TestCase;
@ -24,7 +24,7 @@ public class DefaultProjectDefaultsInjectorTest
new DefaultProjectDefaultsInjector(); new DefaultProjectDefaultsInjector();
} }
public void testShouldSucceedInMergingDependencyWithDependencyDefault() public void testShouldSucceedInMergingDependencyWithDependency()
{ {
Model model = new Model(); Model model = new Model();
@ -34,12 +34,16 @@ public class DefaultProjectDefaultsInjectorTest
model.addDependency(dep); model.addDependency(dep);
DependencyDefault def = new DependencyDefault(); Dependency def = new Dependency();
def.setGroupId(dep.getGroupId()); def.setGroupId(dep.getGroupId());
def.setArtifactId(dep.getArtifactId()); def.setArtifactId(dep.getArtifactId());
def.setVersion("1.0.1"); def.setVersion("1.0.1");
model.addDependencyDefault(def); DependencyManagement depMgmt = new DependencyManagement();
depMgmt.addDependency(def);
model.setDependencyManagement(depMgmt);
MavenProject project = new MavenProject(model); MavenProject project = new MavenProject(model);
@ -62,14 +66,16 @@ public class DefaultProjectDefaultsInjectorTest
model.addDependency(dep); model.addDependency(dep);
DependencyDefault def = new DependencyDefault(); Dependency def = new Dependency();
def.setGroupId(dep.getGroupId()); def.setGroupId(dep.getGroupId());
def.setArtifactId(dep.getArtifactId()); def.setArtifactId(dep.getArtifactId());
def.setArtifact("myArtifact");
def.setUrl("http://www.google.com");
def.setVersion("1.0.1"); def.setVersion("1.0.1");
model.addDependencyDefault(def); DependencyManagement depMgmt = new DependencyManagement();
depMgmt.addDependency(def);
model.setDependencyManagement(depMgmt);
MavenProject project = new MavenProject(model); MavenProject project = new MavenProject(model);
@ -80,8 +86,6 @@ public class DefaultProjectDefaultsInjectorTest
Dependency result = (Dependency)deps.get(0); Dependency result = (Dependency)deps.get(0);
assertEquals(def.getVersion(), result.getVersion()); assertEquals(def.getVersion(), result.getVersion());
assertEquals(def.getArtifact(), result.getArtifact());
assertEquals(def.getUrl(), result.getUrl());
} }
public void testShouldNotMergeDefaultUrlOrArtifactWhenDependencySuppliesVersion() public void testShouldNotMergeDefaultUrlOrArtifactWhenDependencySuppliesVersion()
@ -95,13 +99,15 @@ public class DefaultProjectDefaultsInjectorTest
model.addDependency(dep); model.addDependency(dep);
DependencyDefault def = new DependencyDefault(); Dependency def = new Dependency();
def.setGroupId(dep.getGroupId()); def.setGroupId(dep.getGroupId());
def.setArtifactId(dep.getArtifactId()); 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); MavenProject project = new MavenProject(model);
@ -112,8 +118,6 @@ public class DefaultProjectDefaultsInjectorTest
Dependency result = (Dependency)deps.get(0); Dependency result = (Dependency)deps.get(0);
assertEquals(dep.getVersion(), result.getVersion()); assertEquals(dep.getVersion(), result.getVersion());
assertNull(result.getArtifact());
assertNull(result.getUrl());
} }
public void testShouldMergeDefaultPropertiesWhenDependencyDoesntSupplyProperties() public void testShouldMergeDefaultPropertiesWhenDependencyDoesntSupplyProperties()
@ -127,7 +131,7 @@ public class DefaultProjectDefaultsInjectorTest
model.addDependency(dep); model.addDependency(dep);
DependencyDefault def = new DependencyDefault(); Dependency def = new Dependency();
def.setGroupId(dep.getGroupId()); def.setGroupId(dep.getGroupId());
def.setArtifactId(dep.getArtifactId()); def.setArtifactId(dep.getArtifactId());
@ -136,7 +140,11 @@ public class DefaultProjectDefaultsInjectorTest
def.setProperties(props); def.setProperties(props);
model.addDependencyDefault(def); DependencyManagement depMgmt = new DependencyManagement();
depMgmt.addDependency(def);
model.setDependencyManagement(depMgmt);
MavenProject project = new MavenProject(model); MavenProject project = new MavenProject(model);
@ -146,6 +154,7 @@ public class DefaultProjectDefaultsInjectorTest
assertEquals(1, deps.size()); assertEquals(1, deps.size());
Dependency result = (Dependency)deps.get(0); Dependency result = (Dependency)deps.get(0);
assertEquals("value", result.getProperties().getProperty("test")); assertEquals("value", result.getProperties().getProperty("test"));
} }
@ -165,7 +174,7 @@ public class DefaultProjectDefaultsInjectorTest
model.addDependency(dep); model.addDependency(dep);
DependencyDefault def = new DependencyDefault(); Dependency def = new Dependency();
def.setGroupId(dep.getGroupId()); def.setGroupId(dep.getGroupId());
def.setArtifactId(dep.getArtifactId()); def.setArtifactId(dep.getArtifactId());
@ -174,7 +183,11 @@ public class DefaultProjectDefaultsInjectorTest
def.setProperties(props2); def.setProperties(props2);
model.addDependencyDefault(def); DependencyManagement depMgmt = new DependencyManagement();
depMgmt.addDependency(def);
model.setDependencyManagement(depMgmt);
MavenProject project = new MavenProject(model); MavenProject project = new MavenProject(model);
@ -197,11 +210,15 @@ public class DefaultProjectDefaultsInjectorTest
model.addDependency(dep); model.addDependency(dep);
DependencyDefault def = new DependencyDefault(); Dependency def = new Dependency();
def.setGroupId(dep.getGroupId()); def.setGroupId(dep.getGroupId());
def.setArtifactId(dep.getArtifactId()); def.setArtifactId(dep.getArtifactId());
model.addDependencyDefault(def); DependencyManagement depMgmt = new DependencyManagement();
depMgmt.addDependency(def);
model.setDependencyManagement(depMgmt);
MavenProject project = new MavenProject(model); MavenProject project = new MavenProject(model);

View File

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

View File

@ -411,13 +411,12 @@
<!-- [ jdcasey:01-Feb-2005 ] Added to handle version management for <!-- [ jdcasey:01-Feb-2005 ] Added to handle version management for
| dependencies to be used in sub-projects. --> | dependencies to be used in sub-projects. -->
<field> <field>
<name>dependencyDefaults</name> <name>dependencyManagement</name>
<version>4.0.0</version> <version>4.0.0</version>
<required>false</required> <required>false</required>
<description><![CDATA[Default dependency information for grouped projects inheriting from this one.]]></description> <description><![CDATA[Default dependency information for grouped projects inheriting from this one.]]></description>
<association> <association>
<type>DependencyDefault</type> <type>DependencyManagement</type>
<multiplicity>*</multiplicity>
</association> </association>
</field> </field>
<field> <field>
@ -826,7 +825,7 @@
</field> </field>
<field> <field>
<name>url</name> <name>url</name>
<version>3.0.0+</version> <version>3.0.0</version>
<description><![CDATA[ <description><![CDATA[
This url will be provided to the user if the jar file cannot be downloaded This url will be provided to the user if the jar file cannot be downloaded
from the central repository. from the central repository.
@ -840,12 +839,6 @@
<description><![CDATA[Literal name of the artifact.]]></description> <description><![CDATA[Literal name of the artifact.]]></description>
<type>String</type> <type>String</type>
</field> </field>
<field>
<name>artifact</name>
<version>4.0.0+</version>
<description><![CDATA[Literal name of the artifact]]></description>
<type>String</type>
</field>
<field> <field>
<name>type</name> <name>type</name>
<version>3.0.0+</version> <version>3.0.0+</version>
@ -892,6 +885,11 @@
{ {
return groupId + ":" + artifactId + ":" + type + ":" + version; return groupId + ":" + artifactId + ":" + type + ":" + version;
} }
public String getManagementKey()
{
return groupId + ":" + artifactId + ":" + type;
}
</code> </code>
</codeSegment> </codeSegment>
<codeSegment> <codeSegment>
@ -1767,90 +1765,29 @@
</field> </field>
</fields> </fields>
</class> </class>
<!-- [ jdcasey:01-Feb-2005 ] Added to handle version management for
| dependencies to be used in sub-projects. -->
<class> <class>
<name>DependencyDefault</name> <name>DependencyManagement</name>
<version>4.0.0</version> <version>4.0.0</version>
<description><![CDATA[ <description><![CDATA[
Default information for a dependency to be used in a sub-project. The Section for management of default dependency information for use in
required fields here will be used to match dependency references. a group of POMs.
]]></description> ]]></description>
<fields> <fields>
<field> <field>
<name>groupId</name> <name>dependencies</name>
<version>4.0.0</version> <version>4.0.0</version>
<required>true</required> <description><![CDATA[
<description><![CDATA[ The dependencies specified here are not validated until they
The project group that produced the dependency, e.g. are referenced in a POM within the group. This allows the
<code>geronimo</code>. specification of a "standard" version for a particular
]]></description> dependency.
<type>String</type> ]]></description>
</field> <association>
<field> <type>Dependency</type>
<name>artifactId</name> <multiplicity>*</multiplicity>
<version>4.0.0</version> </association>
<required>true</required> </field>
<description><![CDATA[ </fields>
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>
</class> </class>
</classes> </classes>
</model> </model>