Merge branch 'stable-2.11' into master

Change-Id: I0e2c67b34696e43c07ff97a8444c43f1fb35042e
diff --git a/BUCK b/BUCK
index a315493..d3cde83 100644
--- a/BUCK
+++ b/BUCK
@@ -1,3 +1,5 @@
+include_defs('//bucklets/gerrit_plugin.bucklet')
+
 gerrit_plugin(
   name = 'its-storyboard',
   srcs = glob(['src/main/java/**/*.java']),
@@ -31,7 +33,6 @@
     name = name_zip,
     cmd = 'cp $SRCS $OUT && zip -qd $OUT ' + ' '.join(excludes),
     srcs = [ src ],
-    deps = [ src ],
     out = name_zip,
     visibility = visibility,
   )
@@ -52,42 +53,17 @@
   ]
 )
 
-TEST_UTIL_SRC = glob(['src/test/java/com/googlesource/gerrit/plugins/its/testutil/**/*.java'])
-
-java_library(
-  name = 'its-storyboard_tests-utils',
-  srcs = TEST_UTIL_SRC,
-  deps = [
-    '//lib:guava',
-    '//lib/easymock:easymock',
-    '//lib/log:impl_log4j',
-    '//lib/log:log4j',
-    '//lib:junit',
-    '//lib/powermock:powermock-api-easymock',
-    '//lib/powermock:powermock-api-support',
-    '//lib/powermock:powermock-core',
-    '//lib/powermock:powermock-module-junit4',
-    '//lib/powermock:powermock-module-junit4-common',
-  ],
-)
-
 java_test(
   name = 'its-storyboard_tests',
-  srcs = glob(
-    ['src/test/java/**/*.java'],
-    excludes = TEST_UTIL_SRC
-  ),
+  srcs = glob(['src/test/java/**/*.java']),
   labels = ['its-storyboard'],
-  source_under_test = [':its-storyboard__plugin'],
-  deps = [
+  deps = GERRIT_PLUGIN_API + GERRIT_TESTS + [
     ':its-storyboard__plugin',
-    ':its-storyboard_tests-utils',
+    '//plugins/its-base:its-base_tests-utils',
     ':its-base_stripped',
-    '//gerrit-plugin-api:lib',
     '//lib/easymock:easymock',
     '//lib:guava',
     '//lib/guice:guice',
-    '//lib/jgit:jgit',
     '//lib:junit',
     '//lib/log:api',
     '//lib/log:impl_log4j',
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/storyboard/StoryboardItsFacade.java b/src/main/java/com/googlesource/gerrit/plugins/its/storyboard/StoryboardItsFacade.java
index 58fcd83..7d63f79 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/storyboard/StoryboardItsFacade.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/storyboard/StoryboardItsFacade.java
@@ -25,7 +25,7 @@
 import com.google.gerrit.server.config.GerritServerConfig;
 import com.google.inject.Inject;
 
-import com.googlesource.gerrit.plugins.hooks.its.ItsFacade;
+import com.googlesource.gerrit.plugins.its.base.its.ItsFacade;
 
 public class StoryboardItsFacade implements ItsFacade {
   private final Logger log = LoggerFactory.getLogger(StoryboardItsFacade.class);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/storyboard/StoryboardModule.java b/src/main/java/com/googlesource/gerrit/plugins/its/storyboard/StoryboardModule.java
index 4c30ce8..5d809b8 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/storyboard/StoryboardModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/storyboard/StoryboardModule.java
@@ -24,8 +24,8 @@
 import com.google.inject.AbstractModule;
 import com.google.inject.Inject;
 
-import com.googlesource.gerrit.plugins.hooks.ItsHookModule;
-import com.googlesource.gerrit.plugins.hooks.its.ItsFacade;
+import com.googlesource.gerrit.plugins.its.base.ItsHookModule;
+import com.googlesource.gerrit.plugins.its.base.its.ItsFacade;
 
 public class StoryboardModule extends AbstractModule {
 
diff --git a/src/main/resources/Documentation/about.md b/src/main/resources/Documentation/about.md
index f47bac2..389b896 100644
--- a/src/main/resources/Documentation/about.md
+++ b/src/main/resources/Documentation/about.md
@@ -9,7 +9,7 @@
 For details on how to install and configure this plugin start with the
 [Quick Install Guide][quick].
 
-[quick]: quick-install-guide.html
+[quick]: quick-install-guide.md
 [its-base]: https://gerrit-review.googlesource.com/#/admin/projects/plugins/its-base
 [storyboard]: http://git.openstack.org/cgit/openstack-infra/storyboard
 
diff --git a/src/main/resources/Documentation/config-connectivity.md b/src/main/resources/Documentation/config-connectivity.md
index a138c82..36ff372 100644
--- a/src/main/resources/Documentation/config-connectivity.md
+++ b/src/main/resources/Documentation/config-connectivity.md
@@ -4,7 +4,7 @@
 Please refer to the [quick install guide][quick] for info on how to
 configure a connection.
 
-[quick]: quick-install-guide.html
+[quick]: quick-install-guide.md
 [Back to @PLUGIN@ documentation index][index]
 
 [index]: index.html
diff --git a/src/main/resources/Documentation/quick-install-guide.md b/src/main/resources/Documentation/quick-install-guide.md
index a2f961c..97327b6 100644
--- a/src/main/resources/Documentation/quick-install-guide.md
+++ b/src/main/resources/Documentation/quick-install-guide.md
@@ -118,7 +118,6 @@
     event-type = patchset-created,change-restored
     action = set-status REVIEW
 ```
-
 *_NOTE_: A Gerrit restart is required to update these settings.
 
 ### <a id="task-status"></a>TaskStatus
@@ -131,10 +130,6 @@
 In order to install the @PLUGIN@ plugin simply copy the built jar
 file into the `plugins` folder.
 
-[config-common-doc]: config-common.html
-[config-doc]: config.html
-[rules-doc]: config-rulebase-common.html
-
 [its-enable]: #its-enable
 <a name="its-enable">Enable the Plugin</a>
 -------------------------------------------------------
diff --git a/src/test/java/com/googlesource/gerrit/plugins/its/storyboard/StoryboardItsFacadeTest.java b/src/test/java/com/googlesource/gerrit/plugins/its/storyboard/StoryboardItsFacadeTest.java
index 8d61348..63caf65 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/its/storyboard/StoryboardItsFacadeTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/its/storyboard/StoryboardItsFacadeTest.java
@@ -18,11 +18,12 @@
 import org.eclipse.jgit.lib.Config;
 
 import com.google.gerrit.extensions.annotations.PluginName;
-import com.google.gerrit.server.config.FactoryModule;
+import com.google.gerrit.extensions.config.FactoryModule;
 import com.google.gerrit.server.config.GerritServerConfig;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
-import com.googlesource.gerrit.plugins.its.testutil.LoggingMockingTestCase;
+
+import com.googlesource.gerrit.plugins.its.base.testutil.LoggingMockingTestCase;
 
 public class StoryboardItsFacadeTest extends LoggingMockingTestCase {
   private Injector injector;
diff --git a/src/test/java/com/googlesource/gerrit/plugins/its/testutil/LoggingMockingTestCase.java b/src/test/java/com/googlesource/gerrit/plugins/its/testutil/LoggingMockingTestCase.java
deleted file mode 100644
index a2d4d00..0000000
--- a/src/test/java/com/googlesource/gerrit/plugins/its/testutil/LoggingMockingTestCase.java
+++ /dev/null
@@ -1,107 +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.its.testutil;
-
-import com.google.common.collect.Lists;
-import com.googlesource.gerrit.plugins.its.testutil.MockingTestCase;
-import com.googlesource.gerrit.plugins.its.testutil.log.LogUtil;
-
-import org.apache.log4j.spi.LoggingEvent;
-import org.junit.After;
-
-import java.util.Iterator;
-import org.apache.log4j.Level;
-
-public abstract class LoggingMockingTestCase extends MockingTestCase {
-
-  private java.util.Collection<LoggingEvent> loggedEvents;
-
-  protected final void assertLogMessageContains(String needle, Level level) {
-    LoggingEvent hit = null;
-    Iterator<LoggingEvent> iter = loggedEvents.iterator();
-    while (hit == null && iter.hasNext()) {
-      LoggingEvent event = iter.next();
-      if (event.getRenderedMessage().contains(needle)) {
-        if (level == null || level.equals(event.getLevel())) {
-          hit = event;
-        }
-      }
-    }
-    assertNotNull("Could not find log message containing '" + needle + "'",
-        hit);
-    assertTrue("Could not remove log message containing '" + needle + "'",
-        loggedEvents.remove(hit));
-  }
-
-  protected final void assertLogMessageContains(String needle) {
-    assertLogMessageContains(needle, null);
-  }
-
-  protected final void assertLogThrowableMessageContains(String needle) {
-    LoggingEvent hit = null;
-    Iterator<LoggingEvent> iter = loggedEvents.iterator();
-    while (hit == null && iter.hasNext()) {
-      LoggingEvent event = iter.next();
-
-      if (event.getThrowableInformation().getThrowable().toString()
-          .contains(needle)) {
-        hit = event;
-      }
-    }
-    assertNotNull("Could not find log message with a Throwable containing '"
-        + needle + "'", hit);
-    assertTrue("Could not remove log message with a Throwable containing '"
-        + needle + "'", loggedEvents.remove(hit));
-  }
-
-  // As the PowerMock runner does not pass through runTest, we inject log
-  // verification through @After
-  @After
-  public final void assertNoUnassertedLogEvents() {
-    if (loggedEvents.size() > 0) {
-      LoggingEvent event = loggedEvents.iterator().next();
-      String msg = "Found untreated logged events. First one is:\n";
-      msg += event.getRenderedMessage();
-      if (event.getThrowableInformation() != null) {
-        msg += "\n" + event.getThrowableInformation().getThrowable();
-      }
-      fail(msg);
-    }
-  }
-
-  @Override
-  public void setUp() throws Exception {
-    super.setUp();
-    loggedEvents = Lists.newArrayList();
-
-    // The logger we're interested is class name without the trailing "Test".
-    // While this is not the most general approach it is sufficient for now,
-    // and we can improve later to allow tests to specify which loggers are
-    // to check.
-    String logName = this.getClass().getCanonicalName();
-    logName = logName.substring(0, logName.length()-4);
-    LogUtil.logToCollection(logName, loggedEvents);
-  }
-
-  @Override
-  protected void runTest() throws Throwable {
-    super.runTest();
-    // Plain JUnit runner does not pick up @After, so we add it here
-    // explicitly. Note, that we cannot put this into tearDown, as failure
-    // to verify mocks would bail out and might leave open resources from
-    // subclasses open.
-    assertNoUnassertedLogEvents();
-  }
-}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/its/testutil/MockingTestCase.java b/src/test/java/com/googlesource/gerrit/plugins/its/testutil/MockingTestCase.java
deleted file mode 100644
index 060269b..0000000
--- a/src/test/java/com/googlesource/gerrit/plugins/its/testutil/MockingTestCase.java
+++ /dev/null
@@ -1,153 +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.its.testutil;
-
-import junit.framework.TestCase;
-
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
-import org.junit.After;
-import org.junit.runner.RunWith;
-import org.powermock.api.easymock.PowerMock;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-/**
- * Test case with some support for automatically verifying mocks.
- */
-public abstract class MockingTestCase extends TestCase {
-  private Collection<Object> mocks;
-  private Collection<IMocksControl> mockControls;
-  private boolean mocksReplayed;
-  private boolean usePowerMock;
-
-  /**
-   * Create and register a mock control.
-   *
-   * @return The mock control instance.
-   */
-  protected final IMocksControl createMockControl() {
-    IMocksControl mockControl = EasyMock.createControl();
-    assertTrue("Adding mock control failed", mockControls.add(mockControl));
-    return mockControl;
-  }
-
-  /**
-   * Create and register a mock.
-   *
-   * Creates a mock and registers it in the list of created mocks, so it gets
-   * treated automatically upon {@code replay} and {@code verify};
-   * @param toMock The class to create a mock for.
-   * @return The mock instance.
-   */
-  protected final <T> T createMock(Class<T> toMock) {
-    return createMock(toMock, null);
-  }
-
-  /**
-   * Create a mock for a mock control and register a mock.
-   *
-   * Creates a mock and registers it in the list of created mocks, so it gets
-   * treated automatically upon {@code replay} and {@code verify};
-   * @param toMock The class to create a mock for.
-   * @param control The mock control to create the mock on. If null, do not use
-   *    a specific control.
-   * @return The mock instance.
-   */
-  protected final <T> T createMock(Class<T> toMock, IMocksControl control) {
-    assertFalse("Mocks have already been set to replay", mocksReplayed);
-    final T mock;
-    if (control == null) {
-      if (usePowerMock) {
-        mock = PowerMock.createMock(toMock);
-      } else {
-        mock = EasyMock.createMock(toMock);
-      }
-      assertTrue("Adding " + toMock.getName() + " mock failed",
-          mocks.add(mock));
-    } else {
-      mock = control.createMock(toMock);
-    }
-    return mock;
-  }
-
-  /**
-   * Set all registered mocks to replay
-   */
-  protected final void replayMocks() {
-    assertFalse("Mocks have already been set to replay", mocksReplayed);
-    if (usePowerMock) {
-      PowerMock.replayAll();
-    } else {
-      EasyMock.replay(mocks.toArray());
-    }
-    for (IMocksControl mockControl : mockControls) {
-      mockControl.replay();
-    }
-    mocksReplayed = true;
-  }
-
-  /**
-   * Verify all registered mocks
-   *
-   * This method is called automatically at the end of a test. Nevertheless,
-   * it is safe to also call it beforehand, if this better meets the
-   * verification part of a test.
-   */
-  // As the PowerMock runner does not pass through runTest, we inject mock
-  // verification through @After
-  @After
-  public final void verifyMocks() {
-    if (!mocks.isEmpty() || !mockControls.isEmpty()) {
-      assertTrue("Created mocks have not been set to replay. Call replayMocks "
-          + "within the test", mocksReplayed);
-      if (usePowerMock) {
-        PowerMock.verifyAll();
-      } else {
-        EasyMock.verify(mocks.toArray());
-      }
-      for (IMocksControl mockControl : mockControls) {
-        mockControl.verify();
-      }
-    }
-  }
-
-  @Override
-  public void setUp() throws Exception {
-    super.setUp();
-
-    usePowerMock = false;
-    RunWith runWith = this.getClass().getAnnotation(RunWith.class);
-    if (runWith != null) {
-      usePowerMock = PowerMockRunner.class.isAssignableFrom(runWith.value());
-    }
-
-    mocks = new ArrayList<Object>();
-    mockControls = new ArrayList<IMocksControl>();
-    mocksReplayed = false;
-  }
-
-  @Override
-  protected void runTest() throws Throwable {
-    super.runTest();
-    // Plain JUnit runner does not pick up @After, so we add it here
-    // explicitly. Note, that we cannot put this into tearDown, as failure
-    // to verify mocks would bail out and might leave open resources from
-    // subclasses open.
-    verifyMocks();
-  }
-}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/its/testutil/log/CollectionAppender.java b/src/test/java/com/googlesource/gerrit/plugins/its/testutil/log/CollectionAppender.java
deleted file mode 100644
index 8f21bde..0000000
--- a/src/test/java/com/googlesource/gerrit/plugins/its/testutil/log/CollectionAppender.java
+++ /dev/null
@@ -1,58 +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.its.testutil.log;
-
-import com.google.common.collect.Lists;
-
-import org.apache.log4j.AppenderSkeleton;
-import org.apache.log4j.spi.LoggingEvent;
-
-import java.util.Collection;
-import java.util.LinkedList;
-
-/**
- * Log4j appender that logs into a list
- */
-public class CollectionAppender extends AppenderSkeleton {
-  private Collection<LoggingEvent> events;
-
-  public CollectionAppender() {
-    events = new LinkedList<LoggingEvent>();
-  }
-
-  public CollectionAppender(Collection<LoggingEvent> events) {
-    this.events = events;
-  }
-
-  @Override
-  public boolean requiresLayout() {
-    return false;
-  }
-
-  @Override
-  protected void append(LoggingEvent event) {
-    if (! events.add(event)) {
-      throw new RuntimeException("Could not append event " + event);
-    }
-  }
-
-  @Override
-  public void close() {
-  }
-
-  public Collection<LoggingEvent> getLoggedEvents() {
-    return Lists.newLinkedList(events);
-  }
-}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/its/testutil/log/LogUtil.java b/src/test/java/com/googlesource/gerrit/plugins/its/testutil/log/LogUtil.java
deleted file mode 100644
index 4fee52f..0000000
--- a/src/test/java/com/googlesource/gerrit/plugins/its/testutil/log/LogUtil.java
+++ /dev/null
@@ -1,35 +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.its.testutil.log;
-
-import org.apache.log4j.LogManager;
-import org.apache.log4j.Logger;
-import org.apache.log4j.spi.LoggingEvent;
-
-import com.googlesource.gerrit.plugins.its.testutil.log.CollectionAppender;
-
-
-import java.util.Collection;
-
-public class LogUtil {
-  public static CollectionAppender logToCollection(String logName,
-      Collection<LoggingEvent> collection) {
-    Logger log = LogManager.getLogger(logName);
-    CollectionAppender listAppender = new CollectionAppender(collection);
-    log.removeAllAppenders();
-    log.addAppender(listAppender);
-    return listAppender;
-  }
-}