Consistently import methods from Preconditions as static
Change-Id: I7e42b182e374967136e85bdc93bd39def493613b
This commit is contained in:
@@ -14,11 +14,11 @@
|
||||
|
||||
package com.google.gerrit.common;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
import com.google.common.annotations.GwtIncompatible;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gerrit.extensions.restapi.RawInput;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -33,7 +33,7 @@ public class RawInputUtil {
|
||||
|
||||
public static RawInput create(byte[] bytes, String contentType) {
|
||||
requireNonNull(bytes);
|
||||
Preconditions.checkArgument(bytes.length > 0);
|
||||
checkArgument(bytes.length > 0);
|
||||
return new RawInput() {
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
|
||||
@@ -14,10 +14,11 @@
|
||||
|
||||
package com.google.gerrit.common.data;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.annotations.GwtIncompatible;
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -49,7 +50,7 @@ public abstract class SubmitRequirement {
|
||||
|
||||
public SubmitRequirement build() {
|
||||
SubmitRequirement requirement = autoBuild();
|
||||
Preconditions.checkState(
|
||||
checkState(
|
||||
validateType(requirement.type()),
|
||||
"SubmitRequirement's type contains non alphanumerical symbols.");
|
||||
return requirement;
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
|
||||
package com.google.gerrit.lifecycle;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.extensions.events.LifecycleListener;
|
||||
@@ -69,7 +70,7 @@ public class LifecycleManager {
|
||||
* @param injector the injector to add.
|
||||
*/
|
||||
public void add(Injector injector) {
|
||||
Preconditions.checkState(startedIndex < 0, "Already started");
|
||||
checkState(startedIndex < 0, "Already started");
|
||||
for (Binding<LifecycleListener> binding : get(injector)) {
|
||||
add(binding.getProvider());
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
|
||||
package com.google.gerrit.server.account;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.io.BaseEncoding;
|
||||
import com.google.common.primitives.Ints;
|
||||
@@ -96,10 +97,10 @@ public class HashedPassword {
|
||||
this.hashed = hashed;
|
||||
this.cost = cost;
|
||||
|
||||
Preconditions.checkState(cost >= 4 && cost < 32);
|
||||
checkState(cost >= 4 && cost < 32);
|
||||
|
||||
// salt must be 128 bit.
|
||||
Preconditions.checkState(salt.length == 16);
|
||||
checkState(salt.length == 16);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
|
||||
package com.google.gerrit.server.git;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.server.config.UrlFormatter;
|
||||
import com.google.inject.Inject;
|
||||
@@ -69,7 +70,7 @@ public class DefaultChangeReportFormatter implements ChangeReportFormatter {
|
||||
protected String formatChangeUrl(Input input) {
|
||||
Change c = input.change();
|
||||
Optional<String> changeUrl = urlFormatter.getChangeViewUrl(c.getProject(), c.getId());
|
||||
Preconditions.checkState(changeUrl.isPresent());
|
||||
checkState(changeUrl.isPresent());
|
||||
|
||||
StringBuilder m =
|
||||
new StringBuilder()
|
||||
|
||||
@@ -14,13 +14,13 @@
|
||||
|
||||
package com.google.gerrit.server.git.validators;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.gerrit.reviewdb.client.Change.CHANGE_ID_PATTERN;
|
||||
import static com.google.gerrit.reviewdb.client.RefNames.REFS_CHANGES;
|
||||
import static com.google.gerrit.reviewdb.client.RefNames.REFS_CONFIG;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
@@ -346,7 +346,7 @@ public class CommitValidators {
|
||||
// HTTP(S)
|
||||
Optional<String> webUrl = urlFormatter.getWebUrl();
|
||||
if (hostKeys.isEmpty()) {
|
||||
Preconditions.checkState(webUrl.isPresent());
|
||||
checkState(webUrl.isPresent());
|
||||
return String.format(
|
||||
" f=\"$(git rev-parse --git-dir)/hooks/commit-msg\"; curl -o \"$f\" %stools/hooks/commit-msg ; chmod +x \"$f\"",
|
||||
webUrl.get());
|
||||
@@ -359,7 +359,7 @@ public class CommitValidators {
|
||||
int c = host.lastIndexOf(':');
|
||||
if (0 <= c) {
|
||||
if (host.startsWith("*:")) {
|
||||
Preconditions.checkState(webUrl.isPresent());
|
||||
checkState(webUrl.isPresent());
|
||||
sshHost = getGerritHost(webUrl.get());
|
||||
} else {
|
||||
sshHost = host.substring(0, c);
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
|
||||
package com.google.gerrit.server.restapi.project;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gerrit.common.data.GarbageCollectionResult;
|
||||
import com.google.gerrit.common.data.GlobalCapability;
|
||||
import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||
@@ -101,7 +101,7 @@ public class GarbageCollect
|
||||
Optional<String> url =
|
||||
urlFormatter.getRestUrl("a/config/server/tasks/" + HexFormat.fromInt(task.getTaskId()));
|
||||
// We're in a HTTP handler, so must be present.
|
||||
Preconditions.checkState(url.isPresent());
|
||||
checkState(url.isPresent());
|
||||
return Response.accepted(url.get());
|
||||
}
|
||||
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
|
||||
package com.google.gerrit.server.schema;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.gerrit.server.config.ConfigUtil.storeSection;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
|
||||
import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
|
||||
@@ -203,7 +203,7 @@ public class Schema_115 extends SchemaVersion {
|
||||
}
|
||||
|
||||
private static boolean toBoolean(String v) {
|
||||
Preconditions.checkState(!Strings.isNullOrEmpty(v));
|
||||
checkState(!Strings.isNullOrEmpty(v));
|
||||
return v.equals("Y");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server.schema;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.gerrit.reviewdb.client.CoreDownloadSchemes.ANON_GIT;
|
||||
import static com.google.gerrit.reviewdb.client.CoreDownloadSchemes.ANON_HTTP;
|
||||
import static com.google.gerrit.reviewdb.client.CoreDownloadSchemes.HTTP;
|
||||
@@ -21,7 +22,6 @@ import static com.google.gerrit.reviewdb.client.CoreDownloadSchemes.REPO_DOWNLOA
|
||||
import static com.google.gerrit.reviewdb.client.CoreDownloadSchemes.SSH;
|
||||
import static com.google.gerrit.server.config.ConfigUtil.storeSection;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
||||
@@ -227,7 +227,7 @@ public class Schema_119 extends SchemaVersion {
|
||||
}
|
||||
|
||||
private static boolean toBoolean(String v) {
|
||||
Preconditions.checkState(!Strings.isNullOrEmpty(v));
|
||||
checkState(!Strings.isNullOrEmpty(v));
|
||||
return v.equals("Y");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,9 @@
|
||||
|
||||
package com.google.gerrit.server.schema;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
import com.google.common.collect.MultimapBuilder;
|
||||
@@ -205,7 +206,7 @@ public class Schema_139 extends SchemaVersion {
|
||||
}
|
||||
|
||||
private static boolean toBoolean(String v) {
|
||||
Preconditions.checkState(!Strings.isNullOrEmpty(v));
|
||||
checkState(!Strings.isNullOrEmpty(v));
|
||||
return v.equals("Y");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
|
||||
package com.google.gerrit.sshd;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static java.nio.charset.StandardCharsets.ISO_8859_1;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.common.FileUtil;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
@@ -101,7 +101,7 @@ class DatabasePubKeyAuth implements PublickeyAuthenticator {
|
||||
@Override
|
||||
public boolean authenticate(String username, PublicKey suppliedKey, ServerSession session) {
|
||||
SshSession sd = session.getAttribute(SshSession.KEY);
|
||||
Preconditions.checkState(sd.getUser() == null);
|
||||
checkState(sd.getUser() == null);
|
||||
if (PeerDaemonUser.USER_NAME.equals(username)) {
|
||||
if (myHostKeys.contains(suppliedKey) || getPeerKeys().contains(suppliedKey)) {
|
||||
PeerDaemonUser user = peerFactory.create(sd.getRemoteAddress());
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
|
||||
package com.google.gerrit.sshd;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import com.google.gerrit.extensions.annotations.PluginName;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.binder.LinkedBindingBuilder;
|
||||
@@ -30,7 +31,7 @@ public abstract class PluginCommandModule extends CommandModule {
|
||||
|
||||
@Override
|
||||
protected final void configure() {
|
||||
Preconditions.checkState(command != null, "@PluginName must be provided");
|
||||
checkState(command != null, "@PluginName must be provided");
|
||||
bind(Commands.key(command)).toProvider(new DispatchCommandProvider(command));
|
||||
configureCommands();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
|
||||
package com.google.gerrit.sshd;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import com.google.gerrit.extensions.annotations.PluginName;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.binder.LinkedBindingBuilder;
|
||||
@@ -35,7 +36,7 @@ public abstract class SingleCommandPluginModule extends CommandModule {
|
||||
|
||||
@Override
|
||||
protected final void configure() {
|
||||
Preconditions.checkState(command != null, "@PluginName must be provided");
|
||||
checkState(command != null, "@PluginName must be provided");
|
||||
configure(bind(Commands.key(command)));
|
||||
}
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
|
||||
package com.google.gerrit.sshd;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.gerrit.server.plugins.AutoRegisterUtil.calculateBindAnnotation;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.LinkedListMultimap;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
import com.google.gerrit.extensions.annotations.Export;
|
||||
@@ -61,7 +61,7 @@ class SshAutoRegisterModuleGenerator extends AbstractModule implements ModuleGen
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void export(Export export, Class<?> type) throws InvalidPluginException {
|
||||
Preconditions.checkState(command != null, "pluginName must be provided");
|
||||
checkState(command != null, "pluginName must be provided");
|
||||
if (Command.class.isAssignableFrom(type)) {
|
||||
Class<Command> old = commands.get(export.value());
|
||||
if (old != null) {
|
||||
@@ -86,7 +86,7 @@ class SshAutoRegisterModuleGenerator extends AbstractModule implements ModuleGen
|
||||
|
||||
@Override
|
||||
public Module create() throws InvalidPluginException {
|
||||
Preconditions.checkState(command != null, "pluginName must be provided");
|
||||
checkState(command != null, "pluginName must be provided");
|
||||
return !commands.isEmpty() ? this : null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user