diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java b/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java index 890c8450f1..7622f8448f 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java @@ -144,12 +144,13 @@ protected static class InheritanceModelMerger { @Override - protected String extrapolateChildUrl( String parentUrl, Map context ) + protected String extrapolateChildUrl( String parentUrl, boolean appendPath, Map context ) { Object childDirectory = context.get( CHILD_DIRECTORY ); Object childPathAdjustment = context.get( CHILD_PATH_ADJUSTMENT ); - if ( StringUtils.isBlank( parentUrl ) || childDirectory == null || childPathAdjustment == null ) + if ( StringUtils.isBlank( parentUrl ) || childDirectory == null || childPathAdjustment == null + || !appendPath ) { return parentUrl; } 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 8e904547ec..640c211b79 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 @@ -103,7 +103,7 @@ protected void mergeModel_Url( Model target, Model source, boolean sourceDominan } else if ( target.getUrl() == null ) { - target.setUrl( extrapolateChildUrl( src, context ) ); + target.setUrl( extrapolateChildUrl( src, source.isChildInheritAppendPath(), context ) ); target.setLocation( "url", source.getLocation( "url" ) ); } } @@ -467,7 +467,7 @@ protected void mergeSite_Url( Site target, Site source, boolean sourceDominant, } else if ( target.getUrl() == null ) { - target.setUrl( extrapolateChildUrl( src, context ) ); + target.setUrl( extrapolateChildUrl( src, source.isChildInheritAppendPath(), context ) ); target.setLocation( "url", source.getLocation( "url" ) ); } } @@ -486,7 +486,7 @@ protected void mergeScm_Url( Scm target, Scm source, boolean sourceDominant, Map } else if ( target.getUrl() == null ) { - target.setUrl( extrapolateChildUrl( src, context ) ); + target.setUrl( extrapolateChildUrl( src, source.isChildInheritAppendPath(), context ) ); target.setLocation( "url", source.getLocation( "url" ) ); } } @@ -505,7 +505,7 @@ protected void mergeScm_Connection( Scm target, Scm source, boolean sourceDomina } else if ( target.getConnection() == null ) { - target.setConnection( extrapolateChildUrl( src, context ) ); + target.setConnection( extrapolateChildUrl( src, source.isChildInheritAppendPath(), context ) ); target.setLocation( "connection", source.getLocation( "connection" ) ); } } @@ -525,7 +525,7 @@ protected void mergeScm_DeveloperConnection( Scm target, Scm source, boolean sou } else if ( target.getDeveloperConnection() == null ) { - target.setDeveloperConnection( extrapolateChildUrl( src, context ) ); + target.setDeveloperConnection( extrapolateChildUrl( src, source.isChildInheritAppendPath(), context ) ); target.setLocation( "developerConnection", source.getLocation( "developerConnection" ) ); } } @@ -671,7 +671,7 @@ protected Object getExclusionKey( Exclusion exclusion ) return exclusion.getGroupId() + ':' + exclusion.getArtifactId(); } - protected String extrapolateChildUrl( String parentUrl, Map context ) + protected String extrapolateChildUrl( String parentUrl, boolean appendPath, Map context ) { return parentUrl; } diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java index 372d0a9b73..68dd71ea8b 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java @@ -98,6 +98,16 @@ public void testFlatUrls() testInheritance( "flat-urls" ); } + /** + * MNG-5951 child.inherit.append.path="false" test + * @throws Exception + */ + public void testNoAppendUrls() + throws Exception + { + testInheritance( "no-append-urls" ); + } + /** * Tricky case: flat directory structure, but child directory != artifactId. * Model interpolation does not give same result when calculated from build or from repo... diff --git a/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls-child.xml b/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls-child.xml new file mode 100644 index 0000000000..d7cc4d0b4f --- /dev/null +++ b/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls-child.xml @@ -0,0 +1,34 @@ + + + + + + 4.0.0 + + + inheritance + parent + 11-SNAPSHOT + + + inheritance + Model urls inheritance test child + \ No newline at end of file diff --git a/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls-expected.xml b/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls-expected.xml new file mode 100644 index 0000000000..d2a8cfe52f --- /dev/null +++ b/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls-expected.xml @@ -0,0 +1,50 @@ + + + + + + 4.0.0 + + + inheritance + parent + 11-SNAPSHOT + + + inheritance + inheritance + 11-SNAPSHOT + Model urls inheritance test child + MNG-5951 child.inherit.append.path="false" for each url to avoid automatic path addition when inheriting + + + http://www.apache.org/path/to/parent/ + + scm:my-scm:http://domain.org/base + scm:my-scm:https://domain.org/base/ + https://domain.org/base + + + + scp://scp.domain.org/base/ + + + diff --git a/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls-parent.xml b/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls-parent.xml new file mode 100644 index 0000000000..e8bc1652a4 --- /dev/null +++ b/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls-parent.xml @@ -0,0 +1,50 @@ + + + + + + 4.0.0 + + inheritance + parent + 11-SNAPSHOT + + Model urls inheritance test parent + MNG-5951 child.inherit.append.path="false" for each url to avoid automatic path addition when inheriting + + + ../inheritance + + + + http://www.apache.org/path/to/parent/ + + scm:my-scm:http://domain.org/base + scm:my-scm:https://domain.org/base/ + https://domain.org/base + + + + scp://scp.domain.org/base/ + + + \ No newline at end of file diff --git a/maven-model/src/main/mdo/maven.mdo b/maven-model/src/main/mdo/maven.mdo index 7ba6106ca5..959c653032 100644 --- a/maven-model/src/main/mdo/maven.mdo +++ b/maven-model/src/main/mdo/maven.mdo @@ -184,7 +184,21 @@ Default value is: parent value [+ path adjustment] + (artifactId or project.directory property) +
Default value is: parent value [+ path adjustment] + (artifactId or project.directory property), or just parent value if + child.urls.inherit.append.path="false" + ]]> +
+ String + + + childInheritAppendPath + 4.0.0+ + + String for technical reasons, the semantic type is actually + Boolean +
Default value is: true ]]>
String @@ -400,6 +414,22 @@ public String toString() { return getId(); + } + ]]> + + + + 4.0.0+ + + @@ -1613,12 +1643,44 @@ Default value is: parent value [+ path adjustment] + (artifactId or project.directory property) +
Default value is: parent value [+ path adjustment] + (artifactId or project.directory property), or just parent value if + child.urls.inherit.append.path="false" + ]]> +
+ String +
+ + childInheritAppendPath + 4.0.0+ + + String for technical reasons, the semantic type is actually + Boolean +
Default value is: true ]]>
String
+ + + 4.0.0+ + + + + + FileSet @@ -1938,12 +2000,44 @@ protocol://hostname/path. -
Default value is: parent value [+ path adjustment] + (artifactId or project.directory property) +
Default value is: parent value [+ path adjustment] + (artifactId or project.directory property), or just parent value if + child.urls.inherit.append.path="false" + ]]> +
+ String + + + childInheritAppendPath + 4.0.0+ + + String for technical reasons, the semantic type is actually + Boolean +
Default value is: true ]]>
String
+ + + 4.0.0+ + + + + +