Coverage Report - org.apache.maven.plugins.help.HelpMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
HelpMojo
14 %
27/189
14 %
15/110
6,667
 
 1  
 package org.apache.maven.plugins.help;
 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-help-plugin.<br/> Call <pre>  mvn help:help -Ddetail=true -Dgoal=&lt;goal-name&gt;</pre> to display parameter details.
 12  
  *
 13  
  * @version generated on Sun Aug 31 11:24:31 EDT 2008
 14  
  * @author org.apache.maven.tools.plugin.generator.PluginHelpGenerator (version 2.4.3)
 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-help-plugin:2.1", 0 );
 68  0
         append( sb, "", 0 );
 69  
 
 70  0
         append( sb, "Maven Help Plugin 2.1", 0 );
 71  0
         append( sb, "The Maven Help plugin provides goals aimed at helping to make sense out of the build environment. It includes the ability to view the effective POM and settings files, after inheritance and active profiles have been applied, as well as a describe a particular plugin goal to give usage information.", 1 );
 72  0
         append( sb, "", 0 );
 73  
 
 74  0
         if ( goal == null || goal.length() <= 0 )
 75  
         {
 76  0
             append( sb, "This plugin has 9 goals:", 0 );
 77  0
             append( sb, "", 0 );
 78  
         }
 79  
 
 80  0
         if ( goal == null || goal.length() <= 0 || "active-profiles".equals( goal ) )
 81  
         {
 82  0
             append( sb, "help:active-profiles", 0 );
 83  0
             append( sb, "Displays a list of the profiles which are currently active for this build.", 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, "output", 2 );
 91  0
                 append( sb, "Optional parameter to write the output of this help in a given file, instead of writing to the console.\nNote: Could be a relative path.", 3 );
 92  0
                 append( sb, "", 0 );
 93  
             }
 94  
         }
 95  
 
 96  0
         if ( goal == null || goal.length() <= 0 || "all-profiles".equals( goal ) )
 97  
         {
 98  0
             append( sb, "help:all-profiles", 0 );
 99  0
             append( sb, "Displays a list of available profiles under the current project.\nNote: it will list all profiles for a project. If a profile comes up with a status inactive then there might be a need to set profile activation switches/property.", 1 );
 100  0
             append( sb, "", 0 );
 101  0
             if ( detail )
 102  
             {
 103  0
                 append( sb, "Available parameters:", 1 );
 104  0
                 append( sb, "", 0 );
 105  
 
 106  0
                 append( sb, "output", 2 );
 107  0
                 append( sb, "Optional parameter to write the output of this help in a given file, instead of writing to the console.\nNote: Could be a relative path.", 3 );
 108  0
                 append( sb, "", 0 );
 109  
             }
 110  
         }
 111  
 
 112  0
         if ( goal == null || goal.length() <= 0 || "describe".equals( goal ) )
 113  
         {
 114  0
             append( sb, "help:describe", 0 );
 115  0
             append( sb, "Displays a list of the attributes for a Maven Plugin and/or goals (aka Mojo - Maven plain Old Java Object).", 1 );
 116  0
             append( sb, "", 0 );
 117  0
             if ( detail )
 118  
             {
 119  0
                 append( sb, "Available parameters:", 1 );
 120  0
                 append( sb, "", 0 );
 121  
 
 122  0
                 append( sb, "artifactId", 2 );
 123  0
                 append( sb, "The Maven Plugin artifactId to describe.\nNote: Should be used with groupId parameter.", 3 );
 124  0
                 append( sb, "", 0 );
 125  
 
 126  0
                 append( sb, "cmd", 2 );
 127  0
                 append( sb, "A Maven command like a single goal or a single phase following the Maven command line:\nmvn [options] [<goal(s)>] [<phase(s)>]", 3 );
 128  0
                 append( sb, "", 0 );
 129  
 
 130  0
                 append( sb, "detail (Default: false)", 2 );
 131  0
                 append( sb, "This flag specifies that a detailed (verbose) list of goal (Mojo) information should be given.", 3 );
 132  0
                 append( sb, "", 0 );
 133  
 
 134  0
                 append( sb, "goal", 2 );
 135  0
                 append( sb, "The goal name of a Mojo to describe within the specified Maven Plugin. If this parameter is specified, only the corresponding goal (Mojo) will be described, rather than the whole Plugin.", 3 );
 136  0
                 append( sb, "", 0 );
 137  
 
 138  0
                 append( sb, "groupId", 2 );
 139  0
                 append( sb, "The Maven Plugin groupId to describe.\nNote: Should be used with artifactId parameter.", 3 );
 140  0
                 append( sb, "", 0 );
 141  
 
 142  0
                 append( sb, "medium (Default: true)", 2 );
 143  0
                 append( sb, "This flag specifies that a medium list of goal (Mojo) information should be given.", 3 );
 144  0
                 append( sb, "", 0 );
 145  
 
 146  0
                 append( sb, "minimal (Default: false)", 2 );
 147  0
                 append( sb, "This flag specifies that a minimal list of goal (Mojo) information should be given.", 3 );
 148  0
                 append( sb, "", 0 );
 149  
 
 150  0
                 append( sb, "output", 2 );
 151  0
                 append( sb, "Optional parameter to write the output of this help in a given file, instead of writing to the console.\nNote: Could be a relative path.", 3 );
 152  0
                 append( sb, "", 0 );
 153  
 
 154  0
                 append( sb, "plugin", 2 );
 155  0
                 append( sb, "The Maven Plugin to describe. This must be specified in one of three ways:\n\n1.\tplugin-prefix, i.e. \'help\'\n2.\tgroupId:artifactId, i.e. \'org.apache.maven.plugins:maven-help-plugin\'\n3.\tgroupId:artifactId:version, i.e. \'org.apache.maven.plugins:maven-help-plugin:2.0\'\n", 3 );
 156  0
                 append( sb, "", 0 );
 157  
 
 158  0
                 append( sb, "version", 2 );
 159  0
                 append( sb, "The Maven Plugin version to describe.\nNote: Should be used with groupId/artifactId parameters.", 3 );
 160  0
                 append( sb, "", 0 );
 161  
             }
 162  
         }
 163  
 
 164  0
         if ( goal == null || goal.length() <= 0 || "effective-pom".equals( goal ) )
 165  
         {
 166  0
             append( sb, "help:effective-pom", 0 );
 167  0
             append( sb, "Displays the effective POM as an XML for this build, with the active profiles factored in.", 1 );
 168  0
             append( sb, "", 0 );
 169  0
             if ( detail )
 170  
             {
 171  0
                 append( sb, "Available parameters:", 1 );
 172  0
                 append( sb, "", 0 );
 173  
 
 174  0
                 append( sb, "output", 2 );
 175  0
                 append( sb, "Optional parameter to write the output of this help in a given file, instead of writing to the console.\nNote: Could be a relative path.", 3 );
 176  0
                 append( sb, "", 0 );
 177  
             }
 178  
         }
 179  
 
 180  0
         if ( goal == null || goal.length() <= 0 || "effective-settings".equals( goal ) )
 181  
         {
 182  0
             append( sb, "help:effective-settings", 0 );
 183  0
             append( sb, "Displays the calculated settings as XML for this project, given any profile enhancement and the inheritance of the global settings into the user-level settings.", 1 );
 184  0
             append( sb, "", 0 );
 185  0
             if ( detail )
 186  
             {
 187  0
                 append( sb, "Available parameters:", 1 );
 188  0
                 append( sb, "", 0 );
 189  
 
 190  0
                 append( sb, "output", 2 );
 191  0
                 append( sb, "Optional parameter to write the output of this help in a given file, instead of writing to the console.\nNote: Could be a relative path.", 3 );
 192  0
                 append( sb, "", 0 );
 193  
 
 194  0
                 append( sb, "showPasswords (Default: false)", 2 );
 195  0
                 append( sb, "For security reasons, all passwords are hidden by default. Set this to true to show all passwords.", 3 );
 196  0
                 append( sb, "", 0 );
 197  
             }
 198  
         }
 199  
 
 200  0
         if ( goal == null || goal.length() <= 0 || "evaluate".equals( goal ) )
 201  
         {
 202  0
             append( sb, "help:evaluate", 0 );
 203  0
             append( sb, "Evaluates Maven expressions given by the user in an interactive mode.", 1 );
 204  0
             append( sb, "", 0 );
 205  0
             if ( detail )
 206  
             {
 207  0
                 append( sb, "Available parameters:", 1 );
 208  0
                 append( sb, "", 0 );
 209  
 
 210  0
                 append( sb, "artifact", 2 );
 211  0
                 append( sb, "An artifact for evaluating Maven expressions.\nNote: Should respect the Maven format, i.e. groupId:artifactId[:version][:classifier].", 3 );
 212  0
                 append( sb, "", 0 );
 213  
             }
 214  
         }
 215  
 
 216  0
         if ( goal == null || goal.length() <= 0 || "expressions".equals( goal ) )
 217  
         {
 218  0
             append( sb, "help:expressions", 0 );
 219  0
             append( sb, "Displays the supported Plugin expressions used by Maven.", 1 );
 220  0
             append( sb, "", 0 );
 221  0
             if ( detail )
 222  
             {
 223  0
                 append( sb, "Available parameters:", 1 );
 224  0
                 append( sb, "", 0 );
 225  
 
 226  0
                 append( sb, "output", 2 );
 227  0
                 append( sb, "Optional parameter to write the output of this help in a given file, instead of writing to the console.\nNote: Could be a relative path.", 3 );
 228  0
                 append( sb, "", 0 );
 229  
             }
 230  
         }
 231  
 
 232  0
         if ( goal == null || goal.length() <= 0 || "help".equals( goal ) )
 233  
         {
 234  0
             append( sb, "help:help", 0 );
 235  0
             append( sb, "Display help information on maven-help-plugin.\nCall\n\u00a0\u00a0mvn\u00a0help:help\u00a0-Ddetail=true\u00a0-Dgoal=<goal-name>\nto display parameter details.", 1 );
 236  0
             append( sb, "", 0 );
 237  0
             if ( detail )
 238  
             {
 239  0
                 append( sb, "Available parameters:", 1 );
 240  0
                 append( sb, "", 0 );
 241  
 
 242  0
                 append( sb, "detail (Default: false)", 2 );
 243  0
                 append( sb, "If true, display all settable properties for each goal.", 3 );
 244  0
                 append( sb, "", 0 );
 245  
 
 246  0
                 append( sb, "goal", 2 );
 247  0
                 append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 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  0
                 append( sb, "indentSize (Default: 2)", 2 );
 255  0
                 append( sb, "The number of spaces per indentation level, should be positive.", 3 );
 256  0
                 append( sb, "", 0 );
 257  
             }
 258  
         }
 259  
 
 260  0
         if ( goal == null || goal.length() <= 0 || "system".equals( goal ) )
 261  
         {
 262  0
             append( sb, "help:system", 0 );
 263  0
             append( sb, "Displays a list of the platform details like system properties and environment variables.", 1 );
 264  0
             append( sb, "", 0 );
 265  0
             if ( detail )
 266  
             {
 267  0
                 append( sb, "Available parameters:", 1 );
 268  0
                 append( sb, "", 0 );
 269  
 
 270  0
                 append( sb, "output", 2 );
 271  0
                 append( sb, "Optional parameter to write the output of this help in a given file, instead of writing to the console.\nNote: Could be a relative path.", 3 );
 272  0
                 append( sb, "", 0 );
 273  
             }
 274  
         }
 275  
 
 276  0
         if ( getLog().isInfoEnabled() )
 277  
         {
 278  0
             getLog().info( sb.toString() );
 279  
         }
 280  0
     }
 281  
 
 282  
     /**
 283  
      * <p>Repeat a String <code>n</code> times to form a new string.</p>
 284  
      *
 285  
      * @param str String to repeat
 286  
      * @param repeat number of times to repeat str
 287  
      * @return String with repeated String
 288  
      * @throws NegativeArraySizeException if <code>repeat < 0</code>
 289  
      * @throws NullPointerException if str is <code>null</code>
 290  
      */
 291  
     private static String repeat( String str, int repeat )
 292  
     {
 293  3
         StringBuffer buffer = new StringBuffer( repeat * str.length() );
 294  
 
 295  9
         for ( int i = 0; i < repeat; i++ )
 296  
         {
 297  6
             buffer.append( str );
 298  
         }
 299  
 
 300  3
         return buffer.toString();
 301  
     }
 302  
 
 303  
     /** 
 304  
      * Append a description to the buffer by respecting the indentSize and lineLength parameters.
 305  
      * <b>Note</b>: The last character is always a new line.
 306  
      * 
 307  
      * @param sb The buffer to append the description, not <code>null</code>.
 308  
      * @param description The description, not <code>null</code>.
 309  
      * @param indent The base indentation level of each line, must not be negative.
 310  
      */
 311  
     private void append( StringBuffer sb, String description, int indent )
 312  
     {
 313  0
         for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); )
 314  
         {
 315  0
             sb.append( it.next().toString() ).append( '\n' );
 316  
         }
 317  0
     }
 318  
 
 319  
     /** 
 320  
      * Splits the specified text into lines of convenient display length.
 321  
      * 
 322  
      * @param text The text to split into lines, must not be <code>null</code>.
 323  
      * @param indent The base indentation level of each line, must not be negative.
 324  
      * @param indentSize The size of each indentation, must not be negative.
 325  
      * @param lineLength The length of the line, must not be negative.
 326  
      * @return The sequence of display lines, never <code>null</code>.
 327  
      * @throws NegativeArraySizeException if <code>indent < 0</code>
 328  
      */
 329  
     private static List toLines( String text, int indent, int indentSize, int lineLength )
 330  
     {
 331  1
         List lines = new ArrayList();
 332  
 
 333  1
         String ind = repeat( "\t", indent );
 334  1
         String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" );
 335  2
         for ( int i = 0; i < plainLines.length; i++ )
 336  
         {
 337  1
             toLines( lines, ind + plainLines[i], indentSize, lineLength );
 338  
         }
 339  
 
 340  1
         return lines;
 341  
     }
 342  
 
 343  
     /** 
 344  
      * Adds the specified line to the output sequence, performing line wrapping if necessary.
 345  
      * 
 346  
      * @param lines The sequence of display lines, must not be <code>null</code>.
 347  
      * @param line The line to add, must not be <code>null</code>.
 348  
      * @param indentSize The size of each indentation, must not be negative.
 349  
      * @param lineLength The length of the line, must not be negative.
 350  
      */
 351  
     private static void toLines( List lines, String line, int indentSize, int lineLength )
 352  
     {
 353  1
         int lineIndent = getIndentLevel( line );
 354  1
         StringBuffer buf = new StringBuffer( 256 );
 355  1
         String[] tokens = line.split( " +" );
 356  2
         for ( int i = 0; i < tokens.length; i++ )
 357  
         {
 358  1
             String token = tokens[i];
 359  1
             if ( i > 0 )
 360  
             {
 361  0
                 if ( buf.length() + token.length() >= lineLength )
 362  
                 {
 363  0
                     lines.add( buf.toString() );
 364  0
                     buf.setLength( 0 );
 365  0
                     buf.append( repeat( " ", lineIndent * indentSize ) );
 366  
                 }
 367  
                 else
 368  
                 {
 369  0
                     buf.append( ' ' );
 370  
                 }
 371  
             }
 372  3
             for ( int j = 0; j < token.length(); j++ )
 373  
             {
 374  2
                 char c = token.charAt( j );
 375  2
                 if ( c == '\t' )
 376  
                 {
 377  2
                     buf.append( repeat( " ", indentSize - buf.length() % indentSize ) );
 378  
                 }
 379  0
                 else if ( c == '\u00A0' )
 380  
                 {
 381  0
                     buf.append( ' ' );
 382  
                 }
 383  
                 else
 384  
                 {
 385  0
                     buf.append( c );
 386  
                 }
 387  
             }
 388  
         }
 389  1
         lines.add( buf.toString() );
 390  1
     }
 391  
 
 392  
     /** 
 393  
      * Gets the indentation level of the specified line.
 394  
      * 
 395  
      * @param line The line whose indentation level should be retrieved, must not be <code>null</code>.
 396  
      * @return The indentation level of the line.
 397  
      */
 398  
     private static int getIndentLevel( String line )
 399  
     {
 400  1
         int level = 0;
 401  3
         for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ )
 402  
         {
 403  2
             level++;
 404  
         }
 405  1
         for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ )
 406  
         {
 407  0
             if ( line.charAt( i ) == '\t' )
 408  
             {
 409  0
                 level++;
 410  0
                 break;
 411  
             }
 412  
         }
 413  1
         return level;
 414  
     }
 415  
 }