[MNG-4238] [regression] plugin parameters of primitive types can't be populated from expression

o First part of the fix, complete solution requires new plexus container (PLX-431) as well

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@808971 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-08-28 17:57:04 +00:00
parent 023afe0dec
commit 0b8b83f670
1 changed files with 19 additions and 1 deletions

View File

@ -309,7 +309,7 @@ public class PluginParameterExpressionEvaluator
* could still be converted by the configurator so we leave those alone). If so, back off to evaluating the * could still be converted by the configurator so we leave those alone). If so, back off to evaluating the
* expression from properties only. * expression from properties only.
*/ */
if ( value != null && type != null && !( value instanceof String ) && !type.isInstance( value ) ) if ( value != null && type != null && !( value instanceof String ) && !isTypeCompatible( type, value ) )
{ {
value = null; value = null;
} }
@ -359,6 +359,24 @@ public class PluginParameterExpressionEvaluator
return value; return value;
} }
private static boolean isTypeCompatible( Class<?> type, Object value )
{
if ( type.isInstance( value ) )
{
return true;
}
else if ( ( type.isPrimitive() || type.getName().startsWith( "java.lang." ) )
&& value.getClass().getName().startsWith( "java.lang." ) )
{
// likely Boolean -> boolean, Short -> int etc. conversions, it's not the problem case we try to avoid
return true;
}
else
{
return false;
}
}
private String stripTokens( String expr ) private String stripTokens( String expr )
{ {
if ( expr.startsWith( "${" ) && ( expr.indexOf( "}" ) == expr.length() - 1 ) ) if ( expr.startsWith( "${" ) && ( expr.indexOf( "}" ) == expr.length() - 1 ) )