From 3d85fa7874e2a7ce281d3b2bb7f3b2dec68fff69 Mon Sep 17 00:00:00 2001 From: Britton Isbell Date: Wed, 5 Nov 2008 23:42:32 +0000 Subject: [PATCH] Fix for IT 2695. Two plugins with different executions that had same id were merging. Created a different container for execution ids, so that they can be queried per plugin, rather than globally. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@711743 13f79535-47bb-0310-9956-ffa450edef68 --- .../builder/IdModelContainerFactory.java | 3 +- ...luginExecutionIdModelContainerFactory.java | 84 +++++++++++++++++++ .../builder/PomClassicTransformer.java | 6 +- 3 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 maven-project/src/main/java/org/apache/maven/project/builder/PluginExecutionIdModelContainerFactory.java 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 )