From 650437ad747362e229c12bda0c60aa8d9686ed4d Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 14 May 2012 20:26:18 +0000 Subject: [PATCH] improve test of requiresDependencyResolution git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1338386 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/it/annotation-with-inheritance/pom.xml | 16 ++++++++++++++++ .../apache/maven/plugin/coreit/FirstMojo.java | 18 +++++++++++++++--- .../annotation-with-inheritance/verify.groovy | 4 ++-- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml b/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml index c495163..d164b1c 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml @@ -45,6 +45,11 @@ under the License. maven-plugin-api 2.0 + + org.apache.maven + maven-artifact + 2.0 + org.apache.maven maven-project @@ -78,6 +83,17 @@ under the License. + + org.codehaus.plexus + plexus-utils + 3.0.1 + + + org.apache.commons + commons-exec + 1.1 + runtime + diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java index 2f143b3..4bd7d66 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java @@ -19,6 +19,7 @@ package org.apache.maven.plugin.coreit; * under the License. */ +import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.DependencyScope; @@ -27,13 +28,16 @@ import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; +import java.util.Set; + /** * Touches a test file. * * @since 1.2 * @deprecated Don't use! */ -@Mojo( name = "first", requiresDependencyResolution = DependencyScope.TEST, defaultPhase = LifecyclePhase.INTEGRATION_TEST ) +@Mojo( name = "first", requiresDependencyResolution = DependencyScope.COMPILE, + defaultPhase = LifecyclePhase.INTEGRATION_TEST ) @Execute( phase = LifecyclePhase.GENERATE_SOURCES, lifecycle = "cobertura" ) public class FirstMojo extends AbstractFirstMojo @@ -49,14 +53,17 @@ public class FirstMojo @Component( role = "org.apache.maven.project.MavenProjectHelper" )//, roleHint = "default" private Object projectHelper; + @Parameter( defaultValue = "${project.artifacts}", required = true, readonly = true ) + private Set dependencies; + public void execute() throws MojoExecutionException { - if (basedir == null) + if ( basedir == null ) { throw new MojoExecutionException( "basedir == null" ); } - if (touchFile == null) + if ( touchFile == null ) { throw new MojoExecutionException( "touchFile == null" ); } @@ -69,6 +76,11 @@ public class FirstMojo throw new MojoExecutionException( "compilerManager == null" ); } + if ( dependencies.isEmpty() ) + { + throw new MojoExecutionException( "dependencies.isEmpty()" ); + } + } } diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy b/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy index 40fd33f..53f6191 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy @@ -19,7 +19,7 @@ assert mojo.implementation.text() == 'org.apache.maven.plugin.coreit.FirstMojo' assert mojo.language.text() == 'java' assert mojo.description.text() == 'Touches a test file.' assert mojo.deprecated.text() == "Don't use!" -assert mojo.requiresDependencyResolution.text() == 'test' +assert mojo.requiresDependencyResolution.text() == 'compile' assert mojo.requiresDependencyCollection.text() == 'runtime' assert mojo.requiresProject.text() == 'true' assert mojo.requiresOnline.text() == 'false' @@ -44,7 +44,7 @@ assert mojo.requirements.requirement[2].role.text() == 'org.apache.maven.project //assert mojo.requirements.requirement[2].'role-hint'.text() == 'default' assert mojo.requirements.requirement[2].'field-name'.text() == 'projectHelper' -assert mojo.parameters.parameter.size() == 3 +assert mojo.parameters.parameter.size() == 4 def parameter = mojo.parameters.parameter.findAll{ it.name.text() == "aliasedParam"}[0]