Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.cloudera.cdk.maven.plugins;
  
 
 import java.util.List;

Display help information on cdk-maven-plugin.
Call mvn cdk:help -Ddetail=true -Dgoal=<goal-name> to display parameter details.

Author(s):
Version:
Goal:
help
RequiresProject:
false
ThreadSafe:
 
 public class HelpMojo
     extends AbstractMojo
 {
    
If true, display all settable properties for each goal.

Parameter:
property="detail" default-value="false"
 
     //@Parameter( property = "detail", defaultValue = "false" )
     private boolean detail;

    
The name of the goal for which to show help. If unspecified, all goals will be displayed.

Parameter:
property="goal"
 
     //@Parameter( property = "goal" )
     private java.lang.String goal;

    
The maximum length of a display line, should be positive.

Parameter:
property="lineLength" default-value="80"
 
     //@Parameter( property = "lineLength", defaultValue = "80" )
     private int lineLength;

    
The number of spaces per indentation level, should be positive.

Parameter:
property="indentSize" default-value="2"
 
     //@Parameter( property = "indentSize", defaultValue = "2" )
     private int indentSize;
 
     // groupId/artifactId/plugin-help.xml
     private static final String PLUGIN_HELP_PATH = "/META-INF/maven/com.cloudera.cdk/cdk-maven-plugin/plugin-help.xml";
 
     private Xpp3Dom build()
         throws MojoExecutionException
     {
         getLog().debug"load plugin-help.xml: " +  );
         try
         {
             return Xpp3DomBuilder.build( ReaderFactory.newXmlReaderis ) );
         }
         catch ( XmlPullParserException e )
         {
             throw new MojoExecutionExceptione.getMessage(), e );
         }
         catch ( IOException e )
         {
             throw new MojoExecutionExceptione.getMessage(), e );
         }
     }

    
 
     public void execute()
         throws MojoExecutionException
     {
         if (  <= 0 )
         {
             getLog().warn"The parameter 'lineLength' should be positive, using '80' as default." );
              = 80;
         }
         if (  <= 0 )
         {
             getLog().warn"The parameter 'indentSize' should be positive, using '2' as default." );
              = 2;
         }
 
        Xpp3Dom pluginElement = build();
        StringBuilder sb = new StringBuilder();
        String name = pluginElement.getChild"name" ).getValue();
        String version = pluginElement.getChild"version" ).getValue();
        String id = pluginElement.getChild"groupId" ).getValue() + ":" + pluginElement.getChild"artifactId" ).getValue()
                    + ":" + version;
        if ( StringUtils.isNotEmptyname ) && !name.containsid ) )
        {
            appendsbname + " " + version, 0 );
        }
        else
        {
            if ( StringUtils.isNotEmptyname ) )
            {
                appendsbname, 0 );
            }
            else
            {
                appendsbid, 0 );
            }
        }
        appendsbpluginElement.getChild"description" ).getValue(), 1 );
        appendsb"", 0 );
        //<goalPrefix>plugin</goalPrefix>
        String goalPrefix = pluginElement.getChild"goalPrefix" ).getValue();
        Xpp3Dom[] mojos = pluginElement.getChild"mojos" ).getChildren"mojo" );
        if (  == null || .length() <= 0 )
        {
            appendsb"This plugin has " + mojos.length + ( mojos.length > 1 ? " goals:" : " goal:" ) , 0 );
            appendsb"", 0 );
        }
        for ( Xpp3Dom mojo : mojos )
        {
            writeGoalsbgoalPrefixmojo );
        }
        if ( getLog().isInfoEnabled() )
        {
            getLog().infosb.toString() );
        }
    }
    private String getValueXpp3Dom mojoString child )
    {
        Xpp3Dom elt = mojo.getChildchild );
        return ( elt == null ) ? "" : elt.getValue();
    }
    private void writeGoalStringBuilder sbString goalPrefixXpp3Dom mojo )
    {
        String mojoGoal = mojo.getChild"goal" ).getValue();
        Xpp3Dom configurationElement = mojo.getChild"configuration" );
        if (  == null || .length() <= 0 || mojoGoal.equals ) )
        {
            appendsbgoalPrefix + ":" + mojoGoal, 0 );
            Xpp3Dom deprecated = mojo.getChild"deprecated" );
            if ( ( deprecated != null ) && StringUtils.isNotEmptydeprecated.getValue() ) )
            {
                appendsb"Deprecated. " + deprecated, 1 );
                if (  )
                {
                    appendsb"", 0 );
                    appendsbgetValuemojo"description" ), 1 );
                }
            }
            else
            {
                appendsbgetValuemojo"description" ), 1 );
            }
            appendsb"", 0 );
            if (  )
            {
                Xpp3Dom[] parameters = mojo.getChild"parameters" ).getChildren"parameter" );
                appendsb"Available parameters:", 1 );
                appendsb"", 0 );
                for ( Xpp3Dom parameter : parameters )
                {
                    writeParametersbparameterconfigurationElement );
                }
            }
        }
    }
    private void writeParameterStringBuilder sbXpp3Dom parameterXpp3Dom configurationElement )
    {
        String parameterName = parameter.getChild"name" ).getValue();
        String parameterDescription = parameter.getChild"description" ).getValue();
        Xpp3Dom fieldConfigurationElement = configurationElement.getChildparameterName );
        String parameterDefaultValue = "";
        if ( fieldConfigurationElement != null && fieldConfigurationElement.getValue() != null )
        {
            parameterDefaultValue = " (Default: " + fieldConfigurationElement.getAttribute"default-value" ) + ")";
        }
        appendsbparameterName + parameterDefaultValue, 2 );
        Xpp3Dom deprecated = parameter.getChild"deprecated" );
        if ( ( deprecated != null ) && StringUtils.isNotEmptydeprecated.getValue() ) )
        {
            appendsb"Deprecated. " + deprecated.getValue(), 3 );
            appendsb"", 0 );
        }
        appendsbparameterDescription, 3 );
        if ( "true".equalsparameter.getChild"required" ).getValue() ) )
        {
            appendsb"Required: Yes", 3 );
        }
        Xpp3Dom expression = parameter.getChild"expression" );
        if ( ( expression != null ) && StringUtils.isNotEmptyexpression.getValue() ) )
        {
            appendsb"Expression: " + expression.getValue(), 3 );
        }
        appendsb"", 0 );
    }

    

