Add more information and options in PluginManager
New option -l, --list displays list of existing plugins New option -h, --help displays help Deprecate options: -install is now -i, --install -remove is now -r, --remove -url is now -u, --url Catch ArraysOutOfBoundException when no arg given to install, remove or url option Add description on plugin name structure: - elasticsearch/plugin/version for official elasticsearch plugins (download from download.elasticsearch.org) - groupId/artifactId/version for community plugins (download from maven central or oss sonatype) - username/repository for site plugins (download from github master) Closes #3112.
This commit is contained in:
parent
c16a46e15c
commit
663f653ced
|
@ -288,6 +288,18 @@ public class PluginManager {
|
|||
}
|
||||
}
|
||||
|
||||
public void listInstalledPlugins() {
|
||||
File[] plugins = environment.pluginsFile().listFiles();
|
||||
System.out.println("Installed plugins:");
|
||||
if (plugins.length == 0) {
|
||||
System.out.println(" - No plugin detected in " + environment.pluginsFile().getAbsolutePath());
|
||||
}
|
||||
|
||||
for (int i = 0; i < plugins.length; i++) {
|
||||
System.out.println(" - " + plugins[i].getName());
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Tuple<Settings, Environment> initialSettings = InternalSettingsPerparer.prepareSettings(EMPTY_SETTINGS, true);
|
||||
|
||||
|
@ -298,9 +310,19 @@ public class PluginManager {
|
|||
String url = null;
|
||||
boolean verbose = false;
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
if ("url".equals(args[i]) || "-url".equals(args[i])) {
|
||||
url = args[i + 1];
|
||||
} else if ("verbose".equals(args[i]) || "-verbose".equals(args[i])) {
|
||||
String command = args[i];
|
||||
if ("-u".equals(command) || "--url".equals(command)
|
||||
// Deprecated commands
|
||||
|| "url".equals(command) || "-url".equals(command)) {
|
||||
try {
|
||||
url = args[i + 1];
|
||||
} catch (Exception e) {
|
||||
displayHelp("Error while installing plugin, reason: " + e.getClass().getSimpleName() +
|
||||
": " + e.getMessage());
|
||||
System.exit(1);
|
||||
}
|
||||
} else if ("-v".equals(command) || "--v".equals(command)
|
||||
|| "verbose".equals(command) || "-verbose".equals(command)) {
|
||||
verbose = true;
|
||||
}
|
||||
}
|
||||
|
@ -309,34 +331,69 @@ public class PluginManager {
|
|||
PluginManager pluginManager = new PluginManager(initialSettings.v2(), url);
|
||||
|
||||
if (args.length < 1) {
|
||||
System.out.println("Usage:");
|
||||
System.out.println(" -url [plugin location] : Set exact URL to download the plugin from");
|
||||
System.out.println(" -install [plugin name] : Downloads and installs listed plugins");
|
||||
System.out.println(" -remove [plugin name] : Removes listed plugins");
|
||||
System.out.println(" -verbose : Prints verbose messages");
|
||||
displayHelp(null);
|
||||
}
|
||||
for (int c = 0; c < args.length; c++) {
|
||||
String command = args[c];
|
||||
if (command.equals("install") || command.equals("-install")) {
|
||||
String pluginName = args[++c];
|
||||
System.out.println("-> Installing " + pluginName + "...");
|
||||
if (command.equals("-i") || command.equals("--install")
|
||||
// Deprecated commands
|
||||
|| command.equals("install") || command.equals("-install")) {
|
||||
String pluginName = null;
|
||||
try {
|
||||
pluginName = args[++c];
|
||||
System.out.println("-> Installing " + pluginName + "...");
|
||||
pluginManager.downloadAndExtract(pluginName, verbose);
|
||||
} catch (IOException e) {
|
||||
System.out.println("Failed to install " + pluginName + ", reason: " + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
displayHelp("Error while installing plugin, reason: " + e.getClass().getSimpleName() +
|
||||
": " + e.getMessage());
|
||||
System.exit(1);
|
||||
}
|
||||
} else if (command.equals("remove") || command.equals("-remove")) {
|
||||
String pluginName = args[++c];
|
||||
System.out.println("-> Removing " + pluginName + " ");
|
||||
} else if (command.equals("-r") || command.equals("--remove")
|
||||
// Deprecated commands
|
||||
|| command.equals("remove") || command.equals("-remove")) {
|
||||
String pluginName = null;
|
||||
try {
|
||||
pluginName = args[++c];
|
||||
System.out.println("-> Removing " + pluginName + " ");
|
||||
pluginManager.removePlugin(pluginName);
|
||||
} catch (IOException e) {
|
||||
System.out.println("Failed to remove " + pluginName + ", reason: " + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
displayHelp("Error while removing plugin, reason: " + e.getClass().getSimpleName() +
|
||||
": " + e.getMessage());
|
||||
}
|
||||
} else if (command.equals("-l") || command.equals("--list")) {
|
||||
pluginManager.listInstalledPlugins();
|
||||
} else if (command.equals("-h") || command.equals("--help")) {
|
||||
displayHelp(null);
|
||||
} else {
|
||||
// not install or remove, continue
|
||||
c++;
|
||||
displayHelp("Command [" + args[c] + "] unknown.");
|
||||
// Unknown command. We break...
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void displayHelp(String message) {
|
||||
System.out.println("Usage:");
|
||||
System.out.println(" -u, --url [plugin location] : Set exact URL to download the plugin from");
|
||||
System.out.println(" -i, --install [plugin name] : Downloads and installs listed plugins [*]");
|
||||
System.out.println(" -r, --remove [plugin name] : Removes listed plugins");
|
||||
System.out.println(" -l, --list : List installed plugins");
|
||||
System.out.println(" -v, --verbose : Prints verbose messages");
|
||||
System.out.println(" -h, --help : Prints this help message");
|
||||
System.out.println();
|
||||
System.out.println(" [*] Plugin name could be:");
|
||||
System.out.println(" elasticsearch/plugin/version for official elasticsearch plugins (download from download.elasticsearch.org)");
|
||||
System.out.println(" groupId/artifactId/version for community plugins (download from maven central or oss sonatype)");
|
||||
System.out.println(" username/repository for site plugins (download from github master)");
|
||||
|
||||
if (message != null) {
|
||||
System.out.println();
|
||||
System.out.println("Message:");
|
||||
System.out.println(" " + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue