Search in sources :

Example 1 with PluginInfo

use of com.google.gerrit.server.plugins.ListPlugins.PluginInfo in project gerrit by GerritCodeReview.

the class InstallPlugin method apply.

@Override
public Response<PluginInfo> apply(TopLevelResource resource, Input input) throws BadRequestException, MethodNotAllowedException, IOException {
    if (!loader.isRemoteAdminEnabled()) {
        throw new MethodNotAllowedException("remote installation is disabled");
    }
    try {
        try (InputStream in = openStream(input)) {
            String pluginName = loader.installPluginFromStream(name, in);
            ListPlugins.PluginInfo info = new ListPlugins.PluginInfo(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());
    }
}
Also used : PluginInfo(com.google.gerrit.server.plugins.ListPlugins.PluginInfo) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) StringWriter(java.io.StringWriter) InputStream(java.io.InputStream) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PluginInfo(com.google.gerrit.server.plugins.ListPlugins.PluginInfo) ZipException(java.util.zip.ZipException) PrintWriter(java.io.PrintWriter)

Aggregations

BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)1 PluginInfo (com.google.gerrit.server.plugins.ListPlugins.PluginInfo)1 InputStream (java.io.InputStream)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ZipException (java.util.zip.ZipException)1