All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.gerrit.server.api.plugins.PluginsImpl Maven / Gradle / Ivy

There is a newer version: 3.10.0-rc5
Show newest version
// Copyright (C) 2017 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.gerrit.server.api.plugins;

import com.google.gerrit.extensions.api.plugins.PluginApi;
import com.google.gerrit.extensions.api.plugins.Plugins;
import com.google.gerrit.extensions.common.InstallPluginInput;
import com.google.gerrit.extensions.common.PluginInfo;
import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.extensions.restapi.TopLevelResource;
import com.google.gerrit.server.plugins.InstallPlugin;
import com.google.gerrit.server.plugins.ListPlugins;
import com.google.gerrit.server.plugins.PluginsCollection;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.io.IOException;
import java.util.SortedMap;

@Singleton
public class PluginsImpl implements Plugins {
  private final PluginsCollection plugins;
  private final Provider listProvider;
  private final Provider installProvider;
  private final PluginApiImpl.Factory pluginApi;

  @Inject
  PluginsImpl(
      PluginsCollection plugins,
      Provider listProvider,
      Provider installProvider,
      PluginApiImpl.Factory pluginApi) {
    this.plugins = plugins;
    this.listProvider = listProvider;
    this.installProvider = installProvider;
    this.pluginApi = pluginApi;
  }

  @Override
  public PluginApi name(String name) throws RestApiException {
    return pluginApi.create(plugins.parse(name));
  }

  @Override
  public ListRequest list() {
    return new ListRequest() {
      @Override
      public SortedMap getAsMap() throws RestApiException {
        return listProvider.get().request(this).apply(TopLevelResource.INSTANCE);
      }
    };
  }

  @Override
  public PluginApi install(String name, InstallPluginInput input) throws RestApiException {
    try {
      Response created =
          installProvider.get().setName(name).apply(TopLevelResource.INSTANCE, input);
      return pluginApi.create(plugins.parse(created.value().id));
    } catch (IOException e) {
      throw new RestApiException("could not install plugin", e);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy