diff --git a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java index b2224526b9..0659b40659 100644 --- a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java @@ -1089,14 +1089,15 @@ public class PomConstructionTest assertEquals(1, ( (Properties) pom.getValue( "properties" ) ).size()); assertEquals("child", pom.getValue( "properties/pomProfile" ) ); } - + public void testPomInheritance() - throws Exception - { - PomTestWrapper pom = buildPom( "pom-inheritance/sub" ); - assertEquals("parent-description", pom.getValue("description")); - } - + throws Exception + { + PomTestWrapper pom = buildPom( "pom-inheritance/sub" ); + assertEquals( "parent-description", pom.getValue( "description" ) ); + assertEquals( "jar", pom.getValue( "packaging" ) ); + } + public void testCompleteModelWithoutParent() throws Exception { @@ -1756,6 +1757,20 @@ public class PomConstructionTest assertEquals( actual, expected ); } + public void testProjectArtifactIdIsNotInheritedButMandatory() + throws Exception + { + try + { + buildPom( "artifact-id-inheritance/child" ); + fail( "Missing artifactId did not cause validation error" ); + } + catch ( ProjectBuildingException e ) + { + // expected + } + } + private void assertPathSuffixEquals( String expected, Object actual ) { String a = actual.toString(); diff --git a/maven-core/src/test/resources-project-builder/artifact-id-inheritance/child/pom.xml b/maven-core/src/test/resources-project-builder/artifact-id-inheritance/child/pom.xml new file mode 100644 index 0000000000..eee189d431 --- /dev/null +++ b/maven-core/src/test/resources-project-builder/artifact-id-inheritance/child/pom.xml @@ -0,0 +1,32 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.mng + parent + 0.1 + + + + diff --git a/maven-core/src/test/resources-project-builder/artifact-id-inheritance/pom.xml b/maven-core/src/test/resources-project-builder/artifact-id-inheritance/pom.xml new file mode 100644 index 0000000000..f22afbc0ba --- /dev/null +++ b/maven-core/src/test/resources-project-builder/artifact-id-inheritance/pom.xml @@ -0,0 +1,35 @@ + + + + + + 4.0.0 + + org.apache.maven.its.mng + parent + 0.1 + pom + + + http://maven.apache.org/ + diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java b/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java index 3a1058cd7a..b8a42a3e19 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java @@ -101,8 +101,7 @@ public class MavenModelMerger } else if ( target.getUrl() == null ) { - target.setUrl( appendPath( src, context.get( ARTIFACT_ID ).toString(), - context.get( CHILD_PATH_ADJUSTMENT ).toString() ) ); + target.setUrl( appendPath( src, context ) ); } } } @@ -168,6 +167,12 @@ public class MavenModelMerger // neither inherited nor injected } + @Override + protected void mergeModel_ArtifactId( Model target, Model source, boolean sourceDominant, Map context ) + { + // neither inherited nor injected + } + @Override protected void mergeModel_Profiles( Model target, Model source, boolean sourceDominant, Map context ) { @@ -396,8 +401,7 @@ public class MavenModelMerger } else if ( target.getUrl() == null ) { - target.setUrl( appendPath( src, context.get( ARTIFACT_ID ).toString(), - context.get( CHILD_PATH_ADJUSTMENT ).toString() ) ); + target.setUrl( appendPath( src, context ) ); } } } @@ -414,8 +418,7 @@ public class MavenModelMerger } else if ( target.getUrl() == null ) { - target.setUrl( appendPath( src, context.get( ARTIFACT_ID ).toString(), - context.get( CHILD_PATH_ADJUSTMENT ).toString() ) ); + target.setUrl( appendPath( src, context ) ); } } } @@ -432,8 +435,7 @@ public class MavenModelMerger } else if ( target.getConnection() == null ) { - target.setConnection( appendPath( src, context.get( ARTIFACT_ID ).toString(), - context.get( CHILD_PATH_ADJUSTMENT ).toString() ) ); + target.setConnection( appendPath( src, context ) ); } } } @@ -451,8 +453,7 @@ public class MavenModelMerger } else if ( target.getDeveloperConnection() == null ) { - target.setDeveloperConnection( appendPath( src, context.get( ARTIFACT_ID ).toString(), - context.get( CHILD_PATH_ADJUSTMENT ).toString() ) ); + target.setDeveloperConnection( appendPath( src, context ) ); } } } @@ -556,6 +557,21 @@ public class MavenModelMerger return object.getGroupId() + ':' + object.getArtifactId(); } + private String appendPath( String parentPath, Map context ) + { + Object artifactId = context.get( ARTIFACT_ID ); + Object childPathAdjustment = context.get( CHILD_PATH_ADJUSTMENT ); + + if ( artifactId != null && childPathAdjustment != null ) + { + return appendPath( parentPath, artifactId.toString(), childPathAdjustment.toString() ); + } + else + { + return parentPath; + } + } + private String appendPath( String parentPath, String childPath, String pathAdjustment ) { String path = parentPath;