From dbcdd0b526b7978e1d7640c5e2f27ea9f6bb843e Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Mon, 20 Jun 2005 03:39:42 +0000 Subject: [PATCH] PR: MNG-471 add @execute phase|lifecycle doclet tag for java and beanshell not sure how this would be configured for marmalade - will leave this for a once over of marmalade wrt the mojo api later git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@191385 13f79535-47bb-0310-9956-ffa450edef68 --- .../plugin/descriptor/MojoDescriptor.java | 13 +++++- .../BeanshellMojoDescriptorExtractor.java | 1 - .../src/main/resources/extractor.bsh | 24 +++++++++- .../java/JavaMojoDescriptorExtractor.java | 46 +++++++++++++------ 4 files changed, 68 insertions(+), 16 deletions(-) diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java index 18b1c561ee..9685aa2b8f 100755 --- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java +++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java @@ -36,7 +36,6 @@ public class MojoDescriptor extends ComponentDescriptor implements Cloneable { - // TODO: share with type handler public static String MAVEN_PLUGIN = "maven-plugin"; public static final String SINGLE_PASS_EXEC_STRATEGY = "once-per-session"; @@ -59,6 +58,8 @@ public class MojoDescriptor private String executePhase; + private String executeLifecycle; + private String deprecated; // ---------------------------------------------------------------------- @@ -375,4 +376,14 @@ public class MojoDescriptor return result; } + + public String getExecuteLifecycle() + { + return executeLifecycle; + } + + public void setExecuteLifecycle( String executeLifecycle ) + { + this.executeLifecycle = executeLifecycle; + } } diff --git a/maven-plugin-tools/maven-plugin-tools-beanshell/src/main/java/org/apache/maven/tools/plugin/extractor/beanshell/BeanshellMojoDescriptorExtractor.java b/maven-plugin-tools/maven-plugin-tools-beanshell/src/main/java/org/apache/maven/tools/plugin/extractor/beanshell/BeanshellMojoDescriptorExtractor.java index 89f0a489f9..49a09393b2 100644 --- a/maven-plugin-tools/maven-plugin-tools-beanshell/src/main/java/org/apache/maven/tools/plugin/extractor/beanshell/BeanshellMojoDescriptorExtractor.java +++ b/maven-plugin-tools/maven-plugin-tools-beanshell/src/main/java/org/apache/maven/tools/plugin/extractor/beanshell/BeanshellMojoDescriptorExtractor.java @@ -33,7 +33,6 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; - /** * @todo share constants * @todo add example usage tag that can be shown in the doco diff --git a/maven-plugin-tools/maven-plugin-tools-beanshell/src/main/resources/extractor.bsh b/maven-plugin-tools/maven-plugin-tools-beanshell/src/main/resources/extractor.bsh index f342c7d4a4..293a945d50 100644 --- a/maven-plugin-tools/maven-plugin-tools-beanshell/src/main/resources/extractor.bsh +++ b/maven-plugin-tools/maven-plugin-tools-beanshell/src/main/resources/extractor.bsh @@ -3,6 +3,7 @@ import java.util.regex.Pattern; import java.io.FileReader; import org.codehaus.plexus.util.StringUtils; import org.apache.maven.plugin.descriptor.Parameter; +import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; // only on start of line this.tag = "\\r?\\n\\s*\\*?\\s*@(\\w+)"; @@ -13,6 +14,8 @@ this.tagsPattern = Pattern.compile( "(?s)" + tag + "\\s*(.*?)" + tagOrEndComment this.descriptionPattern = Pattern.compile( "(?s)\\r?\\n\\s*\\*" ); this.typePattern = Pattern.compile( "type\\s*=\\s*\"(.*?)\"" ); this.expressionPattern = Pattern.compile( "expression\\s*=\\s*\"(.*?)\"" ); +this.phasePattern = Pattern.compile( "phase\\s*=\\s*\"(.*?)\"" ); +this.lifecyclePattern = Pattern.compile( "lifecycle\\s*=\\s*\"(.*?)\"" ); setAccessibility( true ); @@ -135,7 +138,6 @@ extract( file, mojoDescriptor ) this.tags = getTags( text ); mojoDescriptor.setGoal( tags.get( "goal" ) ); mojoDescriptor.setPhase( tags.get( "phase" ) ); - mojoDescriptor.setExecutePhase( tags.get( "executePhase" ) ); this.value = tags.get( "requiresDependencyResolution" ); // TODO: share with java extractor if ( value == null || value.length() == 0 ) @@ -146,6 +148,26 @@ extract( file, mojoDescriptor ) mojoDescriptor.setProjectRequired( tags.containsKey( "requiresProject" ) ); mojoDescriptor.setOnlineRequired( tags.containsKey( "requiresOnline" ) ); + + this.value = tags.get( "execute" ); + if ( value != null ) + { + m = phasePattern.matcher( value ); + if ( m.find() ) + { + mojoDescriptor.setExecutePhase( m.group( 1 ) ); + } + else + { + throw new InvalidPluginDescriptorException( "@execute must have a phase" ); + } + + m = lifecyclePattern.matcher( value ); + if ( m.find() ) + { + mojoDescriptor.setExecuteLifecycle( m.group( 1 ) ); + } + } } } diff --git a/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java b/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java index edd1afaf7c..7e9474fd7e 100644 --- a/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java +++ b/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java @@ -69,7 +69,7 @@ public class JavaMojoDescriptorExtractor public static final String PHASE = "phase"; - public static final String EXECUTE_PHASE = "executePhase"; + public static final String EXECUTE = "execute"; public static final String GOAL_DESCRIPTION = "description"; @@ -184,11 +184,29 @@ public class JavaMojoDescriptorExtractor // Additional phase to execute first // ---------------------------------------------------------------------- - DocletTag executePhase = findInClassHierarchy( javaClass, EXECUTE_PHASE ); - - if ( executePhase != null ) + DocletTag oldExecutePhase = findInClassHierarchy( javaClass, "executePhase" ); + if ( oldExecutePhase != null ) { - mojoDescriptor.setExecutePhase( executePhase.getValue() ); + getLogger().warn( "DEPRECATED: @executePhase is deprecated, please use @execute" ); + mojoDescriptor.setExecutePhase( oldExecutePhase.getValue() ); + } + + DocletTag execute = findInClassHierarchy( javaClass, EXECUTE ); + + if ( execute != null ) + { + String executePhase = execute.getNamedParameter( "phase" ); + if ( executePhase == null ) + { + throw new InvalidPluginDescriptorException( "@execute tag requires a 'phase' parameter" ); + } + mojoDescriptor.setExecutePhase( executePhase ); + + String lifecycle = execute.getNamedParameter( "lifecycle" ); + if ( lifecycle != null ) + { + mojoDescriptor.setExecuteLifecycle( lifecycle ); + } } // ---------------------------------------------------------------------- @@ -268,9 +286,7 @@ public class JavaMojoDescriptorExtractor // We're resolving class-level, ancestor-class-field, local-class-field order here. // --------------------------------------------------------------------------------- - Map rawParams = new TreeMap(); - - extractFieldParameterTags( javaClass, rawParams ); + Map rawParams = extractFieldParameterTags( javaClass ); for ( Iterator it = rawParams.entrySet().iterator(); it.hasNext(); ) { @@ -314,15 +330,21 @@ public class JavaMojoDescriptorExtractor } } - private void extractFieldParameterTags( JavaClass javaClass, Map rawParams ) + private Map extractFieldParameterTags( JavaClass javaClass ) { + Map rawParams; + // we have to add the parent fields first, so that they will be overwritten by the local fields if // that actually happens... JavaClass superClass = javaClass.getSuperJavaClass(); if ( superClass != null ) { - extractFieldParameterTags( superClass, rawParams ); + rawParams = extractFieldParameterTags( superClass ); + } + else + { + rawParams = new TreeMap(); } JavaField[] classFields = javaClass.getFields(); @@ -341,7 +363,7 @@ public class JavaMojoDescriptorExtractor } } } - + return rawParams; } private JavaClass getJavaClass( JavaSource javaSource ) @@ -354,8 +376,6 @@ public class JavaMojoDescriptorExtractor { JavaDocBuilder builder = new JavaDocBuilder(); - File basedir = project.getBasedir(); - for ( Iterator i = project.getCompileSourceRoots().iterator(); i.hasNext(); ) { builder.addSourceTree( new File( (String) i.next() ) );