getLog().warn( "The parameter 'lineLength' should be positive, using '80' as default." ); lineLength = DEFAULT_LINE_LENGTH; getLog().warn( "The parameter 'indentSize' should be positive, using '2' as default." ); indentSize = 2; Document doc = build(); Node plugin = getSingleChild( doc, "plugin" ); String name = getValue( plugin, "name" ); String version = getValue( plugin, "version" ); String id = getValue( plugin, "groupId" ) + ":" + getValue( plugin, "artifactId" ) + ":" + version; if ( isNotEmpty( name ) && !name.contains( id ) ) if ( isNotEmpty( name ) ) append( sb, name, 0 ); append( sb, id, 0 ); append( sb, getValue( plugin, "description" ), 1 ); append( sb, "", 0 ); String goalPrefix = getValue( plugin, "goalPrefix" ); Node mojos1 = getSingleChild( plugin, "mojos" ); List<Node> mojos = findNamedChild( mojos1, "mojo" );
private void writeGoal( StringBuilder sb, String goalPrefix, Element mojo ) throws MojoExecutionException String mojoGoal = getValue( mojo, "goal" ); Node configurationElement = findSingleChild( mojo, "configuration" ); Node description = findSingleChild( mojo, "description" ); if ( goal == null || goal.length() <= 0 || mojoGoal.equals( goal ) ) Node deprecated = findSingleChild( mojo, "deprecated" ); if ( ( deprecated != null ) && isNotEmpty( deprecated.getTextContent() ) ) append( sb, "", 0 ); append( sb, description.getTextContent(), 1 ); append( sb, description.getTextContent(), 1 ); append( sb, "", 0 ); Node parametersNode = getSingleChild( mojo, "parameters" ); List<Node> parameters = findNamedChild( parametersNode, "parameter" ); append( sb, "Available parameters:", 1 ); append( sb, "", 0 ); writeParameter( sb, parameter, configurationElement );
private void writeParameter( StringBuilder sb, Node parameter, Node configurationElement ) throws MojoExecutionException String parameterName = getValue( parameter, "name" ); String parameterDescription = getValue( parameter, "description" ); fieldConfigurationElement = (Element) findSingleChild( configurationElement, parameterName ); Node deprecated = findSingleChild( parameter, "deprecated" ); if ( ( deprecated != null ) && isNotEmpty( deprecated.getTextContent() ) ) append( sb, "Deprecated. " + deprecated.getTextContent(), 3 ); append( sb, "", 0 ); append( sb, parameterDescription, 3 ); if ( "true".equals( getValue( parameter, "required" ) ) ) append( sb, "Required: Yes", 3 ); if ( ( fieldConfigurationElement != null ) && isNotEmpty( fieldConfigurationElement.getTextContent() ) ) String property = getPropertyFromExpression( fieldConfigurationElement.getTextContent() ); append( sb, "User property: " + property, 3 ); append( sb, "", 0 );
int lineIndent = getIndentLevel( line ); StringBuilder buf = new StringBuilder( 256 ); buf.append( repeat( " ", lineIndent * indentSize ) ); if ( c == '\t' ) buf.append( repeat( " ", indentSize - buf.length() % indentSize ) );
private Node findSingleChild( Node node, String elementName ) throws MojoExecutionException { List<Node> elementsByTagName = findNamedChild( node, elementName ); if ( elementsByTagName.isEmpty() ) { return null; } if ( elementsByTagName.size() > 1 ) { throw new MojoExecutionException( "Multiple " + elementName + "in plugin-help.xml" ); } return elementsByTagName.get( 0 ); }
private String getValue( Node node, String elementName ) throws MojoExecutionException { return getSingleChild( node, elementName ).getTextContent(); }
private Document build() throws MojoExecutionException getLog().debug( "load plugin-help.xml: " + PLUGIN_HELP_PATH ); InputStream is = null; try
private Node getSingleChild( Node node, String elementName ) throws MojoExecutionException { List<Node> namedChild = findNamedChild( node, elementName ); if ( namedChild.isEmpty() ) { throw new MojoExecutionException( "Could not find " + elementName + " in plugin-help.xml" ); } if ( namedChild.size() > 1 ) { throw new MojoExecutionException( "Multiple " + elementName + " in plugin-help.xml" ); } return namedChild.get( 0 ); }