Repeat a String n times to form a new string.

Parameters:
str String to repeat
repeat number of times to repeat str
Returns:
String with repeated String
Throws:
java.lang.NegativeArraySizeException if repeat < 0
java.lang.NullPointerException if str is null
    private static String repeatString strint repeat )
    {
        StringBuilder buffer = new StringBuilderrepeat * str.length() );
        for ( int i = 0; i < repeati++ )
        {
            buffer.appendstr );
        }
        return buffer.toString();
    }

    
Append a description to the buffer by respecting the indentSize and lineLength parameters. Note: The last character is always a new line.

Parameters:
sb The buffer to append the description, not null.
description The description, not null.
indent The base indentation level of each line, must not be negative.
    private void appendStringBuilder sbString descriptionint indent )
    {
        for ( String line : toLinesdescriptionindent ) )
        {
            sb.appendline ).append'\n' );
        }
    }

    
Splits the specified text into lines of convenient display length.

Parameters:
text The text to split into lines, must not be null.
indent The base indentation level of each line, must not be negative.
indentSize The size of each indentation, must not be negative.
lineLength The length of the line, must not be negative.
Returns:
The sequence of display lines, never null.
Throws:
java.lang.NegativeArraySizeException if indent < 0
    private static List<StringtoLinesString textint indentint indentSizeint lineLength )
    {
        List<Stringlines = new ArrayList<String>();
        String ind = repeat"\t"indent );
        String[] plainLines = text.split"(\r\n)|(\r)|(\n)" );
        for ( String plainLine : plainLines )
        {
            toLineslinesind + plainLineindentSizelineLength );
        }
        return lines;
    }

    
Adds the specified line to the output sequence, performing line wrapping if necessary.

Parameters:
lines The sequence of display lines, must not be null.
line The line to add, must not be null.
indentSize The size of each indentation, must not be negative.
lineLength The length of the line, must not be negative.
    private static void toLinesList<StringlinesString lineint indentSizeint lineLength )
    {
        int lineIndent = getIndentLevelline );
        StringBuilder buf = new StringBuilder( 256 );
        String[] tokens = line.split" +" );
        for ( String token : tokens )
        {
            if ( buf.length() > 0 )
            {
                if ( buf.length() + token.length() >= lineLength )
                {
                    lines.addbuf.toString() );
                    buf.setLength( 0 );
                    buf.appendrepeat" "lineIndent * indentSize ) );
                }
                else
                {
                    buf.append' ' );
                }
            }
            for ( int j = 0; j < token.length(); j++ )
            {
                char c = token.charAtj );
                if ( c == '\t' )
                {
                    buf.appendrepeat" "indentSize - buf.length() % indentSize ) );
                }
                else if ( c == '\u00A0' )
                {
                    buf.append' ' );
                }
                else
                {
                    buf.appendc );
                }
            }
        }
        lines.addbuf.toString() );
    }

    
Gets the indentation level of the specified line.

Parameters:
line The line whose indentation level should be retrieved, must not be null.
Returns:
The indentation level of the line.
    private static int getIndentLevelString line )
    {
        int level = 0;
        for ( int i = 0; i < line.length() && line.charAti ) == '\t'i++ )
        {
            level++;
        }
        for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ )
        {
            if ( line.charAti ) == '\t' )
            {
                level++;
                break;
            }
        }
        return level;
    }
New to GrepCode? Check out our FAQ X