mirror of https://github.com/apache/maven.git
[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:
parent
1ad780143c
commit
e3aa406cc7
|
@ -1232,33 +1232,7 @@ public class ModelMerger
|
|||
protected void mergeReportSet_Reports( ReportSet target, ReportSet source, boolean sourceDominant,
|
||||
Map<Object, Object> context )
|
||||
{
|
||||
List<String> src = source.getReports();
|
||||
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 ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
target.setReports( merge( target.getReports(), source.getReports(), sourceDominant, e -> e ) );
|
||||
}
|
||||
|
||||
protected void mergeDependencyManagement( DependencyManagement target, DependencyManagement source,
|
||||
|
@ -1520,15 +1494,10 @@ public class ModelMerger
|
|||
protected void mergeMailingList_OtherArchives( MailingList target, MailingList source, boolean sourceDominant,
|
||||
Map<Object, Object> context )
|
||||
{
|
||||
List<String> src = source.getOtherArchives();
|
||||
if ( !src.isEmpty() )
|
||||
{
|
||||
List<String> tgt = target.getOtherArchives();
|
||||
List<String> merged = new ArrayList<>( tgt.size() + src.size() );
|
||||
merged.addAll( tgt );
|
||||
merged.addAll( src );
|
||||
target.setOtherArchives( merged );
|
||||
}
|
||||
target.setOtherArchives( merge( target.getOtherArchives(),
|
||||
source.getOtherArchives(),
|
||||
sourceDominant,
|
||||
e -> e ) );
|
||||
}
|
||||
|
||||
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,
|
||||
Map<Object, Object> context )
|
||||
{
|
||||
List<String> src = source.getRoles();
|
||||
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 );
|
||||
}
|
||||
target.setRoles( merge( target.getRoles(), source.getRoles(), sourceDominant, e -> e ) );
|
||||
}
|
||||
|
||||
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,
|
||||
Map<Object, Object> context )
|
||||
{
|
||||
List<String> src = source.getFilters();
|
||||
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 );
|
||||
}
|
||||
target.setFilters( merge( target.getFilters(), source.getFilters(), sourceDominant, e -> e ) );
|
||||
}
|
||||
|
||||
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,
|
||||
Map<Object, Object> context )
|
||||
{
|
||||
List<String> src = source.getGoals();
|
||||
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 );
|
||||
}
|
||||
target.setGoals( merge( target.getGoals(), source.getGoals(), sourceDominant, e -> e ) );
|
||||
}
|
||||
|
||||
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,
|
||||
Map<Object, Object> context )
|
||||
{
|
||||
List<String> src = source.getIncludes();
|
||||
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 );
|
||||
}
|
||||
target.setIncludes( merge( target.getIncludes(), source.getIncludes(), sourceDominant, e -> e ) );
|
||||
}
|
||||
|
||||
protected void mergePatternSet_Excludes( PatternSet target, PatternSet source, boolean sourceDominant,
|
||||
Map<Object, Object> context )
|
||||
{
|
||||
List<String> src = source.getExcludes();
|
||||
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 );
|
||||
}
|
||||
target.setExcludes( merge( target.getExcludes(), source.getExcludes(), sourceDominant, e -> e ) );
|
||||
}
|
||||
|
||||
protected void mergeProfile( Profile target, Profile source, boolean sourceDominant, Map<Object, Object> context )
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
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
|
||||
* 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.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.Contributor;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Developer;
|
||||
import org.apache.maven.model.MailingList;
|
||||
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.ReportSet;
|
||||
import org.apache.maven.model.Repository;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -131,6 +136,45 @@ public class ModelMergerTest
|
|||
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
|
||||
public void mergeGroupId()
|
||||
{
|
||||
|
@ -165,6 +209,19 @@ public class ModelMergerTest
|
|||
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
|
||||
public void mergeSameMailingLists()
|
||||
{
|
||||
|
@ -229,6 +286,19 @@ public class ModelMergerTest
|
|||
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
|
||||
public void mergePackaging()
|
||||
{
|
||||
|
@ -280,6 +350,19 @@ public class ModelMergerTest
|
|||
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
|
||||
public void mergeSameRepositories()
|
||||
{
|
||||
|
@ -297,6 +380,19 @@ public class ModelMergerTest
|
|||
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
|
||||
public void mergeUrl()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue