| | |
| | | */ |
| | | package com.gitblit.transport.ssh.commands; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | |
| | |
| | | register(user, RefreshPlugins.class); |
| | | register(user, AvailablePlugins.class); |
| | | register(user, InstallPlugin.class); |
| | | register(user, UpgradePlugin.class); |
| | | register(user, UninstallPlugin.class); |
| | | } |
| | | |
| | |
| | | @CommandMetaData(name = "start", description = "Start a plugin") |
| | | public static class StartPlugin extends PluginCommand { |
| | | |
| | | @Argument(index = 0, required = true, metaVar = "ALL|<id>", usage = "the plugin to start") |
| | | @Argument(index = 0, required = true, metaVar = "ALL|<ID>|<INDEX>", usage = "the plugin to start") |
| | | protected String id; |
| | | |
| | | @Override |
| | |
| | | @CommandMetaData(name = "stop", description = "Stop a plugin") |
| | | public static class StopPlugin extends PluginCommand { |
| | | |
| | | @Argument(index = 0, required = true, metaVar = "ALL|<id>", usage = "the plugin to stop") |
| | | @Argument(index = 0, required = true, metaVar = "ALL|<ID>|<INDEX>", usage = "the plugin to stop") |
| | | protected String id; |
| | | |
| | | @Override |
| | |
| | | @CommandMetaData(name = "enable", description = "Enable a plugin") |
| | | public static class EnablePlugin extends PluginCommand { |
| | | |
| | | @Argument(index = 0, required = true, metaVar = "<id>", usage = "the plugin id to enable") |
| | | @Argument(index = 0, required = true, metaVar = "<ID>|<INDEX>", usage = "the plugin to enable") |
| | | protected String id; |
| | | |
| | | @Override |
| | |
| | | @CommandMetaData(name = "disable", description = "Disable a plugin") |
| | | public static class DisablePlugin extends PluginCommand { |
| | | |
| | | @Argument(index = 0, required = true, metaVar = "<id>", usage = "the plugin to disable") |
| | | @Argument(index = 0, required = true, metaVar = "<ID>|<INDEX>", usage = "the plugin to disable") |
| | | protected String id; |
| | | |
| | | @Override |
| | |
| | | @CommandMetaData(name = "show", description = "Show the details of a plugin") |
| | | public static class ShowPlugin extends PluginCommand { |
| | | |
| | | @Argument(index = 0, required = true, metaVar = "<id>", usage = "the plugin to show") |
| | | @Argument(index = 0, required = true, metaVar = "<ID>|<INDEX>", usage = "the plugin to show") |
| | | protected String id; |
| | | |
| | | @Override |
| | |
| | | |
| | | List<PluginRegistration> list; |
| | | if (updates) { |
| | | list = gitblit.getRegisteredPlugins(InstallState.CAN_UPDATE); |
| | | list = gitblit.getRegisteredPlugins(InstallState.UPDATE_AVAILABLE); |
| | | } else { |
| | | list = gitblit.getRegisteredPlugins(); |
| | | } |
| | |
| | | @CommandMetaData(name = "install", description = "Download and installs a plugin") |
| | | public static class InstallPlugin extends SshCommand { |
| | | |
| | | @Argument(index = 0, required = true, metaVar = "<URL>|<ID>|<NAME>", usage = "the id, name, or the url of the plugin to download and install") |
| | | protected String urlOrIdOrName; |
| | | @Argument(index = 0, required = true, metaVar = "<URL>|<ID>", usage = "the id or the url of the plugin to download and install") |
| | | protected String urlOrId; |
| | | |
| | | @Option(name = "--version", usage = "The specific version to install") |
| | | private String version; |
| | |
| | | public void run() throws Failure { |
| | | IGitblit gitblit = getContext().getGitblit(); |
| | | try { |
| | | String ulc = urlOrIdOrName.toLowerCase(); |
| | | String ulc = urlOrId.toLowerCase(); |
| | | if (ulc.startsWith("http://") || ulc.startsWith("https://")) { |
| | | if (gitblit.installPlugin(urlOrIdOrName, !disableChecksum)) { |
| | | stdout.println(String.format("Installed %s", urlOrIdOrName)); |
| | | if (gitblit.installPlugin(urlOrId, !disableChecksum)) { |
| | | stdout.println(String.format("Installed %s", urlOrId)); |
| | | } else { |
| | | new Failure(1, String.format("Failed to install %s", urlOrIdOrName)); |
| | | new Failure(1, String.format("Failed to install %s", urlOrId)); |
| | | } |
| | | } else { |
| | | PluginRelease pv = gitblit.lookupRelease(urlOrIdOrName, version); |
| | | PluginRelease pv = gitblit.lookupRelease(urlOrId, version); |
| | | if (pv == null) { |
| | | throw new Failure(1, String.format("Plugin \"%s\" is not in the registry!", urlOrIdOrName)); |
| | | throw new Failure(1, String.format("Plugin \"%s\" is not in the registry!", urlOrId)); |
| | | } |
| | | if (gitblit.installPlugin(pv.url, !disableChecksum)) { |
| | | stdout.println(String.format("Installed %s", urlOrIdOrName)); |
| | | stdout.println(String.format("Installed %s", urlOrId)); |
| | | } else { |
| | | throw new Failure(1, String.format("Failed to install %s", urlOrIdOrName)); |
| | | throw new Failure(1, String.format("Failed to install %s", urlOrId)); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("Failed to install " + urlOrIdOrName, e); |
| | | throw new Failure(1, String.format("Failed to install %s", urlOrIdOrName), e); |
| | | } catch (IOException e) { |
| | | log.error("Failed to install " + urlOrId, e); |
| | | throw new Failure(1, String.format("Failed to install %s", urlOrId), e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @CommandMetaData(name = "upgrade", description = "Upgrade a plugin") |
| | | public static class UpgradePlugin extends PluginCommand { |
| | | |
| | | @Argument(index = 0, required = true, metaVar = "<ID>|<INDEX>", usage = "the plugin to upgrade") |
| | | protected String id; |
| | | |
| | | @Option(name = "--version", usage = "The specific version to install") |
| | | private String version; |
| | | |
| | | @Option(name = "--noverify", usage = "Disable checksum verification") |
| | | private boolean disableChecksum; |
| | | |
| | | @Override |
| | | public void run() throws Failure { |
| | | IGitblit gitblit = getContext().getGitblit(); |
| | | PluginWrapper pluginWrapper = getPlugin(id); |
| | | if (pluginWrapper == null) { |
| | | throw new UnloggedFailure("Invalid plugin specified!"); |
| | | } |
| | | |
| | | PluginRelease pv = gitblit.lookupRelease(pluginWrapper.getPluginId(), version); |
| | | if (pv == null) { |
| | | throw new Failure(1, String.format("Plugin \"%s\" is not in the registry!", pluginWrapper.getPluginId())); |
| | | } |
| | | |
| | | try { |
| | | if (gitblit.upgradePlugin(pluginWrapper.getPluginId(), pv.url, !disableChecksum)) { |
| | | stdout.println(String.format("Upgraded %s", pluginWrapper.getPluginId())); |
| | | } else { |
| | | throw new Failure(1, String.format("Failed to upgrade %s", pluginWrapper.getPluginId())); |
| | | } |
| | | } catch (IOException e) { |
| | | log.error("Failed to upgrade " + pluginWrapper.getPluginId(), e); |
| | | throw new Failure(1, String.format("Failed to upgrade %s", pluginWrapper.getPluginId()), e); |
| | | } |
| | | } |
| | | } |
| | |
| | | @CommandMetaData(name = "uninstall", aliases = { "rm", "del" }, description = "Uninstall a plugin") |
| | | public static class UninstallPlugin extends PluginCommand { |
| | | |
| | | @Argument(index = 0, required = true, metaVar = "<id>", usage = "the plugin to uninstall") |
| | | @Argument(index = 0, required = true, metaVar = "<ID>|<INDEX>", usage = "the plugin to uninstall") |
| | | protected String id; |
| | | |
| | | @Override |