Merge branch 'stable-2.16' into stable-3.0
* stable-2.16: ChangeNotificationsIT: Fix eclipse warning(s) about static use CacheMetrics: Make F_NAME a final constant in class scope Fix more cases where Collection.isEmpty() should be used Use Set instead of EnumSet in method signatures Replace negation of anyMatch() with noneMatch() AllExternalIds: Replace lambdas with method references PostReview: Replace filter and findFirst with anyMatch XContentBuilder: Use UTF_8 from Java's StandardCharsets rather than Guava Update git submodules Update git submodules Update git submodules QueryDocumentationExecutor: Make WEIGHTS final and use ImmutableMap BooleanProjectConfigTransformations: Make MAPPER final TestSubmitRuleInfo: Make INSTANCE final TrackingFootersProvider: Make constants final ChangeCleanupConfig: Make constants final SetParent: Simplify lambda expression ProjectsConsistencyChecker: Simplify lambda expression Remove redundant null checks used with "instanceof" Remove unnecessary array creation for varargs parameters Remove redundant parentheses in lambda statements PreferencesBox: Remove unnecessary boxing to Boolean GitwebServlet: Rename bufferSize to BUFFER_SIZE and make static GetPatch: Make FILE_NOT_FOUND static DeleteZombieCommentsRefs: Make constants static AbstractNotificationTest: Make constants static and rename TabFile: Make TRIM final Remove redundant calls to toString() OpenIdServiceImpl: Fix incorrect null comparison of Optional Consistently use isEmpty to check for empty collection PageLinks: Reuse ADMIN_PROJECTS constant PageLinks: Fix typo in method name FlushCaches: Use isEmpty to check for empty list JGitMetricModule: Replace anonymous Supplier instances with method references Adapt to deprecation of WindowCacheStats methods in JGit Documentation: Fix collapsed words and broken link Change-Id: I136c109013a8947ba530a52164e97af2775fe490
This commit is contained in:
@@ -315,6 +315,9 @@ public abstract class AbstractNotificationTest extends AbstractDaemonTest {
|
||||
}
|
||||
|
||||
protected class StagedUsers {
|
||||
public static final String REVIEWER_BY_EMAIL = "reviewerByEmail@example.com";
|
||||
public static final String CC_BY_EMAIL = "ccByEmail@example.com";
|
||||
|
||||
public final TestAccount owner;
|
||||
public final TestAccount author;
|
||||
public final TestAccount uploader;
|
||||
@@ -323,8 +326,6 @@ public abstract class AbstractNotificationTest extends AbstractDaemonTest {
|
||||
public final TestAccount starrer;
|
||||
public final TestAccount assignee;
|
||||
public final TestAccount watchingProjectOwner;
|
||||
public final String reviewerByEmail = "reviewerByEmail@example.com";
|
||||
public final String ccerByEmail = "ccByEmail@example.com";
|
||||
private final Map<NotifyType, TestAccount> watchers = new HashMap<>();
|
||||
private final Map<String, TestAccount> accountsByEmail = new HashMap<>();
|
||||
|
||||
@@ -425,9 +426,9 @@ public abstract class AbstractNotificationTest extends AbstractDaemonTest {
|
||||
ReviewInput in =
|
||||
ReviewInput.noScore()
|
||||
.reviewer(reviewer.email())
|
||||
.reviewer(reviewerByEmail)
|
||||
.reviewer(REVIEWER_BY_EMAIL)
|
||||
.reviewer(ccer.email(), ReviewerState.CC, false)
|
||||
.reviewer(ccerByEmail, ReviewerState.CC, false);
|
||||
.reviewer(CC_BY_EMAIL, ReviewerState.CC, false);
|
||||
ReviewResult result = gApi.changes().id(r.getChangeId()).revision("current").review(in);
|
||||
supportReviewersByEmail = true;
|
||||
if (result.reviewers.values().stream().anyMatch(v -> v.error != null)) {
|
||||
|
||||
@@ -90,16 +90,16 @@ public class PageLinks {
|
||||
return ADMIN_PROJECTS + p.get();
|
||||
}
|
||||
|
||||
public static String toProjectAcceess(Project.NameKey p) {
|
||||
return "/admin/projects/" + p.get() + ",access";
|
||||
public static String toProjectAccess(Project.NameKey p) {
|
||||
return ADMIN_PROJECTS + p.get() + ",access";
|
||||
}
|
||||
|
||||
public static String toProjectBranches(Project.NameKey p) {
|
||||
return "/admin/projects/" + p.get() + ",branches";
|
||||
return ADMIN_PROJECTS + p.get() + ",branches";
|
||||
}
|
||||
|
||||
public static String toProjectTags(Project.NameKey p) {
|
||||
return "/admin/projects/" + p.get() + ",tags";
|
||||
return ADMIN_PROJECTS + p.get() + ",tags";
|
||||
}
|
||||
|
||||
public static String toAccountQuery(String fullname, Status status) {
|
||||
|
||||
@@ -126,7 +126,7 @@ public class LabelType {
|
||||
|
||||
maxNegative = Short.MIN_VALUE;
|
||||
maxPositive = Short.MAX_VALUE;
|
||||
if (values.size() > 0) {
|
||||
if (!values.isEmpty()) {
|
||||
if (values.get(0).getValue() < 0) {
|
||||
maxNegative = values.get(0).getValue();
|
||||
}
|
||||
|
||||
@@ -392,7 +392,7 @@ abstract class AbstractElasticIndex<K, V> implements Index<K, V> {
|
||||
|
||||
@Override
|
||||
public ResultSet<V> read() {
|
||||
return readImpl((doc) -> AbstractElasticIndex.this.fromDocument(doc, opts.fields()));
|
||||
return readImpl(doc -> AbstractElasticIndex.this.fromDocument(doc, opts.fields()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.elasticsearch.builders;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static java.time.format.DateTimeFormatter.ISO_INSTANT;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonEncoding;
|
||||
@@ -21,7 +22,6 @@ import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.json.JsonReadFeature;
|
||||
import com.fasterxml.jackson.core.json.JsonWriteFeature;
|
||||
import com.google.common.base.Charsets;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
@@ -139,7 +139,7 @@ public final class XContentBuilder implements Closeable {
|
||||
public String string() {
|
||||
close();
|
||||
byte[] bytesArray = bos.toByteArray();
|
||||
return new String(bytesArray, Charsets.UTF_8);
|
||||
return new String(bytesArray, UTF_8);
|
||||
}
|
||||
|
||||
private void writeValue(Object value) throws IOException {
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface Accounts {
|
||||
/**
|
||||
@@ -138,7 +139,7 @@ public interface Accounts {
|
||||
private int limit;
|
||||
private int start;
|
||||
private boolean suggest;
|
||||
private EnumSet<ListAccountsOption> options = EnumSet.noneOf(ListAccountsOption.class);
|
||||
private Set<ListAccountsOption> options = EnumSet.noneOf(ListAccountsOption.class);
|
||||
|
||||
/** Execute query and return a list of accounts. */
|
||||
public abstract List<AccountInfo> get() throws RestApiException;
|
||||
@@ -185,7 +186,7 @@ public interface Accounts {
|
||||
}
|
||||
|
||||
/** Set options on the request, replacing existing options. */
|
||||
public QueryRequest withOptions(EnumSet<ListAccountsOption> options) {
|
||||
public QueryRequest withOptions(Set<ListAccountsOption> options) {
|
||||
this.options = options;
|
||||
return this;
|
||||
}
|
||||
@@ -206,7 +207,7 @@ public interface Accounts {
|
||||
return suggest;
|
||||
}
|
||||
|
||||
public EnumSet<ListAccountsOption> getOptions() {
|
||||
public Set<ListAccountsOption> getOptions() {
|
||||
return options;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.google.gerrit.extensions.restapi.RawInput;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* An API for the change edit of a change. A change edit is similar to a patch set and will become
|
||||
@@ -51,7 +52,7 @@ public interface ChangeEditApi {
|
||||
return base;
|
||||
}
|
||||
|
||||
public EnumSet<ChangeEditDetailOption> options() {
|
||||
public Set<ChangeEditDetailOption> options() {
|
||||
return options;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface Changes {
|
||||
/**
|
||||
@@ -78,7 +79,7 @@ public interface Changes {
|
||||
private int limit;
|
||||
private int start;
|
||||
private boolean isNoLimit;
|
||||
private EnumSet<ListChangesOption> options = EnumSet.noneOf(ListChangesOption.class);
|
||||
private Set<ListChangesOption> options = EnumSet.noneOf(ListChangesOption.class);
|
||||
private ListMultimap<String, String> pluginOptions = ArrayListMultimap.create();
|
||||
|
||||
public abstract List<ChangeInfo> get() throws RestApiException;
|
||||
@@ -116,7 +117,7 @@ public interface Changes {
|
||||
}
|
||||
|
||||
/** Set options on the request, replacing existing options. */
|
||||
public QueryRequest withOptions(EnumSet<ListChangesOption> options) {
|
||||
public QueryRequest withOptions(Set<ListChangesOption> options) {
|
||||
this.options = options;
|
||||
return this;
|
||||
}
|
||||
@@ -149,7 +150,7 @@ public interface Changes {
|
||||
return start;
|
||||
}
|
||||
|
||||
public EnumSet<ListChangesOption> getOptions() {
|
||||
public Set<ListChangesOption> getOptions() {
|
||||
return options;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public interface Groups {
|
||||
/**
|
||||
@@ -166,7 +167,7 @@ public interface Groups {
|
||||
return this;
|
||||
}
|
||||
|
||||
public EnumSet<ListGroupsOption> getOptions() {
|
||||
public Set<ListGroupsOption> getOptions() {
|
||||
return options;
|
||||
}
|
||||
|
||||
@@ -224,7 +225,7 @@ public interface Groups {
|
||||
private String query;
|
||||
private int limit;
|
||||
private int start;
|
||||
private EnumSet<ListGroupsOption> options = EnumSet.noneOf(ListGroupsOption.class);
|
||||
private Set<ListGroupsOption> options = EnumSet.noneOf(ListGroupsOption.class);
|
||||
|
||||
/** Execute query and returns the matched groups as list. */
|
||||
public abstract List<GroupInfo> get() throws RestApiException;
|
||||
@@ -266,7 +267,7 @@ public interface Groups {
|
||||
}
|
||||
|
||||
/** Set options on the request, replacing existing options. */
|
||||
public QueryRequest withOptions(EnumSet<ListGroupsOption> options) {
|
||||
public QueryRequest withOptions(Set<ListGroupsOption> options) {
|
||||
this.options = options;
|
||||
return this;
|
||||
}
|
||||
@@ -283,7 +284,7 @@ public interface Groups {
|
||||
return start;
|
||||
}
|
||||
|
||||
public EnumSet<ListGroupsOption> getOptions() {
|
||||
public Set<ListGroupsOption> getOptions() {
|
||||
return options;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class TestSubmitRuleInfo {
|
||||
public static class None {
|
||||
private None() {}
|
||||
|
||||
public static None INSTANCE = new None();
|
||||
public static final None INSTANCE = new None();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -192,7 +192,7 @@ class OpenIdServiceImpl {
|
||||
// We might already have this account on file. Look for it.
|
||||
//
|
||||
try {
|
||||
return accountManager.lookup(aReq.getIdentity()) == null;
|
||||
return !accountManager.lookup(aReq.getIdentity()).isPresent();
|
||||
} catch (AccountException e) {
|
||||
logger.atWarning().withCause(e).log("Cannot determine if user account exists");
|
||||
return true;
|
||||
@@ -333,7 +333,7 @@ class OpenIdServiceImpl {
|
||||
areq.setEmailAddress(fetchRsp.getAttributeValue("Email"));
|
||||
}
|
||||
|
||||
if (openIdDomains != null && openIdDomains.size() > 0) {
|
||||
if (openIdDomains != null && !openIdDomains.isEmpty()) {
|
||||
// Administrator limited email domains, which can be used for OpenID.
|
||||
// Login process will only work if the passed email matches one
|
||||
// of these domains.
|
||||
|
||||
@@ -96,9 +96,9 @@ class GitwebServlet extends HttpServlet {
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
private static final String PROJECT_LIST_ACTION = "project_list";
|
||||
private static final int BUFFER_SIZE = 8192;
|
||||
|
||||
private final Set<String> deniedActions;
|
||||
private final int bufferSize = 8192;
|
||||
private final Path gitwebCgi;
|
||||
private final URI gitwebUrl;
|
||||
private final LocalDiskRepositoryManager repoManager;
|
||||
@@ -506,11 +506,11 @@ class GitwebServlet extends HttpServlet {
|
||||
proc.getOutputStream().close();
|
||||
}
|
||||
|
||||
try (InputStream in = new BufferedInputStream(proc.getInputStream(), bufferSize)) {
|
||||
try (InputStream in = new BufferedInputStream(proc.getInputStream(), BUFFER_SIZE)) {
|
||||
readCgiHeaders(rsp, in);
|
||||
|
||||
try (OutputStream out = rsp.getOutputStream()) {
|
||||
final byte[] buf = new byte[bufferSize];
|
||||
final byte[] buf = new byte[BUFFER_SIZE];
|
||||
int n;
|
||||
while ((n = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, n);
|
||||
@@ -645,7 +645,7 @@ class GitwebServlet extends HttpServlet {
|
||||
() -> {
|
||||
try {
|
||||
try {
|
||||
final byte[] buf = new byte[bufferSize];
|
||||
final byte[] buf = new byte[BUFFER_SIZE];
|
||||
int remaining = contentLength;
|
||||
while (0 < remaining) {
|
||||
final int max = Math.max(buf.length, remaining);
|
||||
|
||||
@@ -1316,7 +1316,7 @@ public class RestApiServlet extends HttpServlet {
|
||||
for (String p : Splitter.on('/').split(path)) {
|
||||
out.add(IdString.fromUrl(p));
|
||||
}
|
||||
if (out.size() > 0 && out.get(out.size() - 1).isEmpty()) {
|
||||
if (!out.isEmpty() && out.get(out.size() - 1).isEmpty()) {
|
||||
out.remove(out.size() - 1);
|
||||
}
|
||||
return out;
|
||||
|
||||
@@ -549,7 +549,7 @@ public class LuceneChangeIndex implements ChangeIndex {
|
||||
|
||||
private void decodeReviewedBy(ListMultimap<String, IndexableField> doc, ChangeData cd) {
|
||||
Collection<IndexableField> reviewedBy = doc.get(REVIEWEDBY_FIELD);
|
||||
if (reviewedBy.size() > 0) {
|
||||
if (!reviewedBy.isEmpty()) {
|
||||
Set<Account.Id> accounts = Sets.newHashSetWithExpectedSize(reviewedBy.size());
|
||||
for (IndexableField r : reviewedBy) {
|
||||
int id = r.numericValue().intValue();
|
||||
|
||||
@@ -69,7 +69,7 @@ public class RawMailParser {
|
||||
}
|
||||
|
||||
// Add From, To and Cc
|
||||
if (mimeMessage.getFrom() != null && mimeMessage.getFrom().size() > 0) {
|
||||
if (mimeMessage.getFrom() != null && !mimeMessage.getFrom().isEmpty()) {
|
||||
Mailbox from = mimeMessage.getFrom().get(0);
|
||||
messageBuilder.from(new Address(from.getName(), from.getAddress()));
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.metrics.proc;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.gerrit.metrics.CallbackMetric1;
|
||||
import com.google.gerrit.metrics.Description;
|
||||
import com.google.gerrit.metrics.Description.Units;
|
||||
@@ -34,23 +33,13 @@ public class JGitMetricModule extends MetricModule {
|
||||
new Description("Bytes of memory retained in JGit block cache.")
|
||||
.setGauge()
|
||||
.setUnit(Units.BYTES),
|
||||
new Supplier<Long>() {
|
||||
@Override
|
||||
public Long get() {
|
||||
return WindowCacheStats.getStats().getOpenByteCount();
|
||||
}
|
||||
});
|
||||
WindowCacheStats.getStats()::getOpenByteCount);
|
||||
|
||||
metrics.newCallbackMetric(
|
||||
"jgit/block_cache/open_files",
|
||||
Long.class,
|
||||
new Description("File handles held open by JGit block cache.").setGauge().setUnit("fds"),
|
||||
new Supplier<Long>() {
|
||||
@Override
|
||||
public Long get() {
|
||||
return WindowCacheStats.getStats().getOpenFileCount();
|
||||
}
|
||||
});
|
||||
WindowCacheStats.getStats()::getOpenFileCount);
|
||||
|
||||
metrics.newCallbackMetric(
|
||||
"jgit/block_cache/avg_load_time",
|
||||
@@ -58,99 +47,55 @@ public class JGitMetricModule extends MetricModule {
|
||||
new Description("Average time to load a cache entry for JGit block cache.")
|
||||
.setGauge()
|
||||
.setUnit(Units.NANOSECONDS),
|
||||
new Supplier<Double>() {
|
||||
@Override
|
||||
public Double get() {
|
||||
return WindowCacheStats.getStats().getAverageLoadTime();
|
||||
}
|
||||
});
|
||||
WindowCacheStats.getStats()::getAverageLoadTime);
|
||||
|
||||
metrics.newCallbackMetric(
|
||||
"jgit/block_cache/eviction_count",
|
||||
Long.class,
|
||||
new Description("Cache evictions for JGit block cache.").setGauge(),
|
||||
new Supplier<Long>() {
|
||||
@Override
|
||||
public Long get() {
|
||||
return WindowCacheStats.getStats().getEvictionCount();
|
||||
}
|
||||
});
|
||||
WindowCacheStats.getStats()::getEvictionCount);
|
||||
|
||||
metrics.newCallbackMetric(
|
||||
"jgit/block_cache/eviction_ratio",
|
||||
Double.class,
|
||||
new Description("Cache eviction ratio for JGit block cache.").setGauge(),
|
||||
new Supplier<Double>() {
|
||||
@Override
|
||||
public Double get() {
|
||||
return WindowCacheStats.getStats().getEvictionRatio();
|
||||
}
|
||||
});
|
||||
WindowCacheStats.getStats()::getEvictionRatio);
|
||||
|
||||
metrics.newCallbackMetric(
|
||||
"jgit/block_cache/hit_count",
|
||||
Long.class,
|
||||
new Description("Cache hits for JGit block cache.").setGauge(),
|
||||
new Supplier<Long>() {
|
||||
@Override
|
||||
public Long get() {
|
||||
return WindowCacheStats.getStats().getHitCount();
|
||||
}
|
||||
});
|
||||
WindowCacheStats.getStats()::getHitCount);
|
||||
|
||||
metrics.newCallbackMetric(
|
||||
"jgit/block_cache/hit_ratio",
|
||||
Double.class,
|
||||
new Description("Cache hit ratio for JGit block cache.").setGauge(),
|
||||
new Supplier<Double>() {
|
||||
@Override
|
||||
public Double get() {
|
||||
return WindowCacheStats.getStats().getHitRatio();
|
||||
}
|
||||
});
|
||||
WindowCacheStats.getStats()::getHitRatio);
|
||||
|
||||
metrics.newCallbackMetric(
|
||||
"jgit/block_cache/load_failure_count",
|
||||
Long.class,
|
||||
new Description("Failed cache loads for JGit block cache.").setGauge(),
|
||||
new Supplier<Long>() {
|
||||
@Override
|
||||
public Long get() {
|
||||
return WindowCacheStats.getStats().getLoadFailureCount();
|
||||
}
|
||||
});
|
||||
WindowCacheStats.getStats()::getLoadFailureCount);
|
||||
|
||||
metrics.newCallbackMetric(
|
||||
"jgit/block_cache/load_failure_ratio",
|
||||
Double.class,
|
||||
new Description("Failed cache load ratio for JGit block cache.").setGauge(),
|
||||
new Supplier<Double>() {
|
||||
@Override
|
||||
public Double get() {
|
||||
return WindowCacheStats.getStats().getLoadFailureRatio();
|
||||
}
|
||||
});
|
||||
WindowCacheStats.getStats()::getLoadFailureRatio);
|
||||
|
||||
metrics.newCallbackMetric(
|
||||
"jgit/block_cache/load_success_count",
|
||||
Long.class,
|
||||
new Description("Successfull cache loads for JGit block cache.").setGauge(),
|
||||
new Supplier<Long>() {
|
||||
@Override
|
||||
public Long get() {
|
||||
return WindowCacheStats.getStats().getLoadSuccessCount();
|
||||
}
|
||||
});
|
||||
WindowCacheStats.getStats()::getLoadSuccessCount);
|
||||
|
||||
metrics.newCallbackMetric(
|
||||
"jgit/block_cache/miss_count",
|
||||
Long.class,
|
||||
new Description("Cache misses for JGit block cache.").setGauge(),
|
||||
new Supplier<Long>() {
|
||||
@Override
|
||||
public Long get() {
|
||||
return WindowCacheStats.getStats().getMissCount();
|
||||
}
|
||||
});
|
||||
WindowCacheStats.getStats()::getMissCount);
|
||||
|
||||
metrics.newCallbackMetric(
|
||||
"jgit/block_cache/miss_ratio",
|
||||
|
||||
@@ -69,7 +69,7 @@ public class Section {
|
||||
all.addAll(Arrays.asList(flags.cfg.getStringList(section, subsection, name)));
|
||||
|
||||
if (value != null) {
|
||||
if (all.size() == 0 || all.size() == 1) {
|
||||
if (all.isEmpty() || all.size() == 1) {
|
||||
flags.cfg.setString(section, subsection, name, value);
|
||||
} else {
|
||||
all.set(0, value);
|
||||
@@ -78,7 +78,7 @@ public class Section {
|
||||
|
||||
} else if (all.size() == 1) {
|
||||
flags.cfg.unset(section, subsection, name);
|
||||
} else if (all.size() != 0) {
|
||||
} else if (!all.isEmpty()) {
|
||||
all.remove(0);
|
||||
flags.cfg.setStringList(section, subsection, name, all);
|
||||
}
|
||||
|
||||
@@ -459,8 +459,8 @@ public class AccountManager {
|
||||
}
|
||||
|
||||
if (filteredExtIdsByScheme.size() > 1
|
||||
|| !filteredExtIdsByScheme.stream()
|
||||
.anyMatch(e -> e.key().equals(who.getExternalIdKey()))) {
|
||||
|| filteredExtIdsByScheme.stream()
|
||||
.noneMatch(e -> e.key().equals(who.getExternalIdKey()))) {
|
||||
u.deleteExternalIds(filteredExtIdsByScheme);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -37,8 +37,8 @@ public class AccountsConsistencyChecker {
|
||||
for (AccountState accountState : accounts.all()) {
|
||||
Account account = accountState.getAccount();
|
||||
if (account.getPreferredEmail() != null) {
|
||||
if (!accountState.getExternalIds().stream()
|
||||
.anyMatch(e -> account.getPreferredEmail().equals(e.email()))) {
|
||||
if (accountState.getExternalIds().stream()
|
||||
.noneMatch(e -> account.getPreferredEmail().equals(e.email()))) {
|
||||
addError(
|
||||
String.format(
|
||||
"Account '%s' has no external ID for its preferred email '%s'",
|
||||
|
||||
@@ -31,10 +31,10 @@ import java.util.Set;
|
||||
|
||||
@Singleton
|
||||
public class CacheMetrics {
|
||||
private static final Field<String> F_NAME = Field.ofString("cache_name");
|
||||
|
||||
@Inject
|
||||
public CacheMetrics(MetricMaker metrics, DynamicMap<Cache<?, ?>> cacheMap) {
|
||||
Field<String> F_NAME = Field.ofString("cache_name");
|
||||
|
||||
CallbackMetric1<String, Long> memEnt =
|
||||
metrics.newCallbackMetric(
|
||||
"caches/memory_cached",
|
||||
|
||||
@@ -25,12 +25,12 @@ import org.eclipse.jgit.lib.Config;
|
||||
|
||||
@Singleton
|
||||
public class ChangeCleanupConfig {
|
||||
private static String SECTION = "changeCleanup";
|
||||
private static String KEY_ABANDON_AFTER = "abandonAfter";
|
||||
private static String KEY_ABANDON_IF_MERGEABLE = "abandonIfMergeable";
|
||||
private static String KEY_ABANDON_MESSAGE = "abandonMessage";
|
||||
private static String KEY_CLEANUP_ACCOUNT_PATCH_REVIEW = "cleanupAccountPatchReview";
|
||||
private static String DEFAULT_ABANDON_MESSAGE =
|
||||
private static final String SECTION = "changeCleanup";
|
||||
private static final String KEY_ABANDON_AFTER = "abandonAfter";
|
||||
private static final String KEY_ABANDON_IF_MERGEABLE = "abandonIfMergeable";
|
||||
private static final String KEY_ABANDON_MESSAGE = "abandonMessage";
|
||||
private static final String KEY_CLEANUP_ACCOUNT_PATCH_REVIEW = "cleanupAccountPatchReview";
|
||||
private static final String DEFAULT_ABANDON_MESSAGE =
|
||||
"Auto-Abandoned due to inactivity, see "
|
||||
+ "${URL}\n"
|
||||
+ "\n"
|
||||
|
||||
@@ -34,10 +34,10 @@ public class TrackingFootersProvider implements Provider<TrackingFooters> {
|
||||
|
||||
private static final int MAX_LENGTH = 10;
|
||||
|
||||
private static String TRACKING_ID_TAG = "trackingid";
|
||||
private static String FOOTER_TAG = "footer";
|
||||
private static String SYSTEM_TAG = "system";
|
||||
private static String REGEX_TAG = "match";
|
||||
private static final String TRACKING_ID_TAG = "trackingid";
|
||||
private static final String FOOTER_TAG = "footer";
|
||||
private static final String SYSTEM_TAG = "system";
|
||||
private static final String REGEX_TAG = "match";
|
||||
private final List<TrackingFooter> trackingFooters = new ArrayList<>();
|
||||
|
||||
@Inject
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import org.apache.lucene.analysis.standard.StandardAnalyzer;
|
||||
@@ -42,7 +41,7 @@ import org.apache.lucene.store.RAMDirectory;
|
||||
public class QueryDocumentationExecutor {
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
private static Map<String, Float> WEIGHTS =
|
||||
private static final ImmutableMap<String, Float> WEIGHTS =
|
||||
ImmutableMap.of(
|
||||
Constants.TITLE_FIELD, 2.0f,
|
||||
Constants.DOC_FIELD, 1.0f);
|
||||
|
||||
@@ -230,7 +230,7 @@ public class StreamEventsApiListener
|
||||
}
|
||||
|
||||
String[] hashtagArray(Collection<String> hashtags) {
|
||||
if (hashtags != null && hashtags.size() > 0) {
|
||||
if (hashtags != null && !hashtags.isEmpty()) {
|
||||
return Sets.newHashSet(hashtags).toArray(new String[hashtags.size()]);
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -141,7 +141,7 @@ public class GroupCollector {
|
||||
checkState(!done, "visit() called after getGroups()");
|
||||
Set<RevCommit> interestingParents = getInterestingParents(c);
|
||||
|
||||
if (interestingParents.size() == 0) {
|
||||
if (interestingParents.isEmpty()) {
|
||||
// All parents are uninteresting: treat this commit as the root of a new
|
||||
// group of related changes.
|
||||
groups.put(c, c.name());
|
||||
|
||||
@@ -49,11 +49,11 @@ public class NotifyConfig implements Comparable<NotifyConfig> {
|
||||
return types.contains(type) || types.contains(NotifyType.ALL);
|
||||
}
|
||||
|
||||
public EnumSet<NotifyType> getNotify() {
|
||||
public Set<NotifyType> getNotify() {
|
||||
return types;
|
||||
}
|
||||
|
||||
public void setTypes(EnumSet<NotifyType> newTypes) {
|
||||
public void setTypes(Set<NotifyType> newTypes) {
|
||||
types = EnumSet.copyOf(newTypes);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ public class TabFile {
|
||||
String parse(String str);
|
||||
}
|
||||
|
||||
public static Parser TRIM = String::trim;
|
||||
public static final Parser TRIM = String::trim;
|
||||
|
||||
protected static class Row {
|
||||
public String left;
|
||||
|
||||
@@ -2205,7 +2205,7 @@ class ReceiveCommits {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
if (changes.size() == 0) {
|
||||
if (changes.isEmpty()) {
|
||||
if (!isValidChangeId(p.changeKey.get())) {
|
||||
reject(magicBranch.cmd, "invalid Change-Id");
|
||||
return Collections.emptyList();
|
||||
|
||||
@@ -77,7 +77,7 @@ public class ChangeIndexRewriter implements IndexRewriter<ChangeData> {
|
||||
* @return the maximal set of statuses that any changes matching the input predicates may have,
|
||||
* based on examining boolean and {@link ChangeStatusPredicate}s.
|
||||
*/
|
||||
public static EnumSet<Change.Status> getPossibleStatus(Predicate<ChangeData> in) {
|
||||
public static Set<Change.Status> getPossibleStatus(Predicate<ChangeData> in) {
|
||||
EnumSet<Change.Status> s = extractStatus(in);
|
||||
return s != null ? s : EnumSet.allOf(Change.Status.class);
|
||||
}
|
||||
|
||||
@@ -45,9 +45,10 @@ import org.eclipse.jgit.transport.ReceiveCommand;
|
||||
public class DeleteZombieCommentsRefs {
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
private final String EMPTY_TREE_ID = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
|
||||
private final String DRAFT_REFS_PREFIX = "refs/draft-comments";
|
||||
private final int CHUNK_SIZE = 100; // log progress after deleting every CHUNK_SIZE refs
|
||||
private static final String EMPTY_TREE_ID = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
|
||||
private static final String DRAFT_REFS_PREFIX = "refs/draft-comments";
|
||||
private static final int CHUNK_SIZE = 100; // log progress after deleting every CHUNK_SIZE refs
|
||||
|
||||
private final GitRepositoryManager repoManager;
|
||||
private final AllUsersName allUsers;
|
||||
private final int cleanupPercentage;
|
||||
|
||||
@@ -501,12 +501,12 @@ public abstract class PermissionBackend {
|
||||
public Set<LabelPermission.WithValue> testLabels(Collection<LabelType> types)
|
||||
throws PermissionBackendException {
|
||||
requireNonNull(types, "LabelType");
|
||||
return test(types.stream().flatMap((t) -> valuesOf(t).stream()).collect(toSet()));
|
||||
return test(types.stream().flatMap(t -> valuesOf(t).stream()).collect(toSet()));
|
||||
}
|
||||
|
||||
private static Set<LabelPermission.WithValue> valuesOf(LabelType label) {
|
||||
return label.getValues().stream()
|
||||
.map((v) -> new LabelPermission.WithValue(label, v))
|
||||
.map(v -> new LabelPermission.WithValue(label, v))
|
||||
.collect(toSet());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.util.HashSet;
|
||||
/** Provides transformations to get and set BooleanProjectConfigs from the API. */
|
||||
public class BooleanProjectConfigTransformations {
|
||||
|
||||
private static ImmutableMap<BooleanProjectConfig, Mapper> MAPPER =
|
||||
private static final ImmutableMap<BooleanProjectConfig, Mapper> MAPPER =
|
||||
ImmutableMap.<BooleanProjectConfig, Mapper>builder()
|
||||
.put(
|
||||
BooleanProjectConfig.USE_CONTRIBUTOR_AGREEMENTS,
|
||||
|
||||
@@ -238,7 +238,7 @@ public class ProjectsConsistencyChecker {
|
||||
predicates.add(new CommitPredicate(commit.name()));
|
||||
}
|
||||
|
||||
if (predicates.size() > 0) {
|
||||
if (!predicates.isEmpty()) {
|
||||
// Execute the query with the remaining predicates that were collected.
|
||||
autoCloseableChanges.addAll(
|
||||
executeQueryAndAutoCloseChanges(
|
||||
@@ -265,13 +265,12 @@ public class ProjectsConsistencyChecker {
|
||||
List<ChangeData> queryResult =
|
||||
retryHelper.execute(
|
||||
ActionType.INDEX_QUERY,
|
||||
() -> {
|
||||
// Execute the query.
|
||||
return changeQueryProvider
|
||||
.get()
|
||||
.setRequestedFields(ChangeField.CHANGE, ChangeField.PATCH_SET)
|
||||
.query(and(basePredicate, or(predicates)));
|
||||
},
|
||||
() ->
|
||||
// Execute the query.
|
||||
changeQueryProvider
|
||||
.get()
|
||||
.setRequestedFields(ChangeField.CHANGE, ChangeField.PATCH_SET)
|
||||
.query(and(basePredicate, or(predicates))),
|
||||
StorageException.class::isInstance);
|
||||
|
||||
// Result for this query that we want to return to the client.
|
||||
|
||||
@@ -72,7 +72,7 @@ public class InternalAccountQuery extends InternalQuery<AccountState, InternalAc
|
||||
List<AccountState> accountStates = byExternalId(externalId);
|
||||
if (accountStates.size() == 1) {
|
||||
return accountStates.get(0);
|
||||
} else if (accountStates.size() > 0) {
|
||||
} else if (!accountStates.isEmpty()) {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append("Ambiguous external ID ").append(externalId).append(" for accounts: ");
|
||||
Joiner.on(", ")
|
||||
|
||||
@@ -35,9 +35,7 @@ public class AndChangeSource extends AndSource<ChangeData> implements ChangeData
|
||||
|
||||
@Override
|
||||
public boolean hasChange() {
|
||||
return source != null
|
||||
&& source instanceof ChangeDataSource
|
||||
&& ((ChangeDataSource) source).hasChange();
|
||||
return source instanceof ChangeDataSource && ((ChangeDataSource) source).hasChange();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -70,7 +70,7 @@ public class DeleteExternalIds implements RestModifyView<AccountResource, List<S
|
||||
permissionBackend.currentUser().check(GlobalPermission.ACCESS_DATABASE);
|
||||
}
|
||||
|
||||
if (extIds == null || extIds.size() == 0) {
|
||||
if (extIds == null || extIds.isEmpty()) {
|
||||
throw new BadRequestException("external IDs are required");
|
||||
}
|
||||
|
||||
|
||||
@@ -253,7 +253,7 @@ public class GetDiff implements RestReadView<FileResource> {
|
||||
throw new IllegalStateException("unknown change type: " + ps.getChangeType());
|
||||
}
|
||||
|
||||
if (ps.getPatchHeader().size() > 0) {
|
||||
if (!ps.getPatchHeader().isEmpty()) {
|
||||
result.diffHeader = ps.getPatchHeader();
|
||||
}
|
||||
result.content = content.lines;
|
||||
|
||||
@@ -43,7 +43,7 @@ import org.kohsuke.args4j.Option;
|
||||
public class GetPatch implements RestReadView<RevisionResource> {
|
||||
private final GitRepositoryManager repoManager;
|
||||
|
||||
private final String FILE_NOT_FOUND = "File not found: %s.";
|
||||
private static final String FILE_NOT_FOUND = "File not found: %s.";
|
||||
|
||||
@Option(name = "--zip")
|
||||
private boolean zip;
|
||||
|
||||
@@ -289,7 +289,7 @@ public class PostReview
|
||||
Account.Id id = revision.getUser().getAccountId();
|
||||
boolean ccOrReviewer = false;
|
||||
if (input.labels != null && !input.labels.isEmpty()) {
|
||||
ccOrReviewer = input.labels.values().stream().filter(v -> v != 0).findFirst().isPresent();
|
||||
ccOrReviewer = input.labels.values().stream().anyMatch(v -> v != 0);
|
||||
}
|
||||
|
||||
if (!ccOrReviewer) {
|
||||
|
||||
@@ -232,7 +232,7 @@ public class ReviewerRecommender {
|
||||
// (weighted 10d), number of comments (weighted 0.5d) and number of owned
|
||||
// changes (weighted 1d).
|
||||
Map<Account.Id, MutableDouble> reviewers = new LinkedHashMap<>();
|
||||
if (candidates.size() == 0) {
|
||||
if (candidates.isEmpty()) {
|
||||
return reviewers;
|
||||
}
|
||||
List<Predicate<ChangeData>> predicates = new ArrayList<>();
|
||||
|
||||
@@ -45,6 +45,7 @@ import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.kohsuke.args4j.Option;
|
||||
|
||||
public class SubmittedTogether implements RestReadView<ChangeResource> {
|
||||
@@ -95,12 +96,12 @@ public class SubmittedTogether implements RestReadView<ChangeResource> {
|
||||
this.sorter = sorter;
|
||||
}
|
||||
|
||||
public SubmittedTogether addListChangesOption(EnumSet<ListChangesOption> o) {
|
||||
public SubmittedTogether addListChangesOption(Set<ListChangesOption> o) {
|
||||
jsonOpt.addAll(o);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SubmittedTogether addSubmittedTogetherOption(EnumSet<SubmittedTogetherOption> o) {
|
||||
public SubmittedTogether addSubmittedTogetherOption(Set<SubmittedTogetherOption> o) {
|
||||
options.addAll(o);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -125,8 +125,8 @@ public class GetSummary implements RestReadView<ConfigResource> {
|
||||
long mTotal = r.totalMemory();
|
||||
long mInuse = mTotal - mFree;
|
||||
|
||||
int jgitOpen = WindowCacheStats.getOpenFiles();
|
||||
long jgitBytes = WindowCacheStats.getOpenBytes();
|
||||
long jgitOpen = WindowCacheStats.getStats().getOpenFileCount();
|
||||
long jgitBytes = WindowCacheStats.getStats().getOpenByteCount();
|
||||
|
||||
MemSummaryInfo memSummaryInfo = new MemSummaryInfo();
|
||||
memSummaryInfo.total = bytes(mTotal);
|
||||
@@ -134,7 +134,7 @@ public class GetSummary implements RestReadView<ConfigResource> {
|
||||
memSummaryInfo.free = bytes(mFree);
|
||||
memSummaryInfo.buffers = bytes(jgitBytes);
|
||||
memSummaryInfo.max = bytes(mMax);
|
||||
memSummaryInfo.openFiles = toInteger(jgitOpen);
|
||||
memSummaryInfo.openFiles = Long.valueOf(jgitOpen);
|
||||
return memSummaryInfo;
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ public class GetSummary implements RestReadView<ConfigResource> {
|
||||
public String free;
|
||||
public String buffers;
|
||||
public String max;
|
||||
public Integer openFiles;
|
||||
public Long openFiles;
|
||||
}
|
||||
|
||||
public static class ThreadSummaryInfo {
|
||||
|
||||
@@ -85,7 +85,7 @@ public class ListGroups implements RestReadView<TopLevelResource> {
|
||||
private final Groups groups;
|
||||
private final GroupResolver groupResolver;
|
||||
|
||||
private EnumSet<ListGroupsOption> options = EnumSet.noneOf(ListGroupsOption.class);
|
||||
private Set<ListGroupsOption> options = EnumSet.noneOf(ListGroupsOption.class);
|
||||
private boolean visibleToAll;
|
||||
private Account.Id user;
|
||||
private boolean owned;
|
||||
@@ -234,7 +234,7 @@ public class ListGroups implements RestReadView<TopLevelResource> {
|
||||
this.groupResolver = groupResolver;
|
||||
}
|
||||
|
||||
public void setOptions(EnumSet<ListGroupsOption> options) {
|
||||
public void setOptions(Set<ListGroupsOption> options) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
|
||||
@@ -348,7 +348,7 @@ public class ListProjects implements RestReadView<TopLevelResource> {
|
||||
queries.add(String.format("(state:%s)", state.name()));
|
||||
}
|
||||
|
||||
return Joiner.on(" AND ").join(queries).toString();
|
||||
return Joiner.on(" AND ").join(queries);
|
||||
}
|
||||
|
||||
private SortedMap<String, ProjectInfo> applyAsQuery(String query) throws BadRequestException {
|
||||
|
||||
@@ -164,12 +164,7 @@ public class SetParent
|
||||
throw new ResourceConflictException("cannot set parent to self");
|
||||
}
|
||||
|
||||
if (Iterables.tryFind(
|
||||
parent.tree(),
|
||||
p -> {
|
||||
return p.getNameKey().equals(project);
|
||||
})
|
||||
.isPresent()) {
|
||||
if (Iterables.tryFind(parent.tree(), p -> p.getNameKey().equals(project)).isPresent()) {
|
||||
throw new ResourceConflictException(
|
||||
"cycle exists between " + project.get() + " and " + parent.getName());
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public abstract class RetryingRestCollectionModifyView<
|
||||
@Override
|
||||
public final O apply(P parentResource, I input)
|
||||
throws AuthException, BadRequestException, ResourceConflictException, Exception {
|
||||
return retryHelper.execute((updateFactory) -> applyImpl(updateFactory, parentResource, input));
|
||||
return retryHelper.execute(updateFactory -> applyImpl(updateFactory, parentResource, input));
|
||||
}
|
||||
|
||||
protected abstract O applyImpl(BatchUpdate.Factory updateFactory, P parentResource, I input)
|
||||
|
||||
@@ -27,7 +27,7 @@ public abstract class RetryingRestModifyView<R extends RestResource, I, O>
|
||||
|
||||
@Override
|
||||
public final O apply(R resource, I input) throws Exception {
|
||||
return retryHelper.execute((updateFactory) -> applyImpl(updateFactory, resource, input));
|
||||
return retryHelper.execute(updateFactory -> applyImpl(updateFactory, resource, input));
|
||||
}
|
||||
|
||||
protected abstract O applyImpl(BatchUpdate.Factory updateFactory, R resource, I input)
|
||||
|
||||
@@ -58,14 +58,14 @@ final class FlushCaches extends SshCommand {
|
||||
protected void run() throws Failure {
|
||||
try {
|
||||
if (list) {
|
||||
if (all || caches.size() > 0) {
|
||||
if (all || !caches.isEmpty()) {
|
||||
throw die("cannot use --list with --all or --cache");
|
||||
}
|
||||
doList();
|
||||
return;
|
||||
}
|
||||
|
||||
if (all && caches.size() > 0) {
|
||||
if (all && !caches.isEmpty()) {
|
||||
throw die("cannot combine --all and --cache");
|
||||
} else if (!all && caches.size() == 1 && caches.contains("all")) {
|
||||
caches.clear();
|
||||
|
||||
@@ -290,6 +290,10 @@ final class ShowCaches extends SshCommand {
|
||||
return i != null ? i : 0;
|
||||
}
|
||||
|
||||
private static long nullToZero(Long i) {
|
||||
return i != null ? i : 0;
|
||||
}
|
||||
|
||||
private void sshSummary() {
|
||||
IoAcceptor acceptor = daemon.getIoAcceptor();
|
||||
if (acceptor == null) {
|
||||
|
||||
Reference in New Issue
Block a user