Coverage Report - org.apache.maven.plugin.PluginParameterException
 
Classes in this File Line Coverage Branch Coverage Complexity
PluginParameterException
88 %
29/33
83 %
10/12
1,833
 
 1  
 package org.apache.maven.plugin;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *  http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import org.apache.maven.plugin.descriptor.MojoDescriptor;
 23  
 import org.apache.maven.plugin.descriptor.Parameter;
 24  
 import org.codehaus.plexus.util.StringUtils;
 25  
 
 26  
 import java.util.Iterator;
 27  
 import java.util.List;
 28  
 
 29  
 public class PluginParameterException
 30  
     extends PluginConfigurationException
 31  
 {
 32  
 
 33  
     private final List parameters;
 34  
 
 35  
     private final MojoDescriptor mojo;
 36  
 
 37  
     public PluginParameterException( MojoDescriptor mojo, List parameters )
 38  
     {
 39  9
         super( mojo.getPluginDescriptor(),
 40  
                "Invalid or missing parameters: " + parameters + " for mojo: " + mojo.getRoleHint() );
 41  
 
 42  9
         this.mojo = mojo;
 43  
 
 44  9
         this.parameters = parameters;
 45  9
     }
 46  
 
 47  
     public PluginParameterException( MojoDescriptor mojo, List parameters, Throwable cause )
 48  
     {
 49  0
         super( mojo.getPluginDescriptor(),
 50  
                "Invalid or missing parameters: " + parameters + " for mojo: " + mojo.getRoleHint(), cause );
 51  
 
 52  0
         this.mojo = mojo;
 53  
 
 54  0
         this.parameters = parameters;
 55  0
     }
 56  
 
 57  
     public MojoDescriptor getMojoDescriptor()
 58  
     {
 59  8
         return mojo;
 60  
     }
 61  
 
 62  
     public List getParameters()
 63  
     {
 64  8
         return parameters;
 65  
     }
 66  
 
 67  
     private static void decomposeParameterIntoUserInstructions( MojoDescriptor mojo, Parameter param,
 68  
                                                                 StringBuffer messageBuffer )
 69  
     {
 70  9
         String expression = param.getExpression();
 71  
 
 72  9
         if ( param.isEditable() )
 73  
         {
 74  3
             messageBuffer.append( "Inside the definition for plugin \'" + mojo.getPluginDescriptor().getArtifactId() +
 75  
                 "\' specify the following:\n\n<configuration>\n  ...\n  <" + param.getName() + ">VALUE</" +
 76  
                 param.getName() + ">\n</configuration>" );
 77  
 
 78  3
             String alias = param.getAlias();
 79  3
             if ( StringUtils.isNotEmpty( alias ) && !alias.equals( param.getName() ) )
 80  
             {
 81  3
                 messageBuffer.append(
 82  
                     "\n\n-OR-\n\n<configuration>\n  ...\n  <" + alias + ">VALUE</" + alias + ">\n</configuration>\n" );
 83  
             }
 84  
         }
 85  
 
 86  9
         if ( StringUtils.isEmpty( expression ) )
 87  
         {
 88  1
             messageBuffer.append( "." );
 89  
         }
 90  
         else
 91  
         {
 92  8
             if ( param.isEditable() )
 93  
             {
 94  2
                 messageBuffer.append( "\n\n-OR-\n\n" );
 95  
             }
 96  
 
 97  8
             addParameterUsageInfo( expression, messageBuffer );
 98  
         }
 99  9
     }
 100  
 
 101  
     public String buildDiagnosticMessage()
 102  
     {
 103  8
         StringBuffer messageBuffer = new StringBuffer();
 104  
 
 105  8
         List params = getParameters();
 106  8
         MojoDescriptor mojo = getMojoDescriptor();
 107  
 
 108  8
         messageBuffer.append( "One or more required plugin parameters are invalid/missing for \'" )
 109  
             .append( mojo.getPluginDescriptor().getGoalPrefix() ).append( ":" ).append( mojo.getGoal() )
 110  
             .append( "\'\n" );
 111  
 
 112  8
         int idx = 0;
 113  17
         for ( Iterator it = params.iterator(); it.hasNext(); idx++ )
 114  
         {
 115  9
             Parameter param = (Parameter) it.next();
 116  
 
 117  9
             messageBuffer.append( "\n[" ).append( idx ).append( "] " );
 118  
 
 119  9
             decomposeParameterIntoUserInstructions( mojo, param, messageBuffer );
 120  
 
 121  9
             messageBuffer.append( "\n" );
 122  
         }
 123  
 
 124  8
         return messageBuffer.toString();
 125  
     }
 126  
 }