[MNG-6505] tweaked distributionManagement.site inheritance

child.site.url.inherit.append.path is inherited independantly from
id/name/url
This commit is contained in:
Hervé Boutemy 2018-11-10 16:43:43 +01:00
parent f97316ceec
commit 07bd5507ae
8 changed files with 315 additions and 2 deletions

View File

@ -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<Object, Object> 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<Object, Object> context )
{

View File

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

View File

@ -0,0 +1,43 @@
<?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>
<scm>
<url>https://domain.org/override</url><!-- check that this won't impact child.site.url.inherit.append.path attribute inheritance -->
</scm>
<distributionManagement>
<site><!-- overriding 1 element will reset all elements, but not child.site.url.inherit.append.path attribute -->
<name>reset</name>
</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.project.url.inherit.append.path="false">
<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>
<scm child.scm.connection.inherit.append.path="false"
child.scm.developerConnection.inherit.append.path="false"
child.scm.url.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/override</url>
</scm>
<distributionManagement>
<site child.site.url.inherit.append.path="false">
<name>reset</name>
</site>
</distributionManagement>
</project>

View File

@ -0,0 +1,45 @@
<?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.project.url.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, with special merge test for mergeSite_ChildSiteUrlInheritAppendPath</name>
<scm child.scm.connection.inherit.append.path="false"
child.scm.developerConnection.inherit.append.path="false"
child.scm.url.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.site.url.inherit.append.path="false">
<url>scp://scp.domain.org/base/</url>
</site>
</distributionManagement>
</project>

View File

@ -0,0 +1,41 @@
<?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>
<scm child.scm.connection.inherit.append.path="true"
child.scm.developerConnection.inherit.append.path="true"
child.scm.url.inherit.append.path="true" />
<distributionManagement>
<site child.site.url.inherit.append.path="true" />
</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.project.url.inherit.append.path="false">
<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>
<scm child.scm.connection.inherit.append.path="true"
child.scm.developerConnection.inherit.append.path="true"
child.scm.url.inherit.append.path="true">
<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.site.url.inherit.append.path="true">
<url>scp://scp.domain.org/base/</url>
</site>
</distributionManagement>
</project>

View File

@ -0,0 +1,45 @@
<?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.project.url.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, with special merge test for mergeSite_ChildSiteUrlInheritAppendPath</name>
<scm child.scm.connection.inherit.append.path="false"
child.scm.developerConnection.inherit.append.path="false"
child.scm.url.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.site.url.inherit.append.path="false">
<url>scp://scp.domain.org/base/</url>
</site>
</distributionManagement>
</project>