This is an automated email from the ASF dual-hosted git repository.
hboutemy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/master by this push:
new 2e8e09f [MNG-5951] add an option to avoid path addition to inherited
URLs
2e8e09f is described below
commit 2e8e09f25be5a99184f23e7a15833c69ff039547
Author: Hervé Boutemy <[email protected]>
AuthorDate: Wed Dec 23 14:49:20 2015 +0100
[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
---
.../inheritance/DefaultInheritanceAssembler.java | 5 +-
.../apache/maven/model/merge/MavenModelMerger.java | 12 +--
.../DefaultInheritanceAssemblerTest.java | 10 +++
.../poms/inheritance/no-append-urls-child.xml | 34 +++++++
.../poms/inheritance/no-append-urls-expected.xml | 50 +++++++++++
.../poms/inheritance/no-append-urls-parent.xml | 50 +++++++++++
maven-model/src/main/mdo/maven.mdo | 100 ++++++++++++++++++++-
7 files changed, 250 insertions(+), 11 deletions(-)
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 890c845..7622f84 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<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;
}
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 8e90454..640c211 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<Object,
Object> context )
+ protected String extrapolateChildUrl( String parentUrl, boolean
appendPath, Map<Object, Object> 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 372d0a9..68dd71e 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
@@ -99,6 +99,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)
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
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>
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
diff --git a/maven-model/src/main/mdo/maven.mdo
b/maven-model/src/main/mdo/maven.mdo
index 7ba6106..959c653 100644
--- a/maven-model/src/main/mdo/maven.mdo
+++ b/maven-model/src/main/mdo/maven.mdo
@@ -184,7 +184,21 @@
<description>
<![CDATA[
The URL to the project's homepage.
- <br><b>Default value is</b>: parent value [+ path adjustment] +
(artifactId or <code>project.directory</code> property)
+ <br><b>Default value is</b>: parent value [+ path adjustment] +
(artifactId or <code>project.directory</code> property), 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>
@@ -404,6 +418,22 @@
]]>
</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">
@@ -1613,12 +1643,44 @@
<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 or <code>project.directory</code> property)
+ <br><b>Default value is</b>: parent value [+ path adjustment] +
(artifactId or <code>project.directory</code> property), 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>
@@ -1938,12 +2000,44 @@
<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 or <code>project.directory</code> property)
+ <br><b>Default value is</b>: parent value [+ path adjustment] +
(artifactId or <code>project.directory</code> property), 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">