o perform some minimal validation of the plugin configuration parameters to make sure they are not null when the parameter is required. throw an exception is the parameter that is required is null.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163173 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2004-09-30 15:48:54 +00:00
parent 4a14895569
commit 9f4113bb5b
1 changed files with 24 additions and 5 deletions

View File

@ -121,11 +121,18 @@ public class GoalAttainmentPhase
Object value = OgnlProjectValueExtractor.evaluate( expression, context );
//@todo: mojo parameter validation
// This is the place where parameter validation should be performed.
//if ( value == null && parameter.isRequired() )
//{
//}
// ----------------------------------------------------------------------
// We will perform a basic check here for parameters values that are
// required. Required parameters can't be null so we throw an
// Exception in the case where they are. We probably want some pluggable
// mechanism here but this will catch the most obvious of
// misconfigurations.
// ----------------------------------------------------------------------
if ( value == null && parameter.isRequired() )
{
throw new PluginConfigurationException( createPluginParameterRequiredMessage( goal, parameter ) );
}
map.put( key, value );
}
@ -134,6 +141,18 @@ public class GoalAttainmentPhase
return map;
}
private String createPluginParameterRequiredMessage( MojoDescriptor mojo, Parameter parameter )
{
StringBuffer message = new StringBuffer();
message.append( "The " + parameter.getName() ).
append( " is required for the execution of the " ).
append( mojo.getId() ).
append( " mojo and cannot be null." );
return message.toString();
}
private void releaseComponents( MojoDescriptor goal, PluginExecutionRequest request, MavenGoalExecutionContext context )
{
if ( request != null && request.getParameters() != null )