Coverage Report - org.apache.maven.plugins.patchtracker.HelpMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
HelpMojo
0 %
0/256
0 %
0/70
6,833
 
 1  
 package org.apache.maven.plugins.patchtracker;
 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-patch-tracker-plugin.<br/> Call <pre>  mvn patch-tracker:help -Ddetail=true -Dgoal=&lt;goal-name&gt;</pre> to display parameter details.
 12  
  *
 13  
  * @version generated on Mon Nov 28 12:09:03 CET 2011
 14  
  * @author org.apache.maven.tools.plugin.generator.PluginHelpGenerator (version 2.8)
 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-patch-tracker-plugin:1.0-SNAPSHOT", 0 );
 70  0
         append( sb, "", 0 );
 71  
 
 72  0
         append( sb, "maven-patch-tracker-plugin Maven Plugin", 0 );
 73  0
         append( sb, "Maven Plugins", 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 || "create".equals( goal ) )
 83  
         {
 84  0
             append( sb, "patch-tracker:create", 0 );
 85  0
             append( sb, "Goal which create a diff/patch file from the current project and create an issue in the project with attaching the created patch file", 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  0
                 append( sb, "description", 2 );
 93  0
                 append( sb, "(no description available)", 3 );
 94  0
                 append( sb, "Expression: ${patch.description}", 3 );
 95  0
                 append( sb, "", 0 );
 96  
 
 97  0
                 append( sb, "issueSystem", 2 );
 98  0
                 append( sb, "(no description available)", 3 );
 99  0
                 append( sb, "Expression: ${patch.issueSystem}", 3 );
 100  0
                 append( sb, "", 0 );
 101  
 
 102  0
                 append( sb, "password", 2 );
 103  0
                 append( sb, "(no description available)", 3 );
 104  0
                 append( sb, "Expression: ${patch.password}", 3 );
 105  0
                 append( sb, "", 0 );
 106  
 
 107  0
                 append( sb, "patchPriority (Default: 3)", 2 );
 108  0
                 append( sb, "the priority of the patch tracker entry to load: default 3 for jira major", 3 );
 109  0
                 append( sb, "Expression: ${patch.priority}", 3 );
 110  0
                 append( sb, "", 0 );
 111  
 
 112  0
                 append( sb, "patchSystem (Default: ${project.patchManagement.system})", 2 );
 113  0
                 append( sb, "(no description available)", 3 );
 114  0
                 append( sb, "Expression: ${patch.patchSystem}", 3 );
 115  0
                 append( sb, "", 0 );
 116  
 
 117  0
                 append( sb, "patchType (Default: 1)", 2 );
 118  0
                 append( sb, "the type of the patch tracker entry to load: default 1 for jira bug", 3 );
 119  0
                 append( sb, "Expression: ${patch.patchType}", 3 );
 120  0
                 append( sb, "", 0 );
 121  
 
 122  0
                 append( sb, "providerType", 2 );
 123  0
                 append( sb, "(no description available)", 3 );
 124  0
                 append( sb, "Expression: ${scm.providerType}", 3 );
 125  0
                 append( sb, "", 0 );
 126  
 
 127  0
                 append( sb, "serverId", 2 );
 128  0
                 append( sb, "if user/password are stored in your settings.xml in a server", 3 );
 129  0
                 append( sb, "Expression: ${patch.serverId}", 3 );
 130  0
                 append( sb, "", 0 );
 131  
 
 132  0
                 append( sb, "serverUrl", 2 );
 133  0
                 append( sb, "if path tracker url is not stored in the pom. For jira, url must include project key!: http://jira.codehaus.org/browse/MNG", 3 );
 134  0
                 append( sb, "Expression: ${patch.serverUrl}", 3 );
 135  0
                 append( sb, "", 0 );
 136  
 
 137  0
                 append( sb, "summary", 2 );
 138  0
                 append( sb, "(no description available)", 3 );
 139  0
                 append( sb, "Expression: ${patch.summary}", 3 );
 140  0
                 append( sb, "", 0 );
 141  
 
 142  0
                 append( sb, "user", 2 );
 143  0
                 append( sb, "(no description available)", 3 );
 144  0
                 append( sb, "Expression: ${patch.user}", 3 );
 145  0
                 append( sb, "", 0 );
 146  
             }
 147  
         }
 148  
 
 149  0
         if ( goal == null || goal.length() <= 0 || "help".equals( goal ) )
 150  
         {
 151  0
             append( sb, "patch-tracker:help", 0 );
 152  0
             append( sb, "Display help information on maven-patch-tracker-plugin.\nCall\n\u00a0\u00a0mvn\u00a0patch-tracker:help\u00a0-Ddetail=true\u00a0-Dgoal=<goal-name>\nto display parameter details.", 1 );
 153  0
             append( sb, "", 0 );
 154  0
             if ( detail )
 155  
             {
 156  0
                 append( sb, "Available parameters:", 1 );
 157  0
                 append( sb, "", 0 );
 158  
 
 159  0
                 append( sb, "detail (Default: false)", 2 );
 160  0
                 append( sb, "If true, display all settable properties for each goal.", 3 );
 161  0
                 append( sb, "Expression: ${detail}", 3 );
 162  0
                 append( sb, "", 0 );
 163  
 
 164  0
                 append( sb, "goal", 2 );
 165  0
                 append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 );
 166  0
                 append( sb, "Expression: ${goal}", 3 );
 167  0
                 append( sb, "", 0 );
 168  
 
 169  0
                 append( sb, "indentSize (Default: 2)", 2 );
 170  0
                 append( sb, "The number of spaces per indentation level, should be positive.", 3 );
 171  0
                 append( sb, "Expression: ${indentSize}", 3 );
 172  0
                 append( sb, "", 0 );
 173  
 
 174  0
                 append( sb, "lineLength (Default: 80)", 2 );
 175  0
                 append( sb, "The maximum length of a display line, should be positive.", 3 );
 176  0
                 append( sb, "Expression: ${lineLength}", 3 );
 177  0
                 append( sb, "", 0 );
 178  
             }
 179  
         }
 180  
 
 181  0
         if ( goal == null || goal.length() <= 0 || "to-issue".equals( goal ) )
 182  
         {
 183  0
             append( sb, "patch-tracker:to-issue", 0 );
 184  0
             append( sb, "(no description available)", 1 );
 185  0
             append( sb, "", 0 );
 186  0
             if ( detail )
 187  
             {
 188  0
                 append( sb, "Available parameters:", 1 );
 189  0
                 append( sb, "", 0 );
 190  
 
 191  0
                 append( sb, "description", 2 );
 192  0
                 append( sb, "(no description available)", 3 );
 193  0
                 append( sb, "Expression: ${patch.description}", 3 );
 194  0
                 append( sb, "", 0 );
 195  
 
 196  0
                 append( sb, "id", 2 );
 197  0
                 append( sb, "for github: pull request id", 3 );
 198  0
                 append( sb, "Expression: ${patch.request.id}", 3 );
 199  0
                 append( sb, "", 0 );
 200  
 
 201  0
                 append( sb, "issueSystem", 2 );
 202  0
                 append( sb, "(no description available)", 3 );
 203  0
                 append( sb, "Expression: ${patch.issueSystem}", 3 );
 204  0
                 append( sb, "", 0 );
 205  
 
 206  0
                 append( sb, "organisation", 2 );
 207  0
                 append( sb, "for github user/organization : github.com/apache use apache", 3 );
 208  0
                 append( sb, "Expression: ${patch.request.organisation}", 3 );
 209  0
                 append( sb, "", 0 );
 210  
 
 211  0
                 append( sb, "password", 2 );
 212  0
                 append( sb, "(no description available)", 3 );
 213  0
                 append( sb, "Expression: ${patch.password}", 3 );
 214  0
                 append( sb, "", 0 );
 215  
 
 216  0
                 append( sb, "patchPriority (Default: 3)", 2 );
 217  0
                 append( sb, "the priority of the patch tracker entry to load: default 3 for jira major", 3 );
 218  0
                 append( sb, "Expression: ${patch.priority}", 3 );
 219  0
                 append( sb, "", 0 );
 220  
 
 221  0
                 append( sb, "patchSystem (Default: ${project.patchManagement.system})", 2 );
 222  0
                 append( sb, "(no description available)", 3 );
 223  0
                 append( sb, "Expression: ${patch.patchSystem}", 3 );
 224  0
                 append( sb, "", 0 );
 225  
 
 226  0
                 append( sb, "patchSystemUrl (Default: ${project.patchManagement.url})", 2 );
 227  0
                 append( sb, "for github api url https://api.github.com", 3 );
 228  0
                 append( sb, "Expression: ${patch.patchSystem.url}", 3 );
 229  0
                 append( sb, "", 0 );
 230  
 
 231  0
                 append( sb, "patchType (Default: 1)", 2 );
 232  0
                 append( sb, "the type of the patch tracker entry to load: default 1 for jira bug", 3 );
 233  0
                 append( sb, "Expression: ${patch.patchType}", 3 );
 234  0
                 append( sb, "", 0 );
 235  
 
 236  0
                 append( sb, "providerType", 2 );
 237  0
                 append( sb, "(no description available)", 3 );
 238  0
                 append( sb, "Expression: ${scm.providerType}", 3 );
 239  0
                 append( sb, "", 0 );
 240  
 
 241  0
                 append( sb, "repository", 2 );
 242  0
                 append( sb, "github repo : github.com/apache/maven-3 use maven-3", 3 );
 243  0
                 append( sb, "Expression: ${patch.request.repository}", 3 );
 244  0
                 append( sb, "", 0 );
 245  
 
 246  0
                 append( sb, "serverId", 2 );
 247  0
                 append( sb, "if user/password are stored in your settings.xml in a server", 3 );
 248  0
                 append( sb, "Expression: ${patch.serverId}", 3 );
 249  0
                 append( sb, "", 0 );
 250  
 
 251  0
                 append( sb, "serverUrl", 2 );
 252  0
                 append( sb, "if path tracker url is not stored in the pom. For jira, url must include project key!: http://jira.codehaus.org/browse/MNG", 3 );
 253  0
                 append( sb, "Expression: ${patch.serverUrl}", 3 );
 254  0
                 append( sb, "", 0 );
 255  
 
 256  0
                 append( sb, "summary", 2 );
 257  0
                 append( sb, "(no description available)", 3 );
 258  0
                 append( sb, "Expression: ${patch.summary}", 3 );
 259  0
                 append( sb, "", 0 );
 260  
 
 261  0
                 append( sb, "user", 2 );
 262  0
                 append( sb, "(no description available)", 3 );
 263  0
                 append( sb, "Expression: ${patch.user}", 3 );
 264  0
                 append( sb, "", 0 );
 265  
             }
 266  
         }
 267  
 
 268  0
         if ( goal == null || goal.length() <= 0 || "update".equals( goal ) )
 269  
         {
 270  0
             append( sb, "patch-tracker:update", 0 );
 271  0
             append( sb, "Goal which create a diff/patch file from the current project and create an issue in the project with attaching the created patch file", 1 );
 272  0
             append( sb, "", 0 );
 273  0
             if ( detail )
 274  
             {
 275  0
                 append( sb, "Available parameters:", 1 );
 276  0
                 append( sb, "", 0 );
 277  
 
 278  0
                 append( sb, "description", 2 );
 279  0
                 append( sb, "(no description available)", 3 );
 280  0
                 append( sb, "Expression: ${patch.description}", 3 );
 281  0
                 append( sb, "", 0 );
 282  
 
 283  0
                 append( sb, "issueSystem", 2 );
 284  0
                 append( sb, "(no description available)", 3 );
 285  0
                 append( sb, "Expression: ${patch.issueSystem}", 3 );
 286  0
                 append( sb, "", 0 );
 287  
 
 288  0
                 append( sb, "password", 2 );
 289  0
                 append( sb, "(no description available)", 3 );
 290  0
                 append( sb, "Expression: ${patch.password}", 3 );
 291  0
                 append( sb, "", 0 );
 292  
 
 293  0
                 append( sb, "patchId", 2 );
 294  0
                 append( sb, "(no description available)", 3 );
 295  0
                 append( sb, "Expression: ${patch.patchId}", 3 );
 296  0
                 append( sb, "", 0 );
 297  
 
 298  0
                 append( sb, "patchPriority (Default: 3)", 2 );
 299  0
                 append( sb, "the priority of the patch tracker entry to load: default 3 for jira major", 3 );
 300  0
                 append( sb, "Expression: ${patch.priority}", 3 );
 301  0
                 append( sb, "", 0 );
 302  
 
 303  0
                 append( sb, "patchSystem (Default: ${project.patchManagement.system})", 2 );
 304  0
                 append( sb, "(no description available)", 3 );
 305  0
                 append( sb, "Expression: ${patch.patchSystem}", 3 );
 306  0
                 append( sb, "", 0 );
 307  
 
 308  0
                 append( sb, "patchType (Default: 1)", 2 );
 309  0
                 append( sb, "the type of the patch tracker entry to load: default 1 for jira bug", 3 );
 310  0
                 append( sb, "Expression: ${patch.patchType}", 3 );
 311  0
                 append( sb, "", 0 );
 312  
 
 313  0
                 append( sb, "providerType", 2 );
 314  0
                 append( sb, "(no description available)", 3 );
 315  0
                 append( sb, "Expression: ${scm.providerType}", 3 );
 316  0
                 append( sb, "", 0 );
 317  
 
 318  0
                 append( sb, "serverId", 2 );
 319  0
                 append( sb, "if user/password are stored in your settings.xml in a server", 3 );
 320  0
                 append( sb, "Expression: ${patch.serverId}", 3 );
 321  0
                 append( sb, "", 0 );
 322  
 
 323  0
                 append( sb, "serverUrl", 2 );
 324  0
                 append( sb, "if path tracker url is not stored in the pom. For jira, url must include project key!: http://jira.codehaus.org/browse/MNG", 3 );
 325  0
                 append( sb, "Expression: ${patch.serverUrl}", 3 );
 326  0
                 append( sb, "", 0 );
 327  
 
 328  0
                 append( sb, "summary", 2 );
 329  0
                 append( sb, "(no description available)", 3 );
 330  0
                 append( sb, "Expression: ${patch.summary}", 3 );
 331  0
                 append( sb, "", 0 );
 332  
 
 333  0
                 append( sb, "user", 2 );
 334  0
                 append( sb, "(no description available)", 3 );
 335  0
                 append( sb, "Expression: ${patch.user}", 3 );
 336  0
                 append( sb, "", 0 );
 337  
             }
 338  
         }
 339  
 
 340  0
         if ( getLog().isInfoEnabled() )
 341  
         {
 342  0
             getLog().info( sb.toString() );
 343  
         }
 344  0
     }
 345  
 
 346  
     /**
 347  
      * <p>Repeat a String <code>n</code> times to form a new string.</p>
 348  
      *
 349  
      * @param str String to repeat
 350  
      * @param repeat number of times to repeat str
 351  
      * @return String with repeated String
 352  
      * @throws NegativeArraySizeException if <code>repeat < 0</code>
 353  
      * @throws NullPointerException if str is <code>null</code>
 354  
      */
 355  
     private static String repeat( String str, int repeat )
 356  
     {
 357  0
         StringBuffer buffer = new StringBuffer( repeat * str.length() );
 358  
 
 359  0
         for ( int i = 0; i < repeat; i++ )
 360  
         {
 361  0
             buffer.append( str );
 362  
         }
 363  
 
 364  0
         return buffer.toString();
 365  
     }
 366  
 
 367  
     /** 
 368  
      * Append a description to the buffer by respecting the indentSize and lineLength parameters.
 369  
      * <b>Note</b>: The last character is always a new line.
 370  
      * 
 371  
      * @param sb The buffer to append the description, not <code>null</code>.
 372  
      * @param description The description, not <code>null</code>.
 373  
      * @param indent The base indentation level of each line, must not be negative.
 374  
      */
 375  
     private void append( StringBuffer sb, String description, int indent )
 376  
     {
 377  0
         for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); )
 378  
         {
 379  0
             sb.append( it.next().toString() ).append( '\n' );
 380  
         }
 381  0
     }
 382  
 
 383  
     /** 
 384  
      * Splits the specified text into lines of convenient display length.
 385  
      * 
 386  
      * @param text The text to split into lines, must not be <code>null</code>.
 387  
      * @param indent The base indentation level of each line, must not be negative.
 388  
      * @param indentSize The size of each indentation, must not be negative.
 389  
      * @param lineLength The length of the line, must not be negative.
 390  
      * @return The sequence of display lines, never <code>null</code>.
 391  
      * @throws NegativeArraySizeException if <code>indent < 0</code>
 392  
      */
 393  
     private static List toLines( String text, int indent, int indentSize, int lineLength )
 394  
     {
 395  0
         List<String> lines = new ArrayList<String>();
 396  
 
 397  0
         String ind = repeat( "\t", indent );
 398  0
         String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" );
 399  0
         for ( int i = 0; i < plainLines.length; i++ )
 400  
         {
 401  0
             toLines( lines, ind + plainLines[i], indentSize, lineLength );
 402  
         }
 403  
 
 404  0
         return lines;
 405  
     }
 406  
 
 407  
     /** 
 408  
      * Adds the specified line to the output sequence, performing line wrapping if necessary.
 409  
      * 
 410  
      * @param lines The sequence of display lines, must not be <code>null</code>.
 411  
      * @param line The line to add, must not be <code>null</code>.
 412  
      * @param indentSize The size of each indentation, must not be negative.
 413  
      * @param lineLength The length of the line, must not be negative.
 414  
      */
 415  
     private static void toLines( List<String> lines, String line, int indentSize, int lineLength )
 416  
     {
 417  0
         int lineIndent = getIndentLevel( line );
 418  0
         StringBuffer buf = new StringBuffer( 256 );
 419  0
         String[] tokens = line.split( " +" );
 420  0
         for ( int i = 0; i < tokens.length; i++ )
 421  
         {
 422  0
             String token = tokens[i];
 423  0
             if ( i > 0 )
 424  
             {
 425  0
                 if ( buf.length() + token.length() >= lineLength )
 426  
                 {
 427  0
                     lines.add( buf.toString() );
 428  0
                     buf.setLength( 0 );
 429  0
                     buf.append( repeat( " ", lineIndent * indentSize ) );
 430  
                 }
 431  
                 else
 432  
                 {
 433  0
                     buf.append( ' ' );
 434  
                 }
 435  
             }
 436  0
             for ( int j = 0; j < token.length(); j++ )
 437  
             {
 438  0
                 char c = token.charAt( j );
 439  0
                 if ( c == '\t' )
 440  
                 {
 441  0
                     buf.append( repeat( " ", indentSize - buf.length() % indentSize ) );
 442  
                 }
 443  0
                 else if ( c == '\u00A0' )
 444  
                 {
 445  0
                     buf.append( ' ' );
 446  
                 }
 447  
                 else
 448  
                 {
 449  0
                     buf.append( c );
 450  
                 }
 451  
             }
 452  
         }
 453  0
         lines.add( buf.toString() );
 454  0
     }
 455  
 
 456  
     /** 
 457  
      * Gets the indentation level of the specified line.
 458  
      * 
 459  
      * @param line The line whose indentation level should be retrieved, must not be <code>null</code>.
 460  
      * @return The indentation level of the line.
 461  
      */
 462  
     private static int getIndentLevel( String line )
 463  
     {
 464  0
         int level = 0;
 465  0
         for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ )
 466  
         {
 467  0
             level++;
 468  
         }
 469  0
         for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ )
 470  
         {
 471  0
             if ( line.charAt( i ) == '\t' )
 472  
             {
 473  0
                 level++;
 474  0
                 break;
 475  
             }
 476  
         }
 477  0
         return level;
 478  
     }
 479  
 }