use of com.google.gerrit.extensions.common.PluginInfo in project gerrit by GerritCodeReview.
the class InstallPlugin method apply.
@Override
public Response<PluginInfo> apply(TopLevelResource resource, InstallPluginInput input) throws RestApiException, IOException {
loader.checkRemoteAdminEnabled();
try {
try (InputStream in = openStream(input)) {
String pluginName = loader.installPluginFromStream(name, in);
PluginInfo info = ListPlugins.toPluginInfo(loader.get(pluginName));
return created ? Response.created(info) : Response.ok(info);
}
} catch (PluginInstallException e) {
StringWriter buf = new StringWriter();
buf.write(String.format("cannot install %s", name));
if (e.getCause() instanceof ZipException) {
buf.write(": ");
buf.write(e.getCause().getMessage());
} else {
buf.write(":\n");
PrintWriter pw = new PrintWriter(buf);
e.printStackTrace(pw);
pw.flush();
}
throw new BadRequestException(buf.toString());
}
}
use of com.google.gerrit.extensions.common.PluginInfo in project gerrit by GerritCodeReview.
the class PluginLsCommand method run.
@Override
public void run() throws Exception {
enableGracefulStop();
Map<String, PluginInfo> output = list.apply(TopLevelResource.INSTANCE).value();
if (format.isJson()) {
format.newGson().toJson(output, new TypeToken<Map<String, PluginInfo>>() {
}.getType(), stdout);
stdout.print('\n');
} else {
String template = "%-30s %-10s %-16s %-8s %s\n";
stdout.format(template, "Name", "Version", "Api-Version", "Status", "File");
stdout.print("-------------------------------------------------------------------------------\n");
for (Map.Entry<String, PluginInfo> p : output.entrySet()) {
PluginInfo info = p.getValue();
stdout.format(template, p.getKey(), Strings.nullToEmpty(info.version), Strings.nullToEmpty(info.apiVersion), status(info.disabled), Strings.nullToEmpty(info.filename));
}
}
stdout.flush();
}
use of com.google.gerrit.extensions.common.PluginInfo in project gerrit by GerritCodeReview.
the class ListPlugins method apply.
@Override
public Response<SortedMap<String, PluginInfo>> apply(TopLevelResource resource) throws BadRequestException {
Stream<Plugin> s = Streams.stream(pluginLoader.getPlugins(all));
if (matchPrefix != null) {
checkMatchOptions(matchSubstring == null && matchRegex == null);
s = s.filter(p -> p.getName().startsWith(matchPrefix));
} else if (matchSubstring != null) {
checkMatchOptions(matchPrefix == null && matchRegex == null);
String substring = matchSubstring.toLowerCase(Locale.US);
s = s.filter(p -> p.getName().toLowerCase(Locale.US).contains(substring));
} else if (matchRegex != null) {
checkMatchOptions(matchPrefix == null && matchSubstring == null);
Pattern pattern = Pattern.compile(matchRegex);
s = s.filter(p -> pattern.matcher(p.getName()).matches());
}
s = s.sorted(comparing(Plugin::getName));
if (start > 0) {
s = s.skip(start);
}
if (limit > 0) {
s = s.limit(limit);
}
return Response.ok(new TreeMap<>(s.collect(toMap(Plugin::getName, ListPlugins::toPluginInfo))));
}
use of com.google.gerrit.extensions.common.PluginInfo in project gerrit by GerritCodeReview.
the class PluginIT method pluginManagement.
@Test
@GerritConfig(name = "plugins.allowRemoteAdmin", value = "true")
public void pluginManagement() throws Exception {
// No plugins are loaded
assertThat(list().get()).isEmpty();
assertThat(list().all().get()).isEmpty();
PluginApi api;
// Install all the plugins
InstallPluginInput input = new InstallPluginInput();
for (String plugin : PLUGINS) {
input.raw = pluginContent(plugin);
api = gApi.plugins().install(plugin, input);
assertThat(api).isNotNull();
PluginInfo info = api.get();
String name = pluginName(plugin);
assertThat(info.id).isEqualTo(name);
assertThat(info.version).isEqualTo(pluginVersion(plugin));
assertThat(info.apiVersion).isEqualTo(pluginApiVersion(plugin));
assertThat(info.indexUrl).isEqualTo(String.format("plugins/%s/", name));
assertThat(info.filename).isEqualTo(plugin);
assertThat(info.disabled).isNull();
}
assertPlugins(list().get(), PLUGINS);
// With pagination
assertPlugins(list().start(1).limit(2).get(), PLUGINS.subList(1, 3));
// With prefix
assertPlugins(list().prefix("plugin-b").get(), ImmutableList.of("plugin-b.js"));
assertPlugins(list().prefix("PLUGIN-").get(), ImmutableList.of());
// With substring
assertPlugins(list().substring("lugin-").get(), PLUGINS.subList(0, PLUGINS.size() - 1));
assertPlugins(list().substring("lugin-").start(1).limit(2).get(), PLUGINS.subList(1, 3));
// With regex
assertPlugins(list().regex(".*in-b").get(), ImmutableList.of("plugin-b.js"));
assertPlugins(list().regex("plugin-.*").get(), PLUGINS.subList(0, PLUGINS.size() - 1));
assertPlugins(list().regex("plugin-.*").start(1).limit(2).get(), PLUGINS.subList(1, 3));
// Invalid match combinations
assertBadRequest(list().regex(".*in-b").substring("a"));
assertBadRequest(list().regex(".*in-b").prefix("a"));
assertBadRequest(list().substring(".*in-b").prefix("a"));
// Disable mandatory
mandatoryPluginsCollection.add("plugin_e");
assertThrows(MethodNotAllowedException.class, () -> gApi.plugins().name("plugin_e").disable());
api = gApi.plugins().name("plugin_e");
assertThat(api.get().disabled).isNull();
// Disable non-mandatory
api = gApi.plugins().name("plugin-a");
api.disable();
api = gApi.plugins().name("plugin-a");
assertThat(api.get().disabled).isTrue();
assertPlugins(list().get(), PLUGINS.subList(1, PLUGINS.size()));
assertPlugins(list().all().get(), PLUGINS);
// Enable
api.enable();
api = gApi.plugins().name("plugin-a");
assertThat(api.get().disabled).isNull();
assertPlugins(list().get(), PLUGINS);
// Using deprecated input
deprecatedInput();
// Non-admin cannot disable
requestScopeOperations.setApiUser(user.id());
assertThrows(AuthException.class, () -> gApi.plugins().name("plugin-a").disable());
}
Aggregations