Split off api classes from giant server lib
Moves the following classes to break dependency cycles: * GpgApiAdapter * AccountExternalIdCreator * AccountInfoComparator Change-Id: Ie081b5d95d7b79f888650752fd55cc4a80f7ef42
This commit is contained in:
21
java/com/google/gerrit/server/api/BUILD
Normal file
21
java/com/google/gerrit/server/api/BUILD
Normal file
@@ -0,0 +1,21 @@
|
||||
java_library(
|
||||
name = "api",
|
||||
srcs = glob(
|
||||
["**/*.java"],
|
||||
),
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//java/com/google/gerrit/common:annotations",
|
||||
"//java/com/google/gerrit/common:server",
|
||||
"//java/com/google/gerrit/extensions:api",
|
||||
"//java/com/google/gerrit/lifecycle",
|
||||
"//java/com/google/gerrit/reviewdb:server",
|
||||
"//java/com/google/gerrit/server",
|
||||
"//lib:guava",
|
||||
"//lib:gwtorm",
|
||||
"//lib:servlet-api-3_1",
|
||||
"//lib/guice",
|
||||
"//lib/guice:guice-assistedinject",
|
||||
"//lib/jgit/org.eclipse.jgit:jgit",
|
||||
],
|
||||
)
|
||||
@@ -15,9 +15,12 @@
|
||||
package com.google.gerrit.server.api;
|
||||
|
||||
import com.google.gerrit.extensions.api.GerritApi;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.gerrit.extensions.api.plugins.Plugins;
|
||||
import com.google.gerrit.extensions.config.FactoryModule;
|
||||
import com.google.gerrit.server.api.plugins.PluginApiImpl;
|
||||
import com.google.gerrit.server.api.plugins.PluginsImpl;
|
||||
|
||||
public class Module extends AbstractModule {
|
||||
public class GerritApiModule extends FactoryModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(GerritApi.class).to(GerritApiImpl.class);
|
||||
@@ -27,5 +30,8 @@ public class Module extends AbstractModule {
|
||||
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());
|
||||
|
||||
bind(Plugins.class).to(PluginsImpl.class);
|
||||
factory(PluginApiImpl.Factory.class);
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,7 @@ import com.google.gerrit.server.account.GetGroups;
|
||||
import com.google.gerrit.server.account.GetPreferences;
|
||||
import com.google.gerrit.server.account.GetSshKeys;
|
||||
import com.google.gerrit.server.account.GetWatchedProjects;
|
||||
import com.google.gerrit.server.account.GpgApiAdapter;
|
||||
import com.google.gerrit.server.account.Index;
|
||||
import com.google.gerrit.server.account.PostWatchedProjects;
|
||||
import com.google.gerrit.server.account.PutActive;
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
// Copyright (C) 2016 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.accounts;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.server.account.externalids.ExternalId;
|
||||
import java.util.List;
|
||||
|
||||
public interface AccountExternalIdCreator {
|
||||
|
||||
/**
|
||||
* Returns additional external identifiers to assign to a given user when creating an account.
|
||||
*
|
||||
* @param id the identifier of the account.
|
||||
* @param username the name of the user.
|
||||
* @param email an optional email address to assign to the external identifiers, or {@code null}.
|
||||
* @return a list of external identifiers, or an empty list.
|
||||
*/
|
||||
List<ExternalId> create(Account.Id id, String username, String email);
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
// 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.accounts;
|
||||
|
||||
import com.google.common.collect.ComparisonChain;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import java.util.Comparator;
|
||||
|
||||
public class AccountInfoComparator extends Ordering<AccountInfo>
|
||||
implements Comparator<AccountInfo> {
|
||||
public static final AccountInfoComparator ORDER_NULLS_FIRST = new AccountInfoComparator();
|
||||
public static final AccountInfoComparator ORDER_NULLS_LAST =
|
||||
new AccountInfoComparator().setNullsLast();
|
||||
|
||||
private boolean nullsLast;
|
||||
|
||||
private AccountInfoComparator() {}
|
||||
|
||||
private AccountInfoComparator setNullsLast() {
|
||||
this.nullsLast = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(AccountInfo a, AccountInfo b) {
|
||||
return ComparisonChain.start()
|
||||
.compare(a.name, b.name, createOrdering())
|
||||
.compare(a.email, b.email, createOrdering())
|
||||
.compare(a._accountId, b._accountId, createOrdering())
|
||||
.result();
|
||||
}
|
||||
|
||||
private <S extends Comparable<?>> Ordering<S> createOrdering() {
|
||||
if (nullsLast) {
|
||||
return Ordering.natural().nullsLast();
|
||||
}
|
||||
return Ordering.natural().nullsFirst();
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
// 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.accounts;
|
||||
|
||||
import com.google.gerrit.extensions.api.accounts.GpgKeyApi;
|
||||
import com.google.gerrit.extensions.common.GpgKeyInfo;
|
||||
import com.google.gerrit.extensions.common.PushCertificateInfo;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.server.GpgException;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.AccountResource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface GpgApiAdapter {
|
||||
boolean isEnabled();
|
||||
|
||||
Map<String, GpgKeyInfo> listGpgKeys(AccountResource account)
|
||||
throws RestApiException, GpgException;
|
||||
|
||||
Map<String, GpgKeyInfo> putGpgKeys(AccountResource account, List<String> add, List<String> delete)
|
||||
throws RestApiException, GpgException;
|
||||
|
||||
GpgKeyApi gpgKey(AccountResource account, IdString idStr) throws RestApiException, GpgException;
|
||||
|
||||
PushCertificateInfo checkPushCertificate(String certStr, IdentifiedUser expectedUser)
|
||||
throws GpgException;
|
||||
}
|
||||
Reference in New Issue
Block a user