Define API to invoke the REST API from within extensions and plugins
The REST API available over HTTP is planned to be supported for a long
time in the future. It is very well documented and has fairly clean
resource semantics. Extension and plugin authors want to use this API
from within the server itself to access resources, shielding them from
any internal changes.
GerritApi is a simple API exposed to plugins as an interface. The
API mirrors the REST API resource tree. Posting a review on a commit
is similar:
@Inject
private GerritApi api;
[...]
ReviewInput input = new ReviewInput();
input.message = "Looks good!";
input.labels = new HashMap<String, Short>();
input.labels.put("Code-Review", (short) 2);
api.changes().id(12345).revision("c0ffee....").review(input);
In this commit we provide only the basic skeleton and a single API
call for posting review comments.
An alternative approach is to use reflection to generate a proxy
implementation of the interfaces and bind everything dynamically at
runtime similar to the way RestApiServlet is implemented. The hand
coded implementation offered here provides some compile-time
assurances the server has each API implemented and the API accepts the
correct input type.
Change-Id: Ic25c69c0660e2796d090a4a37445820726e543d2
20 files changed