Update for Gerrit v3.2

Since the plugin used GWT UI, which no longer exists in Gerrit v3.2,
the plugin's GWT part got removed. As the plugin did not yet come with
a PolyGerrit interface, it is currently without UI, but it still allows
to query dependency information.

Change-Id: I7c088de8550ae791b19cf4d02befbc8d233cfcc5
diff --git a/BUILD b/BUILD
index 45a2bbb..4fd31b4 100644
--- a/BUILD
+++ b/BUILD
@@ -4,10 +4,8 @@
     name = "zuul",
     srcs = glob(["src/main/java/**/*.java"]),
     resources = glob(["src/main/**/*"]),
-    gwt_module = 'com.googlesource.gerrit.plugins.zuul.Zuul',
     manifest_entries = [
         "Gerrit-PluginName: zuul",
         "Gerrit-Module: com.googlesource.gerrit.plugins.zuul.Module",
-        "Gerrit-HttpModule: com.googlesource.gerrit.plugins.zuul.HttpModule",
     ],
 )
diff --git a/README.md b/README.md
index 8ba1066..873877e 100644
--- a/README.md
+++ b/README.md
@@ -12,11 +12,7 @@
 detect.
 
 To help alleviate these issues this plugin adds the following:
-* A reverse lookup for the 'depends-on' reference. The 'needed-by' reference has
-been added to the Gerrit UI to let users know that the currently viewed change
-is needed by a referenced change.
-* Dependency cycle detection which will display the CRD references in red if a
-dependency cycle has been detected.
+* A reverse lookup for the 'depends-on' reference.
 * A REST endpoint to allow other clients to retrieve CRD info.
 
 Detailed information about this plugin can be found in the documentation.
diff --git a/src/main/java/com/googlesource/gerrit/plugins/zuul/GetCrd.java b/src/main/java/com/googlesource/gerrit/plugins/zuul/GetCrd.java
index 3bc8092..e23a117 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/zuul/GetCrd.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/zuul/GetCrd.java
@@ -14,19 +14,19 @@
 
 package com.googlesource.gerrit.plugins.zuul;
 
+import com.google.gerrit.entities.Change;
+import com.google.gerrit.entities.Project;
 import com.google.gerrit.extensions.common.ChangeInfo;
 import com.google.gerrit.extensions.restapi.AuthException;
 import com.google.gerrit.extensions.restapi.BadRequestException;
+import com.google.gerrit.extensions.restapi.Response;
 import com.google.gerrit.extensions.restapi.RestReadView;
 import com.google.gerrit.extensions.restapi.TopLevelResource;
-import com.google.gerrit.reviewdb.client.Change;
-import com.google.gerrit.reviewdb.client.Project;
 import com.google.gerrit.server.change.RevisionResource;
 import com.google.gerrit.server.git.GitRepositoryManager;
 import com.google.gerrit.server.permissions.PermissionBackendException;
 import com.google.gerrit.server.restapi.change.ChangesCollection;
 import com.google.gerrit.server.restapi.change.QueryChanges;
-import com.google.gwtorm.server.OrmException;
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 import java.io.IOException;
@@ -53,10 +53,9 @@
 
   @Override
   @SuppressWarnings("unchecked")
-  public CrdInfo apply(RevisionResource rsrc)
+  public Response<CrdInfo> apply(RevisionResource rsrc)
       throws RepositoryNotFoundException, IOException, BadRequestException, AuthException,
