diff --git a/maven-core-it/it0011/pom.xml b/maven-core-it/it0011/pom.xml index 3881e5f423..6398a69ce3 100644 --- a/maven-core-it/it0011/pom.xml +++ b/maven-core-it/it0011/pom.xml @@ -1,30 +1,30 @@ - 4.0.0 - maven - maven-core-it0011 - 1.0 - - - maven - maven-plugin - - - junit - junit - - - - - - maven - maven-plugin - 2.0-SNAPSHOT - - - junit - junit - 3.8.1 - - - - + 4.0.0 + maven + maven-core-it0011 + 1.0 + + + maven + maven-plugin + + + junit + junit + + + + + + maven + maven-plugin + 2.0-SNAPSHOT + + + junit + junit + 3.8.1 + + + + \ No newline at end of file diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDefaultsInjector.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDefaultsInjector.java index 8da7efa55b..ca3a4643b4 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDefaultsInjector.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDefaultsInjector.java @@ -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 diff --git a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java index c6f4294255..6842ff7041 100644 --- a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java @@ -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(); } // ---------------------------------------------------------------------- diff --git a/maven-core/src/test/java/org/apache/maven/project/DefaultProjectDefaultsInjectorTest.java b/maven-core/src/test/java/org/apache/maven/project/DefaultProjectDefaultsInjectorTest.java index 0b0c88c87b..3def09d467 100644 --- a/maven-core/src/test/java/org/apache/maven/project/DefaultProjectDefaultsInjectorTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/DefaultProjectDefaultsInjectorTest.java @@ -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); diff --git a/maven-core/src/test/java/org/apache/maven/project/helpers/ProjectTestHelper.java b/maven-core/src/test/java/org/apache/maven/project/helpers/ProjectTestHelper.java index fcd4c35c91..4f64ad6bc4 100644 --- a/maven-core/src/test/java/org/apache/maven/project/helpers/ProjectTestHelper.java +++ b/maven-core/src/test/java/org/apache/maven/project/helpers/ProjectTestHelper.java @@ -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 // ---------------------------------------------------------------------- diff --git a/maven-model/maven.mdo b/maven-model/maven.mdo index 24ed831efe..e5c9116d4b 100644 --- a/maven-model/maven.mdo +++ b/maven-model/maven.mdo @@ -411,13 +411,12 @@ - dependencyDefaults + dependencyManagement 4.0.0 false - DependencyDefault - * + DependencyManagement @@ -826,7 +825,7 @@ url - 3.0.0+ + 3.0.0 String - - artifact - 4.0.0+ - - String - type 3.0.0+ @@ -892,6 +885,11 @@ { return groupId + ":" + artifactId + ":" + type + ":" + version; } + + public String getManagementKey() + { + return groupId + ":" + artifactId + ":" + type; + } @@ -1767,90 +1765,29 @@ - - DependencyDefault - 4.0.0 - - - - groupId - 4.0.0 - true - geronimo. - ]]> - String - - - artifactId - 4.0.0 - true - germonimo-jms - ]]> - String - - - version - 4.0.0 - 3.2.1 - ]]> - String - - - url - 4.0.0 - - String - The URL should really be gleaned from a shared database of dependency information. - - - artifact - 4.0.0 - - String - - - type - 4.0.0 - ejb and - plugin. - ]]> - String - jar - - - properties - 4.0.0 - mark dependencies with properties. For example the - war plugin looks for a - war.bundle property, and if found will include the dependency - in - WEB-INF/lib. For example syntax, check the war plugin docs. - ]]> - Properties - - String - * - - - + DependencyManagement + 4.0.0 + + + + dependencies + 4.0.0 + + + Dependency + * + + +