You are viewing a plain text version of this content. The canonical link for it is here.
Posted to m2-dev@maven.apache.org by jv...@apache.org on 2004/09/30 17:48:54 UTC

cvs commit: maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/goal/phase GoalAttainmentPhase.java

jvanzyl     2004/09/30 08:48:54

  Modified:    maven-core/src/main/java/org/apache/maven/lifecycle/goal/phase
                        GoalAttainmentPhase.java
  Log:
  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.
  
  Revision  Changes    Path
  1.3       +25 -6     maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/goal/phase/GoalAttainmentPhase.java
  
  Index: GoalAttainmentPhase.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/goal/phase/GoalAttainmentPhase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- GoalAttainmentPhase.java	30 Sep 2004 15:09:48 -0000	1.2
  +++ GoalAttainmentPhase.java	30 Sep 2004 15:48:54 -0000	1.3
  @@ -121,17 +121,36 @@
   
                   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 );
               }
           }
   
           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 )