diff --git a/core/src/main/java/org/elasticsearch/plugins/ListPluginsCommand.java b/core/src/main/java/org/elasticsearch/plugins/ListPluginsCommand.java index b513be99dcfcb..c03e70ad4da3d 100644 --- a/core/src/main/java/org/elasticsearch/plugins/ListPluginsCommand.java +++ b/core/src/main/java/org/elasticsearch/plugins/ListPluginsCommand.java @@ -23,6 +23,9 @@ import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import joptsimple.OptionSet; import org.elasticsearch.cli.Command; @@ -48,12 +51,17 @@ protected void execute(Terminal terminal, OptionSet options) throws Exception { } terminal.println(Terminal.Verbosity.VERBOSE, "Plugins directory: " + env.pluginsFile()); - try (DirectoryStream stream = Files.newDirectoryStream(env.pluginsFile())) { - for (Path plugin : stream) { - terminal.println(plugin.getFileName().toString()); - PluginInfo info = PluginInfo.readFromProperties(env.pluginsFile().resolve(plugin.toAbsolutePath())); - terminal.println(Terminal.Verbosity.VERBOSE, info.toString()); + final List plugins = new ArrayList<>(); + try (DirectoryStream paths = Files.newDirectoryStream(env.pluginsFile())) { + for (Path plugin : paths) { + plugins.add(plugin); } } + Collections.sort(plugins); + for (final Path plugin : plugins) { + terminal.println(plugin.getFileName().toString()); + PluginInfo info = PluginInfo.readFromProperties(env.pluginsFile().resolve(plugin.toAbsolutePath())); + terminal.println(Terminal.Verbosity.VERBOSE, info.toString()); + } } }