001 package org.codehaus.gmaven.plugin.tools; 002 003 import java.util.ArrayList; 004 import java.util.Iterator; 005 import java.util.List; 006 007 import org.apache.maven.plugin.AbstractMojo; 008 import org.apache.maven.plugin.MojoExecutionException; 009 010 /** 011 * Display help information on gmaven-plugin.<br/> Call <pre> mvn groovy:help -Ddetail=true -Dgoal=<goal-name></pre> to display parameter details. 012 * 013 * @version generated on Sat Aug 18 23:38:11 CEST 2012 014 * @author org.apache.maven.tools.plugin.generator.PluginHelpGenerator (version 2.4.3) 015 * @goal help 016 * @requiresProject false 017 */ 018 public class HelpMojo 019 extends AbstractMojo 020 { 021 /** 022 * If <code>true</code>, display all settable properties for each goal. 023 * 024 * @parameter expression="${detail}" default-value="false" 025 */ 026 private boolean detail; 027 028 /** 029 * The name of the goal for which to show help. If unspecified, all goals will be displayed. 030 * 031 * @parameter expression="${goal}" 032 */ 033 private java.lang.String goal; 034 035 /** 036 * The maximum length of a display line, should be positive. 037 * 038 * @parameter expression="${lineLength}" default-value="80" 039 */ 040 private int lineLength; 041 042 /** 043 * The number of spaces per indentation level, should be positive. 044 * 045 * @parameter expression="${indentSize}" default-value="2" 046 */ 047 private int indentSize; 048 049 050 /** {@inheritDoc} */ 051 public void execute() 052 throws MojoExecutionException 053 { 054 if ( lineLength <= 0 ) 055 { 056 getLog().warn( "The parameter 'lineLength' should be positive, using '80' as default." ); 057 lineLength = 80; 058 } 059 if ( indentSize <= 0 ) 060 { 061 getLog().warn( "The parameter 'indentSize' should be positive, using '2' as default." ); 062 indentSize = 2; 063 } 064 065 StringBuffer sb = new StringBuffer(); 066 067 append( sb, "org.codehaus.gmaven:gmaven-plugin:1.3", 0 ); 068 append( sb, "", 0 ); 069 070 append( sb, "GMaven Plugin 1.3", 0 ); 071 append( sb, "Provides support for execution, compilation and other facets of Groovy development.", 1 ); 072 append( sb, "", 0 ); 073 074 if ( goal == null || goal.length() <= 0 ) 075 { 076 append( sb, "This plugin has 9 goals:", 0 ); 077 append( sb, "", 0 ); 078 } 079 080 if ( goal == null || goal.length() <= 0 || "compile".equals( goal ) ) 081 { 082 append( sb, "groovy:compile", 0 ); 083 append( sb, "Compiles Groovy sources.", 1 ); 084 append( sb, "", 0 ); 085 if ( detail ) 086 { 087 append( sb, "Available parameters:", 1 ); 088 append( sb, "", 0 ); 089 090 append( sb, "classpath", 2 ); 091 append( sb, "Additional artifacts to add to the classpath (in addition to the classpath which is picked up from the executing poms configuration).", 3 ); 092 append( sb, "", 0 ); 093 094 append( sb, "debug (Default: false)", 2 ); 095 append( sb, "Turns debugging operation on or off.", 3 ); 096 append( sb, "", 0 ); 097 098 append( sb, "defaultScriptExtension (Default: .groovy)", 2 ); 099 append( sb, "Set the default extention for Groovy script source files.", 3 ); 100 append( sb, "", 0 ); 101 102 append( sb, "outputDirectory (Default: ${project.build.outputDirectory})", 2 ); 103 append( sb, "The directory where generated Java class files will be placed.", 3 ); 104 append( sb, "", 0 ); 105 106 append( sb, "providerSelection", 2 ); 107 append( sb, "A comma-seperated list of provider keys, in order of preference of selection. If the invoking JVM is at least Java 1.5, then the Groovy 1.6 runtime will be used, else the Groovy 1.5 runtime is used.", 3 ); 108 append( sb, "", 0 ); 109 110 append( sb, "scriptBaseClassname", 2 ); 111 append( sb, "Sets the name of the base class for scripts. It must be a subclass of groovy.lang.Script.", 3 ); 112 append( sb, "", 0 ); 113 114 append( sb, "sourceEncoding (Default: ${project.build.sourceEncoding})", 2 ); 115 append( sb, "Sets the encoding to be used when reading source files.", 3 ); 116 append( sb, "", 0 ); 117 118 append( sb, "sources", 2 ); 119 append( sb, "Source files to be included. If not specified, then the default will be used.", 3 ); 120 append( sb, "", 0 ); 121 122 append( sb, "stacktrace (Default: false)", 2 ); 123 append( sb, "Enable compiler to report stack trace information if a problem occurs.", 3 ); 124 append( sb, "", 0 ); 125 126 append( sb, "targetBytecode", 2 ); 127 append( sb, "Allow setting the bytecode compatibility.", 3 ); 128 append( sb, "", 0 ); 129 130 append( sb, "tolerance (Default: 0)", 2 ); 131 append( sb, "Sets the error tolerance, which is the number of non-fatal errors (per unit) that should be tolerated before compilation is aborted.", 3 ); 132 append( sb, "", 0 ); 133 134 append( sb, "verbose (Default: false)", 2 ); 135 append( sb, "Turns verbose operation on or off.", 3 ); 136 append( sb, "", 0 ); 137 } 138 } 139 140 if ( goal == null || goal.length() <= 0 || "console".equals( goal ) ) 141 { 142 append( sb, "groovy:console", 0 ); 143 append( sb, "Launches the Groovy GUI console.", 1 ); 144 append( sb, "", 0 ); 145 if ( detail ) 146 { 147 append( sb, "Available parameters:", 1 ); 148 append( sb, "", 0 ); 149 150 append( sb, "providerSelection", 2 ); 151 append( sb, "A comma-seperated list of provider keys, in order of preference of selection. If the invoking JVM is at least Java 1.5, then the Groovy 1.6 runtime will be used, else the Groovy 1.5 runtime is used.", 3 ); 152 append( sb, "", 0 ); 153 } 154 } 155 156 if ( goal == null || goal.length() <= 0 || "execute".equals( goal ) ) 157 { 158 append( sb, "groovy:execute", 0 ); 159 append( sb, "Executes a Groovy script.", 1 ); 160 append( sb, "", 0 ); 161 if ( detail ) 162 { 163 append( sb, "Available parameters:", 1 ); 164 append( sb, "", 0 ); 165 166 append( sb, "classpath", 2 ); 167 append( sb, "Additional artifacts to add to the scripts classpath.", 3 ); 168 append( sb, "", 0 ); 169 170 append( sb, "defaults", 2 ); 171 append( sb, "A set of default project properties, which the values will be used only if the project or system does not override.", 3 ); 172 append( sb, "", 0 ); 173 174 append( sb, "properties", 2 ); 175 append( sb, "A set of additional project properties.", 3 ); 176 append( sb, "", 0 ); 177 178 append( sb, "providerSelection", 2 ); 179 append( sb, "A comma-seperated list of provider keys, in order of preference of selection. If the invoking JVM is at least Java 1.5, then the Groovy 1.6 runtime will be used, else the Groovy 1.5 runtime is used.", 3 ); 180 append( sb, "", 0 ); 181 182 append( sb, "sanitizeErrors (Default: true)", 2 ); 183 append( sb, "Sanatize errors, stripping out Groovy internals.", 3 ); 184 append( sb, "", 0 ); 185 186 append( sb, "scriptpath", 2 ); 187 append( sb, "Path to search for imported scripts.", 3 ); 188 append( sb, "", 0 ); 189 190 append( sb, "source", 2 ); 191 append( sb, "The source of the script to execute. This can be a URL, File or script body.", 3 ); 192 append( sb, "", 0 ); 193 194 append( sb, "trapAssertionErrors (Default: true)", 2 ); 195 append( sb, "Trap assertion errors and rethrow them as execution failures.", 3 ); 196 append( sb, "", 0 ); 197 } 198 } 199 200 if ( goal == null || goal.length() <= 0 || "generateStubs".equals( goal ) ) 201 { 202 append( sb, "groovy:generateStubs", 0 ); 203 append( sb, "Generate Java stubs from Groovy sources.", 1 ); 204 append( sb, "", 0 ); 205 if ( detail ) 206 { 207 append( sb, "Available parameters:", 1 ); 208 append( sb, "", 0 ); 209 210 append( sb, "classpath", 2 ); 211 append( sb, "Additional artifacts to add to the classpath (in addition to the classpath which is picked up from the executing poms configuration).", 3 ); 212 append( sb, "", 0 ); 213 214 append( sb, "outputDirectory (Default: ${project.build.directory}/generated-sources/groovy-stubs/main)", 2 ); 215 append( sb, "The directory where generated Java stub files will be placed.", 3 ); 216 append( sb, "", 0 ); 217 218 append( sb, "providerSelection", 2 ); 219 append( sb, "A comma-seperated list of provider keys, in order of preference of selection. If the invoking JVM is at least Java 1.5, then the Groovy 1.6 runtime will be used, else the Groovy 1.5 runtime is used.", 3 ); 220 append( sb, "", 0 ); 221 222 append( sb, "sources", 2 ); 223 append( sb, "Source files to be included. If not specified, then the default will be used.", 3 ); 224 append( sb, "", 0 ); 225 } 226 } 227 228 if ( goal == null || goal.length() <= 0 || "generateTestStubs".equals( goal ) ) 229 { 230 append( sb, "groovy:generateTestStubs", 0 ); 231 append( sb, "Generate Java stubs from Groovy test sources.", 1 ); 232 append( sb, "", 0 ); 233 if ( detail ) 234 { 235 append( sb, "Available parameters:", 1 ); 236 append( sb, "", 0 ); 237 238 append( sb, "classpath", 2 ); 239 append( sb, "Additional artifacts to add to the classpath (in addition to the classpath which is picked up from the executing poms configuration).", 3 ); 240 append( sb, "", 0 ); 241 242 append( sb, "outputDirectory (Default: ${project.build.directory}/generated-sources/groovy-stubs/test)", 2 ); 243 append( sb, "The directory where generated Java stub files will be placed.", 3 ); 244 append( sb, "", 0 ); 245 246 append( sb, "providerSelection", 2 ); 247 append( sb, "A comma-seperated list of provider keys, in order of preference of selection. If the invoking JVM is at least Java 1.5, then the Groovy 1.6 runtime will be used, else the Groovy 1.5 runtime is used.", 3 ); 248 append( sb, "", 0 ); 249 250 append( sb, "sources", 2 ); 251 append( sb, "Source files to be included. If not specified, then the default will be used.", 3 ); 252 append( sb, "", 0 ); 253 } 254 } 255 256 if ( goal == null || goal.length() <= 0 || "help".equals( goal ) ) 257 { 258 append( sb, "groovy:help", 0 ); 259 append( sb, "Display help information on gmaven-plugin.\nCall\n\u00a0\u00a0mvn\u00a0groovy:help\u00a0-Ddetail=true\u00a0-Dgoal=<goal-name>\nto display parameter details.", 1 ); 260 append( sb, "", 0 ); 261 if ( detail ) 262 { 263 append( sb, "Available parameters:", 1 ); 264 append( sb, "", 0 ); 265 266 append( sb, "detail (Default: false)", 2 ); 267 append( sb, "If true, display all settable properties for each goal.", 3 ); 268 append( sb, "", 0 ); 269 270 append( sb, "goal", 2 ); 271 append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 ); 272 append( sb, "", 0 ); 273 274 append( sb, "lineLength (Default: 80)", 2 ); 275 append( sb, "The maximum length of a display line, should be positive.", 3 ); 276 append( sb, "", 0 ); 277 278 append( sb, "indentSize (Default: 2)", 2 ); 279 append( sb, "The number of spaces per indentation level, should be positive.", 3 ); 280 append( sb, "", 0 ); 281 } 282 } 283 284 if ( goal == null || goal.length() <= 0 || "providers".equals( goal ) ) 285 { 286 append( sb, "groovy:providers", 0 ); 287 append( sb, "Displays information about the Groovy runtime providers which are configured and selected.", 1 ); 288 append( sb, "", 0 ); 289 if ( detail ) 290 { 291 append( sb, "Available parameters:", 1 ); 292 append( sb, "", 0 ); 293 294 append( sb, "providerSelection", 2 ); 295 append( sb, "A comma-seperated list of provider keys, in order of preference of selection. If the invoking JVM is at least Java 1.5, then the Groovy 1.6 runtime will be used, else the Groovy 1.5 runtime is used.", 3 ); 296 append( sb, "", 0 ); 297 } 298 } 299 300 if ( goal == null || goal.length() <= 0 || "shell".equals( goal ) ) 301 { 302 append( sb, "groovy:shell", 0 ); 303 append( sb, "Launches the Groovy Shell (aka. groovysh).", 1 ); 304 append( sb, "", 0 ); 305 if ( detail ) 306 { 307 append( sb, "Available parameters:", 1 ); 308 append( sb, "", 0 ); 309 310 append( sb, "args", 2 ); 311 append( sb, "Optional arguments to pass to the shell when executing.", 3 ); 312 append( sb, "", 0 ); 313 314 append( sb, "color", 2 ); 315 append( sb, "Enable or disable use of ANSI colors (aka. groovysh --color). Normally auto-detected.", 3 ); 316 append( sb, "", 0 ); 317 318 append( sb, "debug (Default: false)", 2 ); 319 append( sb, "Enable debug output (aka. groovysh --debug).", 3 ); 320 append( sb, "", 0 ); 321 322 append( sb, "legacy (Default: false)", 2 ); 323 append( sb, "Enable the legacy shell.", 3 ); 324 append( sb, "", 0 ); 325 326 append( sb, "providerSelection", 2 ); 327 append( sb, "A comma-seperated list of provider keys, in order of preference of selection. If the invoking JVM is at least Java 1.5, then the Groovy 1.6 runtime will be used, else the Groovy 1.5 runtime is used.", 3 ); 328 append( sb, "", 0 ); 329 330 append( sb, "quiet (Default: false)", 2 ); 331 append( sb, "Suppress superfluous output (aka. groovysh --quiet).", 3 ); 332 append( sb, "", 0 ); 333 334 append( sb, "terminal", 2 ); 335 append( sb, "Specify the terminal type to use (aka. groovysh --terminal). Normally auto-detected. Full class name or one of \'unix\', \'win\', \'windows\', \'false\', \'off\' or \'none\' expected.", 3 ); 336 append( sb, "", 0 ); 337 338 append( sb, "verbose (Default: false)", 2 ); 339 append( sb, "Enable verbose output (aka. groovysh --verbose).", 3 ); 340 append( sb, "", 0 ); 341 } 342 } 343 344 if ( goal == null || goal.length() <= 0 || "testCompile".equals( goal ) ) 345 { 346 append( sb, "groovy:testCompile", 0 ); 347 append( sb, "Compiles Groovy test sources.", 1 ); 348 append( sb, "", 0 ); 349 if ( detail ) 350 { 351 append( sb, "Available parameters:", 1 ); 352 append( sb, "", 0 ); 353 354 append( sb, "classpath", 2 ); 355 append( sb, "Additional artifacts to add to the classpath (in addition to the classpath which is picked up from the executing poms configuration).", 3 ); 356 append( sb, "", 0 ); 357 358 append( sb, "debug (Default: false)", 2 ); 359 append( sb, "Turns debugging operation on or off.", 3 ); 360 append( sb, "", 0 ); 361 362 append( sb, "defaultScriptExtension (Default: .groovy)", 2 ); 363 append( sb, "Set the default extention for Groovy script source files.", 3 ); 364 append( sb, "", 0 ); 365 366 append( sb, "outputDirectory (Default: ${project.build.testOutputDirectory})", 2 ); 367 append( sb, "The directory where generated Java class files will be placed.", 3 ); 368 append( sb, "", 0 ); 369 370 append( sb, "providerSelection", 2 ); 371 append( sb, "A comma-seperated list of provider keys, in order of preference of selection. If the invoking JVM is at least Java 1.5, then the Groovy 1.6 runtime will be used, else the Groovy 1.5 runtime is used.", 3 ); 372 append( sb, "", 0 ); 373 374 append( sb, "scriptBaseClassname", 2 ); 375 append( sb, "Sets the name of the base class for scripts. It must be a subclass of groovy.lang.Script.", 3 ); 376 append( sb, "", 0 ); 377 378 append( sb, "skip (Default: false)", 2 ); 379 append( sb, "Flag to allow test compiliation to be skipped.", 3 ); 380 append( sb, "", 0 ); 381 382 append( sb, "sourceEncoding (Default: ${project.build.sourceEncoding})", 2 ); 383 append( sb, "Sets the encoding to be used when reading source files.", 3 ); 384 append( sb, "", 0 ); 385 386 append( sb, "sources", 2 ); 387 append( sb, "Source files to be included. If not specified, then the default will be used.", 3 ); 388 append( sb, "", 0 ); 389 390 append( sb, "stacktrace (Default: false)", 2 ); 391 append( sb, "Enable compiler to report stack trace information if a problem occurs.", 3 ); 392 append( sb, "", 0 ); 393 394 append( sb, "targetBytecode", 2 ); 395 append( sb, "Allow setting the bytecode compatibility.", 3 ); 396 append( sb, "", 0 ); 397 398 append( sb, "tolerance (Default: 0)", 2 ); 399 append( sb, "Sets the error tolerance, which is the number of non-fatal errors (per unit) that should be tolerated before compilation is aborted.", 3 ); 400 append( sb, "", 0 ); 401 402 append( sb, "verbose (Default: false)", 2 ); 403 append( sb, "Turns verbose operation on or off.", 3 ); 404 append( sb, "", 0 ); 405 } 406 } 407 408 if ( getLog().isInfoEnabled() ) 409 { 410 getLog().info( sb.toString() ); 411 } 412 } 413 414 /** 415 * <p>Repeat a String <code>n</code> times to form a new string.</p> 416 * 417 * @param str String to repeat 418 * @param repeat number of times to repeat str 419 * @return String with repeated String 420 * @throws NegativeArraySizeException if <code>repeat < 0</code> 421 * @throws NullPointerException if str is <code>null</code> 422 */ 423 private static String repeat( String str, int repeat ) 424 { 425 StringBuffer buffer = new StringBuffer( repeat * str.length() ); 426 427 for ( int i = 0; i < repeat; i++ ) 428 { 429 buffer.append( str ); 430 } 431 432 return buffer.toString(); 433 } 434 435 /** 436 * Append a description to the buffer by respecting the indentSize and lineLength parameters. 437 * <b>Note</b>: The last character is always a new line. 438 * 439 * @param sb The buffer to append the description, not <code>null</code>. 440 * @param description The description, not <code>null</code>. 441 * @param indent The base indentation level of each line, must not be negative. 442 */ 443 private void append( StringBuffer sb, String description, int indent ) 444 { 445 for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); ) 446 { 447 sb.append( it.next().toString() ).append( '\n' ); 448 } 449 } 450 451 /** 452 * Splits the specified text into lines of convenient display length. 453 * 454 * @param text The text to split into lines, must not be <code>null</code>. 455 * @param indent The base indentation level of each line, must not be negative. 456 * @param indentSize The size of each indentation, must not be negative. 457 * @param lineLength The length of the line, must not be negative. 458 * @return The sequence of display lines, never <code>null</code>. 459 * @throws NegativeArraySizeException if <code>indent < 0</code> 460 */ 461 private static List toLines( String text, int indent, int indentSize, int lineLength ) 462 { 463 List lines = new ArrayList(); 464 465 String ind = repeat( "\t", indent ); 466 String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" ); 467 for ( int i = 0; i < plainLines.length; i++ ) 468 { 469 toLines( lines, ind + plainLines[i], indentSize, lineLength ); 470 } 471 472 return lines; 473 } 474 475 /** 476 * Adds the specified line to the output sequence, performing line wrapping if necessary. 477 * 478 * @param lines The sequence of display lines, must not be <code>null</code>. 479 * @param line The line to add, must not be <code>null</code>. 480 * @param indentSize The size of each indentation, must not be negative. 481 * @param lineLength The length of the line, must not be negative. 482 */ 483 private static void toLines( List lines, String line, int indentSize, int lineLength ) 484 { 485 int lineIndent = getIndentLevel( line ); 486 StringBuffer buf = new StringBuffer( 256 ); 487 String[] tokens = line.split( " +" ); 488 for ( int i = 0; i < tokens.length; i++ ) 489 { 490 String token = tokens[i]; 491 if ( i > 0 ) 492 { 493 if ( buf.length() + token.length() >= lineLength ) 494 { 495 lines.add( buf.toString() ); 496 buf.setLength( 0 ); 497 buf.append( repeat( " ", lineIndent * indentSize ) ); 498 } 499 else 500 { 501 buf.append( ' ' ); 502 } 503 } 504 for ( int j = 0; j < token.length(); j++ ) 505 { 506 char c = token.charAt( j ); 507 if ( c == '\t' ) 508 { 509 buf.append( repeat( " ", indentSize - buf.length() % indentSize ) ); 510 } 511 else if ( c == '\u00A0' ) 512 { 513 buf.append( ' ' ); 514 } 515 else 516 { 517 buf.append( c ); 518 } 519 } 520 } 521 lines.add( buf.toString() ); 522 } 523 524 /** 525 * Gets the indentation level of the specified line. 526 * 527 * @param line The line whose indentation level should be retrieved, must not be <code>null</code>. 528 * @return The indentation level of the line. 529 */ 530 private static int getIndentLevel( String line ) 531 { 532 int level = 0; 533 for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ ) 534 { 535 level++; 536 } 537 for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ ) 538 { 539 if ( line.charAt( i ) == '\t' ) 540 { 541 level++; 542 break; 543 } 544 } 545 return level; 546 } 547 }