mirror of https://github.com/apache/maven.git
o Continued work on model merging
git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@772980 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f6401b60b5
commit
c17cfb0076
|
@ -30,12 +30,21 @@ import java.util.Set;
|
|||
import java.util.StringTokenizer;
|
||||
|
||||
import org.apache.maven.model.BuildBase;
|
||||
import org.apache.maven.model.CiManagement;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.DeploymentRepository;
|
||||
import org.apache.maven.model.DistributionManagement;
|
||||
import org.apache.maven.model.Extension;
|
||||
import org.apache.maven.model.IssueManagement;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.ModelBase;
|
||||
import org.apache.maven.model.Organization;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.PluginContainer;
|
||||
import org.apache.maven.model.PluginExecution;
|
||||
import org.apache.maven.model.ReportPlugin;
|
||||
import org.apache.maven.model.ReportSet;
|
||||
import org.apache.maven.model.Reporting;
|
||||
import org.apache.maven.model.Repository;
|
||||
import org.apache.maven.model.RepositoryBase;
|
||||
import org.apache.maven.model.Scm;
|
||||
|
@ -86,6 +95,57 @@ public class MavenModelMerger
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: Whether the merge continues recursively into an existing node or not could be an option for the generated merger
|
||||
*/
|
||||
@Override
|
||||
protected void mergeModel_Organization( Model target, Model source, boolean sourceDominant,
|
||||
Map<Object, Object> context )
|
||||
{
|
||||
Organization src = source.getOrganization();
|
||||
if ( source.getOrganization() != null )
|
||||
{
|
||||
Organization tgt = target.getOrganization();
|
||||
if ( tgt == null )
|
||||
{
|
||||
target.setOrganization( tgt = new Organization() );
|
||||
mergeOrganization( tgt, src, sourceDominant, context );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mergeModel_IssueManagement( Model target, Model source, boolean sourceDominant,
|
||||
Map<Object, Object> context )
|
||||
{
|
||||
IssueManagement src = source.getIssueManagement();
|
||||
if ( source.getIssueManagement() != null )
|
||||
{
|
||||
IssueManagement tgt = target.getIssueManagement();
|
||||
if ( tgt == null )
|
||||
{
|
||||
target.setIssueManagement( tgt = new IssueManagement() );
|
||||
mergeIssueManagement( tgt, src, sourceDominant, context );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mergeModel_CiManagement( Model target, Model source, boolean sourceDominant,
|
||||
Map<Object, Object> context )
|
||||
{
|
||||
CiManagement src = source.getCiManagement();
|
||||
if ( source.getCiManagement() != null )
|
||||
{
|
||||
CiManagement tgt = target.getCiManagement();
|
||||
if ( tgt == null )
|
||||
{
|
||||
target.setCiManagement( tgt = new CiManagement() );
|
||||
mergeCiManagement( tgt, src, sourceDominant, context );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mergeModelBase_Modules( ModelBase target, ModelBase source, boolean sourceDominant,
|
||||
Map<Object, Object> context )
|
||||
|
@ -180,6 +240,56 @@ public class MavenModelMerger
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mergeDistributionManagement_Repository( DistributionManagement target,
|
||||
DistributionManagement source, boolean sourceDominant,
|
||||
Map<Object, Object> context )
|
||||
{
|
||||
DeploymentRepository src = source.getRepository();
|
||||
if ( src != null )
|
||||
{
|
||||
DeploymentRepository tgt = target.getRepository();
|
||||
if ( tgt == null )
|
||||
{
|
||||
target.setRepository( tgt = new DeploymentRepository() );
|
||||
mergeDeploymentRepository( tgt, src, sourceDominant, context );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mergeDistributionManagement_SnapshotRepository( DistributionManagement target,
|
||||
DistributionManagement source,
|
||||
boolean sourceDominant, Map<Object, Object> context )
|
||||
{
|
||||
DeploymentRepository src = source.getSnapshotRepository();
|
||||
if ( src != null )
|
||||
{
|
||||
DeploymentRepository tgt = target.getSnapshotRepository();
|
||||
if ( tgt == null )
|
||||
{
|
||||
target.setSnapshotRepository( tgt = new DeploymentRepository() );
|
||||
mergeDeploymentRepository( tgt, src, sourceDominant, context );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mergeDistributionManagement_Site( DistributionManagement target, DistributionManagement source,
|
||||
boolean sourceDominant, Map<Object, Object> context )
|
||||
{
|
||||
Site src = source.getSite();
|
||||
if ( src != null )
|
||||
{
|
||||
Site tgt = target.getSite();
|
||||
if ( tgt == null )
|
||||
{
|
||||
target.setSite( tgt = new Site() );
|
||||
mergeSite( tgt, src, sourceDominant, context );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mergeSite_Url( Site target, Site source, boolean sourceDominant, Map<Object, Object> context )
|
||||
{
|
||||
|
@ -289,6 +399,43 @@ public class MavenModelMerger
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mergeReporting_Plugins( Reporting target, Reporting source, boolean sourceDominant,
|
||||
Map<Object, Object> context )
|
||||
{
|
||||
List<ReportPlugin> src = source.getPlugins();
|
||||
if ( !src.isEmpty() )
|
||||
{
|
||||
List<ReportPlugin> tgt = target.getPlugins();
|
||||
Map<Object, ReportPlugin> merged =
|
||||
new LinkedHashMap<Object, ReportPlugin>( ( src.size() + tgt.size() ) * 2 );
|
||||
|
||||
for ( Iterator<ReportPlugin> it = tgt.iterator(); it.hasNext(); )
|
||||
{
|
||||
ReportPlugin element = it.next();
|
||||
Object key = getReportPluginKey( element );
|
||||
merged.put( key, element );
|
||||
}
|
||||
|
||||
for ( Iterator<ReportPlugin> it = src.iterator(); it.hasNext(); )
|
||||
{
|
||||
ReportPlugin element = it.next();
|
||||
Object key = getReportPluginKey( element );
|
||||
ReportPlugin existing = merged.get( key );
|
||||
if ( existing != null )
|
||||
{
|
||||
mergeReportPlugin( existing, element, sourceDominant, context );
|
||||
}
|
||||
else
|
||||
{
|
||||
merged.put( key, element );
|
||||
}
|
||||
}
|
||||
|
||||
target.setPlugins( new ArrayList<ReportPlugin>( merged.values() ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getDependencyKey( Dependency dependency )
|
||||
{
|
||||
|
@ -307,12 +454,30 @@ public class MavenModelMerger
|
|||
return object.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getReportPluginKey( ReportPlugin object )
|
||||
{
|
||||
return object.getKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getReportSetKey( ReportSet object )
|
||||
{
|
||||
return object.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getRepositoryBaseKey( RepositoryBase object )
|
||||
{
|
||||
return object.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getExtensionKey( Extension object )
|
||||
{
|
||||
return object.getGroupId() + ':' + object.getArtifactId();
|
||||
}
|
||||
|
||||
private String appendPath( String parentPath, String childPath, String pathAdjustment )
|
||||
{
|
||||
String uncleanPath = parentPath;
|
||||
|
|
|
@ -58,6 +58,7 @@ import org.apache.maven.model.Prerequisites;
|
|||
import org.apache.maven.model.Profile;
|
||||
import org.apache.maven.model.Relocation;
|
||||
import org.apache.maven.model.ReportPlugin;
|
||||
import org.apache.maven.model.ReportSet;
|
||||
import org.apache.maven.model.Reporting;
|
||||
import org.apache.maven.model.Repository;
|
||||
import org.apache.maven.model.RepositoryBase;
|
||||
|
@ -1097,6 +1098,118 @@ public class ModelMerger
|
|||
}
|
||||
}
|
||||
|
||||
protected void mergeReportPlugin( ReportPlugin target, ReportPlugin source, boolean sourceDominant,
|
||||
Map<Object, Object> context )
|
||||
{
|
||||
mergeReportPlugin_Inherited( target, source, sourceDominant, context );
|
||||
mergeReportPlugin_Configuration( target, source, sourceDominant, context );
|
||||
mergeReportPlugin_GroupId( target, source, sourceDominant, context );
|
||||
mergeReportPlugin_ArtifactId( target, source, sourceDominant, context );
|
||||
mergeReportPlugin_Version( target, source, sourceDominant, context );
|
||||
mergeReportPlugin_ReportSets( target, source, sourceDominant, context );
|
||||
}
|
||||
|
||||
protected void mergeReportPlugin_GroupId( ReportPlugin target, ReportPlugin source, boolean sourceDominant,
|
||||
Map<Object, Object> context )
|
||||
{
|
||||
String src = source.getGroupId();
|
||||
if ( src != null )
|
||||
{
|
||||
if ( sourceDominant || target.getGroupId() == null )
|
||||
{
|
||||
target.setGroupId( src );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void mergeReportPlugin_ArtifactId( ReportPlugin target, ReportPlugin source, boolean sourceDominant,
|
||||
Map<Object, Object> context )
|
||||
{
|
||||
String src = source.getArtifactId();
|
||||
if ( src != null )
|
||||
{
|
||||
if ( sourceDominant || target.getArtifactId() == null )
|
||||
{
|
||||
target.setArtifactId( src );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void mergeReportPlugin_Version( ReportPlugin target, ReportPlugin source, boolean sourceDominant,
|
||||
Map<Object, Object> context )
|
||||
{
|
||||
String src = source.getVersion();
|
||||
if ( src != null )
|
||||
{
|
||||
if ( sourceDominant || target.getVersion() == null )
|
||||
{
|
||||
target.setVersion( src );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void mergeReportPlugin_Inherited( ReportPlugin target, ReportPlugin source, boolean sourceDominant,
|
||||
Map<Object, Object> context )
|
||||
{
|
||||
String src = source.getInherited();
|
||||
if ( src != null )
|
||||
{
|
||||
if ( sourceDominant || target.getInherited() == null )
|
||||
{
|
||||
target.setInherited( src );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void mergeReportPlugin_Configuration( ReportPlugin target, ReportPlugin source, boolean sourceDominant,
|
||||
Map<Object, Object> context )
|
||||
{
|
||||
Xpp3Dom src = (Xpp3Dom) source.getConfiguration();
|
||||
if ( src != null )
|
||||
{
|
||||
Xpp3Dom tgt = (Xpp3Dom) target.getConfiguration();
|
||||
if ( sourceDominant || tgt == null )
|
||||
{
|
||||
tgt = Xpp3Dom.mergeXpp3Dom( new Xpp3Dom( src ), tgt );
|
||||
}
|
||||
else
|
||||
{
|
||||
tgt = Xpp3Dom.mergeXpp3Dom( tgt, src );
|
||||
}
|
||||
target.setConfiguration( tgt );
|
||||
}
|
||||
}
|
||||
|
||||
protected void mergeReportPlugin_ReportSets( ReportPlugin target, ReportPlugin source, boolean sourceDominant,
|
||||
Map<Object, Object> context )
|
||||
{
|
||||
List<ReportSet> src = source.getReportSets();
|
||||
if ( !src.isEmpty() )
|
||||
{
|
||||
List<ReportSet> tgt = target.getReportSets();
|
||||
Map<Object, ReportSet> merged = new LinkedHashMap<Object, ReportSet>( ( src.size() + tgt.size() ) * 2 );
|
||||
|
||||
for ( Iterator<ReportSet> it = tgt.iterator(); it.hasNext(); )
|
||||
{
|
||||
ReportSet element = it.next();
|
||||
Object key = getReportSetKey( element );
|
||||
merged.put( key, element );
|
||||
}
|
||||
|
||||
for ( Iterator<ReportSet> it = src.iterator(); it.hasNext(); )
|
||||
{
|
||||
ReportSet element = it.next();
|
||||
Object key = getReportSetKey( element );
|
||||
if ( sourceDominant || !merged.containsKey( key ) )
|
||||
{
|
||||
merged.put( key, element );
|
||||
}
|
||||
}
|
||||
|
||||
target.setReportSets( new ArrayList<ReportSet>( merged.values() ) );
|
||||
}
|
||||
}
|
||||
|
||||
protected void mergeDependencyManagement( DependencyManagement target, DependencyManagement source,
|
||||
boolean sourceDominant, Map<Object, Object> context )
|
||||
{
|
||||
|
@ -2428,6 +2541,11 @@ public class ModelMerger
|
|||
return object;
|
||||
}
|
||||
|
||||
protected Object getReportSetKey( ReportSet object )
|
||||
{
|
||||
return object;
|
||||
}
|
||||
|
||||
protected Object getLicenseKey( License object )
|
||||
{
|
||||
return object;
|
||||
|
|
Loading…
Reference in New Issue