Coverage Report - org.apache.maven.plugins.jarsigner.HelpMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
HelpMojo
0%
0/196
0%
0/62
4,667
 
 1  
 package org.apache.maven.plugins.jarsigner;
 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-jarsigner-plugin.<br/> Call <pre>  mvn jarsigner:help -Ddetail=true -Dgoal=&lt;goal-name&gt;</pre> to display parameter details.
 12  
  *
 13  
  * @version generated on Sun Aug 09 23:34:32 CEST 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-jarsigner-plugin:1.1", 0 );
 68  0
         append( sb, "", 0 );
 69  
 
 70  0
         append( sb, "Maven Jarsigner Plugin", 0 );
 71  0
         append( sb, "Signs or verifies a project artifact and attachments using jarsigner.", 1 );
 72  0
         append( sb, "", 0 );
 73  
 
 74  0
         if ( goal == null || goal.length() <= 0 )
 75  
         {
 76  0
             append( sb, "This plugin has 3 goals:", 0 );
 77  0
             append( sb, "", 0 );
 78  
         }
 79  
 
 80  0
         if ( goal == null || goal.length() <= 0 || "help".equals( goal ) )
 81  
         {
 82  0
             append( sb, "jarsigner:help", 0 );
 83  0
             append( sb, "Display help information on maven-jarsigner-plugin.\nCall\n\u00a0\u00a0mvn\u00a0jarsigner:help\u00a0-Ddetail=true\u00a0-Dgoal=<goal-name>\nto display parameter details.", 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, "detail (Default: false)", 2 );
 91  0
                 append( sb, "If true, display all settable properties for each goal.", 3 );
 92  0
                 append( sb, "", 0 );
 93  
 
 94  0
                 append( sb, "goal", 2 );
 95  0
                 append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 );
 96  0
                 append( sb, "", 0 );
 97  
 
 98  0
                 append( sb, "indentSize (Default: 2)", 2 );
 99  0
                 append( sb, "The number of spaces per indentation level, should be positive.", 3 );
 100  0
                 append( sb, "", 0 );
 101  
 
 102  0
                 append( sb, "lineLength (Default: 80)", 2 );
 103  0
                 append( sb, "The maximum length of a display line, should be positive.", 3 );
 104  0
                 append( sb, "", 0 );
 105  
             }
 106  
         }
 107  
 
 108  0
         if ( goal == null || goal.length() <= 0 || "sign".equals( goal ) )
 109  
         {
 110  0
             append( sb, "jarsigner:sign", 0 );
 111  0
             append( sb, "Signs a project artifact and attachments using jarsigner.", 1 );
 112  0
             append( sb, "", 0 );
 113  0
             if ( detail )
 114  
             {
 115  0
                 append( sb, "Available parameters:", 1 );
 116  0
                 append( sb, "", 0 );
 117  
 
 118  0
                 append( sb, "alias", 2 );
 119  0
                 append( sb, "See options.", 3 );
 120  0
                 append( sb, "", 0 );
 121  
 
 122  0
                 append( sb, "archive", 2 );
 123  0
                 append( sb, "Archive to process. If set, neither the project artifact nor any attachments or archive sets are processed.", 3 );
 124  0
                 append( sb, "", 0 );
 125  
 
 126  0
                 append( sb, "archiveDirectory", 2 );
 127  0
                 append( sb, "The base directory to scan for JAR files using Ant-like inclusion/exclusion patterns.", 3 );
 128  0
                 append( sb, "", 0 );
 129  
 
 130  0
                 append( sb, "arguments", 2 );
 131  0
                 append( sb, "List of additional arguments to append to the jarsigner command line.", 3 );
 132  0
                 append( sb, "", 0 );
 133  
 
 134  0
                 append( sb, "attachments", 2 );
 135  0
                 append( sb, "Deprecated. As of version 1.1 in favor of the new parameter processAttachedArtifacts.", 3 );
 136  0
                 append( sb, "", 0 );
 137  0
                 append( sb, "Controls processing of project attachments.", 3 );
 138  0
                 append( sb, "", 0 );
 139  
 
 140  0
                 append( sb, "excludes", 2 );
 141  0
                 append( sb, "The Ant-like exclusion patterns used to exclude JAR files from processing. The patterns must be relative to the directory given by the parameter archiveDirectory.", 3 );
 142  0
                 append( sb, "", 0 );
 143  
 
 144  0
                 append( sb, "includes", 2 );
 145  0
                 append( sb, "The Ant-like inclusion patterns used to select JAR files to process. The patterns must be relative to the directory given by the parameter archiveDirectory. By default, the pattern **/*.?ar is used.", 3 );
 146  0
                 append( sb, "", 0 );
 147  
 
 148  0
                 append( sb, "keypass", 2 );
 149  0
                 append( sb, "See options.", 3 );
 150  0
                 append( sb, "", 0 );
 151  
 
 152  0
                 append( sb, "keystore", 2 );
 153  0
                 append( sb, "See options.", 3 );
 154  0
                 append( sb, "", 0 );
 155  
 
 156  0
                 append( sb, "maxMemory", 2 );
 157  0
                 append( sb, "The maximum memory available to the JAR signer, e.g. 256M. See -Xmx for more details.", 3 );
 158  0
                 append( sb, "", 0 );
 159  
 
 160  0
                 append( sb, "processAttachedArtifacts (Default: true)", 2 );
 161  0
                 append( sb, "Controls processing of project attachments. If enabled, attached artifacts that are no JARs will be automatically excluded from processing.", 3 );
 162  0
                 append( sb, "", 0 );
 163  
 
 164  0
                 append( sb, "processMainArtifact (Default: true)", 2 );
 165  0
                 append( sb, "Controls processing of the main artifact produced by the project.", 3 );
 166  0
                 append( sb, "", 0 );
 167  
 
 168  0
                 append( sb, "providerArg", 2 );
 169  0
                 append( sb, "See options.", 3 );
 170  0
                 append( sb, "", 0 );
 171  
 
 172  0
                 append( sb, "providerClass", 2 );
 173  0
                 append( sb, "See options.", 3 );
 174  0
                 append( sb, "", 0 );
 175  
 
 176  0
                 append( sb, "providerName", 2 );
 177  0
                 append( sb, "See options.", 3 );
 178  0
                 append( sb, "", 0 );
 179  
 
 180  0
                 append( sb, "removeExistingSignatures (Default: false)", 2 );
 181  0
                 append( sb, "Indicates whether existing signatures should be removed from the processed JAR files prior to signing them. If enabled, the resulting JAR will appear as being signed only once.", 3 );
 182  0
                 append( sb, "", 0 );
 183  
 
 184  0
                 append( sb, "sigfile", 2 );
 185  0
                 append( sb, "See options.", 3 );
 186  0
                 append( sb, "", 0 );
 187  
 
 188  0
                 append( sb, "skip (Default: false)", 2 );
 189  0
                 append( sb, "Set to true to disable the plugin.", 3 );
 190  0
                 append( sb, "", 0 );
 191  
 
 192  0
                 append( sb, "storepass", 2 );
 193  0
                 append( sb, "See options.", 3 );
 194  0
                 append( sb, "", 0 );
 195  
 
 196  0
                 append( sb, "storetype", 2 );
 197  0
                 append( sb, "See options.", 3 );
 198  0
                 append( sb, "", 0 );
 199  
 
 200  0
                 append( sb, "verbose (Default: false)", 2 );
 201  0
                 append( sb, "See options.", 3 );
 202  0
                 append( sb, "", 0 );
 203  
             }
 204  
         }
 205  
 
 206  0
         if ( goal == null || goal.length() <= 0 || "verify".equals( goal ) )
 207  
         {
 208  0
             append( sb, "jarsigner:verify", 0 );
 209  0
             append( sb, "Checks the signatures of a project artifact and attachments using jarsigner.", 1 );
 210  0
             append( sb, "", 0 );
 211  0
             if ( detail )
 212  
             {
 213  0
                 append( sb, "Available parameters:", 1 );
 214  0
                 append( sb, "", 0 );
 215  
 
 216  0
                 append( sb, "archive", 2 );
 217  0
                 append( sb, "Archive to process. If set, neither the project artifact nor any attachments or archive sets are processed.", 3 );
 218  0
                 append( sb, "", 0 );
 219  
 
 220  0
                 append( sb, "archiveDirectory", 2 );
 221  0
                 append( sb, "The base directory to scan for JAR files using Ant-like inclusion/exclusion patterns.", 3 );
 222  0
                 append( sb, "", 0 );
 223  
 
 224  0
                 append( sb, "arguments", 2 );
 225  0
                 append( sb, "List of additional arguments to append to the jarsigner command line.", 3 );
 226  0
                 append( sb, "", 0 );
 227  
 
 228  0
                 append( sb, "attachments", 2 );
 229  0
                 append( sb, "Deprecated. As of version 1.1 in favor of the new parameter processAttachedArtifacts.", 3 );
 230  0
                 append( sb, "", 0 );
 231  0
                 append( sb, "Controls processing of project attachments.", 3 );
 232  0
                 append( sb, "", 0 );
 233  
 
 234  0
                 append( sb, "certs (Default: false)", 2 );
 235  0
                 append( sb, "See options.", 3 );
 236  0
                 append( sb, "", 0 );
 237  
 
 238  0
                 append( sb, "excludes", 2 );
 239  0
                 append( sb, "The Ant-like exclusion patterns used to exclude JAR files from processing. The patterns must be relative to the directory given by the parameter archiveDirectory.", 3 );
 240  0
                 append( sb, "", 0 );
 241  
 
 242  0
                 append( sb, "includes", 2 );
 243  0
                 append( sb, "The Ant-like inclusion patterns used to select JAR files to process. The patterns must be relative to the directory given by the parameter archiveDirectory. By default, the pattern **/*.?ar is used.", 3 );
 244  0
                 append( sb, "", 0 );
 245  
 
 246  0
                 append( sb, "maxMemory", 2 );
 247  0
                 append( sb, "The maximum memory available to the JAR signer, e.g. 256M. See -Xmx for more details.", 3 );
 248  0
                 append( sb, "", 0 );
 249  
 
 250  0
                 append( sb, "processAttachedArtifacts (Default: true)", 2 );
 251  0
                 append( sb, "Controls processing of project attachments. If enabled, attached artifacts that are no JARs will be automatically excluded from processing.", 3 );
 252  0
                 append( sb, "", 0 );
 253  
 
 254  0
                 append( sb, "processMainArtifact (Default: true)", 2 );
 255  0
                 append( sb, "Controls processing of the main artifact produced by the project.", 3 );
 256  0
                 append( sb, "", 0 );
 257  
 
 258  0
                 append( sb, "skip (Default: false)", 2 );
 259  0
                 append( sb, "Set to true to disable the plugin.", 3 );
 260  0
                 append( sb, "", 0 );
 261  
 
 262  0
                 append( sb, "verbose (Default: false)", 2 );
 263  0
                 append( sb, "See options.", 3 );
 264  0
                 append( sb, "", 0 );
 265  
             }
 266  
         }
 267  
 
 268  0
         if ( getLog().isInfoEnabled() )
 269  
         {
 270  0
             getLog().info( sb.toString() );
 271  
         }
 272  0
     }
 273  
 
 274  
     /**
 275  
      * <p>Repeat a String <code>n</code> times to form a new string.</p>
 276  
      *
 277  
      * @param str String to repeat
 278  
      * @param repeat number of times to repeat str
 279  
      * @return String with repeated String
 280  
      * @throws NegativeArraySizeException if <code>repeat < 0</code>
 281  
      * @throws NullPointerException if str is <code>null</code>
 282  
      */
 283  
     private static String repeat( String str, int repeat )
 284  
     {
 285  0
         StringBuffer buffer = new StringBuffer( repeat * str.length() );
 286  
 
 287  0
         for ( int i = 0; i < repeat; i++ )
 288  
         {
 289  0
             buffer.append( str );
 290  
         }
 291  
 
 292  0
         return buffer.toString();
 293  
     }
 294  
 
 295  
     /** 
 296  
      * Append a description to the buffer by respecting the indentSize and lineLength parameters.
 297  
      * <b>Note</b>: The last character is always a new line.
 298  
      * 
 299  
      * @param sb The buffer to append the description, not <code>null</code>.
 300  
      * @param description The description, not <code>null</code>.
 301  
      * @param indent The base indentation level of each line, must not be negative.
 302  
      */
 303  
     private void append( StringBuffer sb, String description, int indent )
 304  
     {
 305  0
         for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); )
 306  
         {
 307  0
             sb.append( it.next().toString() ).append( '\n' );
 308  
         }
 309  0
     }
 310  
 
 311  
     /** 
 312  
      * Splits the specified text into lines of convenient display length.
 313  
      * 
 314  
      * @param text The text to split into lines, must not be <code>null</code>.
 315  
      * @param indent The base indentation level of each line, must not be negative.
 316  
      * @param indentSize The size of each indentation, must not be negative.
 317  
      * @param lineLength The length of the line, must not be negative.
 318  
      * @return The sequence of display lines, never <code>null</code>.
 319  
      * @throws NegativeArraySizeException if <code>indent < 0</code>
 320  
      */
 321  
     private static List toLines( String text, int indent, int indentSize, int lineLength )
 322  
     {
 323  0
         List lines = new ArrayList();
 324  
 
 325  0
         String ind = repeat( "\t", indent );
 326  0
         String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" );
 327  0
         for ( int i = 0; i < plainLines.length; i++ )
 328  
         {
 329  0
             toLines( lines, ind + plainLines[i], indentSize, lineLength );
 330  
         }
 331  
 
 332  0
         return lines;
 333  
     }
 334  
 
 335  
     /** 
 336  
      * Adds the specified line to the output sequence, performing line wrapping if necessary.
 337  
      * 
 338  
      * @param lines The sequence of display lines, must not be <code>null</code>.
 339  
      * @param line The line to add, must not be <code>null</code>.
 340  
      * @param indentSize The size of each indentation, must not be negative.
 341  
      * @param lineLength The length of the line, must not be negative.
 342  
      */
 343  
     private static void toLines( List lines, String line, int indentSize, int lineLength )
 344  
     {
 345  0
         int lineIndent = getIndentLevel( line );
 346  0
         StringBuffer buf = new StringBuffer( 256 );
 347  0
         String[] tokens = line.split( " +" );
 348  0
         for ( int i = 0; i < tokens.length; i++ )
 349  
         {
 350  0
             String token = tokens[i];
 351  0
             if ( i > 0 )
 352  
             {
 353  0
                 if ( buf.length() + token.length() >= lineLength )
 354  
                 {
 355  0
                     lines.add( buf.toString() );
 356  0
                     buf.setLength( 0 );
 357  0
                     buf.append( repeat( " ", lineIndent * indentSize ) );
 358  
                 }
 359  
                 else
 360  
                 {
 361  0
                     buf.append( ' ' );
 362  
                 }
 363  
             }
 364  0
             for ( int j = 0; j < token.length(); j++ )
 365  
             {
 366  0
                 char c = token.charAt( j );
 367  0
                 if ( c == '\t' )
 368  
                 {
 369  0
                     buf.append( repeat( " ", indentSize - buf.length() % indentSize ) );
 370  
                 }
 371  0
                 else if ( c == '\u00A0' )
 372  
                 {
 373  0
                     buf.append( ' ' );
 374  
                 }
 375  
                 else
 376  
                 {
 377  0
                     buf.append( c );
 378  
                 }
 379  
             }
 380  
         }
 381  0
         lines.add( buf.toString() );
 382  0
     }
 383  
 
 384  
     /** 
 385  
      * Gets the indentation level of the specified line.
 386  
      * 
 387  
      * @param line The line whose indentation level should be retrieved, must not be <code>null</code>.
 388  
      * @return The indentation level of the line.
 389  
      */
 390  
     private static int getIndentLevel( String line )
 391  
     {
 392  0
         int level = 0;
 393  0
         for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ )
 394  
         {
 395  0
             level++;
 396  
         }
 397  0
         for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ )
 398  
         {
 399  0
             if ( line.charAt( i ) == '\t' )
 400  
             {
 401  0
                 level++;
 402  0
                 break;
 403  
             }
 404  
         }
 405  0
         return level;
 406  
     }
 407  
 }