Merge branch 'stable-2.14' into stable-2.15

* stable-2.14:
  HttpPluginServlet: Don't trim leading whitespace from about.md content
  ProjectConfig: Don't use JGit's StringUtils to convert to lower case
  Do not abort indexing if < 50% projects failed
  Revert "AllChangesIndexer: Don't abort when failing to open repository"
  VersionedAccountDestinations: Remove unused createSink(String) method
  ProjectBasicAuthFilter: Add comment why cause is not logged
  BazelBuild: Fix exception message when command was interrupted
  GitwebServlet: Write only one log entry for CGI errors
  GitwebServlet: Log unexpected errors on error level
  PostGpgKeys: Remove unneeded use of Joiner
  Remove some logs for errors that are rethrown
  DropWizardMetricMaker: Improve error messages for invalid arguments
  DropWizardMetricMaker: Improve error message when metric name is invalid
  AllChangesIndexer: Don't abort when failing to open repository

Change-Id: I6febb890b7717731fcb5f0653360982668469069
This commit is contained in:
David Pursehouse
2018-05-17 15:39:34 +09:00
10 changed files with 29 additions and 26 deletions

View File

@@ -261,10 +261,10 @@ public class PostGpgKeys implements RestModifyView<AccountResource, Input> {
if (accountStates.size() > 1) { if (accountStates.size() > 1) {
StringBuilder msg = new StringBuilder(); StringBuilder msg = new StringBuilder();
msg.append("GPG key ").append(extIdKey.get()).append(" associated with multiple accounts: "); msg.append("GPG key ")
Joiner.on(", ") .append(extIdKey.get())
.appendTo(msg, Lists.transform(accountStates, AccountState.ACCOUNT_ID_FUNCTION)); .append(" associated with multiple accounts: ")
log.error(msg.toString()); .append(Lists.transform(accountStates, AccountState.ACCOUNT_ID_FUNCTION));
throw new IllegalStateException(msg.toString()); throw new IllegalStateException(msg.toString());
} }

View File

@@ -42,6 +42,7 @@ java_library(
"//lib:soy", "//lib:soy",
"//lib/auto:auto-value", "//lib/auto:auto-value",
"//lib/commons:codec", "//lib/commons:codec",
"//lib/commons:lang",
"//lib/guice", "//lib/guice",
"//lib/guice:guice-assistedinject", "//lib/guice:guice-assistedinject",
"//lib/guice:guice-servlet", "//lib/guice:guice-servlet",

View File

@@ -164,6 +164,8 @@ class ProjectBasicAuthFilter implements Filter {
rsp.sendError(SC_UNAUTHORIZED); rsp.sendError(SC_UNAUTHORIZED);
return false; return false;
} catch (AuthenticationFailedException e) { } catch (AuthenticationFailedException e) {
// This exception is thrown if the user provided wrong credentials, we don't need to log a
// stacktrace for it.
log.warn("Authentication failed for " + username + ": " + e.getMessage()); log.warn("Authentication failed for " + username + ": " + e.getMessage());
rsp.sendError(SC_UNAUTHORIZED); rsp.sendError(SC_UNAUTHORIZED);
return false; return false;

View File

@@ -643,7 +643,7 @@ class GitwebServlet extends HttpServlet {
dst.close(); dst.close();
} }
} catch (IOException e) { } catch (IOException e) {
log.debug("Unexpected error copying input to CGI", e); log.error("Unexpected error copying input to CGI", e);
} }
}, },
"Gitweb-InputFeeder") "Gitweb-InputFeeder")
@@ -653,14 +653,19 @@ class GitwebServlet extends HttpServlet {
private void copyStderrToLog(InputStream in) { private void copyStderrToLog(InputStream in) {
new Thread( new Thread(
() -> { () -> {
StringBuilder b = new StringBuilder();
try (BufferedReader br = try (BufferedReader br =
new BufferedReader(new InputStreamReader(in, ISO_8859_1.name()))) { new BufferedReader(new InputStreamReader(in, ISO_8859_1.name()))) {
String line; String line;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
log.error("CGI: " + line); if (b.length() > 0) {
b.append('\n');
}
b.append("CGI: ").append(line);
} }
log.error(b.toString());
} catch (IOException e) { } catch (IOException e) {
log.debug("Unexpected error copying stderr from CGI", e); log.error("Unexpected error copying stderr from CGI", e);
} }
}, },
"Gitweb-ErrorLogger") "Gitweb-ErrorLogger")

View File

@@ -88,6 +88,7 @@ import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.util.IO; import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.RawParseUtils; import org.eclipse.jgit.util.RawParseUtils;
@@ -478,7 +479,7 @@ class HttpPluginServlet extends HttpServlet implements StartPluginListener, Relo
try (BufferedReader reader = new BufferedReader(isr)) { try (BufferedReader reader = new BufferedReader(isr)) {
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
line = line.trim(); line = StringUtils.stripEnd(line, null);
if (line.isEmpty()) { if (line.isEmpty()) {
aboutContent.append("\n"); aboutContent.append("\n");
} else { } else {

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.httpd.raw;
import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.MoreObjects.firstNonNull;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.base.Joiner;
import com.google.common.escape.Escaper; import com.google.common.escape.Escaper;
import com.google.common.html.HtmlEscapers; import com.google.common.html.HtmlEscapers;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
@@ -62,7 +63,8 @@ public class BazelBuild {
try { try {
status = rebuild.waitFor(); status = rebuild.waitFor();
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new InterruptedIOException("interrupted waiting for " + proc.toString()); throw new InterruptedIOException(
"interrupted waiting for: " + Joiner.on(' ').join(proc.command()));
} }
if (status != 0) { if (status != 0) {
log.warn("build failed: " + new String(out, UTF_8)); log.warn("build failed: " + new String(out, UTF_8));

View File

@@ -69,13 +69,9 @@ import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.util.thread.ThreadPool; import org.eclipse.jetty.util.thread.ThreadPool;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Singleton @Singleton
public class JettyServer { public class JettyServer {
private static final Logger log = LoggerFactory.getLogger(JettyServer.class);
static class Lifecycle implements LifecycleListener { static class Lifecycle implements LifecycleListener {
private final JettyServer server; private final JettyServer server;
private final Config cfg; private final Config cfg;
@@ -425,9 +421,8 @@ public class JettyServer {
"/*", "/*",
EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC)); EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
} catch (Throwable e) { } catch (Throwable e) {
String errorMessage = "Unable to instantiate front-end HTTP Filter " + filterClassName; throw new IllegalArgumentException(
log.error(errorMessage, e); "Unable to instantiate front-end HTTP Filter " + filterClassName, e);
throw new IllegalArgumentException(errorMessage, e);
} }
} }

View File

@@ -151,8 +151,8 @@ public class DropWizardMetricMaker extends MetricMaker {
private static void checkCounterDescription(String name, Description desc) { private static void checkCounterDescription(String name, Description desc) {
checkMetricName(name); checkMetricName(name);
checkArgument(!desc.isConstant(), "counters must not be constant"); checkArgument(!desc.isConstant(), "counter must not be constant");
checkArgument(!desc.isGauge(), "counters must not be gauge"); checkArgument(!desc.isGauge(), "counter must not be gauge");
} }
CounterImpl newCounterImpl(String name, boolean isRate) { CounterImpl newCounterImpl(String name, boolean isRate) {
@@ -326,7 +326,7 @@ public class DropWizardMetricMaker extends MetricMaker {
if (!desc.getAnnotations() if (!desc.getAnnotations()
.get(Description.DESCRIPTION) .get(Description.DESCRIPTION)
.equals(annotations.get(Description.DESCRIPTION))) { .equals(annotations.get(Description.DESCRIPTION))) {
throw new IllegalStateException(String.format("metric %s already defined", name)); throw new IllegalStateException(String.format("metric '%s' already defined", name));
} }
} else { } else {
descriptions.put(name, desc.getAnnotations()); descriptions.put(name, desc.getAnnotations());
@@ -339,7 +339,8 @@ public class DropWizardMetricMaker extends MetricMaker {
private static void checkMetricName(String name) { private static void checkMetricName(String name) {
checkArgument( checkArgument(
METRIC_NAME_PATTERN.matcher(name).matches(), METRIC_NAME_PATTERN.matcher(name).matches(),
"metric name must match %s", "invalid metric name '%s': must match pattern '%s'",
name,
METRIC_NAME_PATTERN.pattern()); METRIC_NAME_PATTERN.pattern());
} }

View File

@@ -69,10 +69,6 @@ public class VersionedAccountDestinations extends VersionedMetaData {
} }
} }
public ValidationError.Sink createSink(String file) {
return ValidationError.createLoggerSink(file, log);
}
@Override @Override
protected boolean onSave(CommitBuilder commit) throws IOException, ConfigInvalidException { protected boolean onSave(CommitBuilder commit) throws IOException, ConfigInvalidException {
throw new UnsupportedOperationException("Cannot yet save destinations"); throw new UnsupportedOperationException("Cannot yet save destinations");

View File

@@ -64,6 +64,7 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Optional; import java.util.Optional;
@@ -75,7 +76,6 @@ import org.eclipse.jgit.lib.CommitBuilder;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.util.StringUtils;
public class ProjectConfig extends VersionedMetaData implements ValidationError.Sink { public class ProjectConfig extends VersionedMetaData implements ValidationError.Sink {
public static final String COMMENTLINK = "commentlink"; public static final String COMMENTLINK = "commentlink";
@@ -1250,7 +1250,7 @@ public class ProjectConfig extends VersionedMetaData implements ValidationError.
List<String> types = Lists.newArrayListWithCapacity(4); List<String> types = Lists.newArrayListWithCapacity(4);
for (NotifyType t : NotifyType.values()) { for (NotifyType t : NotifyType.values()) {
if (nc.isNotify(t)) { if (nc.isNotify(t)) {
types.add(StringUtils.toLowerCase(t.name())); types.add(t.name().toLowerCase(Locale.US));
} }
} }
rc.setStringList(NOTIFY, nc.getName(), KEY_TYPE, types); rc.setStringList(NOTIFY, nc.getName(), KEY_TYPE, types);