From 2e8e09f25be5a99184f23e7a15833c69ff039547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Wed, 23 Dec 2015 14:49:20 +0100 Subject: [PATCH] [MNG-5951] add an option to avoid path addition to inherited URLs This is done as child.inherit.append.path XML attribute on 3 locations: - project, for project.url - project.distributionManagement.site for its url - project.scm, for the 3 scm urls in one unique config --- .../DefaultInheritanceAssembler.java | 5 +- .../maven/model/merge/MavenModelMerger.java | 12 +-- .../DefaultInheritanceAssemblerTest.java | 10 ++ .../poms/inheritance/no-append-urls-child.xml | 34 ++++++ .../inheritance/no-append-urls-expected.xml | 50 +++++++++ .../inheritance/no-append-urls-parent.xml | 50 +++++++++ maven-model/src/main/mdo/maven.mdo | 100 +++++++++++++++++- 7 files changed, 250 insertions(+), 11 deletions(-) create mode 100644 maven-model-builder/src/test/resources/poms/inheritance/no-append-urls-child.xml create mode 100644 maven-model-builder/src/test/resources/poms/inheritance/no-append-urls-expected.xml create mode 100644 maven-model-builder/src/test/resources/poms/inheritance/no-append-urls-parent.xml 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 @@ public class DefaultInheritanceAssembler { @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 @@ public class MavenModelMerger } 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 @@ public class MavenModelMerger } 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 @@ public class MavenModelMerger } 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 @@ public class MavenModelMerger } 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 @@ public class MavenModelMerger } 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 @@ public class MavenModelMerger 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 class DefaultInheritanceAssemblerTest 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+ + + + + +