maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rfscho...@apache.org
Subject svn commit: r1440711 - in /maven/plugins/trunk/maven-help-plugin/src: main/java/org/apache/maven/plugins/help/DescribeMojo.java test/java/org/apache/maven/plugins/help/DescribeMojoTest.java
Date Wed, 30 Jan 2013 22:22:09 GMT
Author: rfscholte
Date: Wed Jan 30 22:22:08 2013
New Revision: 1440711

URL: http://svn.apache.org/viewvc?rev=1440711&view=rev
Log:
[MPH-93] Replace expression label with user property when possible 

Modified:
    maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
    maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java

Modified: maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java?rev=1440711&r1=1440710&r2=1440711&view=diff
==============================================================================
--- maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
(original)
+++ maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
Wed Jan 30 22:22:08 2013
@@ -19,6 +19,17 @@ package org.apache.maven.plugins.help;
  * under the License.
  */
 
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -54,16 +65,6 @@ import org.apache.maven.tools.plugin.uti
 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 import org.codehaus.plexus.util.StringUtils;
 
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.List;
-import java.util.StringTokenizer;
-
 /**
  * Displays a list of the attributes for a Maven Plugin and/or goals (aka Mojo - Maven plain
Old Java Object).
  *
@@ -94,6 +95,8 @@ public class DescribeMojo
      * For deprecated values
      */
     private static final String NO_REASON = "No reason given";
+    
+    private static final Pattern EXPRESSION = Pattern.compile( "^\\$\\{([^}]+)\\}$" );
 
     // ----------------------------------------------------------------------
     // Mojo components
@@ -782,11 +785,20 @@ public class DescribeMojo
             if ( StringUtils.isEmpty( expression ) )
             {
                 // expression is ALWAYS null, this is a bug in PluginDescriptorBuilder (cf.
MNG-4941).
+                // Fixed with Maven-3.0.1
                 expression = md.getMojoConfiguration().getChild( parameter.getName() ).getValue(
null );
             }
             if ( StringUtils.isNotEmpty( expression ) )
             {
-                append( buffer, "Expression", expression, 3 );
+                Matcher matcher = EXPRESSION.matcher( expression );
+                if ( matcher.matches() )
+                {
+                    append( buffer, "User property", matcher.group( 1 ), 3 );
+                }
+                else
+                {
+                    append( buffer, "Expression", expression, 3 );
+                }
             }
 
             append( buffer, toDescription( parameter.getDescription() ), 3 );

Modified: maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java?rev=1440711&r1=1440710&r2=1440711&view=diff
==============================================================================
--- maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java
(original)
+++ maven/plugins/trunk/maven-help-plugin/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java
Wed Jan 30 22:22:08 2013
@@ -19,6 +19,9 @@ package org.apache.maven.plugins.help;
  * under the License.
  */
 
+import org.apache.maven.plugin.descriptor.MojoDescriptor;
+import org.apache.maven.plugin.descriptor.Parameter;
+
 import junit.framework.Assert;
 import junit.framework.TestCase;
 import junitx.util.PrivateAccessor;
@@ -50,4 +53,56 @@ public class DescribeMojoTest
             Assert.fail( "The API changes" );
         }
     }
+    
+    public void testValidExpression() throws Exception
+    {
+        StringBuilder sb = new StringBuilder();
+        MojoDescriptor md = new MojoDescriptor();
+        Parameter parameter = new Parameter();
+        parameter.setName( "name" );
+        parameter.setExpression( "${valid.expression}" );
+        md.addParameter( parameter );
+        
+        try
+        {
+            PrivateAccessor.invoke( new DescribeMojo(), "describeMojoParameters", new Class[]{
MojoDescriptor.class, StringBuilder.class}, new Object[] {md, sb});
+            
+            assertEquals( "  Available parameters:\n" +
+            		      "\n" +
+            		      "    name\n" +
+            		      "      User property: valid.expression\n" +
+            		      "      (no description available)\n", sb.toString() );
+        }
+        catch ( Throwable e )
+        {
+            fail(e.getMessage());
+        }
+    }
+    
+    public void testInvalidExpression() throws Exception
+    {
+        StringBuilder sb = new StringBuilder();
+        MojoDescriptor md = new MojoDescriptor();
+        Parameter parameter = new Parameter();
+        parameter.setName( "name" );
+        parameter.setExpression( "${project.build.directory}/generated-sources/foobar" );
//this is a defaultValue
+        md.addParameter( parameter );
+        
+        try
+        {
+            PrivateAccessor.invoke( new DescribeMojo(), "describeMojoParameters", new Class[]{
MojoDescriptor.class, StringBuilder.class}, new Object[] {md, sb});
+            
+            assertEquals( "  Available parameters:\n" +
+                          "\n" +
+                          "    name\n" +
+                          "      Expression: ${project.build.directory}/generated-sources/foobar\n"
+
+                          "      (no description available)\n", sb.toString() );
+        }
+        catch ( Throwable e )
+        {
+            fail(e.getMessage());
+        }
+        
+    }
+
 }



Mime
View raw message