From 9f4113bb5b227ddc04c88cd21e69e96417e26066 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Thu, 30 Sep 2004 15:48:54 +0000 Subject: [PATCH] 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 --- .../goal/phase/GoalAttainmentPhase.java | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/goal/phase/GoalAttainmentPhase.java b/maven-core/src/main/java/org/apache/maven/lifecycle/goal/phase/GoalAttainmentPhase.java index 4fe717788e..a8706f803d 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/goal/phase/GoalAttainmentPhase.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/goal/phase/GoalAttainmentPhase.java @@ -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 )