1 package org.apache.maven.plugin; 2 3 18 19 import org.apache.maven.plugin.descriptor.MojoDescriptor; 20 import org.apache.maven.plugin.descriptor.Parameter; 21 import org.codehaus.plexus.util.StringUtils; 22 23 import java.util.Iterator ; 24 import java.util.List ; 25 26 public class PluginParameterException 27 extends PluginConfigurationException 28 { 29 30 private final List parameters; 31 32 private final MojoDescriptor mojo; 33 34 public PluginParameterException( MojoDescriptor mojo, List parameters ) 35 { 36 super( mojo.getPluginDescriptor(), 37 "Invalid or missing parameters: " + parameters + " for mojo: " + mojo.getRoleHint() ); 38 39 this.mojo = mojo; 40 41 this.parameters = parameters; 42 } 43 44 public PluginParameterException( MojoDescriptor mojo, List parameters, Throwable cause ) 45 { 46 super( mojo.getPluginDescriptor(), 47 "Invalid or missing parameters: " + parameters + " for mojo: " + mojo.getRoleHint(), cause ); 48 49 this.mojo = mojo; 50 51 this.parameters = parameters; 52 } 53 54 public MojoDescriptor getMojoDescriptor() 55 { 56 return mojo; 57 } 58 59 public List getParameters() 60 { 61 return parameters; 62 } 63 64 private static void decomposeParameterIntoUserInstructions( MojoDescriptor mojo, Parameter param, 65 StringBuffer messageBuffer ) 66 { 67 String expression = param.getExpression(); 68 69 if ( param.isEditable() ) 70 { 71 messageBuffer.append( "inside the definition for plugin: \'" + mojo.getPluginDescriptor().getArtifactId() + 72 "\'specify the following:\n\n<configuration>\n ...\n <" + param.getName() + ">VALUE</" + 73 param.getName() + ">\n</configuration>" ); 74 75 String alias = param.getAlias(); 76 if ( StringUtils.isNotEmpty( alias ) && !alias.equals( param.getName() ) ) 77 { 78 messageBuffer.append( 79 "\n\n-OR-\n\n<configuration>\n ...\n <" + alias + ">VALUE</" + alias + ">\n</configuration>\n" ); 80 } 81 } 82 83 if ( StringUtils.isEmpty( expression ) ) 84 { 85 messageBuffer.append( "." ); 86 } 87 else 88 { 89 if ( param.isEditable() ) 90 { 91 messageBuffer.append( "\n\n-OR-\n\n" ); 92 } 93 94 addParameterUsageInfo( expression, messageBuffer ); 95 } 96 } 97 98 public String buildDiagnosticMessage() 99 { 100 StringBuffer messageBuffer = new StringBuffer (); 101 102 List params = getParameters(); 103 MojoDescriptor mojo = getMojoDescriptor(); 104 105 messageBuffer.append( "One or more required plugin parameters are invalid/missing for \'" ) 106 .append( mojo.getPluginDescriptor().getGoalPrefix() ).append( ":" ).append( mojo.getGoal() ) 107 .append( "\'\n" ); 108 109 int idx = 0; 110 for ( Iterator it = params.iterator(); it.hasNext(); idx++ ) 111 { 112 Parameter param = (Parameter) it.next(); 113 114 messageBuffer.append( "\n[" ).append( idx ).append( "] " ); 115 116 decomposeParameterIntoUserInstructions( mojo, param, messageBuffer ); 117 118 messageBuffer.append( "\n" ); 119 } 120 121 return messageBuffer.toString(); 122 } 123 } 124 | Popular Tags |