Add initial framework of Plugin API

Add initial implementation of Plugin API providing the list of plugins,
with integration test stub.

Since we're not loading plugins during acceptance tests, the API will
always return an empty list, and the test only really serves to ensure
that there are no missing dependency injections etc.

After finding a way to make the list return actual data, either by
installing dummy plugins or mocking the PluginLoader, the tests can
be expanded.

Change-Id: I02e3b34a64fa1134dee4b1375fdb9a635651c0ca
This commit is contained in:
David Pursehouse
2017-07-25 11:41:34 +01:00
parent ebbc55a809
commit e253101f5a
11 changed files with 191 additions and 2 deletions

View File

@@ -18,6 +18,7 @@ import com.google.gerrit.extensions.api.accounts.Accounts;
import com.google.gerrit.extensions.api.changes.Changes;
import com.google.gerrit.extensions.api.config.Config;
import com.google.gerrit.extensions.api.groups.Groups;
import com.google.gerrit.extensions.api.plugins.Plugins;
import com.google.gerrit.extensions.api.projects.Projects;
import com.google.gerrit.extensions.restapi.NotImplementedException;
@@ -32,6 +33,8 @@ public interface GerritApi {
Projects projects();
Plugins plugins();
/**
* A default implementation which allows source compatibility when adding new methods to the
* interface.
@@ -61,5 +64,10 @@ public interface GerritApi {
public Projects projects() {
throw new NotImplementedException();
}
@Override
public Plugins plugins() {
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,51 @@
// 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.extensions.api.plugins;
import com.google.gerrit.extensions.common.PluginInfo;
import com.google.gerrit.extensions.restapi.RestApiException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
public interface Plugins {
ListRequest list();
abstract class ListRequest {
private boolean all;
public List<PluginInfo> get() throws RestApiException {
Map<String, PluginInfo> map = getAsMap();
List<PluginInfo> result = new ArrayList<>(map.size());
for (Map.Entry<String, PluginInfo> e : map.entrySet()) {
result.add(e.getValue());
}
return result;
}
public abstract SortedMap<String, PluginInfo> getAsMap() throws RestApiException;
public ListRequest all(boolean all) {
this.all = all;
return this;
}
public boolean getAll() {
return all;
}
}
}