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 new file mode 100644 index 0000000000..9a1d58bf40 --- /dev/null +++ b/maven-project-builder/src/test/java/org/apache/maven/project/builder/PluginSpecTest.java @@ -0,0 +1,90 @@ +package org.apache.maven.project.builder; + +import static org.junit.Assert.*; +import org.apache.maven.shared.model.*; +import org.apache.maven.shared.model.impl.DefaultModelDataSource; + +import java.util.List; +import java.util.ArrayList; +import java.util.Arrays; +import java.io.IOException; + +public class PluginSpecTest { + + @org.junit.Test + public void goalsInherited() throws IOException { + + List mp0 = new ArrayList(); + mp0.add(new ModelProperty(ProjectUri.xUri, null)); + mp0.add(new ModelProperty(ProjectUri.Build.xUri, null)); + mp0.add(new ModelProperty(ProjectUri.Build.PluginManagement.xUri, null)); + mp0.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.xUri, null)); + mp0.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.xUri, null)); + mp0.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.groupId, "org.codehaus.modello")); + mp0.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.artifactId, "modello-maven-plugin")); + mp0.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.version, "v1")); + + List mp = new ArrayList(); + mp.add(new ModelProperty(ProjectUri.xUri, null)); + mp.add(new ModelProperty(ProjectUri.Build.xUri, null)); + mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.xUri, null)); + mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.xUri, null)); + mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.xUri, null)); + mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.groupId, "org.codehaus.modello")); + mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.artifactId, "modello-maven-plugin")); + mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.version, "v1")); + + mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.xUri, null)); + mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.xUri, null)); + mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.id, "site-docs")); + mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.phase, "phase")); + mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.xURI, null)); + mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.goal, "xdoc")); + mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.goal, "xsd")); + + mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.xUri, null)); + mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.id, "standard")); + mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.xURI, null)); + mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.goal, "xpp3-reader")); + mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.goal, "xpp3-writer")); + + DomainModel parentModel = new DefaultDomainModel(mp); + + ModelTransformerContext ctx = new ModelTransformerContext(Arrays.asList(new ArtifactModelContainerFactory(), + new IdModelContainerFactory())); + + ModelTransformer transformer = new PomTransformer(new DefaultDomainModelFactory()); + DomainModel domainModel = ctx.transform( Arrays.asList(parentModel, new DefaultDomainModel(mp0)), transformer, transformer ); + + DefaultModelDataSource source = new DefaultModelDataSource(); + source.init(domainModel.getModelProperties(), Arrays.asList(new ArtifactModelContainerFactory(), + new IdModelContainerFactory(), new PluginExecutionIdModelContainerFactory())); + List containers = source.queryFor(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.xUri); + assertTrue(2 == containers.size()); + + int numberOfGoals = 0; + for(ModelProperty x : containers.get(0).getProperties()) + { + if(x.getUri().equals(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.goal)) + { + numberOfGoals++; + } + } + assertTrue(numberOfGoals == 2); + + numberOfGoals = 0; + for(ModelProperty x : containers.get(1).getProperties()) + { + if(x.getUri().equals(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.goal)) + { + numberOfGoals++; + } + } + assertTrue(numberOfGoals == 2); + + // System.out.println(ModelMarshaller.unmarshalModelPropertiesToXml(domainModel.getModelProperties(), ProjectUri.baseUri)); + + + } + +}