diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/IdModelContainerFactory.java b/maven-project/src/main/java/org/apache/maven/project/builder/IdModelContainerFactory.java index 054df8ee04..b04821270b 100644 --- a/maven-project/src/main/java/org/apache/maven/project/builder/IdModelContainerFactory.java +++ b/maven-project/src/main/java/org/apache/maven/project/builder/IdModelContainerFactory.java @@ -36,8 +36,7 @@ public class IdModelContainerFactory private static final Collection uris = Collections.unmodifiableList( Arrays.asList( ProjectUri.PluginRepositories.PluginRepository.xUri, ProjectUri.Repositories.Repository.xUri, - ProjectUri.Reporting.Plugins.Plugin.ReportSets.ReportSet.xUri, ProjectUri.Profiles.Profile.xUri, - ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri ) ); + ProjectUri.Reporting.Plugins.Plugin.ReportSets.ReportSet.xUri, ProjectUri.Profiles.Profile.xUri) ); public Collection getUris() { diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/PluginExecutionIdModelContainerFactory.java b/maven-project/src/main/java/org/apache/maven/project/builder/PluginExecutionIdModelContainerFactory.java new file mode 100644 index 0000000000..3a132ec50f --- /dev/null +++ b/maven-project/src/main/java/org/apache/maven/project/builder/PluginExecutionIdModelContainerFactory.java @@ -0,0 +1,84 @@ +package org.apache.maven.project.builder; + +import org.apache.maven.shared.model.ModelContainerFactory; +import org.apache.maven.shared.model.ModelContainer; +import org.apache.maven.shared.model.ModelProperty; +import org.apache.maven.shared.model.ModelContainerAction; + +import java.util.*; + +public class PluginExecutionIdModelContainerFactory implements ModelContainerFactory { + + private static final Collection uris = Collections.unmodifiableList(Arrays.asList( + ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri)); + + public Collection getUris() { + return uris; + } + + public ModelContainer create(List modelProperties) { + if ( modelProperties == null || modelProperties.size() == 0 ) + { + throw new IllegalArgumentException( "modelProperties: null or empty" ); + } + return new PluginExecutionIdModelContainer( modelProperties ); + } + + private static class PluginExecutionIdModelContainer + implements ModelContainer + { + + private String id; + + private List properties; + + private PluginExecutionIdModelContainer( List properties ) + { + this.properties = new ArrayList( properties ); + this.properties = Collections.unmodifiableList( this.properties ); + + for ( ModelProperty mp : properties ) + { + if ( mp.getUri().endsWith( "/id" ) ) + { + this.id = mp.getResolvedValue(); + } + } + } + + public ModelContainerAction containerAction( ModelContainer modelContainer ) + { + if ( modelContainer == null ) + { + throw new IllegalArgumentException( "modelContainer: null" ); + } + + if ( !( modelContainer instanceof PluginExecutionIdModelContainer ) ) + { + throw new IllegalArgumentException( "modelContainer: wrong type" ); + } + + PluginExecutionIdModelContainer c = (PluginExecutionIdModelContainer) modelContainer; + if ( c.id == null || id == null ) + { + return ModelContainerAction.NOP; + } + return ( c.id.equals( id ) ) ? ModelContainerAction.JOIN : ModelContainerAction.NOP; + } + + public ModelContainer createNewInstance( List modelProperties ) + { + return new PluginExecutionIdModelContainer( modelProperties ); + } + + public List getProperties() + { + return properties; + } + + public String toString() + { + return "ID = " + id; + } + } +} diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java b/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java index 59c3b40dc4..cbf4f465b6 100644 --- a/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java +++ b/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java @@ -46,14 +46,12 @@ public final class PomClassicTransformer ProjectUri.Build.PluginManagement.Plugins.Plugin.configuration, ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.xUri, ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.Dependency.Exclusions.xUri, - ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.xUri, ProjectUri.Build.Plugins.xUri, ProjectUri.Build.Plugins.Plugin.configuration, ProjectUri.Reporting.Plugins.xUri, ProjectUri.Reporting.Plugins.Plugin.configuration, ProjectUri.Build.Plugins.Plugin.Dependencies.xUri, - ProjectUri.Build.Plugins.Plugin.Executions.xUri, ProjectUri.Build.Resources.xUri, ProjectUri.Build.Resources.Resource.includes, ProjectUri.Build.Resources.Resource.excludes, @@ -202,7 +200,7 @@ public final class PomClassicTransformer { ModelDataSource executionSource = new DefaultModelDataSource(); executionSource.init( pluginContainer.getProperties(), - Arrays.asList( new ArtifactModelContainerFactory(), new IdModelContainerFactory() ) ); + Arrays.asList( new ArtifactModelContainerFactory(), new PluginExecutionIdModelContainerFactory() ) ); List executionContainers = executionSource.queryFor( ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri ); if ( executionContainers.size() < 2 ) @@ -318,7 +316,7 @@ public final class PomClassicTransformer { List removeProperties = new ArrayList(); ModelDataSource source = new DefaultModelDataSource(); - source.init( tmp, Arrays.asList( new ArtifactModelContainerFactory(), new IdModelContainerFactory() ) ); + source.init( tmp, Arrays.asList( new ArtifactModelContainerFactory(), new PluginExecutionIdModelContainerFactory() ) ); List containers = source.queryFor( ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri ); for ( ModelContainer container : containers )