code formatting

git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1405094 13f79535-47bb-0310-9956-ffa450edef68
master
Herve Boutemy 2012-11-02 18:37:37 +00:00
parent 0ba0555964
commit a757bee927
1 changed files with 65 additions and 51 deletions

View File

@ -75,17 +75,17 @@ public class HelpMojo
{ {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
return dBuilder.parse(is); return dBuilder.parse( is );
} }
catch ( IOException e ) catch ( IOException e )
{ {
throw new MojoExecutionException( e.getMessage(), e ); throw new MojoExecutionException( e.getMessage(), e );
} }
catch (ParserConfigurationException e) catch ( ParserConfigurationException e )
{ {
throw new MojoExecutionException( e.getMessage(), e ); throw new MojoExecutionException( e.getMessage(), e );
} }
catch (SAXException e) catch ( SAXException e )
{ {
throw new MojoExecutionException( e.getMessage(), e ); throw new MojoExecutionException( e.getMessage(), e );
} }
@ -111,12 +111,12 @@ public class HelpMojo
Document doc = build(); Document doc = build();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
Node plugin = getSingleChild(doc, "plugin"); Node plugin = getSingleChild( doc, "plugin" );
String name = getValue(plugin, "name"); String name = getValue( plugin, "name" );
String version = getValue(plugin, "version"); String version = getValue( plugin, "version" );
String id = getValue( plugin, "groupId" )+ ":" + getValue( plugin, "artifactId" ) + ":" + version; String id = getValue( plugin, "groupId" ) + ":" + getValue( plugin, "artifactId" ) + ":" + version;
if ( isNotEmpty( name ) && !name.contains( id ) ) if ( isNotEmpty( name ) && !name.contains( id ) )
{ {
append( sb, name + " " + version, 0 ); append( sb, name + " " + version, 0 );
@ -132,24 +132,25 @@ public class HelpMojo
append( sb, id, 0 ); append( sb, id, 0 );
} }
} }
append( sb, getValue(plugin, "description"), 1 ); append( sb, getValue( plugin, "description" ), 1 );
append( sb, "", 0 ); append( sb, "", 0 );
//<goalPrefix>plugin</goalPrefix> //<goalPrefix>plugin</goalPrefix>
String goalPrefix = getValue(plugin, "goalPrefix"); String goalPrefix = getValue( plugin, "goalPrefix" );
Node mojos1 = getSingleChild(plugin, "mojos"); Node mojos1 = getSingleChild( plugin, "mojos" );
List<Node> mojos = findNamedChild(mojos1, "mojo"); List<Node> mojos = findNamedChild( mojos1, "mojo" );
if ( goal == null || goal.length() <= 0 ) if ( goal == null || goal.length() <= 0 )
{ {
append( sb, "This plugin has " + mojos.size() + ( mojos.size() > 1 ? " goals:" : " goal:" ) , 0 ); append( sb, "This plugin has " + mojos.size() + ( mojos.size() > 1 ? " goals:" : " goal:" ), 0 );
append( sb, "", 0 ); append( sb, "", 0 );
} }
for (Node mojo : mojos) { for ( Node mojo : mojos )
writeGoal(sb, goalPrefix, (Element) mojo); {
writeGoal( sb, goalPrefix, (Element) mojo );
} }
if ( getLog().isInfoEnabled() ) if ( getLog().isInfoEnabled() )
@ -159,63 +160,73 @@ public class HelpMojo
} }
private static boolean isNotEmpty( String string) private static boolean isNotEmpty( String string )
{ {
return string != null && string.length() > 0; return string != null && string.length() > 0;
} }
private String getValue(Node node, String elementName) throws MojoExecutionException { private String getValue( Node node, String elementName )
return getSingleChild(node, elementName).getTextContent(); throws MojoExecutionException
{
return getSingleChild( node, elementName ).getTextContent();
} }
private Node getSingleChild(Node node, String elementName) throws MojoExecutionException { private Node getSingleChild( Node node, String elementName )
List<Node> namedChild = findNamedChild(node, elementName); throws MojoExecutionException
if (namedChild.isEmpty())
{ {
throw new MojoExecutionException("Could not find " + elementName + "in plugin-help.xml"); List<Node> namedChild = findNamedChild( node, elementName );
} if ( namedChild.isEmpty() )
if (namedChild.size() > 1)
{ {
throw new MojoExecutionException("Multiple " + elementName + "in plugin-help.xml"); throw new MojoExecutionException( "Could not find " + elementName + "in plugin-help.xml" );
} }
Node node1 = namedChild.get(0); if ( namedChild.size() > 1 )
{
throw new MojoExecutionException( "Multiple " + elementName + "in plugin-help.xml" );
}
Node node1 = namedChild.get( 0 );
return node1; return node1;
} }
private List<Node> findNamedChild(Node node, String elementName){ private List<Node> findNamedChild( Node node, String elementName )
{
List<Node> result = new ArrayList<Node>(); List<Node> result = new ArrayList<Node>();
NodeList childNodes = node.getChildNodes(); NodeList childNodes = node.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++){ for ( int i = 0; i < childNodes.getLength(); i++ )
Node item = childNodes.item(i); {
if (elementName.equals(item.getNodeName())){ Node item = childNodes.item( i );
result.add( item); if ( elementName.equals( item.getNodeName() ) )
{
result.add( item );
} }
} }
return result; return result;
} }
private Node findSingleChild( Node node, String elementName )
private Node findSingleChild(Node node, String elementName) throws MojoExecutionException { throws MojoExecutionException
List<Node> elementsByTagName = findNamedChild(node, elementName); {
if (elementsByTagName.isEmpty()) List<Node> elementsByTagName = findNamedChild( node, elementName );
if ( elementsByTagName.isEmpty() )
{ {
return null; return null;
} }
if (elementsByTagName.size() > 1) if ( elementsByTagName.size() > 1 )
{ {
throw new MojoExecutionException("Multiple " + elementName + "in plugin-help.xml"); throw new MojoExecutionException( "Multiple " + elementName + "in plugin-help.xml" );
} }
return elementsByTagName.get(0); return elementsByTagName.get( 0 );
} }
private void writeGoal( StringBuilder sb, String goalPrefix, Element mojo ) throws MojoExecutionException { private void writeGoal( StringBuilder sb, String goalPrefix, Element mojo )
String mojoGoal = getValue(mojo, "goal"); throws MojoExecutionException
Node configurationElement = findSingleChild(mojo, "configuration"); {
String mojoGoal = getValue( mojo, "goal" );
Node configurationElement = findSingleChild( mojo, "configuration" );
if ( goal == null || goal.length() <= 0 || mojoGoal.equals( goal ) ) if ( goal == null || goal.length() <= 0 || mojoGoal.equals( goal ) )
{ {
append( sb, goalPrefix + ":" + mojoGoal, 0 ); append( sb, goalPrefix + ":" + mojoGoal, 0 );
Node deprecated = findSingleChild(mojo, "deprecated"); Node deprecated = findSingleChild( mojo, "deprecated" );
if ( ( deprecated != null ) && isNotEmpty( deprecated.getNodeValue() ) ) if ( ( deprecated != null ) && isNotEmpty( deprecated.getNodeValue() ) )
{ {
append( sb, "Deprecated. " + deprecated, 1 ); append( sb, "Deprecated. " + deprecated, 1 );
@ -233,23 +244,26 @@ public class HelpMojo
if ( detail ) if ( detail )
{ {
Node parametersNode = getSingleChild(mojo, "parameters"); Node parametersNode = getSingleChild( mojo, "parameters" );
List<Node> parameters = findNamedChild(parametersNode, "parameter"); List<Node> parameters = findNamedChild( parametersNode, "parameter" );
append( sb, "Available parameters:", 1 ); append( sb, "Available parameters:", 1 );
append( sb, "", 0 ); append( sb, "", 0 );
for (Node parameter : parameters) { for ( Node parameter : parameters )
writeParameter(sb, parameter, configurationElement); {
writeParameter( sb, parameter, configurationElement );
} }
} }
} }
} }
private void writeParameter( StringBuilder sb, Node parameter, Node configurationElement ) throws MojoExecutionException { private void writeParameter( StringBuilder sb, Node parameter, Node configurationElement )
String parameterName = getValue(parameter, "name"); throws MojoExecutionException
String parameterDescription = getValue(parameter, "description"); {
String parameterName = getValue( parameter, "name" );
String parameterDescription = getValue( parameter, "description" );
Node fieldConfigurationElement = findSingleChild(configurationElement, parameterName); Node fieldConfigurationElement = findSingleChild( configurationElement, parameterName );
String parameterDefaultValue = ""; String parameterDefaultValue = "";
if ( fieldConfigurationElement != null && fieldConfigurationElement.getNodeValue() != null ) if ( fieldConfigurationElement != null && fieldConfigurationElement.getNodeValue() != null )
@ -257,18 +271,18 @@ public class HelpMojo
parameterDefaultValue = " (Default: " + ((Element)fieldConfigurationElement).getAttribute( "default-value" ) + ")"; parameterDefaultValue = " (Default: " + ((Element)fieldConfigurationElement).getAttribute( "default-value" ) + ")";
} }
append( sb, parameterName + parameterDefaultValue, 2 ); append( sb, parameterName + parameterDefaultValue, 2 );
Node deprecated = findSingleChild(parameter, "deprecated"); Node deprecated = findSingleChild( parameter, "deprecated" );
if ( ( deprecated != null ) && isNotEmpty( deprecated.getNodeValue() ) ) if ( ( deprecated != null ) && isNotEmpty( deprecated.getNodeValue() ) )
{ {
append( sb, "Deprecated. " + deprecated.getNodeValue(), 3 ); append( sb, "Deprecated. " + deprecated.getNodeValue(), 3 );
append( sb, "", 0 ); append( sb, "", 0 );
} }
append( sb, parameterDescription, 3 ); append( sb, parameterDescription, 3 );
if ( "true".equals( getValue(parameter, "required")) ) if ( "true".equals( getValue( parameter, "required" ) ) )
{ {
append( sb, "Required: Yes", 3 ); append( sb, "Required: Yes", 3 );
} }
Node expression = findSingleChild(parameter, "expression"); Node expression = findSingleChild( parameter, "expression" );
if ( ( expression != null ) && isNotEmpty( expression.getNodeValue() ) ) if ( ( expression != null ) && isNotEmpty( expression.getNodeValue() ) )
{ {
append( sb, "Expression: " + expression.getNodeValue(), 3 ); append( sb, "Expression: " + expression.getNodeValue(), 3 );