From da4f1a1bf7009408c13fd9b95bc2643f5c7b900c Mon Sep 17 00:00:00 2001 From: Herve Boutemy Date: Sat, 17 Dec 2011 16:03:52 +0000 Subject: [PATCH] [MPLUGIN-190@ added @executionStrategy support and deprecated @attainAlways git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1215517 13f79535-47bb-0310-9956-ffa450edef68 --- .../plugin/extractor/java/JavaMojoAnnotation.java | 1 + .../extractor/java/JavaMojoDescriptorExtractor.java | 10 ++++++++++ .../java/JavaMojoDescriptorExtractorTest.java | 8 ++++++++ .../src/test/resources/source/plugin-expected.xml | 2 +- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoAnnotation.java b/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoAnnotation.java index 653a2ca..1463e4b 100644 --- a/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoAnnotation.java +++ b/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoAnnotation.java @@ -160,6 +160,7 @@ public interface JavaMojoAnnotation * Refer to @attainAlways. *
* Note: Should be defined in a Mojo Type. + * @deprecated use @executionStrategy always instead */ String MULTI_EXECUTION_STRATEGY = "attainAlways"; diff --git a/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java b/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java index b3280be..ce69597 100644 --- a/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java +++ b/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java @@ -271,15 +271,25 @@ public class JavaMojoDescriptorExtractor { mojoDescriptor.setInstantiationStrategy( tag.getValue() ); } + + // executionStrategy (and deprecated @attainAlways) tag = findInClassHierarchy( javaClass, JavaMojoAnnotation.MULTI_EXECUTION_STRATEGY ); if ( tag != null ) { + getLogger().warn( "@" + JavaMojoAnnotation.MULTI_EXECUTION_STRATEGY + " in " + + javaClass.getFullyQualifiedName() + " is deprecated: please use '@" + + JavaMojoAnnotation.EXECUTION_STATEGY + " always' instead."); mojoDescriptor.setExecutionStrategy( MojoDescriptor.MULTI_PASS_EXEC_STRATEGY ); } else { mojoDescriptor.setExecutionStrategy( MojoDescriptor.SINGLE_PASS_EXEC_STRATEGY ); } + tag = findInClassHierarchy( javaClass, JavaMojoAnnotation.EXECUTION_STATEGY ); + if ( tag != null ) + { + mojoDescriptor.setExecutionStrategy( tag.getValue() ); + } // Phase name DocletTag phase = findInClassHierarchy( javaClass, JavaMojoAnnotation.PHASE ); diff --git a/maven-plugin-tools-java/src/test/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractorTest.java b/maven-plugin-tools-java/src/test/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractorTest.java index 20a17f0..c6e18b5 100644 --- a/maven-plugin-tools-java/src/test/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractorTest.java +++ b/maven-plugin-tools-java/src/test/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractorTest.java @@ -155,6 +155,14 @@ public class JavaMojoDescriptorExtractorTest return descriptor.getMojos(); } + public void testShouldFindTwoMojoDescriptorsInTestSourceDirectory() + throws Exception + { + List results = extract( "source" ); + + assertEquals( "Extracted mojos", 2, results.size() ); + } + public void testShouldPropagateImplementationParameter() throws Exception { diff --git a/maven-plugin-tools-java/src/test/resources/source/plugin-expected.xml b/maven-plugin-tools-java/src/test/resources/source/plugin-expected.xml index 6ed507d..258f7e2 100644 --- a/maven-plugin-tools-java/src/test/resources/source/plugin-expected.xml +++ b/maven-plugin-tools-java/src/test/resources/source/plugin-expected.xml @@ -76,7 +76,7 @@ java "role-hint" singleton - once-per-session + always deprecation text test test true