o Made order of goals in help output deterministic

git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@654827 13f79535-47bb-0310-9956-ffa450edef68
master
Benjamin Bentmann 2008-05-09 14:42:06 +00:00
parent 27cb7927a9
commit 790e6439bb
1 changed files with 32 additions and 9 deletions

View File

@ -24,9 +24,13 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.StringReader;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.swing.text.html.HTMLEditorKit;
@ -278,6 +282,31 @@ public class PluginHelpGenerator
private static void writeExecute( Writer writer, PluginDescriptor pluginDescriptor )
throws IOException
{
List mojoDescriptors = new ArrayList( pluginDescriptor.getMojos() );
for ( Iterator it = mojoDescriptors.iterator(); it.hasNext(); )
{
MojoDescriptor mojoDescriptor = (MojoDescriptor) it.next();
if ( getHelpGoalName().equals( mojoDescriptor.getGoal() ) )
{
// remove previously generated help goal
it.remove();
}
}
Collections.sort( mojoDescriptors, new Comparator()
{
public int compare( Object arg0, Object arg1 )
{
MojoDescriptor mojo0 = (MojoDescriptor) arg0;
MojoDescriptor mojo1 = (MojoDescriptor) arg1;
return mojo0.getGoal().compareToIgnoreCase( mojo1.getGoal() );
}
} );
writer.write( " /** {@inheritDoc} */" + LS );
writer.write( " public void execute()" + LS );
writer.write( " throws MojoExecutionException" + LS );
@ -286,22 +315,16 @@ public class PluginHelpGenerator
writer.write( " StringBuffer sb = new StringBuffer();" + LS );
writer.write( LS );
writer.write( " sb.append( \"The '" + pluginDescriptor.getPluginLookupKey() + "' plugin has "
+ ( pluginDescriptor.getMojos().size() + 1 ) + " "
+ ( ( pluginDescriptor.getMojos().size() + 1 ) > 1 ? "goals" : "goal" ) + ":\" ).append( \"\\n\" );" + LS );
+ ( mojoDescriptors.size() + 1 ) + " "
+ ( ( mojoDescriptors.size() + 1 ) > 1 ? "goals" : "goal" ) + ":\" ).append( \"\\n\" );" + LS );
writer.write( " sb.append( \"\\n\" );" + LS );
writer.write( LS );
for ( Iterator it = pluginDescriptor.getMojos().iterator(); it.hasNext(); )
for ( Iterator it = mojoDescriptors.iterator(); it.hasNext(); )
{
MojoDescriptor descriptor = (MojoDescriptor) it.next();
if ( getHelpGoalName().equals( descriptor.getGoal() ) )
{
// don't document help goal twice
continue;
}
String goal = descriptor.getFullGoalName();
String description = StringUtils.isNotEmpty( descriptor.getDescription() ) ?
StringUtils.escape( toText( descriptor.getDescription() ) ) : "No description available.";