View Javadoc

1   package org.scalabench.plugins.dacapo;
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 dacapo-benchmark-maven-plugin.<br/> Call <pre>  mvn dacapo-benchmark:help -Ddetail=true -Dgoal=&lt;goal-name&gt;</pre> to display parameter details.
12   *
13   * @version generated on Wed Aug 29 17:31:33 CEST 2012
14   * @author org.apache.maven.tools.plugin.generator.PluginHelpGenerator (version 2.9)
15   * @goal help
16   * @requiresProject false
17   * @threadSafe
18   */
19  @SuppressWarnings( "all" )
20  public class HelpMojo
21      extends AbstractMojo
22  {
23      /**
24       * If <code>true</code>, display all settable properties for each goal.
25       * 
26       * @parameter expression="${detail}" default-value="false"
27       */
28      private boolean detail;
29  
30      /**
31       * The name of the goal for which to show help. If unspecified, all goals will be displayed.
32       * 
33       * @parameter expression="${goal}"
34       */
35      private java.lang.String goal;
36  
37      /**
38       * The maximum length of a display line, should be positive.
39       * 
40       * @parameter expression="${lineLength}" default-value="80"
41       */
42      private int lineLength;
43  
44      /**
45       * The number of spaces per indentation level, should be positive.
46       * 
47       * @parameter expression="${indentSize}" default-value="2"
48       */
49      private int indentSize;
50  
51  
52      /** {@inheritDoc} */
53      public void execute()
54          throws MojoExecutionException
55      {
56          if ( lineLength <= 0 )
57          {
58              getLog().warn( "The parameter 'lineLength' should be positive, using '80' as default." );
59              lineLength = 80;
60          }
61          if ( indentSize <= 0 )
62          {
63              getLog().warn( "The parameter 'indentSize' should be positive, using '2' as default." );
64              indentSize = 2;
65          }
66  
67          StringBuffer sb = new StringBuffer();
68  
69          append( sb, "org.scalabench.plugins:dacapo-benchmark-maven-plugin:0.1.0-SNAPSHOT", 0 );
70          append( sb, "", 0 );
71  
72          append( sb, "DaCapo Benchmark Maven Plugin", 0 );
73          append( sb, "A Maven Plugin to Build an Individual DaCapo Benchmark", 1 );
74          append( sb, "", 0 );
75  
76          if ( goal == null || goal.length() <= 0 )
77          {
78              append( sb, "This plugin has 7 goals:", 0 );
79              append( sb, "", 0 );
80          }
81  
82          if ( goal == null || goal.length() <= 0 || "configuration".equals( goal ) )
83          {
84              append( sb, "dacapo-benchmark:configuration", 0 );
85              append( sb, "Generate the benchmark\'s configuration file (.cnf). While most configuration options need to be configured explicitly, the benchmark\'s dependency declarations are derived from the POM; all provided-scoped dependencies are assumed to be dependencies of the benchmark itself (as opposed to dependencies of the harness).", 1 );
86              append( sb, "", 0 );
87              if ( detail )
88              {
89                  append( sb, "Available parameters:", 1 );
90                  append( sb, "", 0 );
91  
92                  append( sb, "benchmark", 2 );
93                  append( sb, "The benchmark\'s configuration. If not present, a hand-crafted configuration file is assumed to be present.", 3 );
94                  append( sb, "", 0 );
95  
96                  append( sb, "benchmarkName", 2 );
97                  append( sb, "The name of the benchmark. If unspecified, it is derived from the project\'s artifactId. If the artifactId matches one of the following patterns, the benchmark name is extracted from it as indicated:\n-\t${benchmarkName}-dacapo-benchmark\n-\tdacapo-${benchmarkName}-benchmark\nOtherwise, the artifactId is taken wholesale.", 3 );
98                  append( sb, "", 0 );
99              }
100         }
101 
102         if ( goal == null || goal.length() <= 0 || "help".equals( goal ) )
103         {
104             append( sb, "dacapo-benchmark:help", 0 );
105             append( sb, "Display help information on dacapo-benchmark-maven-plugin.\nCall\n\u00a0\u00a0mvn\u00a0dacapo-benchmark:help\u00a0-Ddetail=true\u00a0-Dgoal=<goal-name>\nto display parameter details.", 1 );
106             append( sb, "", 0 );
107             if ( detail )
108             {
109                 append( sb, "Available parameters:", 1 );
110                 append( sb, "", 0 );
111 
112                 append( sb, "detail (Default: false)", 2 );
113                 append( sb, "If true, display all settable properties for each goal.", 3 );
114                 append( sb, "Expression: ${detail}", 3 );
115                 append( sb, "", 0 );
116 
117                 append( sb, "goal", 2 );
118                 append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 );
119                 append( sb, "Expression: ${goal}", 3 );
120                 append( sb, "", 0 );
121 
122                 append( sb, "indentSize (Default: 2)", 2 );
123                 append( sb, "The number of spaces per indentation level, should be positive.", 3 );
124                 append( sb, "Expression: ${indentSize}", 3 );
125                 append( sb, "", 0 );
126 
127                 append( sb, "lineLength (Default: 80)", 2 );
128                 append( sb, "The maximum length of a display line, should be positive.", 3 );
129                 append( sb, "Expression: ${lineLength}", 3 );
130                 append( sb, "", 0 );
131             }
132         }
133 
134         if ( goal == null || goal.length() <= 0 || "integration-test".equals( goal ) )
135         {
136             append( sb, "dacapo-benchmark:integration-test", 0 );
137             append( sb, "Perform sanity checks for integration testing. Note: This goal only runs the benchmarks (possibly for multiple invocations/iterations).", 1 );
138             append( sb, "", 0 );
139             if ( detail )
140             {
141                 append( sb, "Available parameters:", 1 );
142                 append( sb, "", 0 );
143 
144                 append( sb, "benchmarkName", 2 );
145                 append( sb, "The name of the benchmark. If unspecified, it is derived from the project\'s artifactId. If the artifactId matches one of the following patterns, the benchmark name is extracted from it as indicated:\n-\t${benchmarkName}-dacapo-benchmark\n-\tdacapo-${benchmarkName}-benchmark\nOtherwise, the artifactId is taken wholesale.", 3 );
146                 append( sb, "", 0 );
147 
148                 append( sb, "skipITs (Default: false)", 2 );
149                 append( sb, "Set this to true to skip executing integration tests, but still compile them. Its use is not recommended, but quite convenient on occasion. This property is also honored by the Maven Failsafe Plugin.", 3 );
150                 append( sb, "Expression: ${skipITs}", 3 );
151                 append( sb, "", 0 );
152 
153                 append( sb, "skipTests (Default: false)", 2 );
154                 append( sb, "Set this to true to skip executing tests, but still compile them. Its use is not recommended, but quite convenient on occasion. This property is also honored by the Maven Surefire Plugin and the Maven Failsafe Plugin.", 3 );
155                 append( sb, "Expression: ${skipTests}", 3 );
156                 append( sb, "", 0 );
157 
158                 append( sb, "summaryFile (Default: ${project.build.directory}/dacapo-benchmark-reports/dacapo-benchmark-summary.xml)", 2 );
159                 append( sb, "The summary file to write integration test results to.", 3 );
160                 append( sb, "", 0 );
161 
162                 append( sb, "testInvocations (Default: 1)", 2 );
163                 append( sb, "The number of invocations to perform for each benchmark size.", 3 );
164                 append( sb, "", 0 );
165 
166                 append( sb, "testIterations (Default: 1)", 2 );
167                 append( sb, "The number of iterations to perform for each invocation.", 3 );
168                 append( sb, "", 0 );
169             }
170         }
171 
172         if ( goal == null || goal.length() <= 0 || "package-data".equals( goal ) )
173         {
174             append( sb, "dacapo-benchmark:package-data", 0 );
175             append( sb, "Package the benchmark\'s input data.", 1 );
176             append( sb, "", 0 );
177             if ( detail )
178             {
179                 append( sb, "Available parameters:", 1 );
180                 append( sb, "", 0 );
181 
182                 append( sb, "additionalDataSourceDirectories", 2 );
183                 append( sb, "Additional directories for input data to include.", 3 );
184                 append( sb, "", 0 );
185 
186                 append( sb, "benchmarkName", 2 );
187                 append( sb, "The name of the benchmark. If unspecified, it is derived from the project\'s artifactId. If the artifactId matches one of the following patterns, the benchmark name is extracted from it as indicated:\n-\t${benchmarkName}-dacapo-benchmark\n-\tdacapo-${benchmarkName}-benchmark\nOtherwise, the artifactId is taken wholesale.", 3 );
188                 append( sb, "", 0 );
189 
190                 append( sb, "compressData (Default: true)", 2 );
191                 append( sb, "Should the input data be compressed?", 3 );
192                 append( sb, "Required: Yes", 3 );
193                 append( sb, "", 0 );
194 
195                 append( sb, "dataSourceDirectory (Default: ${basedir}/src/main/data)", 2 );
196                 append( sb, "Main directory for input data to include as a ZIP file in the JAR.", 3 );
197                 append( sb, "Required: Yes", 3 );
198                 append( sb, "", 0 );
199             }
200         }
201 
202         if ( goal == null || goal.length() <= 0 || "package-libraries".equals( goal ) )
203         {
204             append( sb, "dacapo-benchmark:package-libraries", 0 );
205             append( sb, "Package the benchmark\'s required libraries.", 1 );
206             append( sb, "", 0 );
207             if ( detail )
208             {
209                 append( sb, "Available parameters:", 1 );
210                 append( sb, "", 0 );
211 
212                 append( sb, "benchmarkName", 2 );
213                 append( sb, "The name of the benchmark. If unspecified, it is derived from the project\'s artifactId. If the artifactId matches one of the following patterns, the benchmark name is extracted from it as indicated:\n-\t${benchmarkName}-dacapo-benchmark\n-\tdacapo-${benchmarkName}-benchmark\nOtherwise, the artifactId is taken wholesale.", 3 );
214                 append( sb, "", 0 );
215             }
216         }
217 
218         if ( goal == null || goal.length() <= 0 || "report-configuration".equals( goal ) )
219         {
220             append( sb, "dacapo-benchmark:report-configuration", 0 );
221             append( sb, "Reports the benchmark\'s configuration.", 1 );
222             append( sb, "", 0 );
223             if ( detail )
224             {
225                 append( sb, "Available parameters:", 1 );
226                 append( sb, "", 0 );
227 
228                 append( sb, "benchmarkName", 2 );
229                 append( sb, "The name of the benchmark. If unspecified, it is derived from the project\'s artifactId. If the artifactId matches one of the following patterns, the benchmark name is extracted from it as indicated:\n-\t${benchmarkName}-dacapo-benchmark\n-\tdacapo-${benchmarkName}-benchmark\nOtherwise, the artifactId is taken wholesale.", 3 );
230                 append( sb, "", 0 );
231             }
232         }
233 
234         if ( goal == null || goal.length() <= 0 || "verify".equals( goal ) )
235         {
236             append( sb, "dacapo-benchmark:verify", 0 );
237             append( sb, "Perform sanity checks for integration testing. Note: This goal only verifies the results.", 1 );
238             append( sb, "", 0 );
239             if ( detail )
240             {
241                 append( sb, "Available parameters:", 1 );
242                 append( sb, "", 0 );
243 
244                 append( sb, "benchmarkName", 2 );
245                 append( sb, "The name of the benchmark. If unspecified, it is derived from the project\'s artifactId. If the artifactId matches one of the following patterns, the benchmark name is extracted from it as indicated:\n-\t${benchmarkName}-dacapo-benchmark\n-\tdacapo-${benchmarkName}-benchmark\nOtherwise, the artifactId is taken wholesale.", 3 );
246                 append( sb, "", 0 );
247 
248                 append( sb, "skipITs (Default: false)", 2 );
249                 append( sb, "Set this to true to skip executing integration tests, but still compile them. Its use is not recommended, but quite convenient on occasion. This property is also honored by the Maven Failsafe Plugin.", 3 );
250                 append( sb, "Expression: ${skipITs}", 3 );
251                 append( sb, "", 0 );
252 
253                 append( sb, "skipTests (Default: false)", 2 );
254                 append( sb, "Set this to true to skip executing tests, but still compile them. Its use is not recommended, but quite convenient on occasion. This property is also honored by the Maven Surefire Plugin and the Maven Failsafe Plugin.", 3 );
255                 append( sb, "Expression: ${skipTests}", 3 );
256                 append( sb, "", 0 );
257 
258                 append( sb, "summaryFile (Default: ${project.build.directory}/dacapo-benchmark-reports/dacapo-benchmark-summary.xml)", 2 );
259                 append( sb, "The summary file to write integration test results to.", 3 );
260                 append( sb, "", 0 );
261 
262                 append( sb, "testFailureIgnore (Default: false)", 2 );
263                 append( sb, "Set this to true to ignore failures during testing. Its use is not recommended, but quite convenient on occasion.", 3 );
264                 append( sb, "Expression: ${maven.test.failure.ignore}", 3 );
265                 append( sb, "", 0 );
266             }
267         }
268 
269         if ( getLog().isInfoEnabled() )
270         {
271             getLog().info( sb.toString() );
272         }
273     }
274 
275     /**
276      * <p>Repeat a String <code>n</code> times to form a new string.</p>
277      *
278      * @param str String to repeat
279      * @param repeat number of times to repeat str
280      * @return String with repeated String
281      * @throws NegativeArraySizeException if <code>repeat < 0</code>
282      * @throws NullPointerException if str is <code>null</code>
283      */
284     private static String repeat( String str, int repeat )
285     {
286         StringBuffer buffer = new StringBuffer( repeat * str.length() );
287 
288         for ( int i = 0; i < repeat; i++ )
289         {
290             buffer.append( str );
291         }
292 
293         return buffer.toString();
294     }
295 
296     /** 
297      * Append a description to the buffer by respecting the indentSize and lineLength parameters.
298      * <b>Note</b>: The last character is always a new line.
299      * 
300      * @param sb The buffer to append the description, not <code>null</code>.
301      * @param description The description, not <code>null</code>.
302      * @param indent The base indentation level of each line, must not be negative.
303      */
304     private void append( StringBuffer sb, String description, int indent )
305     {
306         for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); )
307         {
308             sb.append( it.next().toString() ).append( '\n' );
309         }
310     }
311 
312     /** 
313      * Splits the specified text into lines of convenient display length.
314      * 
315      * @param text The text to split into lines, must not be <code>null</code>.
316      * @param indent The base indentation level of each line, must not be negative.
317      * @param indentSize The size of each indentation, must not be negative.
318      * @param lineLength The length of the line, must not be negative.
319      * @return The sequence of display lines, never <code>null</code>.
320      * @throws NegativeArraySizeException if <code>indent < 0</code>
321      */
322     private static List toLines( String text, int indent, int indentSize, int lineLength )
323     {
324         List<String> lines = new ArrayList<String>();
325 
326         String ind = repeat( "\t", indent );
327         String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" );
328         for ( int i = 0; i < plainLines.length; i++ )
329         {
330             toLines( lines, ind + plainLines[i], indentSize, lineLength );
331         }
332 
333         return lines;
334     }
335 
336     /** 
337      * Adds the specified line to the output sequence, performing line wrapping if necessary.
338      * 
339      * @param lines The sequence of display lines, must not be <code>null</code>.
340      * @param line The line to add, must not be <code>null</code>.
341      * @param indentSize The size of each indentation, must not be negative.
342      * @param lineLength The length of the line, must not be negative.
343      */
344     private static void toLines( List<String> lines, String line, int indentSize, int lineLength )
345     {
346         int lineIndent = getIndentLevel( line );
347         StringBuffer buf = new StringBuffer( 256 );
348         String[] tokens = line.split( " +" );
349         for ( int i = 0; i < tokens.length; i++ )
350         {
351             String token = tokens[i];
352             if ( i > 0 )
353             {
354                 if ( buf.length() + token.length() >= lineLength )
355                 {
356                     lines.add( buf.toString() );
357                     buf.setLength( 0 );
358                     buf.append( repeat( " ", lineIndent * indentSize ) );
359                 }
360                 else
361                 {
362                     buf.append( ' ' );
363                 }
364             }
365             for ( int j = 0; j < token.length(); j++ )
366             {
367                 char c = token.charAt( j );
368                 if ( c == '\t' )
369                 {
370                     buf.append( repeat( " ", indentSize - buf.length() % indentSize ) );
371                 }
372                 else if ( c == '\u00A0' )
373                 {
374                     buf.append( ' ' );
375                 }
376                 else
377                 {
378                     buf.append( c );
379                 }
380             }
381         }
382         lines.add( buf.toString() );
383     }
384 
385     /** 
386      * Gets the indentation level of the specified line.
387      * 
388      * @param line The line whose indentation level should be retrieved, must not be <code>null</code>.
389      * @return The indentation level of the line.
390      */
391     private static int getIndentLevel( String line )
392     {
393         int level = 0;
394         for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ )
395         {
396             level++;
397         }
398         for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ )
399         {
400             if ( line.charAt( i ) == '\t' )
401             {
402                 level++;
403                 break;
404             }
405         }
406         return level;
407     }
408 }