diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/extensions/ListXPackExtensionCommand.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/extensions/ListXPackExtensionCommand.java index c9c81828cb7..622e93434d2 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/extensions/ListXPackExtensionCommand.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/extensions/ListXPackExtensionCommand.java @@ -16,6 +16,9 @@ import java.io.IOException; 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 java.util.Map; import static org.elasticsearch.cli.Terminal.Verbosity.VERBOSE; @@ -37,14 +40,19 @@ class ListXPackExtensionCommand extends SettingCommand { throw new IOException("Extensions directory missing: " + resolveXPackExtensionsFile(env)); } terminal.println(VERBOSE, "XPack Extensions directory: " + resolveXPackExtensionsFile(env)); - try (DirectoryStream stream = Files.newDirectoryStream(resolveXPackExtensionsFile(env))) { - for (Path extension : stream) { - terminal.println(extension.getFileName().toString()); - XPackExtensionInfo info = - XPackExtensionInfo.readFromProperties(extension); - terminal.println(VERBOSE, info.toString()); + final List extensions = new ArrayList<>(); + try (DirectoryStream paths = Files.newDirectoryStream(resolveXPackExtensionsFile(env))) { + for (Path extension : paths) { + extensions.add(extension); } } + Collections.sort(extensions); + for (final Path extension : extensions) { + terminal.println(extension.getFileName().toString()); + XPackExtensionInfo info = + XPackExtensionInfo.readFromProperties(extension); + terminal.println(VERBOSE, info.toString()); + } } }