diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PluginExecutionIdModelContainerFactory.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PluginExecutionIdModelContainerFactory.java index 3a132ec50f..f330c06bc3 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PluginExecutionIdModelContainerFactory.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PluginExecutionIdModelContainerFactory.java @@ -10,7 +10,8 @@ import java.util.*; public class PluginExecutionIdModelContainerFactory implements ModelContainerFactory { private static final Collection uris = Collections.unmodifiableList(Arrays.asList( - ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri)); + ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri, + ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.xUri)); public Collection getUris() { return uris; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java index b247226258..ce57834832 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java @@ -44,6 +44,7 @@ public class PomTransformer public static final Set URIS = Collections.unmodifiableSet(new HashSet( Arrays.asList( ProjectUri.Build.Extensions.xUri, ProjectUri.Build.PluginManagement.Plugins.xUri, ProjectUri.Build.PluginManagement.Plugins.Plugin.configuration, + //ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.xUri, ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.xUri, ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.Dependency.Exclusions.xUri, @@ -149,6 +150,7 @@ public class PomTransformer transformPluginManagement( managementContainer.getProperties() ) ); //Remove duplicate executions tags + boolean hasExecutionsTag = false; for ( ModelProperty mp : dependencyContainer.getProperties() ) { @@ -176,9 +178,71 @@ public class PomTransformer managementContainer = new ArtifactModelContainerFactory().create( pList ); ModelContainerAction action = dependencyContainer.containerAction( managementContainer ); + // System.out.println(action); if ( action.equals( ModelContainerAction.JOIN ) || action.equals( ModelContainerAction.DELETE ) ) - { - source.join( dependencyContainer, managementContainer ); + { //System.out.println("A:"); + ModelDataSource dependencyDatasource = new DefaultModelDataSource(); + dependencyDatasource.init( dependencyContainer.getProperties(), Arrays.asList( new ArtifactModelContainerFactory(), + new IdModelContainerFactory() ) ); + + ModelDataSource managementDatasource = new DefaultModelDataSource(); + managementDatasource.init( managementContainer.getProperties(), Arrays.asList( new ArtifactModelContainerFactory(), + new IdModelContainerFactory() ) ); + + List managementExecutionContainers = managementDatasource.queryFor(ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri); + List managementPropertiesWithoutExecutions = new ArrayList(managementContainer.getProperties()); + for(ModelContainer a : managementExecutionContainers) + { + managementPropertiesWithoutExecutions.removeAll(a.getProperties()); + } + + source.join( dependencyContainer, new ArtifactModelContainerFactory().create(managementPropertiesWithoutExecutions) ); + + List dependencyExecutionContainers = dependencyDatasource.queryFor(ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri); + List joinedExecutionContainers = new ArrayList(); + //System.out.println(managementExecutionContainers.size()); + for(ModelContainer a : managementExecutionContainers) + { + for(ModelContainer b : dependencyExecutionContainers) + { + if(b.containerAction(a).equals(ModelContainerAction.JOIN)) + { + source.join(b, a); + joinedExecutionContainers.add(a); + } + } + } + + ModelProperty executionsProperty = null; + for(ModelProperty a : dependencyContainer.getProperties()) + { + if(a.getUri().equals(ProjectUri.Build.Plugins.Plugin.Executions.xUri)) { + executionsProperty = a; + break; + } + } + + if(executionsProperty == null) + { + for(ModelProperty a : managementPropertiesWithoutExecutions) + { + if(a.getUri().equals(ProjectUri.Build.Plugins.Plugin.Executions.xUri)) { + executionsProperty = a; + break; + } + } + } + + if(executionsProperty != null) + { + managementExecutionContainers.removeAll(joinedExecutionContainers); + Collections.reverse(managementExecutionContainers); + for(ModelContainer a : managementExecutionContainers) + { + source.insertModelPropertiesAfter(executionsProperty, + ModelTransformerContext.sort(a.getProperties(), ProjectUri.Build.Plugins.Plugin.Executions.xUri)); + } + } } } } diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java b/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java index 6870d7bf09..ad5b99c70c 100644 --- a/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java +++ b/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java @@ -40,6 +40,8 @@ import java.io.InputStream; import java.io.Writer; import java.util.List; import java.util.ArrayList; +import java.util.Set; +import java.util.HashSet; /** * Provides a wrapper for the maven model. @@ -283,8 +285,13 @@ public final class PomClassicDomainModel { if(modelProperties == null) { + Set s = new HashSet(); + //TODO: Should add all collections from ProjectUri + s.addAll(PomTransformer.URIS); + s.add(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.xUri); + s.add(ProjectUri.Build.Plugins.Plugin.Executions.xUri); modelProperties = ModelMarshaller.marshallXmlToModelProperties( - getInputStream(), ProjectUri.baseUri, PomTransformer.URIS ); + getInputStream(), ProjectUri.baseUri, s ); } return new ArrayList(modelProperties); }