From db413a5a751c372f883039d960207963f2996743 Mon Sep 17 00:00:00 2001 From: Michael Keppler Date: Wed, 27 Sep 2023 07:29:51 +0200 Subject: [PATCH] Sort output of discover mojo (#630) * sort just for output, not in any of the APIs returning the data * sort case insensitive, which is generally better suited for humans reading a list --- .../maven/RewriteDiscoverMojo.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/openrewrite/maven/RewriteDiscoverMojo.java b/src/main/java/org/openrewrite/maven/RewriteDiscoverMojo.java index cdb0adf0..28459368 100644 --- a/src/main/java/org/openrewrite/maven/RewriteDiscoverMojo.java +++ b/src/main/java/org/openrewrite/maven/RewriteDiscoverMojo.java @@ -28,8 +28,12 @@ import org.openrewrite.maven.ui.RecipeDescriptorTreePrompter; import org.openrewrite.style.NamedStyles; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; import java.util.HashSet; +import java.util.List; /** * Generate a report of the available recipes and styles found on the classpath.
@@ -95,26 +99,34 @@ public void execute() throws MojoExecutionException { } private void writeDiscovery(Collection availableRecipeDescriptors, Collection activeRecipeDescriptors, Collection availableStyles) { + List availableRecipesSorted = new ArrayList<>(availableRecipeDescriptors); + availableRecipesSorted.sort(Comparator.comparing(RecipeDescriptor::getName, String.CASE_INSENSITIVE_ORDER)); getLog().info("Available Recipes:"); - for (RecipeDescriptor recipeDescriptor : availableRecipeDescriptors) { + for (RecipeDescriptor recipeDescriptor : availableRecipesSorted) { writeRecipeDescriptor(recipeDescriptor, detail, 0, 1); } + List availableStylesSorted = new ArrayList<>(availableStyles); + availableStylesSorted.sort(Comparator.comparing(NamedStyles::getName, String.CASE_INSENSITIVE_ORDER)); getLog().info(""); getLog().info("Available Styles:"); - for (NamedStyles style : availableStyles) { + for (NamedStyles style : availableStylesSorted) { getLog().info(" " + style.getName()); } + List activeStylesSorted = new ArrayList<>(getActiveStyles()); + activeStylesSorted.sort(String.CASE_INSENSITIVE_ORDER); getLog().info(""); getLog().info("Active Styles:"); - for (String activeStyle : getActiveStyles()) { + for (String activeStyle : activeStylesSorted) { getLog().info(" " + activeStyle); } + List activeRecipesSorted = new ArrayList<>(activeRecipeDescriptors); + activeRecipesSorted.sort(Comparator.comparing(RecipeDescriptor::getName, String.CASE_INSENSITIVE_ORDER)); getLog().info(""); getLog().info("Active Recipes:"); - for (RecipeDescriptor recipeDescriptor : activeRecipeDescriptors) { + for (RecipeDescriptor recipeDescriptor : activeRecipesSorted) { writeRecipeDescriptor(recipeDescriptor, detail, 0, 1); }