Coverage Report - org.apache.maven.plugin.antrun.HelpMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
HelpMojo
0%
0/68
0%
0/40
6.25
 
 1  
 package org.apache.maven.plugin.antrun;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.Iterator;
 5  
 import java.util.List;
 6  
 import java.util.StringTokenizer;
 7  
 
 8  
 import org.apache.maven.plugin.AbstractMojo;
 9  
 import org.apache.maven.plugin.MojoExecutionException;
 10  
 
 11  
 /**
 12  
  * Display help information on 'org.apache.maven.plugins:maven-antrun-plugin' plugin. Call 'mvn antrun:help -Ddetail=true' to display all details.
 13  
  *
 14  
  * @version generated on Sun Jul 20 12:17:18 PDT 2008
 15  
  * @goal help
 16  
  */
 17  0
 public class HelpMojo
 18  
     extends AbstractMojo
 19  
 {
 20  
     /** 80-character display buffer */
 21  
     private static final int DEFAULT_WIDTH = 80;
 22  
 
 23  
     /** 4 indent spaces */
 24  0
     private static final String DEFAULT_INDENT = repeat( " ", 2 );
 25  
 
 26  
     /**
 27  
      * If true, display all settable properies for each goal.
 28  
      *
 29  
      * @parameter expression="${detail}" default-value="false"
 30  
      */
 31  
     private boolean detail;
 32  
 
 33  
     /** {@inheritDoc} */
 34  
     public void execute()
 35  
         throws MojoExecutionException
 36  
     {
 37  0
         StringBuffer sb = new StringBuffer();
 38  
 
 39  0
         sb.append( "The 'org.apache.maven.plugins:maven-antrun-plugin' plugin has 3 goals:" ).append( "\n" );
 40  0
         sb.append( "\n" );
 41  
 
 42  0
         sb.append( "antrun:run" ).append( "\n" );
 43  0
         for ( Iterator it = toLines( "Maven AntRun Mojo. This plugin provides the capability of calling Ant tasks from a POM by running the nested ant tasks inside the <tasks/> parameter. It is encouraged to move the actual tasks to a separate build.xml file and call that file with an <ant/> task." ).iterator(); it.hasNext(); )
 44  
         {
 45  0
             sb.append( it.next().toString() ).append( "\n" );
 46  
         }
 47  0
         if ( detail )
 48  
         {
 49  0
             sb.append( "\n" );
 50  
 
 51  0
             sb.append( repeat( " ", 2 ) );
 52  0
             sb.append( "Available parameters:" ).append( "\n" );
 53  
 
 54  0
             sb.append( "\n" );
 55  
 
 56  0
         for ( Iterator it = toLines( "sourceRoot", repeat( " ", 4 ), DEFAULT_WIDTH ).iterator(); it.hasNext(); )
 57  
         {
 58  0
             sb.append( it.next().toString() ).append( "\n" );
 59  
         }
 60  0
             for ( Iterator it = toLines( "This folder is added to the list of those folders containing source to be compiled. Use this if your ant script generates source code.", repeat( " ", 6 ), DEFAULT_WIDTH ).iterator(); it.hasNext(); )
 61  
             {
 62  0
                 sb.append( it.next().toString() ).append( "\n" );
 63  
             }
 64  0
         for ( Iterator it = toLines( "tasks", repeat( " ", 4 ), DEFAULT_WIDTH ).iterator(); it.hasNext(); )
 65  
         {
 66  0
             sb.append( it.next().toString() ).append( "\n" );
 67  
         }
 68  0
             for ( Iterator it = toLines( "The XML for the Ant task. You can add anything you can add between <target> and </target> in a build.xml.", repeat( " ", 6 ), DEFAULT_WIDTH ).iterator(); it.hasNext(); )
 69  
             {
 70  0
                 sb.append( it.next().toString() ).append( "\n" );
 71  
             }
 72  0
         for ( Iterator it = toLines( "testSourceRoot", repeat( " ", 4 ), DEFAULT_WIDTH ).iterator(); it.hasNext(); )
 73  
         {
 74  0
             sb.append( it.next().toString() ).append( "\n" );
 75  
         }
 76  0
             for ( Iterator it = toLines( "This folder is added to the list of those folders containing source to be compiled for testing. Use this if your ant script generates test source code.", repeat( " ", 6 ), DEFAULT_WIDTH ).iterator(); it.hasNext(); )
 77  
             {
 78  0
                 sb.append( it.next().toString() ).append( "\n" );
 79  
             }
 80  
         }
 81  
 
 82  0
         sb.append( "\n" );
 83  
 
 84  0
         sb.append( "antrun:help" ).append( "\n" );
 85  0
         for ( Iterator it = toLines( "Display help information on 'org.apache.maven.plugins:maven-antrun-plugin' plugin. Call 'mvn antrun:help -Ddetail=true' to display all details." ).iterator(); it.hasNext(); )
 86  
         {
 87  0
             sb.append( it.next().toString() ).append( "\n" );
 88  
         }
 89  0
         if ( detail )
 90  
         {
 91  0
             sb.append( "\n" );
 92  
 
 93  0
             sb.append( repeat( " ", 2 ) );
 94  0
             sb.append( "Available parameters:" ).append( "\n" );
 95  
 
 96  0
             sb.append( "\n" );
 97  
 
 98  0
         for ( Iterator it = toLines( "detail (Default: 'false')", repeat( " ", 4 ), DEFAULT_WIDTH ).iterator(); it.hasNext(); )
 99  
         {
 100  0
             sb.append( it.next().toString() ).append( "\n" );
 101  
         }
 102  0
             for ( Iterator it = toLines( "If true, display all settable properies for each goal.", repeat( " ", 6 ), DEFAULT_WIDTH ).iterator(); it.hasNext(); )
 103  
             {
 104  0
                 sb.append( it.next().toString() ).append( "\n" );
 105  
             }
 106  
         }
 107  
 
 108  0
         sb.append( "\n" );
 109  
 
 110  0
         sb.append( "antrun:help" ).append( "\n" );
 111  0
         for ( Iterator it = toLines( "Display help information on 'org.apache.maven.plugins:maven-antrun-plugin' plugin. Call 'mvn antrun:help -Ddetail=true' to display all details." ).iterator(); it.hasNext(); )
 112  
         {
 113  0
             sb.append( it.next().toString() ).append( "\n" );
 114  
         }
 115  
 
 116  0
         if ( getLog().isInfoEnabled() )
 117  
         {
 118  0
             getLog().info( sb.toString() );
 119  
         }
 120  0
     }
 121  
 
 122  
     /**
 123  
      * <p>Repeat a String <code>n</code> times to form a new string.</p>
 124  
      *
 125  
      * @param str String to repeat
 126  
      * @param repeat number of times to repeat str
 127  
      * @return String with repeated String
 128  
      * @throws NegativeArraySizeException if <code>repeat < 0</code>
 129  
      * @throws NullPointerException if str is <code>null</code>
 130  
      */
 131  
     private static String repeat( String str, int repeat )
 132  
     {
 133  0
         StringBuffer buffer = new StringBuffer( repeat * str.length() );
 134  
 
 135  0
         for ( int i = 0; i < repeat; i++ )
 136  
         {
 137  0
             buffer.append( str );
 138  
         }
 139  
 
 140  0
         return buffer.toString();
 141  
     }
 142  
 
 143  
     /**
 144  
      * <p>Give a list of lines for the <code>str</code>. Each line is indented by 4 spaces
 145  
      * and has a maximum of <code>80</code> characters.</p>
 146  
      *
 147  
      * @param str String to split in lines
 148  
      * @return List of lines
 149  
      * @throws NullPointerException if str is <code>null</code>
 150  
      */
 151  
     private static List toLines( String str )
 152  
     {
 153  0
         return toLines( str, DEFAULT_INDENT, DEFAULT_WIDTH );
 154  
     }
 155  
 
 156  
     /**
 157  
      * <p>Give a list of lines for the <code>str</code>. Each line is indented by <code>indent</code>
 158  
      * and has a maximum of <code>size</code> characters.</p>
 159  
      *
 160  
      * @param str String to split in lines
 161  
      * @param indent the string to precede each line
 162  
      * @param size the size of the character display buffer
 163  
      * @return List of lines
 164  
      * @throws IllegalArgumentException if <code>size < 0</code>
 165  
      * @throws NullPointerException if str is <code>null</code>
 166  
      */
 167  
     private static List toLines( String str, String indent, int size )
 168  
     {
 169  0
         List sentences = new ArrayList();
 170  
 
 171  0
         if ( indent == null )
 172  
         {
 173  0
             indent = "";
 174  
         }
 175  
 
 176  0
         if ( size < 0 )
 177  
         {
 178  0
             throw new IllegalArgumentException( "size should be positive" );
 179  
         }
 180  
 
 181  0
         StringBuffer tmp = new StringBuffer( indent );
 182  0
         StringTokenizer tokenizer = new StringTokenizer( str, " " );
 183  0
         while ( tokenizer.hasMoreTokens() )
 184  
         {
 185  0
             String word = tokenizer.nextToken();
 186  
 
 187  0
             if ( tmp.length() + word.length() + 1 < size )
 188  
             {
 189  0
                 tmp.append( word ).append( " " );
 190  
             }
 191  
             else
 192  
             {
 193  0
                 sentences.add( tmp.toString() );
 194  0
                 tmp = new StringBuffer( indent );
 195  0
                 tmp.append( word ).append( " " );
 196  
             }
 197  0
         }
 198  
 
 199  0
         if ( tmp.toString().length() > 0 )
 200  
         {
 201  0
             sentences.add( tmp.toString() );
 202  
         }
 203  
 
 204  0
         return sentences;
 205  
     }
 206  
 }