Drop legacy commenting framework
The legacy way of commenting on an Its has been deprecated ~9 months
ago. It is time to remove it for good. The “actions.config”-way is way
more powerful and better adaptable to what people need.
Change-Id: I6704a7049c6420f1b90b2c80089f439369adcf11
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/RTCModule.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/RTCModule.java
index fc27dbd..05737ab 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/RTCModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/RTCModule.java
@@ -34,11 +34,7 @@
import com.googlesource.gerrit.plugins.hooks.its.ItsFacade;
import com.googlesource.gerrit.plugins.hooks.its.ItsHookEnabledConfigEntry;
-import com.googlesource.gerrit.plugins.hooks.rtc.filters.RTCAddComment;
-import com.googlesource.gerrit.plugins.hooks.rtc.filters.RTCAddRelatedLinkToChangeId;
-import com.googlesource.gerrit.plugins.hooks.rtc.filters.RTCAddRelatedLinkToGitWeb;
-import com.googlesource.gerrit.plugins.hooks.rtc.filters.RTCChangeState;
-import com.googlesource.gerrit.plugins.hooks.validation.ItsValidateComment;
+import com.googlesource.gerrit.plugins.hooks.ItsHookModule;
public class RTCModule extends AbstractModule {
@@ -68,18 +64,7 @@
.toInstance(new ItsHookEnabledConfigEntry(
pluginName, pluginCfgFactory));
- DynamicSet.bind(binder(), CommitValidationListener.class).to(
- ItsValidateComment.class);
-
- bind(ExecutorService.class).toInstance(
- new ScheduledThreadPoolExecutor(THREAD_POOL_EXECUTORS));
-
- DynamicSet.bind(binder(), EventListener.class).to(
- RTCAddRelatedLinkToChangeId.class);
- DynamicSet.bind(binder(), EventListener.class).to(RTCAddComment.class);
- DynamicSet.bind(binder(), EventListener.class).to(RTCChangeState.class);
- DynamicSet.bind(binder(), EventListener.class).to(
- RTCAddRelatedLinkToGitWeb.class);
+ install(new ItsHookModule(pluginName, pluginCfgFactory));
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/filters/ChangeListenerAsyncDecorator.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/filters/ChangeListenerAsyncDecorator.java
deleted file mode 100644
index 8734ca7..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/filters/ChangeListenerAsyncDecorator.java
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright (C) 2013 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.googlesource.gerrit.plugins.hooks.rtc.filters;
-
-import com.google.gerrit.common.EventListener;
-import com.google.gerrit.server.events.Event;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.ArrayList;
-import java.util.Queue;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.LinkedBlockingQueue;
-
-public class ChangeListenerAsyncDecorator<T extends EventListener> implements
- EventListener {
- private static final int MAX_PENDING_EVENTS = 1024;
- private static final int MAX_BATCH_SIZE = 64;
- private static final Logger log = LoggerFactory
- .getLogger(ChangeListenerAsyncDecorator.class);
- private T innerListener;
- private final LinkedBlockingQueue<Event> queue =
- new LinkedBlockingQueue<>(MAX_PENDING_EVENTS);
- private ExecutorService executor;
-
- public class ChangeRunner implements Runnable {
- @Override
- public void run() {
- ArrayList<Event> failedEvents = new ArrayList<>();
- for (int i = 0; !queue.isEmpty() && i < MAX_BATCH_SIZE; i++) {
- Event event = queue.remove();
- try {
- innerListener.onEvent(event);
- } catch (Throwable e) {
- log.error("Execution of event " + event.getClass().getName() + "/"
- + event.toString()
- + " FAILED\nEvent requeued for later execution", event);
- failedEvents.add(event);
- }
- }
-
- queue.addAll(failedEvents);
- }
- }
-
- public ChangeListenerAsyncDecorator(T innerListener, ExecutorService executor) {
- this.innerListener = innerListener;
- this.executor = executor;
- }
-
- @Override
- public void onEvent(Event event) {
- queue.add(event);
- executor.submit(new ChangeRunner());
- }
-
- public Queue<Event> getQueue() {
- return queue;
- }
-}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/filters/RTCAddComment.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/filters/RTCAddComment.java
deleted file mode 100644
index 8e2d92d..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/filters/RTCAddComment.java
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright (C) 2013 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.googlesource.gerrit.plugins.hooks.rtc.filters;
-
-import java.util.concurrent.ExecutorService;
-
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import com.googlesource.gerrit.plugins.hooks.workflow.GerritHookFilterAddComment;
-
-@Singleton
-public class RTCAddComment extends
- ChangeListenerAsyncDecorator<GerritHookFilterAddComment> {
-
- @Inject
- public RTCAddComment(GerritHookFilterAddComment innerListener,
- ExecutorService executor) {
- super(innerListener, executor);
- }
-
-}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/filters/RTCAddRelatedLinkToChangeId.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/filters/RTCAddRelatedLinkToChangeId.java
deleted file mode 100644
index cfaad15..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/filters/RTCAddRelatedLinkToChangeId.java
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright (C) 2013 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.googlesource.gerrit.plugins.hooks.rtc.filters;
-
-import java.util.concurrent.ExecutorService;
-
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import com.googlesource.gerrit.plugins.hooks.workflow.GerritHookFilterAddRelatedLinkToChangeId;
-
-@Singleton
-public class RTCAddRelatedLinkToChangeId extends
- ChangeListenerAsyncDecorator<GerritHookFilterAddRelatedLinkToChangeId> {
-
- @Inject
- public RTCAddRelatedLinkToChangeId(
- GerritHookFilterAddRelatedLinkToChangeId innerListener,
- ExecutorService executor) {
- super(innerListener, executor);
- }
-}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/filters/RTCAddRelatedLinkToGitWeb.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/filters/RTCAddRelatedLinkToGitWeb.java
deleted file mode 100644
index 6f94e43..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/filters/RTCAddRelatedLinkToGitWeb.java
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright (C) 2013 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.googlesource.gerrit.plugins.hooks.rtc.filters;
-
-import java.util.concurrent.ExecutorService;
-
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import com.googlesource.gerrit.plugins.hooks.workflow.GerritHookFilterAddRelatedLinkToGitWeb;
-
-@Singleton
-public class RTCAddRelatedLinkToGitWeb extends
- ChangeListenerAsyncDecorator<GerritHookFilterAddRelatedLinkToGitWeb> {
-
- @Inject
- public RTCAddRelatedLinkToGitWeb(
- GerritHookFilterAddRelatedLinkToGitWeb innerListener,
- ExecutorService executor) {
- super(innerListener, executor);
- }
-}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/filters/RTCChangeState.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/filters/RTCChangeState.java
deleted file mode 100644
index 63a7f15..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/rtc/filters/RTCChangeState.java
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (C) 2013 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.googlesource.gerrit.plugins.hooks.rtc.filters;
-
-import java.util.concurrent.ExecutorService;
-
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import com.googlesource.gerrit.plugins.hooks.workflow.GerritHookFilterChangeState;
-
-@Singleton
-public class RTCChangeState extends
- ChangeListenerAsyncDecorator<GerritHookFilterChangeState> {
-
- @Inject
- public RTCChangeState(GerritHookFilterChangeState innerListener,
- ExecutorService executor) {
- super(innerListener, executor);
- }
-}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/hooks/rtc/ChangeListenerAsyncDecoratorTest.java b/src/test/java/com/googlesource/gerrit/plugins/hooks/rtc/ChangeListenerAsyncDecoratorTest.java
deleted file mode 100644
index 1b47829..0000000
--- a/src/test/java/com/googlesource/gerrit/plugins/hooks/rtc/ChangeListenerAsyncDecoratorTest.java
+++ /dev/null
@@ -1,136 +0,0 @@
-// Copyright (C) 2013 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.googlesource.gerrit.plugins.hooks.rtc;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import com.google.gerrit.common.EventListener;
-import com.google.gerrit.server.events.ChangeEvent;
-
-import com.googlesource.gerrit.plugins.hooks.rtc.filters.ChangeListenerAsyncDecorator;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.mockito.stubbing.Answer;
-
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-
-@RunWith(MockitoJUnitRunner.class)
-public class ChangeListenerAsyncDecoratorTest {
-
- @Mock
- EventListener listener;
- @Mock
- ChangeEvent event;
- @Mock
- ExecutorService executor;
- @Mock
- ExecutorService immediateExecutor;
-
- ChangeListenerAsyncDecorator<EventListener> asyncListener;
-
- @Before
- public void setUp() {
- when(immediateExecutor.submit(any(Runnable.class))).thenAnswer(
- new Answer<Future<?>>() {
-
- @Override
- public Future<?> answer(InvocationOnMock invocation) throws Throwable {
- Runnable task = (Runnable) invocation.getArguments()[0];
- task.run();
- return null;
-
- }
- });
- asyncListener =
- new ChangeListenerAsyncDecorator<EventListener>(listener, executor);
- }
-
- @Test
- public void testQueueShouldBeEmptyWhenCreated() {
- assertTrue(asyncListener.getQueue().isEmpty());
- }
-
- @Test
- public void testQueueShouldNotBeEmptyWhenOneEventSubmitted() {
- asyncListener.onEvent(event);
- assertFalse(asyncListener.getQueue().isEmpty());
- }
-
- @Test
- public void testChangeEventShouldBeQueuedWhenSubmitted() {
- asyncListener.onEvent(event);
- assertEquals(event, asyncListener.getQueue().peek());
- }
-
- @Test
- public void testChangeEventShouldBeSentToExecutor() {
- asyncListener.onEvent(event);
- verify(executor).submit(
- any(ChangeListenerAsyncDecorator.ChangeRunner.class));
- }
-
- @Test
- public void testChangeEventShouldBePropagatedToListenerWhenImmediatelyExecuted() {
- asyncListener =
- new ChangeListenerAsyncDecorator<>(listener, immediateExecutor);
- asyncListener.onEvent(event);
- verify(listener).onEvent(event);
- assertTrue(asyncListener.getQueue().isEmpty());
- }
-
- @Test
- public void testChangeEventShouldStayInQueueWhenExecutionFailed() {
- asyncListener =
- new ChangeListenerAsyncDecorator<>(listener, immediateExecutor);
- doThrow(new IllegalArgumentException()).when(listener).onEvent(
- any(ChangeEvent.class));
-
- asyncListener.onEvent(event);
- verify(listener).onEvent(event);
- assertFalse(asyncListener.getQueue().isEmpty());
- }
-
- @Test
- public void testChangeShouldProcessAllPreviouslyFailedEventsInQueue() {
- asyncListener =
- new ChangeListenerAsyncDecorator<>(listener, immediateExecutor);
-
- doThrow(new IllegalArgumentException()).when(listener).onEvent(
- any(ChangeEvent.class));
- asyncListener.onEvent(event);
- verify(listener).onEvent(event);
- assertFalse(asyncListener.getQueue().isEmpty());
-
- doNothing().when(listener).onEvent(any(ChangeEvent.class));
- asyncListener.onEvent(event);
- verify(listener, times(3)).onEvent(event);
-
- assertTrue(asyncListener.getQueue().isEmpty());
- }
-
-}