parent
a45e1cc750
commit
0660386976
|
@ -51,6 +51,8 @@ class ListPluginsCommand extends Command {
|
||||||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(env.pluginsFile())) {
|
try (DirectoryStream<Path> stream = Files.newDirectoryStream(env.pluginsFile())) {
|
||||||
for (Path plugin : stream) {
|
for (Path plugin : stream) {
|
||||||
terminal.println(plugin.getFileName().toString());
|
terminal.println(plugin.getFileName().toString());
|
||||||
|
PluginInfo info = PluginInfo.readFromProperties(env.pluginsFile().resolve(plugin.toAbsolutePath()));
|
||||||
|
terminal.println(Terminal.Verbosity.VERBOSE, info.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,13 @@
|
||||||
|
|
||||||
package org.elasticsearch.plugins;
|
package org.elasticsearch.plugins;
|
||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.NoSuchFileException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
import org.apache.lucene.util.LuceneTestCase;
|
||||||
import org.elasticsearch.cli.ExitCodes;
|
import org.elasticsearch.cli.ExitCodes;
|
||||||
|
@ -29,6 +33,7 @@ import org.elasticsearch.cli.MockTerminal;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.env.Environment;
|
import org.elasticsearch.env.Environment;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
|
import org.elasticsearch.Version;
|
||||||
|
|
||||||
@LuceneTestCase.SuppressFileSystems("*")
|
@LuceneTestCase.SuppressFileSystems("*")
|
||||||
public class ListPluginsCommandTests extends ESTestCase {
|
public class ListPluginsCommandTests extends ESTestCase {
|
||||||
|
@ -43,20 +48,38 @@ public class ListPluginsCommandTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
static MockTerminal listPlugins(Environment env) throws Exception {
|
static MockTerminal listPlugins(Environment env) throws Exception {
|
||||||
|
return listPlugins(env, new String[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static MockTerminal listPlugins(Environment env, String[] args) throws Exception {
|
||||||
MockTerminal terminal = new MockTerminal();
|
MockTerminal terminal = new MockTerminal();
|
||||||
String[] args = {};
|
|
||||||
int status = new ListPluginsCommand(env).main(args, terminal);
|
int status = new ListPluginsCommand(env).main(args, terminal);
|
||||||
assertEquals(ExitCodes.OK, status);
|
assertEquals(ExitCodes.OK, status);
|
||||||
return terminal;
|
return terminal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String buildMultiline(String... args){
|
||||||
|
return Arrays.asList(args).stream().collect(Collectors.joining("\n", "", "\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void buildFakePlugin(Environment env, String description, String name, String classname) throws IOException {
|
||||||
|
PluginTestUtil.writeProperties(env.pluginsFile().resolve(name),
|
||||||
|
"description", description,
|
||||||
|
"name", name,
|
||||||
|
"version", "1.0",
|
||||||
|
"elasticsearch.version", Version.CURRENT.toString(),
|
||||||
|
"java.version", System.getProperty("java.specification.version"),
|
||||||
|
"classname", classname);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testPluginsDirMissing() throws Exception {
|
public void testPluginsDirMissing() throws Exception {
|
||||||
Environment env = createEnv();
|
Environment env = createEnv();
|
||||||
Files.delete(env.pluginsFile());
|
Files.delete(env.pluginsFile());
|
||||||
IOException e = expectThrows(IOException.class, () -> {
|
IOException e = expectThrows(IOException.class, () -> {
|
||||||
listPlugins(env);
|
listPlugins(env);
|
||||||
});
|
});
|
||||||
assertTrue(e.getMessage(), e.getMessage().contains("Plugins directory missing"));
|
assertEquals(e.getMessage(), "Plugins directory missing: " + env.pluginsFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoPlugins() throws Exception {
|
public void testNoPlugins() throws Exception {
|
||||||
|
@ -66,18 +89,63 @@ public class ListPluginsCommandTests extends ESTestCase {
|
||||||
|
|
||||||
public void testOnePlugin() throws Exception {
|
public void testOnePlugin() throws Exception {
|
||||||
Environment env = createEnv();
|
Environment env = createEnv();
|
||||||
Files.createDirectory(env.pluginsFile().resolve("fake"));
|
buildFakePlugin(env, "fake desc", "fake", "org.fake");
|
||||||
MockTerminal terminal = listPlugins(env);
|
MockTerminal terminal = listPlugins(env);
|
||||||
assertTrue(terminal.getOutput(), terminal.getOutput().contains("fake"));
|
assertEquals(terminal.getOutput(), buildMultiline("fake"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTwoPlugins() throws Exception {
|
public void testTwoPlugins() throws Exception {
|
||||||
Environment env = createEnv();
|
Environment env = createEnv();
|
||||||
Files.createDirectory(env.pluginsFile().resolve("fake1"));
|
buildFakePlugin(env, "fake desc", "fake1", "org.fake");
|
||||||
Files.createDirectory(env.pluginsFile().resolve("fake2"));
|
buildFakePlugin(env, "fake desc 2", "fake2", "org.fake");
|
||||||
MockTerminal terminal = listPlugins(env);
|
MockTerminal terminal = listPlugins(env);
|
||||||
|
assertEquals(terminal.getOutput(), buildMultiline("fake1", "fake2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPluginWithVerbose() throws Exception {
|
||||||
|
Environment env = createEnv();
|
||||||
|
buildFakePlugin(env, "fake desc", "fake_plugin", "org.fake");
|
||||||
|
String[] params = { "-v" };
|
||||||
|
MockTerminal terminal = listPlugins(env, params);
|
||||||
|
assertEquals(terminal.getOutput(), buildMultiline("Plugins directory: " + env.pluginsFile(), "fake_plugin",
|
||||||
|
"- Plugin information:", "Name: fake_plugin", "Description: fake desc", "Version: 1.0", " * Classname: org.fake"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPluginWithVerboseMultiplePlugins() throws Exception {
|
||||||
|
Environment env = createEnv();
|
||||||
|
buildFakePlugin(env, "fake desc 1", "fake_plugin1", "org.fake");
|
||||||
|
buildFakePlugin(env, "fake desc 2", "fake_plugin2", "org.fake2");
|
||||||
|
String[] params = { "-v" };
|
||||||
|
MockTerminal terminal = listPlugins(env, params);
|
||||||
|
assertEquals(terminal.getOutput(), buildMultiline("Plugins directory: " + env.pluginsFile(),
|
||||||
|
"fake_plugin1", "- Plugin information:", "Name: fake_plugin1", "Description: fake desc 1", "Version: 1.0",
|
||||||
|
" * Classname: org.fake", "fake_plugin2", "- Plugin information:", "Name: fake_plugin2",
|
||||||
|
"Description: fake desc 2", "Version: 1.0", " * Classname: org.fake2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPluginWithoutVerboseMultiplePlugins() throws Exception {
|
||||||
|
Environment env = createEnv();
|
||||||
|
buildFakePlugin(env, "fake desc 1", "fake_plugin1", "org.fake");
|
||||||
|
buildFakePlugin(env, "fake desc 2", "fake_plugin2", "org.fake2");
|
||||||
|
MockTerminal terminal = listPlugins(env, new String[0]);
|
||||||
String output = terminal.getOutput();
|
String output = terminal.getOutput();
|
||||||
assertTrue(output, output.contains("fake1"));
|
assertEquals(output, buildMultiline("fake_plugin1", "fake_plugin2"));
|
||||||
assertTrue(output, output.contains("fake2"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testPluginWithoutDescriptorFile() throws Exception{
|
||||||
|
Environment env = createEnv();
|
||||||
|
Files.createDirectories(env.pluginsFile().resolve("fake1"));
|
||||||
|
NoSuchFileException e = expectThrows(NoSuchFileException.class, () -> listPlugins(env));
|
||||||
|
assertEquals(e.getFile(), env.pluginsFile().resolve("fake1").resolve(PluginInfo.ES_PLUGIN_PROPERTIES).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPluginWithWrongDescriptorFile() throws Exception{
|
||||||
|
Environment env = createEnv();
|
||||||
|
PluginTestUtil.writeProperties(env.pluginsFile().resolve("fake1"),
|
||||||
|
"description", "fake desc");
|
||||||
|
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> listPlugins(env));
|
||||||
|
assertEquals(e.getMessage(), "Property [name] is missing in [" +
|
||||||
|
env.pluginsFile().resolve("fake1").resolve(PluginInfo.ES_PLUGIN_PROPERTIES).toString() + "]");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue