From 27414b458d38cfd59b048889efb63a4f16575cb9 Mon Sep 17 00:00:00 2001 From: Vincent Siveton Date: Fri, 29 Aug 2008 22:08:31 +0000 Subject: [PATCH] o revert part of r690203 and improved it git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@690403 13f79535-47bb-0310-9956-ffa450edef68 --- .../plugin/generator/PluginHelpGenerator.java | 26 +----------------- .../maven/tools/plugin/util/PluginUtils.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java index d3bcaef..9b2e2d6 100644 --- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java +++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java @@ -25,8 +25,6 @@ import java.io.IOException; import java.io.InputStream; 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; @@ -453,18 +451,6 @@ public class PluginHelpGenerator writer.write( LS ); - Collections.sort( mojoDescriptors, new Comparator() - { - /** {@inheritDoc} */ - public int compare( Object o1, Object o2 ) - { - MojoDescriptor md1 = (MojoDescriptor) o1; - MojoDescriptor md2 = (MojoDescriptor) o2; - - return md1.getId().compareTo( md2.getId() ); - } - } ); - for ( Iterator it = mojoDescriptors.iterator(); it.hasNext(); ) { MojoDescriptor descriptor = (MojoDescriptor) it.next(); @@ -514,17 +500,7 @@ public class PluginHelpGenerator { List params = descriptor.getParameters(); - Collections.sort( params, new Comparator() - { - /** {@inheritDoc} */ - public int compare( Object o1, Object o2 ) - { - Parameter parameter1 = (Parameter) o1; - Parameter parameter2 = (Parameter) o2; - - return parameter1.getName().compareTo( parameter2.getName() ); - } - } ); + PluginUtils.sortMojoParameters( params ); writer.write( " if ( detail )" + LS ); writer.write( " {" + LS ); diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java index 28644b5..e26c7fe 100644 --- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java +++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java @@ -46,6 +46,7 @@ import javax.swing.text.html.parser.ParserDelegator; import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.model.Dependency; import org.apache.maven.plugin.descriptor.MojoDescriptor; +import org.apache.maven.plugin.descriptor.Parameter; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; import org.apache.maven.reporting.MavenReport; @@ -413,6 +414,7 @@ public final class PluginUtils * Sorts the specified mojo descriptors by goal name. * * @param mojoDescriptors The mojo descriptors to sort, may be null. + * @see MojoDescriptor#getGoal() */ public static void sortMojos( List mojoDescriptors ) { @@ -425,9 +427,34 @@ public final class PluginUtils { MojoDescriptor mojo0 = (MojoDescriptor) arg0; MojoDescriptor mojo1 = (MojoDescriptor) arg1; + return mojo0.getGoal().compareToIgnoreCase( mojo1.getGoal() ); } + } ); + } + } + /** + * Sorts the specified mojo parameters by name. + * + * @param parameters The mojo parameters to sort, may be null. + * @see Parameter#getName() + * @since 2.4.4 + */ + public static void sortMojoParameters( List parameters ) + { + if ( parameters != null ) + { + Collections.sort( parameters, new Comparator() + { + /** {@inheritDoc} */ + public int compare( Object arg0, Object arg1 ) + { + Parameter parameter1 = (Parameter) arg0; + Parameter parameter2 = (Parameter) arg1; + + return parameter1.getName().compareToIgnoreCase( parameter2.getName() ); + } } ); } }