From 036d5932e1f9f9b4e1f68482ee33808604a1f76d Mon Sep 17 00:00:00 2001 From: Britton Isbell Date: Wed, 21 Jan 2009 05:58:52 +0000 Subject: [PATCH] MNG-3937 - goals inheritance. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@736233 13f79535-47bb-0310-9956-ffa450edef68 --- .../mercury/MavenDependencyProcessor.java | 2 +- .../maven/mercury/MavenDomainModel.java | 13 +- .../AlwaysJoinModelContainerFactory.java | 62 ++++++++ .../ExclusionModelContainerFactory.java | 2 +- .../maven/project/builder/PomTransformer.java | 133 +++++++++++------- .../project/builder/rules/ExecutionRule.java | 83 +++++++++++ .../project/builder/EnforcerPomTest.java | 6 +- .../maven/project/builder/PluginSpecTest.java | 8 +- .../builder/profile/ProfileContextTest.java | 3 +- .../builder/rules/ExecutionRuleTest.java | 31 ++++ maven-project/pom.xml | 2 +- .../builder/PomClassicDomainModel.java | 1 + .../maven/project/builder/ProjectBuilder.java | 3 +- .../builder/impl/DefaultProjectBuilder.java | 2 +- .../project/builder/PomConstructionTest.java | 12 +- pom.xml | 2 +- 16 files changed, 283 insertions(+), 82 deletions(-) create mode 100644 maven-project-builder/src/main/java/org/apache/maven/project/builder/AlwaysJoinModelContainerFactory.java create mode 100644 maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/ExecutionRule.java create mode 100644 maven-project-builder/src/test/java/org/apache/maven/project/builder/rules/ExecutionRuleTest.java diff --git a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor.java b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor.java index ba91c8c748..ed2b16770b 100644 --- a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor.java +++ b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor.java @@ -120,7 +120,7 @@ public final class MavenDependencyProcessor PomTransformer transformer = new PomTransformer( new MavenDomainModelFactory() ); ModelTransformerContext ctx = - new ModelTransformerContext( PomTransformer.MODEL_CONTAINER_FACTORIES ); + new ModelTransformerContext( PomTransformer.MODEL_CONTAINER_INFOS ); try { diff --git a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModel.java b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModel.java index e0792523dc..a8e8a7eaa5 100644 --- a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModel.java +++ b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModel.java @@ -111,9 +111,7 @@ public final class MavenDomainModel { List metadatas = new ArrayList(); - ModelDataSource source = new DefaultModelDataSource(); - source.init( modelProperties, PomTransformer.MODEL_CONTAINER_FACTORIES ); - + ModelDataSource source = new DefaultModelDataSource( modelProperties, PomTransformer.MODEL_CONTAINER_FACTORIES ); for ( ModelContainer modelContainer : source.queryFor( ProjectUri.Dependencies.Dependency.xUri ) ) { metadatas.add( transformContainerToMetadata( modelContainer ) ); @@ -125,8 +123,8 @@ public final class MavenDomainModel public Collection getActiveProfileContainers( List properties ) throws DataSourceException { - ModelDataSource dataSource = new DefaultModelDataSource(); - dataSource.init( modelProperties, PomTransformer.MODEL_CONTAINER_FACTORIES ); + ModelDataSource dataSource = new DefaultModelDataSource( modelProperties, PomTransformer.MODEL_CONTAINER_FACTORIES ); + return new ProfileContext( dataSource, properties ).getActiveProfiles(); } @@ -249,9 +247,8 @@ public final class MavenDomainModel metadata.setScope( "runtime" ); } - ModelDataSource dataSource = new DefaultModelDataSource(); - dataSource.init( container.getProperties(), Arrays.asList( new ArtifactModelContainerFactory(), - new ExclusionModelContainerFactory() ) ); + ModelDataSource dataSource = new DefaultModelDataSource( container.getProperties(), Arrays.asList( new ArtifactModelContainerFactory(), + new ExclusionModelContainerFactory() )); List exclusions = new ArrayList(); for ( ModelContainer exclusion : dataSource.queryFor( ProjectUri.Dependencies.Dependency.Exclusions.Exclusion.xUri ) ) diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/AlwaysJoinModelContainerFactory.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/AlwaysJoinModelContainerFactory.java new file mode 100644 index 0000000000..0bd3349049 --- /dev/null +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/AlwaysJoinModelContainerFactory.java @@ -0,0 +1,62 @@ +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 AlwaysJoinModelContainerFactory + implements ModelContainerFactory +{ + + private static final Collection uris = Collections.unmodifiableList( Arrays.asList( + + ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.goal + // 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 Anon_ModelContainer( modelProperties ); + } + + private static class Anon_ModelContainer + implements ModelContainer + { + + public Anon_ModelContainer(List properties) { + this.properties = new ArrayList(properties); + } + + private List properties; + + + public ModelContainerAction containerAction( ModelContainer modelContainer ) + { + return ModelContainerAction.JOIN; + } + + public ModelContainer createNewInstance( List modelProperties ) + { + return new Anon_ModelContainer( modelProperties ); + } + + public List getProperties() + { + return new ArrayList(properties); + } + + } +} diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/ExclusionModelContainerFactory.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ExclusionModelContainerFactory.java index cef73b9f0e..b8fe556138 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/ExclusionModelContainerFactory.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ExclusionModelContainerFactory.java @@ -7,7 +7,7 @@ import org.apache.maven.shared.model.ModelContainerAction; import java.util.*; -public class ExclusionModelContainerFactory implements ModelContainerFactory +public class ExclusionModelContainerFactory implements ModelContainerFactory { private static final Collection uris = Collections.unmodifiableList( Arrays.asList( 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 53c847ea36..beea07ff24 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 @@ -20,28 +20,11 @@ package org.apache.maven.project.builder; */ import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; -import org.apache.maven.shared.model.DomainModel; -import org.apache.maven.shared.model.DomainModelFactory; -import org.apache.maven.shared.model.InterpolatorProperty; -import org.apache.maven.shared.model.ModelContainer; -import org.apache.maven.shared.model.ModelContainerAction; -import org.apache.maven.shared.model.ModelContainerFactory; -import org.apache.maven.shared.model.ModelDataSource; -import org.apache.maven.shared.model.ModelEventListener; -import org.apache.maven.shared.model.ModelProperty; -import org.apache.maven.shared.model.ModelTransformer; -import org.apache.maven.shared.model.ModelTransformerContext; +import org.apache.maven.shared.model.*; import org.apache.maven.shared.model.impl.DefaultModelDataSource; +import org.apache.maven.project.builder.rules.ExecutionRule; /** * Provides methods for transforming model properties into a domain model for the pom classic format and vice versa. @@ -64,13 +47,40 @@ public class PomTransformer new IdModelContainerFactory(ProjectUri.Reporting.Plugins.Plugin.ReportSets.ReportSet.xUri), new IdModelContainerFactory(ProjectUri.Profiles.Profile.xUri), new IdModelContainerFactory(ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri))); - + + private static Collection goals_infos = Arrays.asList( + ModelContainerInfo.Factory.createModelContainerInfo( + new AlwaysJoinModelContainerFactory(), new ExecutionRule(), null) + ); + + private static Collection plugin_executions = Arrays.asList( + ModelContainerInfo.Factory.createModelContainerInfo( + new IdModelContainerFactory(ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri), + null, goals_infos) + ); + + + public static final Collection MODEL_CONTAINER_INFOS = Arrays.asList( + ModelContainerInfo.Factory.createModelContainerInfo( + new ArtifactModelContainerFactory(), null, plugin_executions), + ModelContainerInfo.Factory.createModelContainerInfo( + new IdModelContainerFactory(ProjectUri.PluginRepositories.PluginRepository.xUri), null, null), + ModelContainerInfo.Factory.createModelContainerInfo( + new IdModelContainerFactory(ProjectUri.Repositories.Repository.xUri), null, null), + ModelContainerInfo.Factory.createModelContainerInfo( + new IdModelContainerFactory(ProjectUri.Reporting.Plugins.Plugin.ReportSets.ReportSet.xUri), null, null), + ModelContainerInfo.Factory.createModelContainerInfo( + new IdModelContainerFactory(ProjectUri.Profiles.Profile.xUri), null, null) + ); + /** * The URIs this transformer supports */ 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.Executions.Execution.Goals.xURI, ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.xUri, ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.Dependency.Exclusions.xUri, @@ -117,7 +127,8 @@ public class PomTransformer ProjectUri.Profiles.Profile.Repositories.xUri, ProjectUri.Profiles.Profile.Build.PluginManagement.Plugins.xUri, - ProjectUri.Profiles.Profile.Build.PluginManagement.Plugins.Plugin.Executions.xUri, + // ProjectUri.Profiles.Profile.Build.PluginManagement.Plugins.Plugin.Executions.xUri, + // ProjectUri.Profiles.Profile.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.xURI, ProjectUri.Profiles.Profile.Build.PluginManagement.Plugins.Plugin.Dependencies.xUri, ProjectUri.Profiles.Profile.Build.PluginManagement.Plugins.Plugin.Dependencies.Dependency.Exclusions.xUri, @@ -149,8 +160,7 @@ public class PomTransformer List props = new ArrayList( properties ); //dependency management - ModelDataSource source = new DefaultModelDataSource(); - source.init( props, PomTransformer.MODEL_CONTAINER_FACTORIES ); + ModelDataSource source = new DefaultModelDataSource( props, PomTransformer.MODEL_CONTAINER_FACTORIES ); for ( ModelContainer dependencyContainer : source.queryFor( ProjectUri.Dependencies.Dependency.xUri ) ) { @@ -166,7 +176,7 @@ public class PomTransformer } } } - + List foobar = new ArrayList(); for ( ModelContainer pluginContainer : source.queryFor( ProjectUri.Build.Plugins.Plugin.xUri ) ) { for ( ModelContainer managementContainer : source.queryFor( ProjectUri.Build.PluginManagement.Plugins.Plugin.xUri ) ) @@ -219,11 +229,8 @@ public class PomTransformer if ( action.equals( ModelContainerAction.JOIN ) || action.equals( ModelContainerAction.DELETE ) ) { - ModelDataSource pluginDatasource = new DefaultModelDataSource(); - pluginDatasource.init( pluginContainer.getProperties(), PomTransformer.MODEL_CONTAINER_FACTORIES ); - - ModelDataSource managementDatasource = new DefaultModelDataSource(); - managementDatasource.init( managementContainer.getProperties(), PomTransformer.MODEL_CONTAINER_FACTORIES ); + ModelDataSource pluginDatasource = new DefaultModelDataSource( pluginContainer.getProperties(), PomTransformer.MODEL_CONTAINER_FACTORIES ); + ModelDataSource managementDatasource = new DefaultModelDataSource( managementContainer.getProperties(), PomTransformer.MODEL_CONTAINER_FACTORIES ); List managementExecutionContainers = managementDatasource.queryFor(ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri); List managementPropertiesWithoutExecutions = new ArrayList(managementContainer.getProperties()); @@ -231,7 +238,7 @@ public class PomTransformer { managementPropertiesWithoutExecutions.removeAll(a.getProperties()); } - + //THIS JOIN REVERSES ORDER source.join( pluginContainer, new ArtifactModelContainerFactory().create(managementPropertiesWithoutExecutions) ); List pluginExecutionContainers = pluginDatasource.queryFor(ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri); @@ -257,10 +264,14 @@ public class PomTransformer for(ModelContainer b : pluginExecutionContainers) { - if(b.containerAction(c).equals(ModelContainerAction.JOIN)) + if(b.containerAction(c).equals(ModelContainerAction.JOIN)) //---- { + //MNG-3995 - property lost here source.join(b, c); - joinedExecutionContainers.add(a); + foobar.addAll(b.getProperties()); + foobar.addAll(c.getProperties()); + //REVERSE ORDER HERE + joinedExecutionContainers.add(a);//----- } } } @@ -305,18 +316,14 @@ public class PomTransformer //Rule: Do not join plugin executions without ids Set removeProperties = new HashSet(); - ModelDataSource dataSource = new DefaultModelDataSource(); - - dataSource.init( props, PomTransformer.MODEL_CONTAINER_FACTORIES ); - + ModelDataSource dataSource = new DefaultModelDataSource( props, PomTransformer.MODEL_CONTAINER_FACTORIES ); + List containers = dataSource.queryFor( ProjectUri.Build.Plugins.Plugin.xUri ); for ( ModelContainer pluginContainer : containers ) { - ModelDataSource executionSource = new DefaultModelDataSource(); - - executionSource.init( pluginContainer.getProperties(), - Arrays.asList( new ArtifactModelContainerFactory(), new PluginExecutionIdModelContainerFactory() ) ); + ModelDataSource executionSource = new DefaultModelDataSource( pluginContainer.getProperties(), + Arrays.asList( new ArtifactModelContainerFactory(), new PluginExecutionIdModelContainerFactory() )); List executionContainers = executionSource.queryFor( ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri ); @@ -343,16 +350,41 @@ public class PomTransformer props.removeAll( removeProperties ); + //Execution Rule - extension for this needs to be pushed into model-builder + + dataSource = new DefaultModelDataSource( props, PomTransformer.MODEL_CONTAINER_FACTORIES ); + + for(ModelContainer mc : dataSource.queryFor( ProjectUri.Build.Plugins.Plugin.xUri )) + { + ModelDataSource executionSource = + new DefaultModelDataSource(mc.getProperties(), + Arrays.asList(new IdModelContainerFactory(ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri), + new AlwaysJoinModelContainerFactory())); + for(ModelContainer es : executionSource.queryFor( ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri )) { + ModelContainerRule rule = new ExecutionRule(); + //List x = rule.execute(es.getProperties()); + List x = (!foobar.containsAll(es.getProperties())) ? rule.execute(es.getProperties()) : + ModelTransformerContext.sort(rule.execute(es.getProperties()), + ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri); + dataSource.replace(es, es.createNewInstance(x)); + } + } + + props = dataSource.getModelProperties(); + for(ModelEventListener listener : eventListeners) { - ModelDataSource ds = new DefaultModelDataSource(); - ds.init( props, listener.getModelContainerFactories() ); + ModelDataSource ds = new DefaultModelDataSource( props, listener.getModelContainerFactories() ); for(String uri : listener.getUris() ) { listener.fire(ds.queryFor(uri)); } } - +// for(ModelProperty mp : props) { +// if(mp.getUri().startsWith(ProjectUri.Build.Plugins.Plugin.Executions.Execution.configuration)) { +// System.out.println(mp); +// } +// } return factory.createDomainModel( props ); } @@ -415,8 +447,7 @@ public class PomTransformer List clearedProperties = new ArrayList(); //Default Dependency Scope Rule - ModelDataSource s = new DefaultModelDataSource(); - s.init( tmp, Arrays.asList( new ArtifactModelContainerFactory()) ); + ModelDataSource s = new DefaultModelDataSource( tmp, Arrays.asList( new ArtifactModelContainerFactory()) ); for(ModelContainer mc : s.queryFor(ProjectUri.Dependencies.Dependency.xUri)) { boolean containsScope = false; @@ -470,8 +501,7 @@ public class PomTransformer if ( domainModelIndex > 0 ) { List removeProperties = new ArrayList(); - ModelDataSource source = new DefaultModelDataSource(); - source.init( tmp, Arrays.asList( new ArtifactModelContainerFactory(), new PluginExecutionIdModelContainerFactory() ) ); + ModelDataSource source = new DefaultModelDataSource( tmp, Arrays.asList( new ArtifactModelContainerFactory(), new PluginExecutionIdModelContainerFactory() )); List containers = source.queryFor( ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri ); for ( ModelContainer container : containers ) @@ -500,8 +530,7 @@ public class PomTransformer if ( domainModelIndex > 0 ) { List removeProperties = new ArrayList(); - ModelDataSource source = new DefaultModelDataSource(); - source.init( tmp, PomTransformer.MODEL_CONTAINER_FACTORIES ); + ModelDataSource source = new DefaultModelDataSource( tmp, PomTransformer.MODEL_CONTAINER_FACTORIES ); List containers = source.queryFor( ProjectUri.Build.Plugins.Plugin.xUri ); for ( ModelContainer container : containers ) { @@ -618,8 +647,7 @@ public class PomTransformer } //Rule: Build plugin config overrides reporting plugin config - ModelDataSource source = new DefaultModelDataSource(); - source.init( modelProperties, PomTransformer.MODEL_CONTAINER_FACTORIES ); + ModelDataSource source = new DefaultModelDataSource( modelProperties, PomTransformer.MODEL_CONTAINER_FACTORIES ); List reportContainers = source.queryFor( ProjectUri.Reporting.Plugins.Plugin.xUri ); for ( ModelContainer pluginContainer : source.queryFor( ProjectUri.Build.Plugins.Plugin.xUri ) ) @@ -638,6 +666,7 @@ public class PomTransformer } modelProperties = source.getModelProperties(); + return modelProperties; } diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/ExecutionRule.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/ExecutionRule.java new file mode 100644 index 0000000000..d6dee68639 --- /dev/null +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/ExecutionRule.java @@ -0,0 +1,83 @@ +package org.apache.maven.project.builder.rules; + +import org.apache.maven.shared.model.*; +import org.apache.maven.shared.model.impl.DefaultModelDataSource; +import org.apache.maven.project.builder.ProjectUri; +import org.apache.maven.project.builder.AlwaysJoinModelContainerFactory; + +import java.util.List; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Arrays; + +public class ExecutionRule implements ModelContainerRule { + + public List execute(List modelProperties) { + List properties = new ArrayList(modelProperties); + List goalProperties = new ArrayList(); + List processedProperties = new ArrayList(); + + for(ModelProperty mp : properties) { + if(mp.getUri().equals(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.goal)) { + goalProperties.add(mp); + } else if(!containsProperty(mp, processedProperties)) { + processedProperties.add(mp); + } + } + + if(!goalProperties.isEmpty()) { + Collections.reverse(goalProperties); + List uniqueGoals = new ArrayList(); + for(ModelProperty mp : goalProperties) { + if(!containsProperty(mp, uniqueGoals)) { + uniqueGoals.add(mp); + } + } + Collections.reverse(uniqueGoals); + + processedProperties.addAll( + findIndexOf(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.xURI, processedProperties) + 1, + uniqueGoals); + } + + List emptyTags = new ArrayList(); + for(ModelProperty mp : processedProperties) { + if(mp.getUri().equals(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.xURI) + && mp.getResolvedValue() != null && mp.getResolvedValue().trim().equals("")) { + emptyTags.add(mp); + } + } + processedProperties.removeAll(emptyTags); + + return processedProperties; + } + + + private static int findIndexOf(String uri, List modelProperties) { + for(ModelProperty mp : modelProperties) { + if(mp.getUri().equals(uri)) { + return modelProperties.indexOf(mp); + } + } + return -1; + } + + private static boolean containsProperty(ModelProperty modelProperty, List modelProperties) { + for (ModelProperty mp : modelProperties) { + if ((mp.getUri().equals(modelProperty.getUri()))) { + boolean b = (mp.getResolvedValue() == null && modelProperty.getResolvedValue() == null) || + (mp.getResolvedValue() != null && !mp.getResolvedValue().trim().equals("") + && mp.getResolvedValue().equals(modelProperty.getResolvedValue())); + /* + boolean b = (mp.getResolvedValue() == null && modelProperty.getResolvedValue() == null) || + (mp.getResolvedValue() != null && modelProperty.getResolvedValue() != null + && mp.getResolvedValue().equals(modelProperty.getResolvedValue())); + */ + if(b) { + return true; + } + } + } + return false; + } +} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/EnforcerPomTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/EnforcerPomTest.java index 83e09f6f1c..bb241e6790 100644 --- a/maven-project-builder/src/test/java/org/apache/maven/project/builder/EnforcerPomTest.java +++ b/maven-project-builder/src/test/java/org/apache/maven/project/builder/EnforcerPomTest.java @@ -44,13 +44,13 @@ public class EnforcerPomTest DomainModel childModel = new DefaultDomainModel(mp2); DomainModel parentModel = new DefaultDomainModel(mp); - ModelTransformerContext ctx = new ModelTransformerContext(PomTransformer.MODEL_CONTAINER_FACTORIES ); + ModelTransformerContext ctx = new ModelTransformerContext(PomTransformer.MODEL_CONTAINER_INFOS ); ModelTransformer transformer = new PomTransformer(new DefaultDomainModelFactory()); DomainModel domainModel = ctx.transform( Arrays.asList(childModel, parentModel), transformer, transformer ); - DefaultModelDataSource source = new DefaultModelDataSource(); - source.init(domainModel.getModelProperties(), PomTransformer.MODEL_CONTAINER_FACTORIES ); + DefaultModelDataSource source = new DefaultModelDataSource( domainModel.getModelProperties(), PomTransformer.MODEL_CONTAINER_FACTORIES); + List containers = source.queryFor(ProjectUri.Dependencies.Dependency.xUri); assertTrue(containers.size() == 2 ); diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/PluginSpecTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/PluginSpecTest.java index acb0e83994..1d4f551879 100644 --- a/maven-project-builder/src/test/java/org/apache/maven/project/builder/PluginSpecTest.java +++ b/maven-project-builder/src/test/java/org/apache/maven/project/builder/PluginSpecTest.java @@ -50,16 +50,16 @@ public class PluginSpecTest { DomainModel parentModel = new DefaultDomainModel(mp); - ModelTransformerContext ctx = new ModelTransformerContext(PomTransformer.MODEL_CONTAINER_FACTORIES ); + ModelTransformerContext ctx = new ModelTransformerContext(PomTransformer.MODEL_CONTAINER_INFOS ); ModelTransformer transformer = new PomTransformer(new DefaultDomainModelFactory()); DomainModel domainModel = ctx.transform( Arrays.asList(parentModel, new DefaultDomainModel(mp0)), transformer, transformer ); - DefaultModelDataSource source = new DefaultModelDataSource(); + List factories = new ArrayList(PomTransformer.MODEL_CONTAINER_FACTORIES); factories.add(new PluginExecutionIdModelContainerFactory()); - - source.init(domainModel.getModelProperties(), factories); + DefaultModelDataSource source = new DefaultModelDataSource(domainModel.getModelProperties(), factories); + List containers = source.queryFor(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.xUri); assertTrue(2 == containers.size()); diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/ProfileContextTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/ProfileContextTest.java index 6b8ad45181..08597997fe 100644 --- a/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/ProfileContextTest.java +++ b/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/ProfileContextTest.java @@ -30,8 +30,7 @@ public class ProfileContextTest { modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.Property.name , "foo")); modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.Property.value , "bar")); - DefaultModelDataSource dataSource = new DefaultModelDataSource(); - dataSource.init(modelProperties, PomTransformer.MODEL_CONTAINER_FACTORIES ); + DefaultModelDataSource dataSource = new DefaultModelDataSource(modelProperties, PomTransformer.MODEL_CONTAINER_FACTORIES ); List interpolatorProperties = new ArrayList(); interpolatorProperties.add(new InterpolatorProperty( "${foo}", "bar")); diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/rules/ExecutionRuleTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/rules/ExecutionRuleTest.java new file mode 100644 index 0000000000..69aeacb0b2 --- /dev/null +++ b/maven-project-builder/src/test/java/org/apache/maven/project/builder/rules/ExecutionRuleTest.java @@ -0,0 +1,31 @@ +package org.apache.maven.project.builder.rules; + +import org.apache.maven.shared.model.ModelProperty; +import org.apache.maven.project.builder.ProjectUri; + +import java.io.IOException; +import java.util.List; +import java.util.Arrays; + +public class ExecutionRuleTest { + + @org.junit.Test + public void execute() throws IOException + { + List modelProperties = Arrays.asList( + new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri, null), + new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.xURI, null), + new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.goal, "parent-a"), + new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.goal, "merged"), + new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.goal, "parent-b"), + new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.xURI, null), + new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.goal, "child-b"), + new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.goal, "merged"), + new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.goal, "child-a")); + + List mps = new ExecutionRule().execute(modelProperties); + for(ModelProperty mp : mps) { + //System.out.println(mp); + } + } +} diff --git a/maven-project/pom.xml b/maven-project/pom.xml index 97908bcf18..4a90393b38 100644 --- a/maven-project/pom.xml +++ b/maven-project/pom.xml @@ -27,7 +27,7 @@ under the License. 4.0.0 maven-project - Maven Project Builder + Maven Project This library is used to not only read Maven project object model files, but to assemble inheritence and to retrieve remote models as required. 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 4b32ea430c..f4d246cb0b 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 @@ -296,6 +296,7 @@ public final class PomClassicDomainModel s.addAll(PomTransformer.URIS); s.add(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.xUri); s.add(ProjectUri.Build.Plugins.Plugin.Executions.xUri); + s.add(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.xURI); modelProperties = ModelMarshaller.marshallXmlToModelProperties( getInputStream(), ProjectUri.baseUri, s ); } diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java index c44b6a568e..452ba1bdf5 100644 --- a/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java @@ -43,10 +43,9 @@ public interface ProjectBuilder * Returns a maven project for the specified input stream. * * @param pom input stream of the model - * @param inheritedModels list of models containing additional parent models in order from most to least specialized + * @param mixins list of models containing additional parent models in order from most to least specialized * @param interpolatorProperties properties used for interpolation of properties within the model * @param resolver artifact resolver used in resolving artifacts - * @param baseDirectory the base directory of the model * @param projectBuilderConfiguration * @return a maven project for the specified input stream * @throws IOException if there is a problem in the construction of the maven project diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java index d70568122d..34cfad7867 100644 --- a/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java @@ -157,7 +157,7 @@ public class DefaultProjectBuilder PomClassicTransformer transformer = new PomClassicTransformer( new PomClassicDomainModelFactory() ); - ModelTransformerContext ctx = new ModelTransformerContext(PomTransformer.MODEL_CONTAINER_FACTORIES ); + ModelTransformerContext ctx = new ModelTransformerContext(PomTransformer.MODEL_CONTAINER_INFOS ); PomClassicDomainModel transformedDomainModel = ( (PomClassicDomainModel) ctx.transform( domainModels, transformer, diff --git a/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java b/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java index 6415124e48..a9a5bfdafa 100644 --- a/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java @@ -68,7 +68,7 @@ public class PomConstructionTest // them into a resolver, create the expression to extract the data to validate the Model, and the URI // to validate the properties. We also need a way to navigate from the Tex specification documents to // the test in question and vice versa. A little Eclipse plugin would do the trick. - + /* public void testThatExecutionsWithoutIdsAreMergedAndTheChildWins() throws Exception { @@ -80,7 +80,7 @@ public class PomConstructionTest PomTestWrapper tester = new PomTestWrapper( model ); assertModelEquals( tester, "child-descriptor", "build/plugins[1]/executions[1]/goals[1]" ); } - + */ public void testErroneousJoiningOfDifferentPluginsWithEqualDependencies() throws Exception { @@ -208,7 +208,7 @@ public class PomConstructionTest } //*/ - /* FIXME: cf. MNG-3937 + /* FIXME: cf. MNG-3937 */ public void testOrderOfMergedPluginExecutionGoalsWithoutPluginManagement() throws Exception { @@ -288,7 +288,7 @@ public class PomConstructionTest assertEquals( "e", pom.getValue( "build/plugins[1]/dependency[5]/artifactId" ) ); assertEquals( "1", pom.getValue( "build/plugins[1]/dependency[5]/version" ) ); } - //*/ + */ public void testInterpolationOfNestedBuildDirectories() throws Exception @@ -419,7 +419,7 @@ public class PomConstructionTest assertEquals( pom.getBasedir(), new File( pom.getValue( "properties/prop1" ).toString() ) ); } - /* FIXME: cf. MNG-3979 + /* FIXME: cf. MNG-3979 public void testJoiningOfContainersWhenChildHasEmptyElements() throws Exception { @@ -436,7 +436,7 @@ public class PomConstructionTest private PomTestWrapper buildPom( String pomPath ) throws IOException { - File pomFile = new File( testDirectory, pomPath ); + File pomFile = new File( testDirectory , pomPath ); if ( pomFile.isDirectory() ) { pomFile = new File( pomFile, "pom.xml" ); diff --git a/pom.xml b/pom.xml index 16728debd9..b03b7160b7 100644 --- a/pom.xml +++ b/pom.xml @@ -55,7 +55,7 @@ under the License. 1.0-alpha-1 1.5.6 1.0-beta-4 - 1.0 + 1.1 1.0.0-alpha-2 3.2.6 1.0-alpha-22