Coverage Report - org.apache.maven.plugins.enforcer.HelpMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
HelpMojo
0%
0/144
0%
0/70
6.833
 
 1  
 package org.apache.maven.plugins.enforcer;
 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-enforcer-plugin.<br/> Call <pre>  mvn enforcer:help -Ddetail=true -Dgoal=&lt;goal-name&gt;</pre> to display parameter details.
 12  
  *
 13  
  * @version generated on Tue May 08 21:10:26 CDT 2012
 14  
  * @author org.apache.maven.tools.plugin.generator.PluginHelpGenerator (version 2.7)
 15  
  * @goal help
 16  
  * @requiresProject false
 17  
  * @threadSafe
 18  
  */
 19  
 @SuppressWarnings( "all" )
 20  0
 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  0
         if ( lineLength <= 0 )
 57  
         {
 58  0
             getLog().warn( "The parameter 'lineLength' should be positive, using '80' as default." );
 59  0
             lineLength = 80;
 60  
         }
 61  0
         if ( indentSize <= 0 )
 62  
         {
 63  0
             getLog().warn( "The parameter 'indentSize' should be positive, using '2' as default." );
 64  0
             indentSize = 2;
 65  
         }
 66  
 
 67  0
         StringBuffer sb = new StringBuffer();
 68  
 
 69  0
         append( sb, "org.apache.maven.plugins:maven-enforcer-plugin:1.1", 0 );
 70  0
         append( sb, "", 0 );
 71  
 
 72  0
         append( sb, "Maven Enforcer Plugin", 0 );
 73  0
         append( sb, "The Loving Iron Fist of Maven", 1 );
 74  0
         append( sb, "", 0 );
 75  
 
 76  0
         if ( goal == null || goal.length() <= 0 )
 77  
         {
 78  0
             append( sb, "This plugin has 4 goals:", 0 );
 79  0
             append( sb, "", 0 );
 80  
         }
 81  
 
 82  0
         if ( goal == null || goal.length() <= 0 || "display-info".equals( goal ) )
 83  
         {
 84  0
             append( sb, "enforcer:display-info", 0 );
 85  0
             append( sb, "This goal displays the current platform information.", 1 );
 86  0
             append( sb, "", 0 );
 87  0
             if ( detail )
 88  
             {
 89  0
                 append( sb, "Available parameters:", 1 );
 90  0
                 append( sb, "", 0 );
 91  
             }
 92  
         }
 93  
 
 94  0
         if ( goal == null || goal.length() <= 0 || "enforce".equals( goal ) )
 95  
         {
 96  0
             append( sb, "enforcer:enforce", 0 );
 97  0
             append( sb, "This goal executes the defined enforcer-rules once per module.", 1 );
 98  0
             append( sb, "", 0 );
 99  0
             if ( detail )
 100  
             {
 101  0
                 append( sb, "Available parameters:", 1 );
 102  0
                 append( sb, "", 0 );
 103  
 
 104  0
                 append( sb, "fail (Default: true)", 2 );
 105  0
                 append( sb, "Flag to fail the build if a version check fails.", 3 );
 106  0
                 append( sb, "Expression: ${enforcer.fail}", 3 );
 107  0
                 append( sb, "", 0 );
 108  
 
 109  0
                 append( sb, "failFast (Default: false)", 2 );
 110  0
                 append( sb, "Fail on the first rule that doesn\'t pass", 3 );
 111  0
                 append( sb, "Expression: ${enforcer.failFast}", 3 );
 112  0
                 append( sb, "", 0 );
 113  
 
 114  0
                 append( sb, "ignoreCache (Default: false)", 2 );
 115  0
                 append( sb, "Use this flag to disable rule result caching. This will cause all rules to execute on each project even if the rule indicates it can safely be cached.", 3 );
 116  0
                 append( sb, "Expression: ${enforcer.ignoreCache}", 3 );
 117  0
                 append( sb, "", 0 );
 118  
 
 119  0
                 append( sb, "rules", 2 );
 120  0
                 append( sb, "Array of objects that implement the EnforcerRule interface to execute.", 3 );
 121  0
                 append( sb, "Required: Yes", 3 );
 122  0
                 append( sb, "", 0 );
 123  
 
 124  0
                 append( sb, "skip (Default: false)", 2 );
 125  0
                 append( sb, "Flag to easily skip all checks", 3 );
 126  0
                 append( sb, "Expression: ${enforcer.skip}", 3 );
 127  0
                 append( sb, "", 0 );
 128  
             }
 129  
         }
 130  
 
 131  0
         if ( goal == null || goal.length() <= 0 || "enforce-once".equals( goal ) )
 132  
         {
 133  0
             append( sb, "enforcer:enforce-once", 0 );
 134  0
             append( sb, "This goal has been deprecated.", 1 );
 135  0
             append( sb, "", 0 );
 136  0
             if ( detail )
 137  
             {
 138  0
                 append( sb, "Available parameters:", 1 );
 139  0
                 append( sb, "", 0 );
 140  
 
 141  0
                 append( sb, "fail (Default: true)", 2 );
 142  0
                 append( sb, "Flag to fail the build if a version check fails.", 3 );
 143  0
                 append( sb, "Expression: ${enforcer.fail}", 3 );
 144  0
                 append( sb, "", 0 );
 145  
 
 146  0
                 append( sb, "failFast (Default: false)", 2 );
 147  0
                 append( sb, "Fail on the first rule that doesn\'t pass", 3 );
 148  0
                 append( sb, "Expression: ${enforcer.failFast}", 3 );
 149  0
                 append( sb, "", 0 );
 150  
 
 151  0
                 append( sb, "ignoreCache (Default: false)", 2 );
 152  0
                 append( sb, "Use this flag to disable rule result caching. This will cause all rules to execute on each project even if the rule indicates it can safely be cached.", 3 );
 153  0
                 append( sb, "Expression: ${enforcer.ignoreCache}", 3 );
 154  0
                 append( sb, "", 0 );
 155  
 
 156  0
                 append( sb, "rules", 2 );
 157  0
                 append( sb, "Array of objects that implement the EnforcerRule interface to execute.", 3 );
 158  0
                 append( sb, "Required: Yes", 3 );
 159  0
                 append( sb, "", 0 );
 160  
 
 161  0
                 append( sb, "skip (Default: false)", 2 );
 162  0
                 append( sb, "Flag to easily skip all checks", 3 );
 163  0
                 append( sb, "Expression: ${enforcer.skip}", 3 );
 164  0
                 append( sb, "", 0 );
 165  
             }
 166  
         }
 167  
 
 168  0
         if ( goal == null || goal.length() <= 0 || "help".equals( goal ) )
 169  
         {
 170  0
             append( sb, "enforcer:help", 0 );
 171  0
             append( sb, "Display help information on maven-enforcer-plugin.\nCall\n\u00a0\u00a0mvn\u00a0enforcer:help\u00a0-Ddetail=true\u00a0-Dgoal=<goal-name>\nto display parameter details.", 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, "detail (Default: false)", 2 );
 179  0
                 append( sb, "If true, display all settable properties for each goal.", 3 );
 180  0
                 append( sb, "Expression: ${detail}", 3 );
 181  0
                 append( sb, "", 0 );
 182  
 
 183  0
                 append( sb, "goal", 2 );
 184  0
                 append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 );
 185  0
                 append( sb, "Expression: ${goal}", 3 );
 186  0
                 append( sb, "", 0 );
 187  
 
 188  0
                 append( sb, "indentSize (Default: 2)", 2 );
 189  0
                 append( sb, "The number of spaces per indentation level, should be positive.", 3 );
 190  0
                 append( sb, "Expression: ${indentSize}", 3 );
 191  0
                 append( sb, "", 0 );
 192  
 
 193  0
                 append( sb, "lineLength (Default: 80)", 2 );
 194  0
                 append( sb, "The maximum length of a display line, should be positive.", 3 );
 195  0
                 append( sb, "Expression: ${lineLength}", 3 );
 196  0
                 append( sb, "", 0 );
 197  
             }
 198  
         }
 199  
 
 200  0
         if ( getLog().isInfoEnabled() )
 201  
         {
 202  0
             getLog().info( sb.toString() );
 203  
         }
 204  0
     }
 205  
 
 206  
     /**
 207  
      * <p>Repeat a String <code>n</code> times to form a new string.</p>
 208  
      *
 209  
      * @param str String to repeat
 210  
      * @param repeat number of times to repeat str
 211  
      * @return String with repeated String
 212  
      * @throws NegativeArraySizeException if <code>repeat < 0</code>
 213  
      * @throws NullPointerException if str is <code>null</code>
 214  
      */
 215  
     private static String repeat( String str, int repeat )
 216  
     {
 217  0
         StringBuffer buffer = new StringBuffer( repeat * str.length() );
 218  
 
 219  0
         for ( int i = 0; i < repeat; i++ )
 220  
         {
 221  0
             buffer.append( str );
 222  
         }
 223  
 
 224  0
         return buffer.toString();
 225  
     }
 226  
 
 227  
     /** 
 228  
      * Append a description to the buffer by respecting the indentSize and lineLength parameters.
 229  
      * <b>Note</b>: The last character is always a new line.
 230  
      * 
 231  
      * @param sb The buffer to append the description, not <code>null</code>.
 232  
      * @param description The description, not <code>null</code>.
 233  
      * @param indent The base indentation level of each line, must not be negative.
 234  
      */
 235  
     private void append( StringBuffer sb, String description, int indent )
 236  
     {
 237  0
         for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); )
 238  
         {
 239  0
             sb.append( it.next().toString() ).append( '\n' );
 240  
         }
 241  0
     }
 242  
 
 243  
     /** 
 244  
      * Splits the specified text into lines of convenient display length.
 245  
      * 
 246  
      * @param text The text to split into lines, must not be <code>null</code>.
 247  
      * @param indent The base indentation level of each line, must not be negative.
 248  
      * @param indentSize The size of each indentation, must not be negative.
 249  
      * @param lineLength The length of the line, must not be negative.
 250  
      * @return The sequence of display lines, never <code>null</code>.
 251  
      * @throws NegativeArraySizeException if <code>indent < 0</code>
 252  
      */
 253  
     private static List toLines( String text, int indent, int indentSize, int lineLength )
 254  
     {
 255  0
         List lines = new ArrayList();
 256  
 
 257  0
         String ind = repeat( "\t", indent );
 258  0
         String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" );
 259  0
         for ( int i = 0; i < plainLines.length; i++ )
 260  
         {
 261  0
             toLines( lines, ind + plainLines[i], indentSize, lineLength );
 262  
         }
 263  
 
 264  0
         return lines;
 265  
     }
 266  
 
 267  
     /** 
 268  
      * Adds the specified line to the output sequence, performing line wrapping if necessary.
 269  
      * 
 270  
      * @param lines The sequence of display lines, must not be <code>null</code>.
 271  
      * @param line The line to add, must not be <code>null</code>.
 272  
      * @param indentSize The size of each indentation, must not be negative.
 273  
      * @param lineLength The length of the line, must not be negative.
 274  
      */
 275  
     private static void toLines( List lines, String line, int indentSize, int lineLength )
 276  
     {
 277  0
         int lineIndent = getIndentLevel( line );
 278  0
         StringBuffer buf = new StringBuffer( 256 );
 279  0
         String[] tokens = line.split( " +" );
 280  0
         for ( int i = 0; i < tokens.length; i++ )
 281  
         {
 282  0
             String token = tokens[i];
 283  0
             if ( i > 0 )
 284  
             {
 285  0
                 if ( buf.length() + token.length() >= lineLength )
 286  
                 {
 287  0
                     lines.add( buf.toString() );
 288  0
                     buf.setLength( 0 );
 289  0
                     buf.append( repeat( " ", lineIndent * indentSize ) );
 290  
                 }
 291  
                 else
 292  
                 {
 293  0
                     buf.append( ' ' );
 294  
                 }
 295  
             }
 296  0
             for ( int j = 0; j < token.length(); j++ )
 297  
             {
 298  0
                 char c = token.charAt( j );
 299  0
                 if ( c == '\t' )
 300  
                 {
 301  0
                     buf.append( repeat( " ", indentSize - buf.length() % indentSize ) );
 302  
                 }
 303  0
                 else if ( c == '\u00A0' )
 304  
                 {
 305  0
                     buf.append( ' ' );
 306  
                 }
 307  
                 else
 308  
                 {
 309  0
                     buf.append( c );
 310  
                 }
 311  
             }
 312  
         }
 313  0
         lines.add( buf.toString() );
 314  0
     }
 315  
 
 316  
     /** 
 317  
      * Gets the indentation level of the specified line.
 318  
      * 
 319  
      * @param line The line whose indentation level should be retrieved, must not be <code>null</code>.
 320  
      * @return The indentation level of the line.
 321  
      */
 322  
     private static int getIndentLevel( String line )
 323  
     {
 324  0
         int level = 0;
 325  0
         for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ )
 326  
         {
 327  0
             level++;
 328  
         }
 329  0
         for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ )
 330  
         {
 331  0
             if ( line.charAt( i ) == '\t' )
 332  
             {
 333  0
                 level++;
 334  0
                 break;
 335  
             }
 336  
         }
 337  0
         return level;
 338  
     }
 339  
 }