Merge branch 'stable-2.15' into stable-2.16
* stable-2.15:
Switch required bazel version to 0.29.1
Change-Id: I592de41654342953e36202e5063ac7e2f4cdb031
diff --git a/WORKSPACE b/WORKSPACE
index 2148a88..11e6ead 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -3,7 +3,7 @@
load("//:bazlets.bzl", "load_bazlets")
load_bazlets(
- commit = "5f03aec7c72e743079ea2ecad5530f4684ca7d45",
+ commit = "6af2e084b72d38a3375925c4586ac2278ef95ee9",
#local_path = "/home/<user>/projects/bazlets",
)
diff --git a/src/main/java/com/googlesource/gerrit/plugins/webhooks/DefaultHttpClientProvider.java b/src/main/java/com/googlesource/gerrit/plugins/webhooks/DefaultHttpClientProvider.java
index 5dc7ff3..f40ef0f 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/webhooks/DefaultHttpClientProvider.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/webhooks/DefaultHttpClientProvider.java
@@ -14,6 +14,7 @@
package com.googlesource.gerrit.plugins.webhooks;
+import com.google.common.flogger.FluentLogger;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.security.KeyManagementException;
@@ -28,12 +29,10 @@
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/* HTTP client that doesn't verify remote's SSL certificate */
class DefaultHttpClientProvider extends HttpClientProvider {
- private static final Logger log = LoggerFactory.getLogger(DefaultHttpClientProvider.class);
+ private static final FluentLogger log = FluentLogger.forEnclosingClass();
static final String DEFAULT = "default";
@@ -63,7 +62,7 @@
context.init(null, trustAllCerts, null);
return context;
} catch (KeyManagementException | NoSuchAlgorithmException e) {
- log.warn("Error building SSLContext object", e);
+ log.atWarning().withCause(e).log("Error building SSLContext object");
return null;
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/webhooks/EventHandler.java b/src/main/java/com/googlesource/gerrit/plugins/webhooks/EventHandler.java
index 1c36eeb..986c84e 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/webhooks/EventHandler.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/webhooks/EventHandler.java
@@ -17,19 +17,18 @@
import static com.googlesource.gerrit.plugins.webhooks.RemoteConfig.REMOTE;
import com.google.common.base.Strings;
-import com.google.gerrit.common.EventListener;
+import com.google.common.flogger.FluentLogger;
import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.server.config.PluginConfigFactory;
import com.google.gerrit.server.events.Event;
+import com.google.gerrit.server.events.EventListener;
import com.google.gerrit.server.events.ProjectEvent;
import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.inject.Inject;
import org.eclipse.jgit.lib.Config;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
class EventHandler implements EventListener {
- private static final Logger log = LoggerFactory.getLogger(EventHandler.class);
+ private static final FluentLogger log = FluentLogger.forEnclosingClass();
private final PluginConfigFactory configFactory;
private final String pluginName;
@@ -61,17 +60,16 @@
configFactory.getProjectPluginConfigWithInheritance(
projectEvent.getProjectNameKey(), pluginName);
} catch (NoSuchProjectException e) {
- log.warn(
- "Ignoring event for a non-existing project {}, {}",
- projectEvent.getProjectNameKey().get(),
- projectEvent);
+ log.atWarning().log(
+ "Ignoring event for a non-existing project %s, %s",
+ projectEvent.getProjectNameKey().get(), projectEvent);
return;
}
for (String name : cfg.getSubsections(REMOTE)) {
RemoteConfig remote = remoteFactory.create(cfg, name);
if (Strings.isNullOrEmpty(remote.getUrl())) {
- log.warn("remote.{}.url not defined, skipping this remote", name);
+ log.atWarning().log("remote.%s.url not defined, skipping this remote", name);
continue;
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/webhooks/HttpClientProvider.java b/src/main/java/com/googlesource/gerrit/plugins/webhooks/HttpClientProvider.java
index aecb43a..f9afd02 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/webhooks/HttpClientProvider.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/webhooks/HttpClientProvider.java
@@ -14,6 +14,9 @@
package com.googlesource.gerrit.plugins.webhooks;
+import static com.google.common.flogger.LazyArgs.lazy;
+
+import com.google.common.flogger.FluentLogger;
import com.google.inject.Provider;
import org.apache.http.HttpResponse;
import org.apache.http.client.ServiceUnavailableRetryStrategy;
@@ -25,12 +28,10 @@
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.protocol.HttpContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/** Provides an HTTP client with SSL capabilities. */
abstract class HttpClientProvider implements Provider<CloseableHttpClient> {
- private static final Logger log = LoggerFactory.getLogger(HttpClientProvider.class);
+ private static final FluentLogger log = FluentLogger.forEnclosingClass();
private static final int CONNECTIONS_PER_ROUTE = 100;
// Up to 2 target instances with the max number of connections per host:
private static final int MAX_CONNECTIONS = 2 * CONNECTIONS_PER_ROUTE;
@@ -85,14 +86,9 @@
}
private void logRetry(String cause, HttpContext context) {
- if (log.isDebugEnabled()) {
- log.debug(
- "Retrying request caused by '"
- + cause
- + "', request: '"
- + context.getAttribute("http.request")
- + "'");
- }
+ log.atFine().log(
+ "Retrying request caused by '%s', request: '%s'",
+ cause, lazy(() -> context.getAttribute("http.request")));
}
private HttpClientConnectionManager create(
diff --git a/src/main/java/com/googlesource/gerrit/plugins/webhooks/HttpResponseHandler.java b/src/main/java/com/googlesource/gerrit/plugins/webhooks/HttpResponseHandler.java
index 0c23b6e..0c5bd24 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/webhooks/HttpResponseHandler.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/webhooks/HttpResponseHandler.java
@@ -18,14 +18,13 @@
import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
import static javax.servlet.http.HttpServletResponse.SC_OK;
+import com.google.common.flogger.FluentLogger;
import com.googlesource.gerrit.plugins.webhooks.HttpResponseHandler.HttpResult;
import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ResponseHandler;
import org.apache.http.util.EntityUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
class HttpResponseHandler implements ResponseHandler<HttpResult> {
@@ -39,7 +38,7 @@
}
}
- private static final Logger log = LoggerFactory.getLogger(HttpResponseHandler.class);
+ private static final FluentLogger log = FluentLogger.forEnclosingClass();
@Override
public HttpResult handleResponse(HttpResponse response) {
@@ -57,7 +56,7 @@
try {
return EntityUtils.toString(entity);
} catch (IOException e) {
- log.error("Error parsing entity", e);
+ log.atSevere().withCause(e).log("Error parsing entity");
}
}
return "";
diff --git a/src/main/java/com/googlesource/gerrit/plugins/webhooks/Module.java b/src/main/java/com/googlesource/gerrit/plugins/webhooks/Module.java
index 6c06f6f..edaaeff 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/webhooks/Module.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/webhooks/Module.java
@@ -17,10 +17,10 @@
import static com.googlesource.gerrit.plugins.webhooks.DefaultHttpClientProvider.DEFAULT;
import static com.googlesource.gerrit.plugins.webhooks.SslVerifyingHttpClientProvider.SSL_VERIFY;
-import com.google.gerrit.common.EventListener;
import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.extensions.config.FactoryModule;
import com.google.gerrit.extensions.registration.DynamicSet;
+import com.google.gerrit.server.events.EventListener;
import com.google.inject.Inject;
import com.google.inject.Provides;
import com.google.inject.Scopes;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/webhooks/PostTask.java b/src/main/java/com/googlesource/gerrit/plugins/webhooks/PostTask.java
index 0d7fd51..90c03b9 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/webhooks/PostTask.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/webhooks/PostTask.java
@@ -16,6 +16,7 @@
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
+import com.google.common.flogger.FluentLogger;
import com.google.gerrit.server.events.ProjectEvent;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
@@ -25,11 +26,9 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
class PostTask implements Runnable {
- private static final Logger log = LoggerFactory.getLogger(PostTask.class);
+ private static final FluentLogger log = FluentLogger.forEnclosingClass();
interface Factory {
PostTask create(ProjectEvent event, RemoteConfig remote);
@@ -71,7 +70,7 @@
try {
Optional<EventProcessor.Request> content = processor.get();
if (!content.isPresent()) {
- log.debug("No content. Webhook [{}] skipped.", remote.getUrl());
+ log.atFine().log("No content. Webhook [%s] skipped.", remote.getUrl());
return;
}
@@ -86,7 +85,7 @@
logRetry(e);
reschedule();
} else {
- log.error("Failed to post: {}", toString(), e);
+ log.atSevere().withCause(e).log("Failed to post: %s", toString());
}
}
}
@@ -96,15 +95,12 @@
}
private void logRetry(String reason) {
- if (log.isDebugEnabled()) {
- log.debug("Retrying {} in {}ms. Reason: {}", toString(), remote.getRetryInterval(), reason);
- }
+ log.atFine().log(
+ "Retrying %s in %dms. Reason: %s", toString(), remote.getRetryInterval(), reason);
}
private void logRetry(Throwable cause) {
- if (log.isDebugEnabled()) {
- log.debug("Retrying {} in {}ms. Cause: {}", toString(), remote.getRetryInterval(), cause);
- }
+ log.atFine().withCause(cause).log("Retrying %s in %dms", toString(), remote.getRetryInterval());
}
@Override
diff --git a/src/main/java/com/googlesource/gerrit/plugins/webhooks/WebhooksConfig.java b/src/main/java/com/googlesource/gerrit/plugins/webhooks/WebhooksConfig.java
index 88bb951..56db3f6 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/webhooks/WebhooksConfig.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/webhooks/WebhooksConfig.java
@@ -27,7 +27,7 @@
import com.google.common.base.Strings;
import com.google.gerrit.reviewdb.client.RefNames;
-import com.google.gerrit.server.git.VersionedMetaData;
+import com.google.gerrit.server.git.meta.VersionedMetaData;
import com.google.inject.Inject;
import com.googlesource.gerrit.plugins.webhooks.rest.UpsertRemote;
import java.io.IOException;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/webhooks/rest/DeleteRemote.java b/src/main/java/com/googlesource/gerrit/plugins/webhooks/rest/DeleteRemote.java
index 1a4f032..7bb1470 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/webhooks/rest/DeleteRemote.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/webhooks/rest/DeleteRemote.java
@@ -17,7 +17,7 @@
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestModifyView;
-import com.google.gerrit.server.git.MetaDataUpdate;
+import com.google.gerrit.server.git.meta.MetaDataUpdate;
import com.google.gerrit.server.project.ProjectCache;
import com.google.inject.Inject;
import com.google.inject.Provider;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/webhooks/rest/RemotesCollection.java b/src/main/java/com/googlesource/gerrit/plugins/webhooks/rest/RemotesCollection.java
index 4f1508c..f1e8acc 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/webhooks/rest/RemotesCollection.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/webhooks/rest/RemotesCollection.java
@@ -18,7 +18,6 @@
import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.extensions.registration.DynamicMap;
-import com.google.gerrit.extensions.restapi.AcceptsCreate;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.ChildCollection;
import com.google.gerrit.extensions.restapi.IdString;
@@ -32,16 +31,13 @@
import org.eclipse.jgit.lib.Config;
@Singleton
-public class RemotesCollection
- implements ChildCollection<ProjectWebhooksResource, RemoteResource>,
- AcceptsCreate<ProjectWebhooksResource> {
+public class RemotesCollection implements ChildCollection<ProjectWebhooksResource, RemoteResource> {
private final DynamicMap<RestView<RemoteResource>> views;
private final PluginConfigFactory configFactory;
private final RemoteConfig.Factory remoteFactory;
private final Provider<ListRemotes> list;
private final String pluginName;
- private final UpsertRemote.Inserter.Factory inserterFactory;
@Inject
RemotesCollection(
@@ -49,14 +45,12 @@
PluginConfigFactory configFactory,
RemoteConfig.Factory remoteFactory,
Provider<ListRemotes> list,
- @PluginName String pluginName,
- UpsertRemote.Inserter.Factory inserterFactory) {
+ @PluginName String pluginName) {
this.views = views;
this.configFactory = configFactory;
this.remoteFactory = remoteFactory;
this.list = list;
this.pluginName = pluginName;
- this.inserterFactory = inserterFactory;
}
@Override
@@ -80,9 +74,4 @@
public DynamicMap<RestView<RemoteResource>> views() {
return views;
}
-
- @Override
- public UpsertRemote.Inserter create(ProjectWebhooksResource parent, IdString id) {
- return inserterFactory.create(id.get());
- }
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/webhooks/rest/UpsertRemote.java b/src/main/java/com/googlesource/gerrit/plugins/webhooks/rest/UpsertRemote.java
index 0c212c6..41eedae 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/webhooks/rest/UpsertRemote.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/webhooks/rest/UpsertRemote.java
@@ -19,17 +19,17 @@
import com.google.common.base.Strings;
import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.extensions.restapi.AuthException;
+import com.google.gerrit.extensions.restapi.IdString;
+import com.google.gerrit.extensions.restapi.RestCollectionCreateView;
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.config.PluginConfigFactory;
-import com.google.gerrit.server.git.MetaDataUpdate;
+import com.google.gerrit.server.git.meta.MetaDataUpdate;
import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.gerrit.server.project.ProjectCache;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
-import com.google.inject.assistedinject.Assisted;
-import com.google.inject.assistedinject.AssistedInject;
import com.googlesource.gerrit.plugins.webhooks.RemoteConfig;
import com.googlesource.gerrit.plugins.webhooks.WebhooksConfig;
import java.io.IOException;
@@ -67,25 +67,22 @@
}
public static class Inserter
- implements RestModifyView<ProjectWebhooksResource, UpsertRemote.Input> {
- public interface Factory {
- Inserter create(String remoteName);
- }
+ implements RestCollectionCreateView<
+ ProjectWebhooksResource, RemoteResource, UpsertRemote.Input> {
private final UpsertRemote upserter;
- private final String remoteName;
- @AssistedInject
- Inserter(UpsertRemote upserter, @Assisted String remoteName) {
+ @Inject
+ Inserter(UpsertRemote upserter) {
this.upserter = upserter;
- this.remoteName = remoteName;
}
@Override
- public RemoteInfo apply(ProjectWebhooksResource rsrc, UpsertRemote.Input in)
+ public RemoteInfo apply(
+ ProjectWebhooksResource rsrc, IdString remoteName, UpsertRemote.Input in)
throws RepositoryNotFoundException, IOException, ConfigInvalidException,
NoSuchProjectException, AuthException {
- return upserter.upsert(rsrc.getProject(), remoteName, in);
+ return upserter.upsert(rsrc.getProject(), remoteName.get(), in);
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/webhooks/rest/WebhooksRestModule.java b/src/main/java/com/googlesource/gerrit/plugins/webhooks/rest/WebhooksRestModule.java
index 6ab24a4..c227964 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/webhooks/rest/WebhooksRestModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/webhooks/rest/WebhooksRestModule.java
@@ -18,7 +18,6 @@
import static com.googlesource.gerrit.plugins.webhooks.rest.ProjectWebhooksResource.PROJECT_WEBHOOK_KIND;
import static com.googlesource.gerrit.plugins.webhooks.rest.RemoteResource.REMOTE_KIND;
-import com.google.gerrit.extensions.config.FactoryModule;
import com.google.gerrit.extensions.registration.DynamicMap;
import com.google.gerrit.extensions.restapi.RestApiModule;
@@ -31,18 +30,11 @@
child(CONFIG_KIND, "projects").to(ProjectsCollection.class);
child(PROJECT_WEBHOOK_KIND, "remotes").to(RemotesCollection.class);
+ create(REMOTE_KIND).to(UpsertRemote.Inserter.class);
get(REMOTE_KIND).to(GetRemote.class);
put(REMOTE_KIND).to(UpsertRemote.Updater.class);
delete(REMOTE_KIND).to(DeleteRemote.class);
bind(Permissions.class).to(PermissionsImpl.class);
-
- install(
- new FactoryModule() {
- @Override
- protected void configure() {
- factory(UpsertRemote.Inserter.Factory.class);
- }
- });
}
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/webhooks/rest/UpdateRemoteIT.java b/src/test/java/com/googlesource/gerrit/plugins/webhooks/rest/UpdateRemoteIT.java
index 0f3f228..cb6f0c7 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/webhooks/rest/UpdateRemoteIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/webhooks/rest/UpdateRemoteIT.java
@@ -39,8 +39,8 @@
@Override
@Before
- public void setUp() throws Exception {
- super.setUp();
+ public void setUpTestPlugin() throws Exception {
+ super.setUpTestPlugin();
fooEndpoint = String.format("/config/server/webhooks~projects/%s/remotes/foo", project.get());
}