[MNG-6824] ModelMerger is broken

Fixing reportSet.reports, mailingList.otherArchives, contributor.roles, build.filters, execution.goals, patternSet.includes, patternSet.excludes
This commit is contained in:
rfscholte 2019-12-22 17:28:35 +01:00
parent 1ad780143c
commit e3aa406cc7
2 changed files with 109 additions and 84 deletions

View File

@ -1232,33 +1232,7 @@ public class ModelMerger
protected void mergeReportSet_Reports( ReportSet target, ReportSet source, boolean sourceDominant, protected void mergeReportSet_Reports( ReportSet target, ReportSet source, boolean sourceDominant,
Map<Object, Object> context ) Map<Object, Object> context )
{ {
List<String> src = source.getReports(); target.setReports( merge( target.getReports(), source.getReports(), sourceDominant, e -> e ) );
if ( !src.isEmpty() )
{
List<String> tgt = target.getReports();
List<String> merged = new ArrayList<>( tgt.size() + src.size() );
merged.addAll( tgt );
merged.addAll( src );
target.setReports( merged );
InputLocation sourceLocation = source.getLocation( "reports" );
if ( sourceLocation != null )
{
InputLocation targetLocation = target.getLocation( "reports" );
if ( targetLocation == null )
{
target.setLocation( "reports", sourceLocation );
}
else
{
for ( int i = 0; i < src.size(); i++ )
{
targetLocation.setLocation( Integer.valueOf( tgt.size() + i ),
sourceLocation.getLocation( Integer.valueOf( i ) ) );
}
}
}
}
} }
protected void mergeDependencyManagement( DependencyManagement target, DependencyManagement source, protected void mergeDependencyManagement( DependencyManagement target, DependencyManagement source,
@ -1520,15 +1494,10 @@ public class ModelMerger
protected void mergeMailingList_OtherArchives( MailingList target, MailingList source, boolean sourceDominant, protected void mergeMailingList_OtherArchives( MailingList target, MailingList source, boolean sourceDominant,
Map<Object, Object> context ) Map<Object, Object> context )
{ {
List<String> src = source.getOtherArchives(); target.setOtherArchives( merge( target.getOtherArchives(),
if ( !src.isEmpty() ) source.getOtherArchives(),
{ sourceDominant,
List<String> tgt = target.getOtherArchives(); e -> e ) );
List<String> merged = new ArrayList<>( tgt.size() + src.size() );
merged.addAll( tgt );
merged.addAll( src );
target.setOtherArchives( merged );
}
} }
protected void mergeDeveloper( Developer target, Developer source, boolean sourceDominant, protected void mergeDeveloper( Developer target, Developer source, boolean sourceDominant,
@ -1652,15 +1621,7 @@ public class ModelMerger
protected void mergeContributor_Roles( Contributor target, Contributor source, boolean sourceDominant, protected void mergeContributor_Roles( Contributor target, Contributor source, boolean sourceDominant,
Map<Object, Object> context ) Map<Object, Object> context )
{ {
List<String> src = source.getRoles(); target.setRoles( merge( target.getRoles(), source.getRoles(), sourceDominant, e -> e ) );
if ( !src.isEmpty() )
{
List<String> tgt = target.getRoles();
List<String> merged = new ArrayList<>( tgt.size() + src.size() );
merged.addAll( tgt );
merged.addAll( src );
target.setRoles( merged );
}
} }
protected void mergeContributor_Properties( Contributor target, Contributor source, boolean sourceDominant, protected void mergeContributor_Properties( Contributor target, Contributor source, boolean sourceDominant,
@ -2176,15 +2137,7 @@ public class ModelMerger
protected void mergeBuildBase_Filters( BuildBase target, BuildBase source, boolean sourceDominant, protected void mergeBuildBase_Filters( BuildBase target, BuildBase source, boolean sourceDominant,
Map<Object, Object> context ) Map<Object, Object> context )
{ {
List<String> src = source.getFilters(); target.setFilters( merge( target.getFilters(), source.getFilters(), sourceDominant, e -> e ) );
if ( !src.isEmpty() )
{
List<String> tgt = target.getFilters();
List<String> merged = new ArrayList<>( tgt.size() + src.size() );
merged.addAll( tgt );
merged.addAll( src );
target.setFilters( merged );
}
} }
protected void mergeBuildBase_Resources( BuildBase target, BuildBase source, boolean sourceDominant, protected void mergeBuildBase_Resources( BuildBase target, BuildBase source, boolean sourceDominant,
@ -2405,15 +2358,7 @@ public class ModelMerger
protected void mergePluginExecution_Goals( PluginExecution target, PluginExecution source, boolean sourceDominant, protected void mergePluginExecution_Goals( PluginExecution target, PluginExecution source, boolean sourceDominant,
Map<Object, Object> context ) Map<Object, Object> context )
{ {
List<String> src = source.getGoals(); target.setGoals( merge( target.getGoals(), source.getGoals(), sourceDominant, e -> e ) );
if ( !src.isEmpty() )
{
List<String> tgt = target.getGoals();
List<String> merged = new ArrayList<>( tgt.size() + src.size() );
merged.addAll( tgt );
merged.addAll( src );
target.setGoals( merged );
}
} }
protected void mergeResource( Resource target, Resource source, boolean sourceDominant, protected void mergeResource( Resource target, Resource source, boolean sourceDominant,
@ -2496,29 +2441,13 @@ public class ModelMerger
protected void mergePatternSet_Includes( PatternSet target, PatternSet source, boolean sourceDominant, protected void mergePatternSet_Includes( PatternSet target, PatternSet source, boolean sourceDominant,
Map<Object, Object> context ) Map<Object, Object> context )
{ {
List<String> src = source.getIncludes(); target.setIncludes( merge( target.getIncludes(), source.getIncludes(), sourceDominant, e -> e ) );
if ( !src.isEmpty() )
{
List<String> tgt = target.getIncludes();
List<String> merged = new ArrayList<>( tgt.size() + src.size() );
merged.addAll( tgt );
merged.addAll( src );
target.setIncludes( merged );
}
} }
protected void mergePatternSet_Excludes( PatternSet target, PatternSet source, boolean sourceDominant, protected void mergePatternSet_Excludes( PatternSet target, PatternSet source, boolean sourceDominant,
Map<Object, Object> context ) Map<Object, Object> context )
{ {
List<String> src = source.getExcludes(); target.setExcludes( merge( target.getExcludes(), source.getExcludes(), sourceDominant, e -> e ) );
if ( !src.isEmpty() )
{
List<String> tgt = target.getExcludes();
List<String> merged = new ArrayList<>( tgt.size() + src.size() );
merged.addAll( tgt );
merged.addAll( src );
target.setExcludes( merged );
}
} }
protected void mergeProfile( Profile target, Profile source, boolean sourceDominant, Map<Object, Object> context ) protected void mergeProfile( Profile target, Profile source, boolean sourceDominant, Map<Object, Object> context )

View File

@ -1,5 +1,8 @@
package org.apache.maven.model.merge; package org.apache.maven.model.merge;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.is;
/* /*
* Licensed to the Apache Software Foundation (ASF) under one * Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file * or more contributor license agreements. See the NOTICE file
@ -20,17 +23,19 @@ package org.apache.maven.model.merge;
*/ */
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.is;
import java.util.Arrays; import java.util.Arrays;
import org.apache.maven.model.Build;
import org.apache.maven.model.Contributor; import org.apache.maven.model.Contributor;
import org.apache.maven.model.Dependency; import org.apache.maven.model.Dependency;
import org.apache.maven.model.Developer; import org.apache.maven.model.Developer;
import org.apache.maven.model.MailingList; import org.apache.maven.model.MailingList;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.PatternSet;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.Profile; import org.apache.maven.model.Profile;
import org.apache.maven.model.ReportSet;
import org.apache.maven.model.Repository; import org.apache.maven.model.Repository;
import org.junit.Test; import org.junit.Test;
@ -131,6 +136,45 @@ public class ModelMergerTest
assertThat( target.getDevelopers(), contains( developer ) ); assertThat( target.getDevelopers(), contains( developer ) );
} }
@Test
public void mergeSameExcludes()
{
PatternSet target = new PatternSet();
target.setExcludes( Arrays.asList( "first", "second", "third" ) );
PatternSet source = new PatternSet();
source.setExcludes( Arrays.asList( "first", "second", "third" ) );
modelMerger.mergePatternSet_Excludes( target, source, true, null );
assertThat( target.getExcludes(), contains( "first", "second", "third" ) );
}
@Test
public void mergeSameFilters()
{
Build target = new Build();
target.setFilters( Arrays.asList( "first", "second", "third" ) );
Build source = new Build();
source.setFilters( Arrays.asList( "first", "second", "third" ) );
modelMerger.mergeBuild( target, source, true, null );
assertThat( target.getFilters(), contains( "first", "second", "third" ) );
}
@Test
public void mergeSameGoals()
{
PluginExecution target = new PluginExecution();
target.setGoals( Arrays.asList( "first", "second", "third" ) );
PluginExecution source = new PluginExecution();
source.setGoals( Arrays.asList( "first", "second", "third" ) );
modelMerger.mergePluginExecution( target, source, true, null );
assertThat( target.getGoals(), contains( "first", "second", "third" ) );
}
@Test @Test
public void mergeGroupId() public void mergeGroupId()
{ {
@ -164,7 +208,20 @@ public class ModelMergerTest
modelMerger.merge( target, source, false, null ); modelMerger.merge( target, source, false, null );
assertThat( target.getInceptionYear(), is( "TARGET" ) ); assertThat( target.getInceptionYear(), is( "TARGET" ) );
} }
@Test
public void mergeSameIncludes()
{
PatternSet target = new PatternSet();
target.setIncludes( Arrays.asList( "first", "second", "third" ) );
PatternSet source = new PatternSet();
source.setIncludes( Arrays.asList( "first", "second", "third" ) );
modelMerger.mergePatternSet_Includes( target, source, true, null );
assertThat( target.getIncludes(), contains( "first", "second", "third" ) );
}
@Test @Test
public void mergeSameMailingLists() public void mergeSameMailingLists()
{ {
@ -229,6 +286,19 @@ public class ModelMergerTest
assertThat( target.getName(), is( "TARGET" ) ); assertThat( target.getName(), is( "TARGET" ) );
} }
@Test
public void mergeSameOtherArchives()
{
MailingList target = new MailingList();
target.setOtherArchives( Arrays.asList( "first", "second", "third" ) );
MailingList source = new MailingList();
source.setOtherArchives( Arrays.asList( "first", "second", "third" ) );
modelMerger.mergeMailingList( target, source, true, null );
assertThat( target.getOtherArchives(), contains( "first", "second", "third" ) );
}
@Test @Test
public void mergePackaging() public void mergePackaging()
{ {
@ -280,6 +350,19 @@ public class ModelMergerTest
assertThat( target.getProfiles(), contains( profile ) ); assertThat( target.getProfiles(), contains( profile ) );
} }
@Test
public void mergeSameReports()
{
ReportSet target = new ReportSet();
target.setReports( Arrays.asList( "first", "second", "third" ) );
ReportSet source = new ReportSet();
source.setReports( Arrays.asList( "first", "second", "third" ) );
modelMerger.mergeReportSet( target, source, true, null );
assertThat( target.getReports(), contains( "first", "second", "third" ) );
}
@Test @Test
public void mergeSameRepositories() public void mergeSameRepositories()
{ {
@ -297,6 +380,19 @@ public class ModelMergerTest
assertThat( target.getRepositories(), contains( repository ) ); assertThat( target.getRepositories(), contains( repository ) );
} }
@Test
public void mergeSameRoles()
{
Contributor target = new Contributor();
target.setRoles( Arrays.asList( "first", "second", "third" ) );
Contributor source = new Contributor();
source.setRoles( Arrays.asList( "first", "second", "third" ) );
modelMerger.mergeContributor_Roles( target, source, true, null );
assertThat( target.getRoles(), contains( "first", "second", "third" ) );
}
@Test @Test
public void mergeUrl() public void mergeUrl()
{ {