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 a1449ace89..4f4113f986 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 @@ -46,6 +46,7 @@ import org.apache.maven.model.Repository; import org.apache.maven.model.RepositoryBase; import org.apache.maven.model.Scm; import org.apache.maven.model.Site; +import org.codehaus.plexus.util.StringUtils; /** * The domain-specific model merger for the Maven POM, overriding generic code from parent class when necessary with @@ -443,16 +444,34 @@ public class MavenModelMerger if ( src != null ) { Site tgt = target.getSite(); - if ( sourceDominant || tgt == null ) + if ( sourceDominant || tgt == null || isSiteEmpty( tgt ) ) { - tgt = new Site(); + if ( tgt == null ) + { + tgt = new Site(); + } tgt.setLocation( "", src.getLocation( "" ) ); target.setSite( tgt ); mergeSite( tgt, src, sourceDominant, context ); } + mergeSite_ChildSiteUrlInheritAppendPath( tgt, src, sourceDominant, context ); } } + @Override + protected void mergeSite( Site target, Site source, boolean sourceDominant, Map context ) + { + mergeSite_Id( target, source, sourceDominant, context ); + mergeSite_Name( target, source, sourceDominant, context ); + mergeSite_Url( target, source, sourceDominant, context ); + } + + protected boolean isSiteEmpty( Site site ) + { + return StringUtils.isEmpty( site.getId() ) && StringUtils.isEmpty( site.getName() ) + && StringUtils.isEmpty( site.getUrl() ); + } + @Override protected void mergeSite_Url( Site target, Site source, boolean sourceDominant, Map context ) { 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 b97f37c9d8..07a121ae5e 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 @@ -103,6 +103,26 @@ public class DefaultInheritanceAssemblerTest testInheritance( "no-append-urls" ); } + /** + * MNG-5951 special case test: inherit with partial override + * @throws Exception + */ + public void testNoAppendUrls2() + throws Exception + { + testInheritance( "no-append-urls2" ); + } + + /** + * MNG-5951 special case test: child.x.y.inherit.append.path="true" in child should not reset content + * @throws Exception + */ + public void testNoAppendUrls3() + throws Exception + { + testInheritance( "no-append-urls3" ); + } + /** * 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-urls2-child.xml b/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls2-child.xml new file mode 100644 index 0000000000..dbf4dd48d0 --- /dev/null +++ b/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls2-child.xml @@ -0,0 +1,43 @@ + + + + + + 4.0.0 + + + inheritance + parent + 11-SNAPSHOT + + + inheritance + Model urls inheritance test child + + + https://domain.org/override + + + + reset + + + \ No newline at end of file diff --git a/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls2-expected.xml b/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls2-expected.xml new file mode 100644 index 0000000000..4d8e683149 --- /dev/null +++ b/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls2-expected.xml @@ -0,0 +1,50 @@ + + + + + + 4.0.0 + + + inheritance + parent + 11-SNAPSHOT + + + inheritance + inheritance + 11-SNAPSHOT + Model urls inheritance test child + + + scm:my-scm:http://domain.org/base + scm:my-scm:https://domain.org/base/ + https://domain.org/override + + + + reset + + + diff --git a/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls2-parent.xml b/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls2-parent.xml new file mode 100644 index 0000000000..d2e2e71d78 --- /dev/null +++ b/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls2-parent.xml @@ -0,0 +1,45 @@ + + + + + + 4.0.0 + + inheritance + parent + 11-SNAPSHOT + + Model urls inheritance test parent, with special merge test for mergeSite_ChildSiteUrlInheritAppendPath + + + 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-builder/src/test/resources/poms/inheritance/no-append-urls3-child.xml b/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls3-child.xml new file mode 100644 index 0000000000..ccb2d91747 --- /dev/null +++ b/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls3-child.xml @@ -0,0 +1,41 @@ + + + + + + 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-urls3-expected.xml b/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls3-expected.xml new file mode 100644 index 0000000000..a6a884d24e --- /dev/null +++ b/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls3-expected.xml @@ -0,0 +1,50 @@ + + + + + + 4.0.0 + + + inheritance + parent + 11-SNAPSHOT + + + inheritance + inheritance + 11-SNAPSHOT + Model urls inheritance test child + + + 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-urls3-parent.xml b/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls3-parent.xml new file mode 100644 index 0000000000..d2e2e71d78 --- /dev/null +++ b/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls3-parent.xml @@ -0,0 +1,45 @@ + + + + + + 4.0.0 + + inheritance + parent + 11-SNAPSHOT + + Model urls inheritance test parent, with special merge test for mergeSite_ChildSiteUrlInheritAppendPath + + + 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