[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
This commit is contained in:
Hervé Boutemy 2015-12-23 14:49:20 +01:00
parent ce6cc5d008
commit 2e8e09f25b
7 changed files with 250 additions and 11 deletions

View File

@ -144,12 +144,13 @@ public class DefaultInheritanceAssembler
{ {
@Override @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 childDirectory = context.get( CHILD_DIRECTORY );
Object childPathAdjustment = context.get( CHILD_PATH_ADJUSTMENT ); 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; return parentUrl;
} }

View File

@ -103,7 +103,7 @@ public class MavenModelMerger
} }
else if ( target.getUrl() == null ) else if ( target.getUrl() == null )
{ {
target.setUrl( extrapolateChildUrl( src, context ) ); target.setUrl( extrapolateChildUrl( src, source.isChildInheritAppendPath(), context ) );
target.setLocation( "url", source.getLocation( "url" ) ); target.setLocation( "url", source.getLocation( "url" ) );
} }
} }
@ -467,7 +467,7 @@ public class MavenModelMerger
} }
else if ( target.getUrl() == null ) else if ( target.getUrl() == null )
{ {
target.setUrl( extrapolateChildUrl( src, context ) ); target.setUrl( extrapolateChildUrl( src, source.isChildInheritAppendPath(), context ) );
target.setLocation( "url", source.getLocation( "url" ) ); target.setLocation( "url", source.getLocation( "url" ) );
} }
} }
@ -486,7 +486,7 @@ public class MavenModelMerger
} }
else if ( target.getUrl() == null ) else if ( target.getUrl() == null )
{ {
target.setUrl( extrapolateChildUrl( src, context ) ); target.setUrl( extrapolateChildUrl( src, source.isChildInheritAppendPath(), context ) );
target.setLocation( "url", source.getLocation( "url" ) ); target.setLocation( "url", source.getLocation( "url" ) );
} }
} }
@ -505,7 +505,7 @@ public class MavenModelMerger
} }
else if ( target.getConnection() == null ) else if ( target.getConnection() == null )
{ {
target.setConnection( extrapolateChildUrl( src, context ) ); target.setConnection( extrapolateChildUrl( src, source.isChildInheritAppendPath(), context ) );
target.setLocation( "connection", source.getLocation( "connection" ) ); target.setLocation( "connection", source.getLocation( "connection" ) );
} }
} }
@ -525,7 +525,7 @@ public class MavenModelMerger
} }
else if ( target.getDeveloperConnection() == null ) else if ( target.getDeveloperConnection() == null )
{ {
target.setDeveloperConnection( extrapolateChildUrl( src, context ) ); target.setDeveloperConnection( extrapolateChildUrl( src, source.isChildInheritAppendPath(), context ) );
target.setLocation( "developerConnection", source.getLocation( "developerConnection" ) ); target.setLocation( "developerConnection", source.getLocation( "developerConnection" ) );
} }
} }
@ -671,7 +671,7 @@ public class MavenModelMerger
return exclusion.getGroupId() + ':' + exclusion.getArtifactId(); 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; return parentUrl;
} }

View File

@ -98,6 +98,16 @@ public class DefaultInheritanceAssemblerTest
testInheritance( "flat-urls" ); 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. * Tricky case: flat directory structure, but child directory != artifactId.
* Model interpolation does not give same result when calculated from build or from repo... * Model interpolation does not give same result when calculated from build or from repo...

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -184,7 +184,21 @@
<description> <description>
<![CDATA[ <![CDATA[
The URL to the project's homepage. 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> </description>
<type>String</type> <type>String</type>
@ -400,6 +414,22 @@
public String toString() public String toString()
{ {
return getId(); return getId();
}
]]>
</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> </code>
@ -1613,12 +1643,44 @@
<description> <description>
<![CDATA[ <![CDATA[
The URL to the project's browsable SCM repository, such as ViewVC or Fisheye. 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> </description>
<type>String</type> <type>String</type>
</field> </field>
</fields> </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>
<class> <class>
<name>FileSet</name> <name>FileSet</name>
@ -1938,12 +2000,44 @@
<description> <description>
<![CDATA[ <![CDATA[
The url of the location where website is deployed, in the form <code>protocol://hostname/path</code>. 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> </description>
<type>String</type> <type>String</type>
</field> </field>
</fields> </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>
<class java.clone="deep"> <class java.clone="deep">