Extensions API: Add config API
Initial skeleton includes server API with method to get server version. Structure and naming follows existing REST API. Change-Id: I98dbc21889cd6d6ea7ce8dd224b6f013b06c516d
This commit is contained in:
parent
b6b31b42ff
commit
2362cf6a40
@ -0,0 +1,6 @@
|
||||
include_defs('//gerrit-acceptance-tests/tests.defs')
|
||||
|
||||
acceptance_tests(
|
||||
srcs = glob(['*IT.java']),
|
||||
labels = ['api'],
|
||||
)
|
@ -0,0 +1,32 @@
|
||||
// Copyright (C) 2015 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.acceptance.api.config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.NoHttpd;
|
||||
import com.google.gerrit.common.Version;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@NoHttpd
|
||||
public class ServerIT extends AbstractDaemonTest {
|
||||
@Test
|
||||
public void getVersion() throws Exception {
|
||||
assertThat(gApi.config().server().getVersion())
|
||||
.isEqualTo(Version.getVersion());
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ package com.google.gerrit.extensions.api;
|
||||
|
||||
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.projects.Projects;
|
||||
import com.google.gerrit.extensions.restapi.NotImplementedException;
|
||||
@ -23,6 +24,7 @@ import com.google.gerrit.extensions.restapi.NotImplementedException;
|
||||
public interface GerritApi {
|
||||
public Accounts accounts();
|
||||
public Changes changes();
|
||||
public Config config();
|
||||
public Groups groups();
|
||||
public Projects projects();
|
||||
|
||||
@ -41,6 +43,11 @@ public interface GerritApi {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Config config() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Groups groups() {
|
||||
throw new NotImplementedException();
|
||||
|
@ -0,0 +1,35 @@
|
||||
// Copyright (C) 2015 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.config;
|
||||
|
||||
import com.google.gerrit.extensions.restapi.NotImplementedException;
|
||||
|
||||
public interface Config {
|
||||
/**
|
||||
* @return An API for getting server related configurations.
|
||||
*/
|
||||
Server server();
|
||||
|
||||
/**
|
||||
* A default implementation which allows source compatibility
|
||||
* when adding new methods to the interface.
|
||||
**/
|
||||
public class NotImplemented implements Config {
|
||||
@Override
|
||||
public Server server() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2015 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.config;
|
||||
|
||||
import com.google.gerrit.extensions.restapi.NotImplementedException;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
|
||||
public interface Server {
|
||||
/**
|
||||
* @return Version of server.
|
||||
*/
|
||||
String getVersion() throws RestApiException;
|
||||
|
||||
/**
|
||||
* A default implementation which allows source compatibility
|
||||
* when adding new methods to the interface.
|
||||
**/
|
||||
public class NotImplemented implements Server {
|
||||
@Override
|
||||
public String getVersion() throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -17,6 +17,7 @@ package com.google.gerrit.server.api;
|
||||
import com.google.gerrit.extensions.api.GerritApi;
|
||||
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.projects.Projects;
|
||||
import com.google.inject.Inject;
|
||||
@ -26,16 +27,19 @@ import com.google.inject.Singleton;
|
||||
class GerritApiImpl implements GerritApi {
|
||||
private final Accounts accounts;
|
||||
private final Changes changes;
|
||||
private final Config config;
|
||||
private final Groups groups;
|
||||
private final Projects projects;
|
||||
|
||||
@Inject
|
||||
GerritApiImpl(Accounts accounts,
|
||||
Changes changes,
|
||||
Config config,
|
||||
Groups groups,
|
||||
Projects projects) {
|
||||
this.accounts = accounts;
|
||||
this.changes = changes;
|
||||
this.config = config;
|
||||
this.groups = groups;
|
||||
this.projects = projects;
|
||||
}
|
||||
@ -50,6 +54,11 @@ class GerritApiImpl implements GerritApi {
|
||||
return changes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Config config() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Groups groups() {
|
||||
return groups;
|
||||
|
@ -24,6 +24,7 @@ public class Module extends AbstractModule {
|
||||
|
||||
install(new com.google.gerrit.server.api.accounts.Module());
|
||||
install(new com.google.gerrit.server.api.changes.Module());
|
||||
install(new com.google.gerrit.server.api.config.Module());
|
||||
install(new com.google.gerrit.server.api.groups.Module());
|
||||
install(new com.google.gerrit.server.api.projects.Module());
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
// Copyright (C) 2015 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.config;
|
||||
|
||||
import com.google.gerrit.extensions.api.config.Config;
|
||||
import com.google.gerrit.extensions.api.config.Server;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class ConfigImpl implements Config {
|
||||
private final ServerImpl serverApi;
|
||||
|
||||
@Inject
|
||||
ConfigImpl(ServerImpl serverApi) {
|
||||
this.serverApi = serverApi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Server server() {
|
||||
return serverApi;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
// Copyright (C) 2015 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.config;
|
||||
|
||||
import com.google.gerrit.extensions.api.config.Config;
|
||||
import com.google.gerrit.extensions.api.config.Server;
|
||||
import com.google.gerrit.server.config.FactoryModule;
|
||||
|
||||
public class Module extends FactoryModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(Config.class).to(ConfigImpl.class);
|
||||
bind(Server.class).to(ServerImpl.class);
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
// Copyright (C) 2015 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.config;
|
||||
|
||||
import com.google.gerrit.common.Version;
|
||||
import com.google.gerrit.extensions.api.config.Server;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class ServerImpl implements Server {
|
||||
@Override
|
||||
public String getVersion() throws RestApiException {
|
||||
return Version.getVersion();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user