Coverage Report - org.apache.maven.plugin.pmd.HelpMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
HelpMojo
0 %
0/242
0 %
0/78
5,333
 
 1  
 package org.apache.maven.plugin.pmd;
 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-pmd-plugin.<br/> Call <pre>  mvn pmd:help -Ddetail=true -Dgoal=&lt;goal-name&gt;</pre> to display parameter details.
 12  
  *
 13  
  * @version generated on Sat May 01 16:19:14 CEST 2010
 14  
  * @author org.apache.maven.tools.plugin.generator.PluginHelpGenerator (version 2.5.1)
 15  
  * @goal help
 16  
  * @requiresProject false
 17  
  */
 18  0
 public class HelpMojo
 19  
     extends AbstractMojo
 20  
 {
 21  
     /**
 22  
      * If <code>true</code>, display all settable properties for each goal.
 23  
      * 
 24  
      * @parameter expression="${detail}" default-value="false"
 25  
      */
 26  
     private boolean detail;
 27  
 
 28  
     /**
 29  
      * The name of the goal for which to show help. If unspecified, all goals will be displayed.
 30  
      * 
 31  
      * @parameter expression="${goal}"
 32  
      */
 33  
     private java.lang.String goal;
 34  
 
 35  
     /**
 36  
      * The maximum length of a display line, should be positive.
 37  
      * 
 38  
      * @parameter expression="${lineLength}" default-value="80"
 39  
      */
 40  
     private int lineLength;
 41  
 
 42  
     /**
 43  
      * The number of spaces per indentation level, should be positive.
 44  
      * 
 45  
      * @parameter expression="${indentSize}" default-value="2"
 46  
      */
 47  
     private int indentSize;
 48  
 
 49  
 
 50  
     /** {@inheritDoc} */
 51  
     public void execute()
 52  
         throws MojoExecutionException
 53  
     {
 54  0
         if ( lineLength <= 0 )
 55  
         {
 56  0
             getLog().warn( "The parameter 'lineLength' should be positive, using '80' as default." );
 57  0
             lineLength = 80;
 58  
         }
 59  0
         if ( indentSize <= 0 )
 60  
         {
 61  0
             getLog().warn( "The parameter 'indentSize' should be positive, using '2' as default." );
 62  0
             indentSize = 2;
 63  
         }
 64  
 
 65  0
         StringBuffer sb = new StringBuffer();
 66  
 
 67  0
         append( sb, "org.apache.maven.plugins:maven-pmd-plugin:2.5", 0 );
 68  0
         append( sb, "", 0 );
 69  
 
 70  0
         append( sb, "Maven PMD Plugin", 0 );
 71  0
         append( sb, "A Maven plugin for the PMD toolkit, that produces a report on both code rule violations and detected copy and paste fragments, as well as being able to fail the build based on these metrics.", 1 );
 72  0
         append( sb, "", 0 );
 73  
 
 74  0
         if ( goal == null || goal.length() <= 0 )
 75  
         {
 76  0
             append( sb, "This plugin has 5 goals:", 0 );
 77  0
             append( sb, "", 0 );
 78  
         }
 79  
 
 80  0
         if ( goal == null || goal.length() <= 0 || "check".equals( goal ) )
 81  
         {
 82  0
             append( sb, "pmd:check", 0 );
 83  0
             append( sb, "Fail the build if there were any PMD violations in the source code.", 1 );
 84  0
             append( sb, "", 0 );
 85  0
             if ( detail )
 86  
             {
 87  0
                 append( sb, "Available parameters:", 1 );
 88  0
                 append( sb, "", 0 );
 89  
 
 90  0
                 append( sb, "aggregate (Default: false)", 2 );
 91  0
                 append( sb, "Whether to build an aggregated report at the root, or build individual reports.", 3 );
 92  0
                 append( sb, "", 0 );
 93  
 
 94  0
                 append( sb, "failOnViolation (Default: true)", 2 );
 95  0
                 append( sb, "Whether to fail the build if the validation check fails.", 3 );
 96  0
                 append( sb, "", 0 );
 97  
 
 98  0
                 append( sb, "failurePriority (Default: 5)", 2 );
 99  0
                 append( sb, "What priority level to fail the build on. Failures at or above this level will stop the build. Anything below will be warnings and will be displayed in the build output if verbose=true. Note: Minimum Priority = 5 Maximum Priority = 0", 3 );
 100  0
                 append( sb, "", 0 );
 101  
 
 102  0
                 append( sb, "skip (Default: false)", 2 );
 103  0
                 append( sb, "Skip the PMD checks. Most useful on the command line via \'-Dpmd.skip=true\'.", 3 );
 104  0
                 append( sb, "", 0 );
 105  
 
 106  0
                 append( sb, "targetDirectory", 2 );
 107  0
                 append( sb, "The location of the XML report to check, as generated by the PMD report.", 3 );
 108  0
                 append( sb, "", 0 );
 109  
 
 110  0
                 append( sb, "verbose (Default: false)", 2 );
 111  0
                 append( sb, "Print details of check failures to build output.", 3 );
 112  0
                 append( sb, "", 0 );
 113  
             }
 114  
         }
 115  
 
 116  0
         if ( goal == null || goal.length() <= 0 || "cpd".equals( goal ) )
 117  
         {
 118  0
             append( sb, "pmd:cpd", 0 );
 119  0
             append( sb, "Creates a report for PMD\'s CPD tool. See http://pmd.sourceforge.net/cpd.html for more detail.", 1 );
 120  0
             append( sb, "", 0 );
 121  0
             if ( detail )
 122  
             {
 123  0
                 append( sb, "Available parameters:", 1 );
 124  0
                 append( sb, "", 0 );
 125  
 
 126  0
                 append( sb, "aggregate (Default: false)", 2 );
 127  0
                 append( sb, "Whether to build an aggregated report at the root, or build individual reports.", 3 );
 128  0
                 append( sb, "", 0 );
 129  
 
 130  0
                 append( sb, "excludeRoots", 2 );
 131  0
                 append( sb, "The project source directories that should be excluded.", 3 );
 132  0
                 append( sb, "", 0 );
 133  
 
 134  0
                 append( sb, "excludes", 2 );
 135  0
                 append( sb, "A list of files to exclude from checking. Can contain Ant-style wildcards and double wildcards. Note that these exclusion patterns only operate on the path of a source file relative to its source root directory. In other words, files are excluded based on their package and/or class name. If you want to exclude entire source root directories, use the parameter excludeRoots instead.", 3 );
 136  0
                 append( sb, "", 0 );
 137  
 
 138  0
                 append( sb, "format (Default: xml)", 2 );
 139  0
                 append( sb, "Set the output format type, in addition to the HTML report. Must be one of: \'none\', \'csv\', \'xml\', \'txt\' or the full class name of the PMD renderer to use. See the net.sourceforge.pmd.renderers package javadoc for available renderers. XML is required if the pmd:check goal is being used.", 3 );
 140  0
                 append( sb, "", 0 );
 141  
 
 142  0
                 append( sb, "ignoreIdentifiers (Default: false)", 2 );
 143  0
                 append( sb, "Similar to ignoreLiterals but for identifiers; i.e., variable names, methods names, and so forth.", 3 );
 144  0
                 append( sb, "", 0 );
 145  
 
 146  0
                 append( sb, "ignoreLiterals (Default: false)", 2 );
 147  0
                 append( sb, "If true, CPD ignores literal value differences when evaluating a duplicate block. This means that foo=42; and foo=43; will be seen as equivalent. You may want to run PMD with this option off to start with and then switch it on to see what it turns up.", 3 );
 148  0
                 append( sb, "", 0 );
 149  
 
 150  0
                 append( sb, "includes", 2 );
 151  0
                 append( sb, "A list of files to include from checking. Can contain Ant-style wildcards and double wildcards. Defaults to **\\/*.java.", 3 );
 152  0
                 append( sb, "", 0 );
 153  
 
 154  0
                 append( sb, "includeTests (Default: false)", 2 );
 155  0
                 append( sb, "Run PMD on the tests.", 3 );
 156  0
                 append( sb, "", 0 );
 157  
 
 158  0
                 append( sb, "linkXRef (Default: true)", 2 );
 159  0
                 append( sb, "Link the violation line numbers to the source xref. Links will be created automatically if the jxr plugin is being used.", 3 );
 160  0
                 append( sb, "", 0 );
 161  
 
 162  0
                 append( sb, "minimumTokens (Default: 100)", 2 );
 163  0
                 append( sb, "The minimum number of tokens that need to be duplicated before it causes a violation.", 3 );
 164  0
                 append( sb, "", 0 );
 165  
 
 166  0
                 append( sb, "outputDirectory", 2 );
 167  0
                 append( sb, "The output directory for the final HTML report. Note that this parameter is only evaluated if the goal is run directly from the command line or during the default lifecycle. If the goal is run indirectly as part of a site generation, the output directory configured in the Maven Site Plugin is used instead.", 3 );
 168  0
                 append( sb, "", 0 );
 169  
 
 170  0
                 append( sb, "outputEncoding (Default: ${project.reporting.outputEncoding})", 2 );
 171  0
                 append( sb, "The file encoding when writing non-HTML reports.", 3 );
 172  0
                 append( sb, "", 0 );
 173  
 
 174  0
                 append( sb, "skip (Default: false)", 2 );
 175  0
                 append( sb, "Skip the CPD report generation. Most useful on the command line via \'-Dcpd.skip=true\'.", 3 );
 176  0
                 append( sb, "", 0 );
 177  
 
 178  0
                 append( sb, "sourceEncoding (Default: ${project.build.sourceEncoding})", 2 );
 179  0
                 append( sb, "The file encoding to use when reading the Java sources.", 3 );
 180  0
                 append( sb, "", 0 );
 181  
 
 182  0
                 append( sb, "targetDirectory", 2 );
 183  0
                 append( sb, "The output directory for the intermediate XML report.", 3 );
 184  0
                 append( sb, "", 0 );
 185  
 
 186  0
                 append( sb, "xrefLocation (Default: ${project.reporting.outputDirectory}/xref)", 2 );
 187  0
                 append( sb, "Location of the Xrefs to link to.", 3 );
 188  0
                 append( sb, "", 0 );
 189  
 
 190  0
                 append( sb, "xrefTestLocation (Default: ${project.reporting.outputDirectory}/xref-test)", 2 );
 191  0
                 append( sb, "Location of the Test Xrefs to link to.", 3 );
 192  0
                 append( sb, "", 0 );
 193  
             }
 194  
         }
 195  
 
 196  0
         if ( goal == null || goal.length() <= 0 || "cpd-check".equals( goal ) )
 197  
         {
 198  0
             append( sb, "pmd:cpd-check", 0 );
 199  0
             append( sb, "Fail the build if there were any CPD violations in the source code.", 1 );
 200  0
             append( sb, "", 0 );
 201  0
             if ( detail )
 202  
             {
 203  0
                 append( sb, "Available parameters:", 1 );
 204  0
                 append( sb, "", 0 );
 205  
 
 206  0
                 append( sb, "aggregate (Default: false)", 2 );
 207  0
                 append( sb, "Whether to build an aggregated report at the root, or build individual reports.", 3 );
 208  0
                 append( sb, "", 0 );
 209  
 
 210  0
                 append( sb, "failOnViolation (Default: true)", 2 );
 211  0
                 append( sb, "Whether to fail the build if the validation check fails.", 3 );
 212  0
                 append( sb, "", 0 );
 213  
 
 214  0
                 append( sb, "skip (Default: false)", 2 );
 215  0
                 append( sb, "Skip the CPD violation checks. Most useful on the command line via \'-Dcpd.skip=true\'.", 3 );
 216  0
                 append( sb, "", 0 );
 217  
 
 218  0
                 append( sb, "targetDirectory", 2 );
 219  0
                 append( sb, "The location of the XML report to check, as generated by the PMD report.", 3 );
 220  0
                 append( sb, "", 0 );
 221  
 
 222  0
                 append( sb, "verbose (Default: false)", 2 );
 223  0
                 append( sb, "Print details of check failures to build output.", 3 );
 224  0
                 append( sb, "", 0 );
 225  
             }
 226  
         }
 227  
 
 228  0
         if ( goal == null || goal.length() <= 0 || "help".equals( goal ) )
 229  
         {
 230  0
             append( sb, "pmd:help", 0 );
 231  0
             append( sb, "Display help information on maven-pmd-plugin.\nCall\n\u00a0\u00a0mvn\u00a0pmd:help\u00a0-Ddetail=true\u00a0-Dgoal=<goal-name>\nto display parameter details.", 1 );
 232  0
             append( sb, "", 0 );
 233  0
             if ( detail )
 234  
             {
 235  0
                 append( sb, "Available parameters:", 1 );
 236  0
                 append( sb, "", 0 );
 237  
 
 238  0
                 append( sb, "detail (Default: false)", 2 );
 239  0
                 append( sb, "If true, display all settable properties for each goal.", 3 );
 240  0
                 append( sb, "", 0 );
 241  
 
 242  0
                 append( sb, "goal", 2 );
 243  0
                 append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 );
 244  0
                 append( sb, "", 0 );
 245  
 
 246  0
                 append( sb, "indentSize (Default: 2)", 2 );
 247  0
                 append( sb, "The number of spaces per indentation level, should be positive.", 3 );
 248  0
                 append( sb, "", 0 );
 249  
 
 250  0
                 append( sb, "lineLength (Default: 80)", 2 );
 251  0
                 append( sb, "The maximum length of a display line, should be positive.", 3 );
 252  0
                 append( sb, "", 0 );
 253  
             }
 254  
         }
 255  
 
 256  0
         if ( goal == null || goal.length() <= 0 || "pmd".equals( goal ) )
 257  
         {
 258  0
             append( sb, "pmd:pmd", 0 );
 259  0
             append( sb, "Creates a PMD report.", 1 );
 260  0
             append( sb, "", 0 );
 261  0
             if ( detail )
 262  
             {
 263  0
                 append( sb, "Available parameters:", 1 );
 264  0
                 append( sb, "", 0 );
 265  
 
 266  0
                 append( sb, "aggregate (Default: false)", 2 );
 267  0
                 append( sb, "Whether to build an aggregated report at the root, or build individual reports.", 3 );
 268  0
                 append( sb, "", 0 );
 269  
 
 270  0
                 append( sb, "excludeRoots", 2 );
 271  0
                 append( sb, "The project source directories that should be excluded.", 3 );
 272  0
                 append( sb, "", 0 );
 273  
 
 274  0
                 append( sb, "excludes", 2 );
 275  0
                 append( sb, "A list of files to exclude from checking. Can contain Ant-style wildcards and double wildcards. Note that these exclusion patterns only operate on the path of a source file relative to its source root directory. In other words, files are excluded based on their package and/or class name. If you want to exclude entire source root directories, use the parameter excludeRoots instead.", 3 );
 276  0
                 append( sb, "", 0 );
 277  
 
 278  0
                 append( sb, "format (Default: xml)", 2 );
 279  0
                 append( sb, "Set the output format type, in addition to the HTML report. Must be one of: \'none\', \'csv\', \'xml\', \'txt\' or the full class name of the PMD renderer to use. See the net.sourceforge.pmd.renderers package javadoc for available renderers. XML is required if the pmd:check goal is being used.", 3 );
 280  0
                 append( sb, "", 0 );
 281  
 
 282  0
                 append( sb, "includes", 2 );
 283  0
                 append( sb, "A list of files to include from checking. Can contain Ant-style wildcards and double wildcards. Defaults to **\\/*.java.", 3 );
 284  0
                 append( sb, "", 0 );
 285  
 
 286  0
                 append( sb, "includeTests (Default: false)", 2 );
 287  0
                 append( sb, "Run PMD on the tests.", 3 );
 288  0
                 append( sb, "", 0 );
 289  
 
 290  0
                 append( sb, "linkXRef (Default: true)", 2 );
 291  0
                 append( sb, "Link the violation line numbers to the source xref. Links will be created automatically if the jxr plugin is being used.", 3 );
 292  0
                 append( sb, "", 0 );
 293  
 
 294  0
                 append( sb, "minimumPriority (Default: 5)", 2 );
 295  0
                 append( sb, "The rule priority threshold; rules with lower priority than this will not be evaluated.", 3 );
 296  0
                 append( sb, "", 0 );
 297  
 
 298  0
                 append( sb, "outputDirectory", 2 );
 299  0
                 append( sb, "The output directory for the final HTML report. Note that this parameter is only evaluated if the goal is run directly from the command line or during the default lifecycle. If the goal is run indirectly as part of a site generation, the output directory configured in the Maven Site Plugin is used instead.", 3 );
 300  0
                 append( sb, "", 0 );
 301  
 
 302  0
                 append( sb, "outputEncoding (Default: ${project.reporting.outputEncoding})", 2 );
 303  0
                 append( sb, "The file encoding when writing non-HTML reports.", 3 );
 304  0
                 append( sb, "", 0 );
 305  
 
 306  0
                 append( sb, "rulesets", 2 );
 307  0
                 append( sb, "The PMD rulesets to use. See the Stock Rulesets for a list of some included. Since version 2.5, the ruleset \'rulesets/maven.xml\' is also available. Defaults to the basic, imports and unusedcode rulesets.", 3 );
 308  0
                 append( sb, "", 0 );
 309  
 
 310  0
                 append( sb, "skip (Default: false)", 2 );
 311  0
                 append( sb, "Skip the PMD report generation. Most useful on the command line via \'-Dpmd.skip=true\'.", 3 );
 312  0
                 append( sb, "", 0 );
 313  
 
 314  0
                 append( sb, "sourceEncoding (Default: ${project.build.sourceEncoding})", 2 );
 315  0
                 append( sb, "The file encoding to use when reading the Java sources.", 3 );
 316  0
                 append( sb, "", 0 );
 317  
 
 318  0
                 append( sb, "targetDirectory", 2 );
 319  0
                 append( sb, "The output directory for the intermediate XML report.", 3 );
 320  0
                 append( sb, "", 0 );
 321  
 
 322  0
                 append( sb, "targetJdk", 2 );
 323  0
                 append( sb, "The target JDK to analyze based on. Should match the target used in the compiler plugin. Valid values are currently 1.3, 1.4, 1.5 and 1.6.\nNote: support for 1.6 was added in version 2.3 of this plugin.\n", 3 );
 324  0
                 append( sb, "", 0 );
 325  
 
 326  0
                 append( sb, "xrefLocation (Default: ${project.reporting.outputDirectory}/xref)", 2 );
 327  0
                 append( sb, "Location of the Xrefs to link to.", 3 );
 328  0
                 append( sb, "", 0 );
 329  
 
 330  0
                 append( sb, "xrefTestLocation (Default: ${project.reporting.outputDirectory}/xref-test)", 2 );
 331  0
                 append( sb, "Location of the Test Xrefs to link to.", 3 );
 332  0
                 append( sb, "", 0 );
 333  
             }
 334  
         }
 335  
 
 336  0
         if ( getLog().isInfoEnabled() )
 337  
         {
 338  0
             getLog().info( sb.toString() );
 339  
         }
 340  0
     }
 341  
 
 342  
     /**
 343  
      * <p>Repeat a String <code>n</code> times to form a new string.</p>
 344  
      *
 345  
      * @param str String to repeat
 346  
      * @param repeat number of times to repeat str
 347  
      * @return String with repeated String
 348  
      * @throws NegativeArraySizeException if <code>repeat < 0</code>
 349  
      * @throws NullPointerException if str is <code>null</code>
 350  
      */
 351  
     private static String repeat( String str, int repeat )
 352  
     {
 353  0
         StringBuffer buffer = new StringBuffer( repeat * str.length() );
 354  
 
 355  0
         for ( int i = 0; i < repeat; i++ )
 356  
         {
 357  0
             buffer.append( str );
 358  
         }
 359  
 
 360  0
         return buffer.toString();
 361  
     }
 362  
 
 363  
     /** 
 364  
      * Append a description to the buffer by respecting the indentSize and lineLength parameters.
 365  
      * <b>Note</b>: The last character is always a new line.
 366  
      * 
 367  
      * @param sb The buffer to append the description, not <code>null</code>.
 368  
      * @param description The description, not <code>null</code>.
 369  
      * @param indent The base indentation level of each line, must not be negative.
 370  
      */
 371  
     private void append( StringBuffer sb, String description, int indent )
 372  
     {
 373  0
         for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); )
 374  
         {
 375  0
             sb.append( it.next().toString() ).append( '\n' );
 376  
         }
 377  0
     }
 378  
 
 379  
     /** 
 380  
      * Splits the specified text into lines of convenient display length.
 381  
      * 
 382  
      * @param text The text to split into lines, must not be <code>null</code>.
 383  
      * @param indent The base indentation level of each line, must not be negative.
 384  
      * @param indentSize The size of each indentation, must not be negative.
 385  
      * @param lineLength The length of the line, must not be negative.
 386  
      * @return The sequence of display lines, never <code>null</code>.
 387  
      * @throws NegativeArraySizeException if <code>indent < 0</code>
 388  
      */
 389  
     private static List toLines( String text, int indent, int indentSize, int lineLength )
 390  
     {
 391  0
         List lines = new ArrayList();
 392  
 
 393  0
         String ind = repeat( "\t", indent );
 394  0
         String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" );
 395  0
         for ( int i = 0; i < plainLines.length; i++ )
 396  
         {
 397  0
             toLines( lines, ind + plainLines[i], indentSize, lineLength );
 398  
         }
 399  
 
 400  0
         return lines;
 401  
     }
 402  
 
 403  
     /** 
 404  
      * Adds the specified line to the output sequence, performing line wrapping if necessary.
 405  
      * 
 406  
      * @param lines The sequence of display lines, must not be <code>null</code>.
 407  
      * @param line The line to add, must not be <code>null</code>.
 408  
      * @param indentSize The size of each indentation, must not be negative.
 409  
      * @param lineLength The length of the line, must not be negative.
 410  
      */
 411  
     private static void toLines( List lines, String line, int indentSize, int lineLength )
 412  
     {
 413  0
         int lineIndent = getIndentLevel( line );
 414  0
         StringBuffer buf = new StringBuffer( 256 );
 415  0
         String[] tokens = line.split( " +" );
 416  0
         for ( int i = 0; i < tokens.length; i++ )
 417  
         {
 418  0
             String token = tokens[i];
 419  0
             if ( i > 0 )
 420  
             {
 421  0
                 if ( buf.length() + token.length() >= lineLength )
 422  
                 {
 423  0
                     lines.add( buf.toString() );
 424  0
                     buf.setLength( 0 );
 425  0
                     buf.append( repeat( " ", lineIndent * indentSize ) );
 426  
                 }
 427  
                 else
 428  
                 {
 429  0
                     buf.append( ' ' );
 430  
                 }
 431  
             }
 432  0
             for ( int j = 0; j < token.length(); j++ )
 433  
             {
 434  0
                 char c = token.charAt( j );
 435  0
                 if ( c == '\t' )
 436  
                 {
 437  0
                     buf.append( repeat( " ", indentSize - buf.length() % indentSize ) );
 438  
                 }
 439  0
                 else if ( c == '\u00A0' )
 440  
                 {
 441  0
                     buf.append( ' ' );
 442  
                 }
 443  
                 else
 444  
                 {
 445  0
                     buf.append( c );
 446  
                 }
 447  
             }
 448  
         }
 449  0
         lines.add( buf.toString() );
 450  0
     }
 451  
 
 452  
     /** 
 453  
      * Gets the indentation level of the specified line.
 454  
      * 
 455  
      * @param line The line whose indentation level should be retrieved, must not be <code>null</code>.
 456  
      * @return The indentation level of the line.
 457  
      */
 458  
     private static int getIndentLevel( String line )
 459  
     {
 460  0
         int level = 0;
 461  0
         for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ )
 462  
         {
 463  0
             level++;
 464  
         }
 465  0
         for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ )
 466  
         {
 467  0
             if ( line.charAt( i ) == '\t' )
 468  
             {
 469  0
                 level++;
 470  0
                 break;
 471  
             }
 472  
         }
 473  0
         return level;
 474  
     }
 475  
 }