View Javadoc

1   package org.apache.maven.plugins.surefire.report;
2   
3   import java.util.ArrayList;
4   import java.util.Iterator;
5   import java.util.List;
6   
7   import org.apache.maven.plugin.AbstractMojo;
8   import org.apache.maven.plugin.MojoExecutionException;
9   
10  /**
11   * Display help information on maven-surefire-report-plugin.<br/> Call <pre>  mvn surefire-report:help -Ddetail=true -Dgoal=&lt;goal-name&gt;</pre> to display parameter details.
12   *
13   * @version generated on Mon Sep 26 16:26:58 CDT 2011
14   * @author org.apache.maven.tools.plugin.generator.PluginHelpGenerator (version 2.8)
15   * @goal help
16   * @requiresProject false
17   * @threadSafe
18   */
19  public class HelpMojo
20      extends AbstractMojo
21  {
22      /**
23       * If <code>true</code>, display all settable properties for each goal.
24       * 
25       * @parameter expression="${detail}" default-value="false"
26       */
27      private boolean detail;
28  
29      /**
30       * The name of the goal for which to show help. If unspecified, all goals will be displayed.
31       * 
32       * @parameter expression="${goal}"
33       */
34      private java.lang.String goal;
35  
36      /**
37       * The maximum length of a display line, should be positive.
38       * 
39       * @parameter expression="${lineLength}" default-value="80"
40       */
41      private int lineLength;
42  
43      /**
44       * The number of spaces per indentation level, should be positive.
45       * 
46       * @parameter expression="${indentSize}" default-value="2"
47       */
48      private int indentSize;
49  
50  
51      /** {@inheritDoc} */
52      public void execute()
53          throws MojoExecutionException
54      {
55          if ( lineLength <= 0 )
56          {
57              getLog().warn( "The parameter 'lineLength' should be positive, using '80' as default." );
58              lineLength = 80;
59          }
60          if ( indentSize <= 0 )
61          {
62              getLog().warn( "The parameter 'indentSize' should be positive, using '2' as default." );
63              indentSize = 2;
64          }
65  
66          StringBuffer sb = new StringBuffer();
67  
68          append( sb, "org.apache.maven.plugins:maven-surefire-report-plugin:2.10", 0 );
69          append( sb, "", 0 );
70  
71          append( sb, "Maven Surefire Report Plugin", 0 );
72          append( sb, "Surefire is a test framework project.", 1 );
73          append( sb, "", 0 );
74  
75          if ( goal == null || goal.length() <= 0 )
76          {
77              append( sb, "This plugin has 4 goals:", 0 );
78              append( sb, "", 0 );
79          }
80  
81          if ( goal == null || goal.length() <= 0 || "failsafe-report-only".equals( goal ) )
82          {
83              append( sb, "surefire-report:failsafe-report-only", 0 );
84              append( sb, "Creates a nicely formatted Failsafe Test Report in html format. This goal does not run the tests, it only builds the reports. See http://jira.codehaus.org/browse/SUREFIRE-257", 1 );
85              append( sb, "", 0 );
86              if ( detail )
87              {
88                  append( sb, "Available parameters:", 1 );
89                  append( sb, "", 0 );
90  
91                  append( sb, "aggregate (Default: false)", 2 );
92                  append( sb, "Whether to build an aggregated report at the root, or build individual reports.", 3 );
93                  append( sb, "Expression: ${aggregate}", 3 );
94                  append( sb, "", 0 );
95  
96                  append( sb, "linkXRef (Default: true)", 2 );
97                  append( sb, "Whether to link the XRef if found.", 3 );
98                  append( sb, "Expression: ${linkXRef}", 3 );
99                  append( sb, "", 0 );
100 
101                 append( sb, "outputDirectory", 2 );
102                 append( sb, "Location where generated html will be created.", 3 );
103                 append( sb, "Expression: ${project.reporting.outputDirectory}", 3 );
104                 append( sb, "", 0 );
105 
106                 append( sb, "outputName (Default: failsafe-report)", 2 );
107                 append( sb, "The filename to use for the report.", 3 );
108                 append( sb, "Required: Yes", 3 );
109                 append( sb, "Expression: ${outputName}", 3 );
110                 append( sb, "", 0 );
111 
112                 append( sb, "project", 2 );
113                 append( sb, "Maven Project", 3 );
114                 append( sb, "Required: Yes", 3 );
115                 append( sb, "Expression: ${project}", 3 );
116                 append( sb, "", 0 );
117 
118                 append( sb, "reportsDirectories", 2 );
119                 append( sb, "Directories containing the XML Report files that will be parsed and rendered to HTML format.", 3 );
120                 append( sb, "", 0 );
121 
122                 append( sb, "reportsDirectory", 2 );
123                 append( sb, "(Deprecated, use reportsDirectories) This directory contains the XML Report files that will be parsed and rendered to HTML format.", 3 );
124                 append( sb, "", 0 );
125 
126                 append( sb, "showSuccess (Default: true)", 2 );
127                 append( sb, "If set to false, only failures are shown.", 3 );
128                 append( sb, "Required: Yes", 3 );
129                 append( sb, "Expression: ${showSuccess}", 3 );
130                 append( sb, "", 0 );
131 
132                 append( sb, "xrefLocation (Default: ${project.reporting.outputDirectory}/xref-test)", 2 );
133                 append( sb, "Location of the Xrefs to link.", 3 );
134                 append( sb, "", 0 );
135             }
136         }
137 
138         if ( goal == null || goal.length() <= 0 || "help".equals( goal ) )
139         {
140             append( sb, "surefire-report:help", 0 );
141             append( sb, "Display help information on maven-surefire-report-plugin.\nCall\n\u00a0\u00a0mvn\u00a0surefire-report:help\u00a0-Ddetail=true\u00a0-Dgoal=<goal-name>\nto display parameter details.", 1 );
142             append( sb, "", 0 );
143             if ( detail )
144             {
145                 append( sb, "Available parameters:", 1 );
146                 append( sb, "", 0 );
147 
148                 append( sb, "detail (Default: false)", 2 );
149                 append( sb, "If true, display all settable properties for each goal.", 3 );
150                 append( sb, "Expression: ${detail}", 3 );
151                 append( sb, "", 0 );
152 
153                 append( sb, "goal", 2 );
154                 append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 );
155                 append( sb, "Expression: ${goal}", 3 );
156                 append( sb, "", 0 );
157 
158                 append( sb, "indentSize (Default: 2)", 2 );
159                 append( sb, "The number of spaces per indentation level, should be positive.", 3 );
160                 append( sb, "Expression: ${indentSize}", 3 );
161                 append( sb, "", 0 );
162 
163                 append( sb, "lineLength (Default: 80)", 2 );
164                 append( sb, "The maximum length of a display line, should be positive.", 3 );
165                 append( sb, "Expression: ${lineLength}", 3 );
166                 append( sb, "", 0 );
167             }
168         }
169 
170         if ( goal == null || goal.length() <= 0 || "report".equals( goal ) )
171         {
172             append( sb, "surefire-report:report", 0 );
173             append( sb, "Creates a nicely formatted Surefire Test Report in html format.", 1 );
174             append( sb, "", 0 );
175             if ( detail )
176             {
177                 append( sb, "Available parameters:", 1 );
178                 append( sb, "", 0 );
179 
180                 append( sb, "aggregate (Default: false)", 2 );
181                 append( sb, "Whether to build an aggregated report at the root, or build individual reports.", 3 );
182                 append( sb, "Expression: ${aggregate}", 3 );
183                 append( sb, "", 0 );
184 
185                 append( sb, "linkXRef (Default: true)", 2 );
186                 append( sb, "Whether to link the XRef if found.", 3 );
187                 append( sb, "Expression: ${linkXRef}", 3 );
188                 append( sb, "", 0 );
189 
190                 append( sb, "outputDirectory", 2 );
191                 append( sb, "Location where generated html will be created.", 3 );
192                 append( sb, "Expression: ${project.reporting.outputDirectory}", 3 );
193                 append( sb, "", 0 );
194 
195                 append( sb, "outputName (Default: surefire-report)", 2 );
196                 append( sb, "The filename to use for the report.", 3 );
197                 append( sb, "Required: Yes", 3 );
198                 append( sb, "Expression: ${outputName}", 3 );
199                 append( sb, "", 0 );
200 
201                 append( sb, "project", 2 );
202                 append( sb, "Maven Project", 3 );
203                 append( sb, "Required: Yes", 3 );
204                 append( sb, "Expression: ${project}", 3 );
205                 append( sb, "", 0 );
206 
207                 append( sb, "reportsDirectories", 2 );
208                 append( sb, "Directories containing the XML Report files that will be parsed and rendered to HTML format.", 3 );
209                 append( sb, "", 0 );
210 
211                 append( sb, "reportsDirectory", 2 );
212                 append( sb, "(Deprecated, use reportsDirectories) This directory contains the XML Report files that will be parsed and rendered to HTML format.", 3 );
213                 append( sb, "", 0 );
214 
215                 append( sb, "showSuccess (Default: true)", 2 );
216                 append( sb, "If set to false, only failures are shown.", 3 );
217                 append( sb, "Required: Yes", 3 );
218                 append( sb, "Expression: ${showSuccess}", 3 );
219                 append( sb, "", 0 );
220 
221                 append( sb, "xrefLocation (Default: ${project.reporting.outputDirectory}/xref-test)", 2 );
222                 append( sb, "Location of the Xrefs to link.", 3 );
223                 append( sb, "", 0 );
224             }
225         }
226 
227         if ( goal == null || goal.length() <= 0 || "report-only".equals( goal ) )
228         {
229             append( sb, "surefire-report:report-only", 0 );
230             append( sb, "Creates a nicely formatted Surefire Test Report in html format. This goal does not run the tests, it only builds the reports. This is a workaround for http://jira.codehaus.org/browse/SUREFIRE-257", 1 );
231             append( sb, "", 0 );
232             if ( detail )
233             {
234                 append( sb, "Available parameters:", 1 );
235                 append( sb, "", 0 );
236 
237                 append( sb, "aggregate (Default: false)", 2 );
238                 append( sb, "Whether to build an aggregated report at the root, or build individual reports.", 3 );
239                 append( sb, "Expression: ${aggregate}", 3 );
240                 append( sb, "", 0 );
241 
242                 append( sb, "linkXRef (Default: true)", 2 );
243                 append( sb, "Whether to link the XRef if found.", 3 );
244                 append( sb, "Expression: ${linkXRef}", 3 );
245                 append( sb, "", 0 );
246 
247                 append( sb, "outputDirectory", 2 );
248                 append( sb, "Location where generated html will be created.", 3 );
249                 append( sb, "Expression: ${project.reporting.outputDirectory}", 3 );
250                 append( sb, "", 0 );
251 
252                 append( sb, "outputName (Default: surefire-report)", 2 );
253                 append( sb, "The filename to use for the report.", 3 );
254                 append( sb, "Required: Yes", 3 );
255                 append( sb, "Expression: ${outputName}", 3 );
256                 append( sb, "", 0 );
257 
258                 append( sb, "project", 2 );
259                 append( sb, "Maven Project", 3 );
260                 append( sb, "Required: Yes", 3 );
261                 append( sb, "Expression: ${project}", 3 );
262                 append( sb, "", 0 );
263 
264                 append( sb, "reportsDirectories", 2 );
265                 append( sb, "Directories containing the XML Report files that will be parsed and rendered to HTML format.", 3 );
266                 append( sb, "", 0 );
267 
268                 append( sb, "reportsDirectory", 2 );
269                 append( sb, "(Deprecated, use reportsDirectories) This directory contains the XML Report files that will be parsed and rendered to HTML format.", 3 );
270                 append( sb, "", 0 );
271 
272                 append( sb, "showSuccess (Default: true)", 2 );
273                 append( sb, "If set to false, only failures are shown.", 3 );
274                 append( sb, "Required: Yes", 3 );
275                 append( sb, "Expression: ${showSuccess}", 3 );
276                 append( sb, "", 0 );
277 
278                 append( sb, "xrefLocation (Default: ${project.reporting.outputDirectory}/xref-test)", 2 );
279                 append( sb, "Location of the Xrefs to link.", 3 );
280                 append( sb, "", 0 );
281             }
282         }
283 
284         if ( getLog().isInfoEnabled() )
285         {
286             getLog().info( sb.toString() );
287         }
288     }
289 
290     /**
291      * <p>Repeat a String <code>n</code> times to form a new string.</p>
292      *
293      * @param str String to repeat
294      * @param repeat number of times to repeat str
295      * @return String with repeated String
296      * @throws NegativeArraySizeException if <code>repeat < 0</code>
297      * @throws NullPointerException if str is <code>null</code>
298      */
299     private static String repeat( String str, int repeat )
300     {
301         StringBuffer buffer = new StringBuffer( repeat * str.length() );
302 
303         for ( int i = 0; i < repeat; i++ )
304         {
305             buffer.append( str );
306         }
307 
308         return buffer.toString();
309     }
310 
311     /** 
312      * Append a description to the buffer by respecting the indentSize and lineLength parameters.
313      * <b>Note</b>: The last character is always a new line.
314      * 
315      * @param sb The buffer to append the description, not <code>null</code>.
316      * @param description The description, not <code>null</code>.
317      * @param indent The base indentation level of each line, must not be negative.
318      */
319     private void append( StringBuffer sb, String description, int indent )
320     {
321         for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); )
322         {
323             sb.append( it.next().toString() ).append( '\n' );
324         }
325     }
326 
327     /** 
328      * Splits the specified text into lines of convenient display length.
329      * 
330      * @param text The text to split into lines, must not be <code>null</code>.
331      * @param indent The base indentation level of each line, must not be negative.
332      * @param indentSize The size of each indentation, must not be negative.
333      * @param lineLength The length of the line, must not be negative.
334      * @return The sequence of display lines, never <code>null</code>.
335      * @throws NegativeArraySizeException if <code>indent < 0</code>
336      */
337     private static List toLines( String text, int indent, int indentSize, int lineLength )
338     {
339         List lines = new ArrayList();
340 
341         String ind = repeat( "\t", indent );
342         String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" );
343         for ( int i = 0; i < plainLines.length; i++ )
344         {
345             toLines( lines, ind + plainLines[i], indentSize, lineLength );
346         }
347 
348         return lines;
349     }
350 
351     /** 
352      * Adds the specified line to the output sequence, performing line wrapping if necessary.
353      * 
354      * @param lines The sequence of display lines, must not be <code>null</code>.
355      * @param line The line to add, must not be <code>null</code>.
356      * @param indentSize The size of each indentation, must not be negative.
357      * @param lineLength The length of the line, must not be negative.
358      */
359     private static void toLines( List lines, String line, int indentSize, int lineLength )
360     {
361         int lineIndent = getIndentLevel( line );
362         StringBuffer buf = new StringBuffer( 256 );
363         String[] tokens = line.split( " +" );
364         for ( int i = 0; i < tokens.length; i++ )
365         {
366             String token = tokens[i];
367             if ( i > 0 )
368             {
369                 if ( buf.length() + token.length() >= lineLength )
370                 {
371                     lines.add( buf.toString() );
372                     buf.setLength( 0 );
373                     buf.append( repeat( " ", lineIndent * indentSize ) );
374                 }
375                 else
376                 {
377                     buf.append( ' ' );
378                 }
379             }
380             for ( int j = 0; j < token.length(); j++ )
381             {
382                 char c = token.charAt( j );
383                 if ( c == '\t' )
384                 {
385                     buf.append( repeat( " ", indentSize - buf.length() % indentSize ) );
386                 }
387                 else if ( c == '\u00A0' )
388                 {
389                     buf.append( ' ' );
390                 }
391                 else
392                 {
393                     buf.append( c );
394                 }
395             }
396         }
397         lines.add( buf.toString() );
398     }
399 
400     /** 
401      * Gets the indentation level of the specified line.
402      * 
403      * @param line The line whose indentation level should be retrieved, must not be <code>null</code>.
404      * @return The indentation level of the line.
405      */
406     private static int getIndentLevel( String line )
407     {
408         int level = 0;
409         for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ )
410         {
411             level++;
412         }
413         for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ )
414         {
415             if ( line.charAt( i ) == '\t' )
416             {
417                 level++;
418                 break;
419             }
420         }
421         return level;
422     }
423 }