1 package org.apache.maven.plugin;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 super( mojo.getPluginDescriptor(),
40 "Invalid or missing parameters: " + parameters + " for mojo: " + mojo.getRoleHint() );
41
42 this.mojo = mojo;
43
44 this.parameters = parameters;
45 }
46
47 public PluginParameterException( MojoDescriptor mojo, List parameters, Throwable cause )
48 {
49 super( mojo.getPluginDescriptor(),
50 "Invalid or missing parameters: " + parameters + " for mojo: " + mojo.getRoleHint(), cause );
51
52 this.mojo = mojo;
53
54 this.parameters = parameters;
55 }
56
57 public MojoDescriptor getMojoDescriptor()
58 {
59 return mojo;
60 }
61
62 public List getParameters()
63 {
64 return parameters;
65 }
66
67 private static void decomposeParameterIntoUserInstructions( MojoDescriptor mojo, Parameter param,
68 StringBuffer messageBuffer )
69 {
70 String expression = param.getExpression();
71
72 if ( param.isEditable() )
73 {
74 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 String alias = param.getAlias();
79 if ( StringUtils.isNotEmpty( alias ) && !alias.equals( param.getName() ) )
80 {
81 messageBuffer.append(
82 "\n\n-OR-\n\n<configuration>\n ...\n <" + alias + ">VALUE</" + alias + ">\n</configuration>\n" );
83 }
84 }
85
86 if ( StringUtils.isEmpty( expression ) )
87 {
88 messageBuffer.append( "." );
89 }
90 else
91 {
92 if ( param.isEditable() )
93 {
94 messageBuffer.append( "\n\n-OR-\n\n" );
95 }
96
97 addParameterUsageInfo( expression, messageBuffer );
98 }
99 }
100
101 public String buildDiagnosticMessage()
102 {
103 StringBuffer messageBuffer = new StringBuffer();
104
105 List params = getParameters();
106 MojoDescriptor mojo = getMojoDescriptor();
107
108 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 int idx = 0;
113 for ( Iterator it = params.iterator(); it.hasNext(); idx++ )
114 {
115 Parameter param = (Parameter) it.next();
116
117 messageBuffer.append( "\n[" ).append( idx ).append( "] " );
118
119 decomposeParameterIntoUserInstructions( mojo, param, messageBuffer );
120
121 messageBuffer.append( "\n" );
122 }
123
124 return messageBuffer.toString();
125 }
126 }