Thanks Wayne,

Although I found workaround for the tool that I'm working on, the patch for PluginParameterExpression could be really simple:

sh-3.1$ svn diff
Index: maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java
===================================================================
--- maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java (revision 507376) +++ maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java (working copy)
@@ -193,6 +193,10 @@
        {
            value = project.getExecutionProject();
        }
+        else if ( "plugin".equals( expression ) )
+        {
+            value = mojoDescriptor.getPluginDescriptor();
+        }
        else if ( expression.startsWith( "project" ) )
        {
            try

So I'll go ahead and create Jira issue with patch.

Maven is always one of my favorite open source projects since it was under Turbine. I'm very pleased to continue to make contribution.


Regards
-Jiaqi



Wayne Fay wrote:
Without getting too far into the code myself, you seem to make some
very good arguments about possible problems in this code. ;-)

I have no idea if this PluginParameterExpressionEvaluator class (and
the referenced code in Plexus) have proper unit tests etc, but it
seems like you could make a great contribution in this area if you
were interested.

Thanks for the comments -- keep it up!

Wayne

On 2/13/07, Jiaqi Guo <[EMAIL PROTECTED]> wrote:
Hi Franz,

I tried to get PluginDescriptor within a mojo and got
PluginParameterException, then I started looking at this code.

Assume expression is string "plugin", pathSeparator is -1, the
expression.substring(1) becomes "lugin". Did I miss anything here?

And then looking at ReflectionValueExtractor.java today, I just realized
ReflectionValueExtractor.evaluate("lugin", pluginDescriptor) may work
since the first argument is irrelevant if string doesn't contain '.'.
But I'm more confused by the substring part of what .indexOf("/") is for.

And still, in my Mojo, the parameter with expression "${plugin}" is
causing PluginParameterException which indicates the value of it is null.

Regards
-Jiaqi

franz see wrote:
> Good day to you, Jiaqi,
>
> Why do you say that it will be evaluted to null?
>
> Cheers,
> Franz
>
>
> Jiaqi Guo wrote:
>
>> Hi there,
>>
>> I'm trying to find out the build-in variables for a maven2 plugin and
>> found the following code in
>> http://svn.apache.org/repos/asf/maven/components/tags/maven-2.0.4/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java
>>  line 217:
>>
>> ...
>>         else if ( expression.startsWith( "plugin" ) )
>>         {
>>             try
>>             {
>>                 int pathSeparator = expression.indexOf( "/" );
>>
>>                 PluginDescriptor pluginDescriptor =
>> mojoDescriptor.getPluginDescriptor();
>>
>>                 if ( pathSeparator > 0 )
>>                 {
>>                     String pathExpression = expression.substring( 1,
>> pathSeparator );
>>                     value = ReflectionValueExtractor.evaluate(
>> pathExpression, pluginDescriptor );
>> value = value + expression.substring( pathSeparator );
>>                 }
>>                 else
>>                 {
>>                     value = ReflectionValueExtractor.evaluate(
>> expression.substring( 1 ), pluginDescriptor );
>>                 }
>>             }
>>             catch ( Exception e )
>>             {
>>                 // TODO: don't catch exception
>>                 throw new ExpressionEvaluationException( "Error
>> evaluating plugin parameter expression: " + expression,
>>                                                          e );
>>             }
>>         }
>> ...
>>
>> If I didn't miss anything this code make the value of any parameter
>> expression starting with "plugin" to be null for sure, which will cause
>> PluginParameterException in
>> org.apache.maven.plugin.DefaultPluginManager.checkRequiredParameters(DefaultPluginManager.java:809).
>> Same thing happens to "settings" and "project".
>>
>> Is this a bug of maven-2.0.4? Is there any way to get pluginDescriptor
>> in Mojo?
>>
>>
>>
>> Regards
>>
>> --
>>
>>
>> Jiaqi Guo
>>
>> http://www.cyclopsgroup.org
>> [EMAIL PROTECTED]
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>>
>>
>
>


--


Jiaqi Guo

http://www.cyclopsgroup.org
[EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




--


Jiaqi Guo

http://www.cyclopsgroup.org
[EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to