[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
Project: http://git-wip-us.apache.org/repos/asf/maven/repo Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/bd825c53 Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/bd825c53 Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/bd825c53 Branch: refs/heads/slf4j-gossip Commit: bd825c5350b0e0ec10f53667767274004afb5e0d Parents: 9c13922 Author: Hervé Boutemy <hbout...@apache.org> Authored: Wed Dec 23 14:49:20 2015 +0100 Committer: Hervé Boutemy <hbout...@apache.org> Committed: Mon May 30 21:45:47 2016 +0200 ---------------------------------------------------------------------- .../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 +++++++++ .../poms/inheritance/no-append-urls-parent.xml | 50 +++++++++ maven-model/src/main/mdo/maven.mdo | 106 ++++++++++++++++++- 7 files changed, 256 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven/blob/bd825c53/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java ---------------------------------------------------------------------- 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 58d93a7..c59c7a4 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 @@ -139,12 +139,13 @@ public class DefaultInheritanceAssembler { @Override - protected String extrapolateChildUrl( String parentUrl, Map<Object, Object> context ) + protected String extrapolateChildUrl( String parentUrl, boolean appendPath, Map<Object, Object> 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; } http://git-wip-us.apache.org/repos/asf/maven/blob/bd825c53/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java ---------------------------------------------------------------------- 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 0007af5..cae9d73 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 @@ -102,7 +102,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" ) ); } } @@ -466,7 +466,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" ) ); } } @@ -485,7 +485,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" ) ); } } @@ -504,7 +504,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" ) ); } } @@ -524,7 +524,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" ) ); } } @@ -670,7 +670,7 @@ public class MavenModelMerger return exclusion.getGroupId() + ':' + exclusion.getArtifactId(); } - protected String extrapolateChildUrl( String parentUrl, Map<Object, Object> context ) + protected String extrapolateChildUrl( String parentUrl, boolean appendPath, Map<Object, Object> context ) { return parentUrl; } http://git-wip-us.apache.org/repos/asf/maven/blob/bd825c53/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java ---------------------------------------------------------------------- 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 9d88f5f..d49e8df 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 } /** + * 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... * This is why MNG-5000 fix in code is marked as bad practice (uses file names) http://git-wip-us.apache.org/repos/asf/maven/blob/bd825c53/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls-child.xml ---------------------------------------------------------------------- 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 0000000..d7cc4d0 --- /dev/null +++ b/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls-child.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>inheritance</groupId> + <artifactId>parent</artifactId> + <version>11-SNAPSHOT</version> + </parent> + + <artifactId>inheritance</artifactId><!-- same as directory name --> + <name>Model urls inheritance test child</name> +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/maven/blob/bd825c53/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls-expected.xml ---------------------------------------------------------------------- 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 0000000..d2a8cfe --- /dev/null +++ b/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls-expected.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>inheritance</groupId> + <artifactId>parent</artifactId> + <version>11-SNAPSHOT</version> + </parent> + + <groupId>inheritance</groupId> + <artifactId>inheritance</artifactId> + <version>11-SNAPSHOT</version> + <name>Model urls inheritance test child</name> + <description>MNG-5951 child.inherit.append.path="false" for each url to avoid automatic path addition when inheriting</description> + + <!-- 5 inherited urls without anything added to parent --> + <url>http://www.apache.org/path/to/parent/</url> + <scm> + <connection>scm:my-scm:http://domain.org/base</connection> + <developerConnection>scm:my-scm:https://domain.org/base/</developerConnection> + <url>https://domain.org/base</url> + </scm> + <distributionManagement> + <site> + <url>scp://scp.domain.org/base/</url> + </site> + </distributionManagement> +</project> http://git-wip-us.apache.org/repos/asf/maven/blob/bd825c53/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls-parent.xml ---------------------------------------------------------------------- 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 0000000..e8bc165 --- /dev/null +++ b/maven-model-builder/src/test/resources/poms/inheritance/no-append-urls-parent.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" + child.inherit.append.path="false"> + <modelVersion>4.0.0</modelVersion> + + <groupId>inheritance</groupId> + <artifactId>parent</artifactId> + <version>11-SNAPSHOT</version> + + <name>Model urls inheritance test parent</name> + <description>MNG-5951 child.inherit.append.path="false" for each url to avoid automatic path addition when inheriting</description> + + <modules> + <module>../inheritance</module> + </modules> + + <!-- 5 urls in the pom to configure for not adding path --> + <url>http://www.apache.org/path/to/parent/</url> + <scm child.inherit.append.path="false"> + <connection>scm:my-scm:http://domain.org/base</connection> + <developerConnection>scm:my-scm:https://domain.org/base/</developerConnection> + <url>https://domain.org/base</url> + </scm> + <distributionManagement> + <site child.inherit.append.path="false"> + <url>scp://scp.domain.org/base/</url> + </site> + </distributionManagement> +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/maven/blob/bd825c53/maven-model/src/main/mdo/maven.mdo ---------------------------------------------------------------------- diff --git a/maven-model/src/main/mdo/maven.mdo b/maven-model/src/main/mdo/maven.mdo index 5eba3ea..a737fe9 100644 --- a/maven-model/src/main/mdo/maven.mdo +++ b/maven-model/src/main/mdo/maven.mdo @@ -245,7 +245,21 @@ <description> <![CDATA[ The URL to the project's homepage. - <br /><b>Default value is</b>: parent value [+ path adjustment] + artifactId + <br /><b>Default value is</b>: parent value [+ path adjustment] + artifactId, or just parent value if + <code>child.urls.inherit.append.path="false"</code> + ]]> + </description> + <type>String</type> + </field> + <field xml.attribute="true" xml.tagName="child.inherit.append.path"> + <name>childInheritAppendPath</name> + <version>4.0.0+</version> + <description> + <![CDATA[ + When childs inherit from urls, append path or not?. Note: While the type + of this field is <code>String</code> for technical reasons, the semantic type is actually + <code>Boolean</code> + <br /><b>Default value is</b>: <code>true</code> ]]> </description> <type>String</type> @@ -630,6 +644,24 @@ ]]> </code> </codeSegment> + <codeSegment> + <version>4.0.0+</version> + <code> + <![CDATA[ + + public boolean isChildInheritAppendPath() + { + return ( childInheritAppendPath != null ) ? Boolean.parseBoolean( childInheritAppendPath ) : true; + } + + public void setChildInheritAppendPath( boolean childInheritAppendPath ) + { + this.childInheritAppendPath = String.valueOf( childInheritAppendPath ); + } + + ]]> + </code> + </codeSegment> </codeSegments> </class> <class java.clone="deep"> @@ -2172,12 +2204,46 @@ <description> <![CDATA[ The URL to the project's browsable SCM repository, such as ViewVC or Fisheye. - <br /><b>Default value is</b>: parent value [+ path adjustment] + artifactId + <br /><b>Default value is</b>: parent value [+ path adjustment] + artifactId, or just parent value if + <code>child.urls.inherit.append.path="false"</code> + ]]> + </description> + <type>String</type> + </field> + <field xml.attribute="true" xml.tagName="child.inherit.append.path"> + <name>childInheritAppendPath</name> + <version>4.0.0+</version> + <description> + <![CDATA[ + When childs inherit from urls, append path or not?. Note: While the type + of this field is <code>String</code> for technical reasons, the semantic type is actually + <code>Boolean</code> + <br /><b>Default value is</b>: <code>true</code> ]]> </description> <type>String</type> </field> </fields> + <codeSegments> + <codeSegment> + <version>4.0.0+</version> + <code> + <![CDATA[ + + public boolean isChildInheritAppendPath() + { + return ( childInheritAppendPath != null ) ? Boolean.parseBoolean( childInheritAppendPath ) : true; + } + + public void setChildInheritAppendPath( boolean childInheritAppendPath ) + { + this.childInheritAppendPath = String.valueOf( childInheritAppendPath ); + } + + ]]> + </code> + </codeSegment> + </codeSegments> </class> <class> <name>FileSet</name> @@ -2605,12 +2671,46 @@ <description> <![CDATA[ The url of the location where website is deployed, in the form <code>protocol://hostname/path</code>. - <br /><b>Default value is</b>: parent value [+ path adjustment] + artifactId + <br /><b>Default value is</b>: parent value [+ path adjustment] + artifactId, or just parent value if + <code>child.urls.inherit.append.path="false"</code> + ]]> + </description> + <type>String</type> + </field> + <field xml.attribute="true" xml.tagName="child.inherit.append.path"> + <name>childInheritAppendPath</name> + <version>4.0.0+</version> + <description> + <![CDATA[ + When childs inherit from urls, append path or not?. Note: While the type + of this field is <code>String</code> for technical reasons, the semantic type is actually + <code>Boolean</code> + <br /><b>Default value is</b>: <code>true</code> ]]> </description> <type>String</type> </field> </fields> + <codeSegments> + <codeSegment> + <version>4.0.0+</version> + <code> + <![CDATA[ + + public boolean isChildInheritAppendPath() + { + return ( childInheritAppendPath != null ) ? Boolean.parseBoolean( childInheritAppendPath ) : true; + } + + public void setChildInheritAppendPath( boolean childInheritAppendPath ) + { + this.childInheritAppendPath = String.valueOf( childInheritAppendPath ); + } + + ]]> + </code> + </codeSegment> + </codeSegments> </class> <class java.clone="deep">