Coverage Report - org.apache.maven.plugin.resources.HelpMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
HelpMojo
0%
0/202
0%
0/70
5
 
 1  
 package org.apache.maven.plugin.resources;
 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-resources-plugin.<br/> Call <pre>  mvn resources:help -Ddetail=true -Dgoal=&lt;goal-name&gt;</pre> to display parameter details.
 12  
  *
 13  
  * @version generated on Wed Sep 30 13:27:10 EDT 2009
 14  
  * @author org.apache.maven.tools.plugin.generator.PluginHelpGenerator (version 2.5)
 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-resources-plugin:2.4.1", 0 );
 68  0
         append( sb, "", 0 );
 69  
 
 70  0
         append( sb, "Maven Resources Plugin", 0 );
 71  0
         append( sb, "The Resources Plugin handles the copying of project resources to the output directory. There are two different kinds of resources: main resources and test resources. The difference is that the main resources are the resources associated to the main source code while the test resources are associated to the test source code. Thus, this allows the separation of resources for the main source code and its unit tests.", 1 );
 72  0
         append( sb, "", 0 );
 73  
 
 74  0
         if ( goal == null || goal.length() <= 0 )
 75  
         {
 76  0
             append( sb, "This plugin has 4 goals:", 0 );
 77  0
             append( sb, "", 0 );
 78  
         }
 79  
 
 80  0
         if ( goal == null || goal.length() <= 0 || "copy-resources".equals( goal ) )
 81  
         {
 82  0
             append( sb, "resources:copy-resources", 0 );
 83  0
             append( sb, "Copy resources of the configured plugin attribute resources", 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, "delimiters", 2 );
 91  0
                 append( sb, "Set of delimiters for expressions to filter within the resources. These delimiters are specified in the form \'beginToken*endToken\'. If no \'*\' is given, the delimiter is assumed to be the same for start and end.\n\nSo, the default filtering delimiters might be specified as:\n\n<delimiters>\n<delimiter>${*}</delimiter>\n<delimiter>@</delimiter>\n</delimiters>\n\nSince the \'@\' delimiter is the same on both ends, we don\'t need to specify \'@*@\' (though we can).\n", 3 );
 92  0
                 append( sb, "", 0 );
 93  
 
 94  0
                 append( sb, "encoding (Default: ${project.build.sourceEncoding})", 2 );
 95  0
                 append( sb, "The character encoding scheme to be applied when filtering resources.", 3 );
 96  0
                 append( sb, "", 0 );
 97  
 
 98  0
                 append( sb, "escapeString (Default: ${maven.resources.escapeString})", 2 );
 99  0
                 append( sb, "Expression preceded with the String won\'t be interpolated \\${foo} will be replaced with ${foo}", 3 );
 100  0
                 append( sb, "", 0 );
 101  
 
 102  0
                 append( sb, "escapeWindowsPaths (Default: true)", 2 );
 103  0
                 append( sb, "Whether to escape backslashes and colons in windows-style paths.", 3 );
 104  0
                 append( sb, "", 0 );
 105  
 
 106  0
                 append( sb, "filters", 2 );
 107  0
                 append( sb, "The list of extra filter properties files to be used along with System properties, project properties, and filter properties files specified in the POM build/filters section, which should be used for the filtering during the current mojo execution.\nNormally, these will be configured from a plugin\'s execution section, to provide a different set of filters for a particular execution. For instance, starting in Maven 2.2.0, you have the option of configuring executions with the id\'s default-resources and default-testResources to supply different configurations for the two different types of resources. By supplying extraFilters configurations, you can separate which filters are used for which type of resource.", 3 );
 108  0
                 append( sb, "", 0 );
 109  
 
 110  0
                 append( sb, "includeEmptyDirs (Default: false)", 2 );
 111  0
                 append( sb, "Copy any empty directories included in the Ressources.", 3 );
 112  0
                 append( sb, "", 0 );
 113  
 
 114  0
                 append( sb, "nonFilteredFileExtensions", 2 );
 115  0
                 append( sb, "Additionnal file extensions to not apply filtering (already defined are : jpg, jpeg, gif, bmp, png)", 3 );
 116  0
                 append( sb, "", 0 );
 117  
 
 118  0
                 append( sb, "outputDirectory", 2 );
 119  0
                 append( sb, "The output directory into which to copy the resources.", 3 );
 120  0
                 append( sb, "", 0 );
 121  
 
 122  0
                 append( sb, "overwrite (Default: false)", 2 );
 123  0
                 append( sb, "Overwrite existing files even if the destination files are newer.", 3 );
 124  0
                 append( sb, "", 0 );
 125  
 
 126  0
                 append( sb, "resources", 2 );
 127  0
                 append( sb, "The list of resources we want to transfer.", 3 );
 128  0
                 append( sb, "", 0 );
 129  
 
 130  0
                 append( sb, "useBuildFilters (Default: true)", 2 );
 131  0
                 append( sb, "If false, don\'t use the filters specified in the build/filters section of the POM when processing resources in this mojo execution.\nSee also: ResourcesMojo.buildFilters and ResourcesMojo.filters", 3 );
 132  0
                 append( sb, "", 0 );
 133  
 
 134  0
                 append( sb, "useDefaultDelimiters (Default: true)", 2 );
 135  0
                 append( sb, "(no description available)", 3 );
 136  0
                 append( sb, "", 0 );
 137  
             }
 138  
         }
 139  
 
 140  0
         if ( goal == null || goal.length() <= 0 || "help".equals( goal ) )
 141  
         {
 142  0
             append( sb, "resources:help", 0 );
 143  0
             append( sb, "Display help information on maven-resources-plugin.\nCall\n\u00a0\u00a0mvn\u00a0resources:help\u00a0-Ddetail=true\u00a0-Dgoal=<goal-name>\nto display parameter details.", 1 );
 144  0
             append( sb, "", 0 );
 145  0
             if ( detail )
 146  
             {
 147  0
                 append( sb, "Available parameters:", 1 );
 148  0
                 append( sb, "", 0 );
 149  
 
 150  0
                 append( sb, "detail (Default: false)", 2 );
 151  0
                 append( sb, "If true, display all settable properties for each goal.", 3 );
 152  0
                 append( sb, "", 0 );
 153  
 
 154  0
                 append( sb, "goal", 2 );
 155  0
                 append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 );
 156  0
                 append( sb, "", 0 );
 157  
 
 158  0
                 append( sb, "indentSize (Default: 2)", 2 );
 159  0
                 append( sb, "The number of spaces per indentation level, should be positive.", 3 );
 160  0
                 append( sb, "", 0 );
 161  
 
 162  0
                 append( sb, "lineLength (Default: 80)", 2 );
 163  0
                 append( sb, "The maximum length of a display line, should be positive.", 3 );
 164  0
                 append( sb, "", 0 );
 165  
             }
 166  
         }
 167  
 
 168  0
         if ( goal == null || goal.length() <= 0 || "resources".equals( goal ) )
 169  
         {
 170  0
             append( sb, "resources:resources", 0 );
 171  0
             append( sb, "Copy resources for the main source code to the main output directory.", 1 );
 172  0
             append( sb, "", 0 );
 173  0
             if ( detail )
 174  
             {
 175  0
                 append( sb, "Available parameters:", 1 );
 176  0
                 append( sb, "", 0 );
 177  
 
 178  0
                 append( sb, "delimiters", 2 );
 179  0
                 append( sb, "Set of delimiters for expressions to filter within the resources. These delimiters are specified in the form \'beginToken*endToken\'. If no \'*\' is given, the delimiter is assumed to be the same for start and end.\n\nSo, the default filtering delimiters might be specified as:\n\n<delimiters>\n<delimiter>${*}</delimiter>\n<delimiter>@</delimiter>\n</delimiters>\n\nSince the \'@\' delimiter is the same on both ends, we don\'t need to specify \'@*@\' (though we can).\n", 3 );
 180  0
                 append( sb, "", 0 );
 181  
 
 182  0
                 append( sb, "encoding (Default: ${project.build.sourceEncoding})", 2 );
 183  0
                 append( sb, "The character encoding scheme to be applied when filtering resources.", 3 );
 184  0
                 append( sb, "", 0 );
 185  
 
 186  0
                 append( sb, "escapeString (Default: ${maven.resources.escapeString})", 2 );
 187  0
                 append( sb, "Expression preceded with the String won\'t be interpolated \\${foo} will be replaced with ${foo}", 3 );
 188  0
                 append( sb, "", 0 );
 189  
 
 190  0
                 append( sb, "escapeWindowsPaths (Default: true)", 2 );
 191  0
                 append( sb, "Whether to escape backslashes and colons in windows-style paths.", 3 );
 192  0
                 append( sb, "", 0 );
 193  
 
 194  0
                 append( sb, "filters", 2 );
 195  0
                 append( sb, "The list of extra filter properties files to be used along with System properties, project properties, and filter properties files specified in the POM build/filters section, which should be used for the filtering during the current mojo execution.\nNormally, these will be configured from a plugin\'s execution section, to provide a different set of filters for a particular execution. For instance, starting in Maven 2.2.0, you have the option of configuring executions with the id\'s default-resources and default-testResources to supply different configurations for the two different types of resources. By supplying extraFilters configurations, you can separate which filters are used for which type of resource.", 3 );
 196  0
                 append( sb, "", 0 );
 197  
 
 198  0
                 append( sb, "includeEmptyDirs (Default: false)", 2 );
 199  0
                 append( sb, "Copy any empty directories included in the Ressources.", 3 );
 200  0
                 append( sb, "", 0 );
 201  
 
 202  0
                 append( sb, "nonFilteredFileExtensions", 2 );
 203  0
                 append( sb, "Additionnal file extensions to not apply filtering (already defined are : jpg, jpeg, gif, bmp, png)", 3 );
 204  0
                 append( sb, "", 0 );
 205  
 
 206  0
                 append( sb, "outputDirectory (Default: ${project.build.outputDirectory})", 2 );
 207  0
                 append( sb, "The output directory into which to copy the resources.", 3 );
 208  0
                 append( sb, "", 0 );
 209  
 
 210  0
                 append( sb, "overwrite (Default: false)", 2 );
 211  0
                 append( sb, "Overwrite existing files even if the destination files are newer.", 3 );
 212  0
                 append( sb, "", 0 );
 213  
 
 214  0
                 append( sb, "useBuildFilters (Default: true)", 2 );
 215  0
                 append( sb, "If false, don\'t use the filters specified in the build/filters section of the POM when processing resources in this mojo execution.\nSee also: ResourcesMojo.buildFilters and ResourcesMojo.filters", 3 );
 216  0
                 append( sb, "", 0 );
 217  
 
 218  0
                 append( sb, "useDefaultDelimiters (Default: true)", 2 );
 219  0
                 append( sb, "(no description available)", 3 );
 220  0
                 append( sb, "", 0 );
 221  
             }
 222  
         }
 223  
 
 224  0
         if ( goal == null || goal.length() <= 0 || "testResources".equals( goal ) )
 225  
         {
 226  0
             append( sb, "resources:testResources", 0 );
 227  0
             append( sb, "Copy resources for the test source code to the test output directory.", 1 );
 228  0
             append( sb, "", 0 );
 229  0
             if ( detail )
 230  
             {
 231  0
                 append( sb, "Available parameters:", 1 );
 232  0
                 append( sb, "", 0 );
 233  
 
 234  0
                 append( sb, "delimiters", 2 );
 235  0
                 append( sb, "Set of delimiters for expressions to filter within the resources. These delimiters are specified in the form \'beginToken*endToken\'. If no \'*\' is given, the delimiter is assumed to be the same for start and end.\n\nSo, the default filtering delimiters might be specified as:\n\n<delimiters>\n<delimiter>${*}</delimiter>\n<delimiter>@</delimiter>\n</delimiters>\n\nSince the \'@\' delimiter is the same on both ends, we don\'t need to specify \'@*@\' (though we can).\n", 3 );
 236  0
                 append( sb, "", 0 );
 237  
 
 238  0
                 append( sb, "encoding (Default: ${project.build.sourceEncoding})", 2 );
 239  0
                 append( sb, "The character encoding scheme to be applied when filtering resources.", 3 );
 240  0
                 append( sb, "", 0 );
 241  
 
 242  0
                 append( sb, "escapeString (Default: ${maven.resources.escapeString})", 2 );
 243  0
                 append( sb, "Expression preceded with the String won\'t be interpolated \\${foo} will be replaced with ${foo}", 3 );
 244  0
                 append( sb, "", 0 );
 245  
 
 246  0
                 append( sb, "escapeWindowsPaths (Default: true)", 2 );
 247  0
                 append( sb, "Whether to escape backslashes and colons in windows-style paths.", 3 );
 248  0
                 append( sb, "", 0 );
 249  
 
 250  0
                 append( sb, "filters", 2 );
 251  0
                 append( sb, "The list of extra filter properties files to be used along with System properties, project properties, and filter properties files specified in the POM build/filters section, which should be used for the filtering during the current mojo execution.\nNormally, these will be configured from a plugin\'s execution section, to provide a different set of filters for a particular execution. For instance, starting in Maven 2.2.0, you have the option of configuring executions with the id\'s default-resources and default-testResources to supply different configurations for the two different types of resources. By supplying extraFilters configurations, you can separate which filters are used for which type of resource.", 3 );
 252  0
                 append( sb, "", 0 );
 253  
 
 254  0
                 append( sb, "includeEmptyDirs (Default: false)", 2 );
 255  0
                 append( sb, "Copy any empty directories included in the Ressources.", 3 );
 256  0
                 append( sb, "", 0 );
 257  
 
 258  0
                 append( sb, "nonFilteredFileExtensions", 2 );
 259  0
                 append( sb, "Additionnal file extensions to not apply filtering (already defined are : jpg, jpeg, gif, bmp, png)", 3 );
 260  0
                 append( sb, "", 0 );
 261  
 
 262  0
                 append( sb, "outputDirectory", 2 );
 263  0
                 append( sb, "The output directory into which to copy the resources.", 3 );
 264  0
                 append( sb, "", 0 );
 265  
 
 266  0
                 append( sb, "overwrite (Default: false)", 2 );
 267  0
                 append( sb, "Overwrite existing files even if the destination files are newer.", 3 );
 268  0
                 append( sb, "", 0 );
 269  
 
 270  0
                 append( sb, "useBuildFilters (Default: true)", 2 );
 271  0
                 append( sb, "If false, don\'t use the filters specified in the build/filters section of the POM when processing resources in this mojo execution.\nSee also: ResourcesMojo.buildFilters and ResourcesMojo.filters", 3 );
 272  0
                 append( sb, "", 0 );
 273  
 
 274  0
                 append( sb, "useDefaultDelimiters (Default: true)", 2 );
 275  0
                 append( sb, "(no description available)", 3 );
 276  0
                 append( sb, "", 0 );
 277  
             }
 278  
         }
 279  
 
 280  0
         if ( getLog().isInfoEnabled() )
 281  
         {
 282  0
             getLog().info( sb.toString() );
 283  
         }
 284  0
     }
 285  
 
 286  
     /**
 287  
      * <p>Repeat a String <code>n</code> times to form a new string.</p>
 288  
      *
 289  
      * @param str String to repeat
 290  
      * @param repeat number of times to repeat str
 291  
      * @return String with repeated String
 292  
      * @throws NegativeArraySizeException if <code>repeat < 0</code>
 293  
      * @throws NullPointerException if str is <code>null</code>
 294  
      */
 295  
     private static String repeat( String str, int repeat )
 296  
     {
 297  0
         StringBuffer buffer = new StringBuffer( repeat * str.length() );
 298  
 
 299  0
         for ( int i = 0; i < repeat; i++ )
 300  
         {
 301  0
             buffer.append( str );
 302  
         }
 303  
 
 304  0
         return buffer.toString();
 305  
     }
 306  
 
 307  
     /** 
 308  
      * Append a description to the buffer by respecting the indentSize and lineLength parameters.
 309  
      * <b>Note</b>: The last character is always a new line.
 310  
      * 
 311  
      * @param sb The buffer to append the description, not <code>null</code>.
 312  
      * @param description The description, not <code>null</code>.
 313  
      * @param indent The base indentation level of each line, must not be negative.
 314  
      */
 315  
     private void append( StringBuffer sb, String description, int indent )
 316  
     {
 317  0
         for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); )
 318  
         {
 319  0
             sb.append( it.next().toString() ).append( '\n' );
 320  
         }
 321  0
     }
 322  
 
 323  
     /** 
 324  
      * Splits the specified text into lines of convenient display length.
 325  
      * 
 326  
      * @param text The text to split into lines, must not be <code>null</code>.
 327  
      * @param indent The base indentation level of each line, must not be negative.
 328  
      * @param indentSize The size of each indentation, must not be negative.
 329  
      * @param lineLength The length of the line, must not be negative.
 330  
      * @return The sequence of display lines, never <code>null</code>.
 331  
      * @throws NegativeArraySizeException if <code>indent < 0</code>
 332  
      */
 333  
     private static List toLines( String text, int indent, int indentSize, int lineLength )
 334  
     {
 335  0
         List lines = new ArrayList();
 336  
 
 337  0
         String ind = repeat( "\t", indent );
 338  0
         String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" );
 339  0
         for ( int i = 0; i < plainLines.length; i++ )
 340  
         {
 341  0
             toLines( lines, ind + plainLines[i], indentSize, lineLength );
 342  
         }
 343  
 
 344  0
         return lines;
 345  
     }
 346  
 
 347  
     /** 
 348  
      * Adds the specified line to the output sequence, performing line wrapping if necessary.
 349  
      * 
 350  
      * @param lines The sequence of display lines, must not be <code>null</code>.
 351  
      * @param line The line to add, must not be <code>null</code>.
 352  
      * @param indentSize The size of each indentation, must not be negative.
 353  
      * @param lineLength The length of the line, must not be negative.
 354  
      */
 355  
     private static void toLines( List lines, String line, int indentSize, int lineLength )
 356  
     {
 357  0
         int lineIndent = getIndentLevel( line );
 358  0
         StringBuffer buf = new StringBuffer( 256 );
 359  0
         String[] tokens = line.split( " +" );
 360  0
         for ( int i = 0; i < tokens.length; i++ )
 361  
         {
 362  0
             String token = tokens[i];
 363  0
             if ( i > 0 )
 364  
             {
 365  0
                 if ( buf.length() + token.length() >= lineLength )
 366  
                 {
 367  0
                     lines.add( buf.toString() );
 368  0
                     buf.setLength( 0 );
 369  0
                     buf.append( repeat( " ", lineIndent * indentSize ) );
 370  
                 }
 371  
                 else
 372  
                 {
 373  0
                     buf.append( ' ' );
 374  
                 }
 375  
             }
 376  0
             for ( int j = 0; j < token.length(); j++ )
 377  
             {
 378  0
                 char c = token.charAt( j );
 379  0
                 if ( c == '\t' )
 380  
                 {
 381  0
                     buf.append( repeat( " ", indentSize - buf.length() % indentSize ) );
 382  
                 }
 383  0
                 else if ( c == '\u00A0' )
 384  
                 {
 385  0
                     buf.append( ' ' );
 386  
                 }
 387  
                 else
 388  
                 {
 389  0
                     buf.append( c );
 390  
                 }
 391  
             }
 392  
         }
 393  0
         lines.add( buf.toString() );
 394  0
     }
 395  
 
 396  
     /** 
 397  
      * Gets the indentation level of the specified line.
 398  
      * 
 399  
      * @param line The line whose indentation level should be retrieved, must not be <code>null</code>.
 400  
      * @return The indentation level of the line.
 401  
      */
 402  
     private static int getIndentLevel( String line )
 403  
     {
 404  0
         int level = 0;
 405  0
         for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ )
 406  
         {
 407  0
             level++;
 408  
         }
 409  0
         for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ )
 410  
         {
 411  0
             if ( line.charAt( i ) == '\t' )
 412  
             {
 413  0
                 level++;
 414  0
                 break;
 415  
             }
 416  
         }
 417  0
         return level;
 418  
     }
 419  
 }