From 09ebb0f6157c7db0ec4a37b6a87b90c903f63d1d Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Mon, 8 Aug 2005 23:06:48 +0000 Subject: [PATCH] Resolving: MNG-163 Use MavenProject.addResource(..) and .addTestResource(..) to perform this function. I've built a BuildOverlay to insulate the interpolated, initialized Model's Build instance from runtime changes to these, in a similar fashion to addCompileSourceRoots(..), because I wanted to preserve some compat with plugins using ${project.build.resources}. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@230920 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/plugin/resources/ResourcesMojo.java | 2 +- .../plugin/resources/TestResourcesMojo.java | 2 +- .../apache/maven/project/MavenProject.java | 35 ++- .../maven/project/overlay/BuildOverlay.java | 237 ++++++++++++++++++ 4 files changed, 272 insertions(+), 4 deletions(-) create mode 100644 maven-project/src/main/java/org/apache/maven/project/overlay/BuildOverlay.java diff --git a/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java b/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java index 379409e862..83229d1c07 100644 --- a/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java +++ b/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java @@ -62,7 +62,7 @@ public class ResourcesMojo /** * The list of resources we want to transfer. * - * @parameter expression="${project.build.resources}" + * @parameter expression="${project.resources}" * @required */ private List resources; diff --git a/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/TestResourcesMojo.java b/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/TestResourcesMojo.java index bd9337e45e..bd2f8845aa 100644 --- a/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/TestResourcesMojo.java +++ b/maven-plugins/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/TestResourcesMojo.java @@ -42,7 +42,7 @@ public class TestResourcesMojo /** * The list of resources we want to transfer. * - * @parameter expression="${project.build.testResources}" + * @parameter expression="${project.testResources}" * @required */ private List resources; diff --git a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java index cd8fd05200..0b32a2dabc 100644 --- a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java @@ -43,9 +43,11 @@ import org.apache.maven.model.Prerequesites; import org.apache.maven.model.ReportPlugin; import org.apache.maven.model.ReportSet; import org.apache.maven.model.Reporting; +import org.apache.maven.model.Resource; import org.apache.maven.model.Scm; import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.apache.maven.project.artifact.MavenMetadataSource; +import org.apache.maven.project.overlay.BuildOverlay; import org.codehaus.plexus.util.xml.Xpp3Dom; import java.io.File; @@ -132,6 +134,8 @@ public class MavenProject private Map projectReferences = new HashMap(); + private Build buildOverlay; + public MavenProject( Model model ) { this.model = model; @@ -798,12 +802,39 @@ public class MavenProject public void setBuild( Build build ) { + this.buildOverlay = new BuildOverlay( build ); + model.setBuild( build ); } public Build getBuild() { - return model.getBuild(); + if ( buildOverlay == null ) + { + buildOverlay = new BuildOverlay( model.getBuild() ); + } + + return buildOverlay; + } + + public List getResources() + { + return getBuild().getResources(); + } + + public List getTestResources() + { + return getBuild().getTestResources(); + } + + public void addResource( Resource resource ) + { + getBuild().addResource( resource ); + } + + public void addTestResource( Resource testResource ) + { + getBuild().addTestResource( testResource ); } public void setReporting( Reporting reporting ) @@ -1273,5 +1304,5 @@ public class MavenProject { return groupId + ":" + artifactId; } - + } diff --git a/maven-project/src/main/java/org/apache/maven/project/overlay/BuildOverlay.java b/maven-project/src/main/java/org/apache/maven/project/overlay/BuildOverlay.java new file mode 100644 index 0000000000..14bdc1b05e --- /dev/null +++ b/maven-project/src/main/java/org/apache/maven/project/overlay/BuildOverlay.java @@ -0,0 +1,237 @@ +package org.apache.maven.project.overlay; + +import org.apache.maven.model.Build; +import org.apache.maven.model.Extension; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginManagement; +import org.apache.maven.model.Resource; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class BuildOverlay + extends Build +{ + + private final Build build; + + private List resources; + private List testResources; + + public BuildOverlay( Build build ) + { + if ( build == null ) + { + this.build = new Build(); + + this.resources = new ArrayList(); + + this.testResources = new ArrayList(); + } + else + { + this.build = build; + + this.resources = new ArrayList( build.getResources() ); + + this.testResources = new ArrayList( build.getTestResources() ); + } + } + + public void addExtension( Extension extension ) + { + build.addExtension( extension ); + } + + public void addPlugin( Plugin plugin ) + { + build.addPlugin( plugin ); + } + + public void addResource( Resource resource ) + { + resources.add( resource ); + } + + public void addTestResource( Resource resource ) + { + testResources.add( resource ); + } + + public boolean equals( Object obj ) + { + return build.equals( obj ); + } + + public void flushPluginMap() + { + build.flushPluginMap(); + } + + public String getDefaultGoal() + { + return build.getDefaultGoal(); + } + + public String getDirectory() + { + return build.getDirectory(); + } + + public List getExtensions() + { + return build.getExtensions(); + } + + public String getFinalName() + { + return build.getFinalName(); + } + + public String getOutputDirectory() + { + return build.getOutputDirectory(); + } + + public PluginManagement getPluginManagement() + { + return build.getPluginManagement(); + } + + public List getPlugins() + { + return build.getPlugins(); + } + + public Map getPluginsAsMap() + { + return build.getPluginsAsMap(); + } + + public List getResources() + { + return resources; + } + + public String getScriptSourceDirectory() + { + return build.getScriptSourceDirectory(); + } + + public String getSourceDirectory() + { + return build.getSourceDirectory(); + } + + public String getTestOutputDirectory() + { + return build.getTestOutputDirectory(); + } + + public List getTestResources() + { + return testResources; + } + + public String getTestSourceDirectory() + { + return build.getTestSourceDirectory(); + } + + public int hashCode() + { + return build.hashCode(); + } + + public void removeExtension( Extension extension ) + { + build.removeExtension( extension ); + } + + public void removePlugin( Plugin plugin ) + { + build.removePlugin( plugin ); + } + + public void removeResource( Resource resource ) + { + resources.remove( resource ); + } + + public void removeTestResource( Resource resource ) + { + testResources.remove( resource ); + } + + public void setDefaultGoal( String defaultGoal ) + { + build.setDefaultGoal( defaultGoal ); + } + + public void setDirectory( String directory ) + { + build.setDirectory( directory ); + } + + public void setExtensions( List extensions ) + { + build.setExtensions( extensions ); + } + + public void setFinalName( String finalName ) + { + build.setFinalName( finalName ); + } + + public void setOutputDirectory( String outputDirectory ) + { + build.setOutputDirectory( outputDirectory ); + } + + public void setPluginManagement( PluginManagement pluginManagement ) + { + build.setPluginManagement( pluginManagement ); + } + + public void setPlugins( List plugins ) + { + build.setPlugins( plugins ); + } + + public void setResources( List resources ) + { + this.resources = resources; + } + + public void setScriptSourceDirectory( String scriptSourceDirectory ) + { + build.setScriptSourceDirectory( scriptSourceDirectory ); + } + + public void setSourceDirectory( String sourceDirectory ) + { + build.setSourceDirectory( sourceDirectory ); + } + + public void setTestOutputDirectory( String testOutputDirectory ) + { + build.setTestOutputDirectory( testOutputDirectory ); + } + + public void setTestResources( List testResources ) + { + this.testResources = testResources; + } + + public void setTestSourceDirectory( String testSourceDirectory ) + { + build.setTestSourceDirectory( testSourceDirectory ); + } + + public String toString() + { + return build.toString(); + } + +}