-          OrmException, PermissionBackendException {
-
+          PermissionBackendException {
     CrdInfo out = new CrdInfo();
     out.dependsOn = new ArrayList<>();
     out.neededBy = new ArrayList<>();
@@ -65,7 +64,7 @@
     Project.NameKey p = rsrc.getChange().getProject();
     try (Repository repo = repoManager.openRepository(p);
         RevWalk rw = new RevWalk(repo)) {
-      String rev = rsrc.getPatchSet().getRevision().get();
+      String rev = rsrc.getPatchSet().commitId().getName();
       RevCommit commit = rw.parseCommit(ObjectId.fromString(rev));
       String commitMsg = commit.getFullMessage();
       Pattern pattern = Pattern.compile("[Dd]epends-[Oo]n:? (I[0-9a-f]{8,40})", Pattern.DOTALL);
@@ -80,7 +79,8 @@
     QueryChanges query = changes.list();
     String neededByQuery = "message:" + chgKey + " -change:" + chgKey;
     query.addQuery(neededByQuery);
-    List<ChangeInfo> changes = (List<ChangeInfo>) query.apply(TopLevelResource.INSTANCE);
+    Response<List<?>> response = query.apply(TopLevelResource.INSTANCE);
+    List<ChangeInfo> changes = (List<ChangeInfo>) response.value();
     // check for dependency cycles
     for (ChangeInfo change : changes) {
       if (out.dependsOn.contains(change.changeId)) {
@@ -89,6 +89,6 @@
       out.neededBy.add(change.changeId);
     }
 
-    return out;
+    return Response.ok(out);
   }
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/zuul/HttpModule.java b/src/main/java/com/googlesource/gerrit/plugins/zuul/HttpModule.java
deleted file mode 100644
index 3dd15eb..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/zuul/HttpModule.java
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright (C) 2016 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.zuul;
-
-import com.google.gerrit.extensions.registration.DynamicSet;
-import com.google.gerrit.extensions.webui.GwtPlugin;
-import com.google.gerrit.extensions.webui.WebUiPlugin;
-import com.google.gerrit.httpd.plugins.HttpPluginModule;
-
-public class HttpModule extends HttpPluginModule {
-
-  @Override
-  protected void configureServlets() {
-    DynamicSet.bind(binder(), WebUiPlugin.class).toInstance(new GwtPlugin("zuul"));
-  }
-}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/zuul/Zuul.gwt.xml b/src/main/java/com/googlesource/gerrit/plugins/zuul/Zuul.gwt.xml
deleted file mode 100644
index d9bad3d..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/zuul/Zuul.gwt.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Copyright (C) 2016 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.
--->
-<module rename-to="zuul">
-  <!-- Inherit the core Web Toolkit stuff.                        -->
-  <inherits name="com.google.gwt.user.User"/>
-  <!-- Other module inherits                                      -->
-  <inherits name="com.google.gerrit.Plugin"/>
-  <inherits name="com.google.gwt.http.HTTP"/>
-  <!-- Using GWT built-in themes adds a number of static          -->
-  <!-- resources to the plugin. No theme inherits lines were      -->
-  <!-- added in order to make this plugin as simple as possible   -->
-  <!-- Specify the app entry point class.                         -->
-  <entry-point class="com.googlesource.gerrit.plugins.zuul.client.ZuulPlugin"/>
-  <stylesheet src="zuul.css"/>
-</module>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/zuul/client/DependencyInfo.java b/src/main/java/com/googlesource/gerrit/plugins/zuul/client/DependencyInfo.java
deleted file mode 100644
index d1d37d2..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/zuul/client/DependencyInfo.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.googlesource.gerrit.plugins.zuul.client;
-
-import com.google.gwt.core.client.JavaScriptObject;
-import com.google.gwt.core.client.JsArrayString;
-
-public class DependencyInfo extends JavaScriptObject {
-
-  public final native JsArrayString dependsOn() /*-{ return this.depends_on; }-*/;
-
-  public final native JsArrayString neededBy() /*-{ return this.needed_by; }-*/;
-
-  public final native boolean cycle() /*-{ return this.cycle; }-*/;
-
-  protected DependencyInfo() {}
-}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/zuul/client/LabelPanel.java b/src/main/java/com/googlesource/gerrit/plugins/zuul/client/LabelPanel.java
deleted file mode 100644
index 68c1756..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/zuul/client/LabelPanel.java
+++ /dev/null
@@ -1,107 +0,0 @@
-// Copyright (C) 2016 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.zuul.client;
-
-import com.google.gerrit.client.GerritUiExtensionPoint;
-import com.google.gerrit.client.info.ChangeInfo;
-import com.google.gerrit.client.info.ChangeInfo.RevisionInfo;
-import com.google.gerrit.plugin.client.Plugin;
-import com.google.gerrit.plugin.client.extension.Panel;
-import com.google.gerrit.plugin.client.rpc.RestApi;
-import com.google.gwt.http.client.URL;
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.google.gwt.user.client.ui.Grid;
-import com.google.gwt.user.client.ui.HorizontalPanel;
-import com.google.gwt.user.client.ui.Label;
-import com.google.gwt.user.client.ui.VerticalPanel;
-import com.google.gwtexpui.clippy.client.CopyableLabel;
-
-public class LabelPanel extends VerticalPanel {
-  static class Factory implements Panel.EntryPoint {
-    @Override
-    public void onLoad(Panel panel) {
-      panel.setWidget(new LabelPanel(panel));
-    }
-  }
-
-  private static final String COLOR_RED = "#F00";
-
-  LabelPanel(final Panel panel) {
-    final ChangeInfo change = panel.getObject(GerritUiExtensionPoint.Key.CHANGE_INFO).cast();
-    final RevisionInfo rev = panel.getObject(GerritUiExtensionPoint.Key.REVISION_INFO).cast();
-
-    if (!rev.isEdit()) {
-      String decodedChangeId = URL.decodePathSegment(change.id());
-      new RestApi("changes")
-          .id(decodedChangeId)
-          .view("revisions")
-          .id(rev.id())
-          .view(Plugin.get().getPluginName(), "crd")
-          .get(
-              new AsyncCallback<DependencyInfo>() {
-                @Override
-                public void onSuccess(DependencyInfo result) {
-                  if (result != null) {
-                    display(result);
-                  }
-                }
-
-                @Override
-                public void onFailure(Throwable caught) {
-                  // never invoked
-                }
-              });
-    }
-  }
-
-  private void display(DependencyInfo result) {
-    int row = 0;
-    int column = 1;
-    Grid grid = new Grid(row, column);
-    // show depends-on ids
-    for (int i = 0; i < result.dependsOn().length(); i++) {
-      HorizontalPanel p = new HorizontalPanel();
-      p.addStyleName("infoBlock");
-      Label label = new Label("Depends-on");
-      label.setWidth("72px");
-      p.add(label);
-      CopyableLabel cl = new CopyableLabel(result.dependsOn().get(i));
-      if (result.cycle()) {
-        cl.getElement().getStyle().setColor(COLOR_RED);
-      }
-      p.add(cl);
-      grid.insertRow(row);
-      grid.setWidget(row, 0, p);
-      row++;
-    }
-    // show needed-by ids
-    for (int i = 0; i < result.neededBy().length(); i++) {
-      HorizontalPanel p = new HorizontalPanel();
-      p.addStyleName("infoBlock");
-      Label label = new Label("Needed-by");
-      label.setWidth("72px");
-      p.add(label);
-      CopyableLabel cl = new CopyableLabel(result.neededBy().get(i));
-      if (result.cycle()) {
-        cl.getElement().getStyle().setColor(COLOR_RED);
-      }
-      p.add(cl);
-      grid.insertRow(row);
-      grid.setWidget(row, 0, p);
-      row++;
-    }
-    add(grid);
-  }
-}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/zuul/client/ZuulPlugin.java b/src/main/java/com/googlesource/gerrit/plugins/zuul/client/ZuulPlugin.java
deleted file mode 100644
index 9336f47..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/zuul/client/ZuulPlugin.java
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright (C) 2016 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.zuul.client;
-
-import com.google.gerrit.client.GerritUiExtensionPoint;
-import com.google.gerrit.client.Resources;
-import com.google.gerrit.plugin.client.Plugin;
-import com.google.gerrit.plugin.client.PluginEntryPoint;
-import com.google.gwt.core.client.GWT;
-
-public class ZuulPlugin extends PluginEntryPoint {
-  public static final Resources RESOURCES = GWT.create(Resources.class);
-
-  @Override
-  public void onPluginLoad() {
-
-    Plugin.get()
-        .panel(
-            GerritUiExtensionPoint.CHANGE_SCREEN_BELOW_COMMIT_INFO_BLOCK,
-            new LabelPanel.Factory(),
-            null);
-  }
-}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/zuul/public/zuul.css b/src/main/java/com/googlesource/gerrit/plugins/zuul/public/zuul.css
deleted file mode 100644
index bdd428e..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/zuul/public/zuul.css
+++ /dev/null
@@ -1,6 +0,0 @@
-.commitExtension {
-  padding-top: 0px;
-  padding: 0;
-  vertical-align: top;
-}
-.commitExtension { width: COMMIT_WIDTH; }
diff --git a/src/main/resources/Documentation/about.md b/src/main/resources/Documentation/about.md
index e52e83f..19d67ec 100644
--- a/src/main/resources/Documentation/about.md
+++ b/src/main/resources/Documentation/about.md
@@ -1,7 +1,5 @@
 The @PLUGIN@ plugin detects Zuul [cross repository dependencies] (CRD) in
-commit messages and displays it on the Gerrit UI.  [Cycles] are shown in red
-
-![ZuulCRDScreenshot](images/zuul_crd.png)
+commit messages.
 
 [cross repository dependencies]: http://docs.openstack.org/infra/zuul/gating.html#cross-repository-dependencies
 [Cycles]: http://docs.openstack.org/infra/zuul/gating.html#cycles
diff --git a/src/main/resources/Documentation/images/zuul_crd.png b/src/main/resources/Documentation/images/zuul_crd.png
deleted file mode 100644
index 6db8085..0000000
--- a/src/main/resources/Documentation/images/zuul_crd.png
+++ /dev/null
Binary files differ