Convert to Polymer 3

Change-Id: Ia5536353716a01cddf458c1e09817b6d89898ff0
diff --git a/BUILD b/BUILD
index d00bb76..8616c3c 100644
--- a/BUILD
+++ b/BUILD
@@ -1,3 +1,4 @@
+load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
 load("@rules_java//java:defs.bzl", "java_library")
 load("//tools/bzl:junit.bzl", "junit_tests")
 load(
@@ -6,6 +7,8 @@
     "PLUGIN_TEST_DEPS",
     "gerrit_plugin",
 )
+load("//tools/bzl:genrule2.bzl", "genrule2")
+load("//tools/bzl:js.bzl", "polygerrit_plugin")
 
 LFS_DEPS = [
     "@jgit//org.eclipse.jgit.lfs.server:jgit-lfs-server",
@@ -38,10 +41,41 @@
         "Gerrit-SshModule: com.googlesource.gerrit.plugins.lfs.SshModule",
         "Gerrit-InitStep: com.googlesource.gerrit.plugins.lfs.InitLfs",
     ],
+    resource_jars = [":gr-lfs-static"],
     resources = glob(["src/main/resources/**/*"]),
     deps = LFS_DEPS,
 )
 
+genrule2(
+    name = "gr-lfs-static",
+    srcs = [":gr-lfs"],
+    outs = ["gr-lfs-static.jar"],
+    cmd = " && ".join([
+        "mkdir $$TMP/static",
+        "cp -r $(locations :gr-lfs) $$TMP/static",
+        "cd $$TMP",
+        "zip -Drq $$ROOT/$@ -g .",
+    ]),
+)
+
+polygerrit_plugin(
+    name = "gr-lfs",
+    app = "gr-lfs-bundle.js",
+    plugin_name = "gr-lfs",
+)
+
+rollup_bundle(
+    name = "gr-lfs-bundle",
+    srcs = glob(["gr-lfs/*.js"]),
+    entry_point = "gr-lfs/plugin.js",
+    format = "iife",
+    rollup_bin = "//tools/node_tools:rollup-bin",
+    sourcemap = "hidden",
+    deps = [
+        "@tools_npm//rollup-plugin-node-resolve",
+    ],
+)
+
 junit_tests(
     name = "lfs_tests",
     srcs = glob(["src/test/java/**/*.java"]),
diff --git a/gr-lfs/gr-lfs-project-info.js b/gr-lfs/gr-lfs-project-info.js
new file mode 100644
index 0000000..980ce20
--- /dev/null
+++ b/gr-lfs/gr-lfs-project-info.js
@@ -0,0 +1,54 @@
+// Copyright (C) 2021 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.
+
+import {htmlTemplate} from './gr-lfs-project-info_html.js';
+
+class GrLfsProjectInfo extends Polymer.Element {
+  static get is() {
+    return 'gr-lfs-project-info';
+  }
+
+  static get template() {
+    return htmlTemplate;
+  }
+
+  static get properties() {
+    return {
+      repoName: String,
+      _appliedConfig: Object,
+    };
+  }
+
+  connectedCallback() {
+    super.connectedCallback();
+
+    this._getPreferences();
+  }
+
+  _getPreferences() {
+    let encodedRepoName = encodeURIComponent(this.repoName);
+    return this.plugin.restApi('/projects/')
+      .get(`${encodedRepoName}/${this.plugin.getPluginName()}~lfs:config-project`)
+      .then(config => {
+        if (!config || Object.entries(config).length === 0) {
+          this.$.lfsProjectInfo.hidden = true;
+          return;
+        }
+
+        this._appliedConfig = config
+      })
+  }
+}
+
+customElements.define(GrLfsProjectInfo.is, GrLfsProjectInfo);
diff --git a/gr-lfs/gr-lfs-project-info_html.js b/gr-lfs/gr-lfs-project-info_html.js
new file mode 100644
index 0000000..953d594
--- /dev/null
+++ b/gr-lfs/gr-lfs-project-info_html.js
@@ -0,0 +1,44 @@
+/**
+ * @license
+ * Copyright (C) 2021 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.
+ */
+
+export const htmlTemplate = Polymer.html`
+<style include="shared-styles"></style>
+<style include="gr-form-styles"></style>
+<style>
+  .sectionTitle {
+    padding-top: 2em;
+  }
+</style>
+<fieldset id="lfsProjectInfo" class="gr-form-styles">
+  <h2 class="sectionTitle">LFS Info</h2>
+  <section>
+    <span class="title">Enabled</span>
+    <span class="value">[[_appliedConfig.enabled]]</span>
+  </section>
+  <section>
+    <span class="title">Max Object Size</span>
+    <span class="value">[[_appliedConfig.max_object_size]]</span>
+  </section>
+  <section>
+    <span class="title">Read Only</span>
+    <span class="value">[[_appliedConfig.read_only]]</span>
+  </section>
+  <section hidden="[[!_appliedConfig.backend]]">
+    <span class="title">Backend</span>
+    <span class="value">[[_appliedConfig.backend]]</span>
+  </section>
+</fieldset>`;
diff --git a/gr-lfs/plugin.js b/gr-lfs/plugin.js
new file mode 100644
index 0000000..afeacd5
--- /dev/null
+++ b/gr-lfs/plugin.js
@@ -0,0 +1,23 @@
+/**
+ * @license
+ * Copyright (C) 2021 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.
+ */
+
+import './gr-lfs-project-info.js';
+
+Gerrit.install(plugin => {
+  plugin.registerCustomComponent(
+    'repo-config', 'gr-lfs-project-info');
+});
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/HttpModule.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/HttpModule.java
index aabbd69..640704b 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/HttpModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/HttpModule.java
@@ -62,7 +62,7 @@
       populateRepository(backend);
     }
 
-    DynamicSet.bind(binder(), WebUiPlugin.class).toInstance(new JavaScriptPlugin("gr-lfs.html"));
+    DynamicSet.bind(binder(), WebUiPlugin.class).toInstance(new JavaScriptPlugin("gr-lfs.js"));
   }
 
   private void populateRepository(LfsBackend backend) {
diff --git a/src/main/resources/static/gr-lfs-project-info.html b/src/main/resources/static/gr-lfs-project-info.html
deleted file mode 100644
index 4008f89..0000000
--- a/src/main/resources/static/gr-lfs-project-info.html
+++ /dev/null
@@ -1,48 +0,0 @@
-<!--
-@license
-Copyright (C) 2019 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.
--->
-
-<dom-module id="gr-lfs-project-info">
-  <template>
-    <style include="shared-styles"></style>
-    <style include="gr-form-styles"></style>
-    <style>
-      .sectionTitle {
-        padding-top: 2em;
-      }
-    </style>
-    <fieldset id="lfsProjectInfo" class="gr-form-styles">
-      <h2 class="sectionTitle">LFS Info</h2>
-      <section>
-        <span class="title">Enabled</span>
-        <span class="value">[[_appliedConfig.enabled]]</span>
-      </section>
-      <section>
-        <span class="title">Max Object Size</span>
-        <span class="value">[[_appliedConfig.max_object_size]]</span>
-      </section>
-      <section>
-        <span class="title">Read Only</span>
-        <span class="value">[[_appliedConfig.read_only]]</span>
-      </section>
-      <section hidden="[[!_appliedConfig.backend]]">
-        <span class="title">Backend</span>
-        <span class="value">[[_appliedConfig.backend]]</span>
-      </section>
-    </fieldset>
-  </template>
-  <script src="gr-lfs-project-info.js"></script>
-</dom-module>
diff --git a/src/main/resources/static/gr-lfs-project-info.js b/src/main/resources/static/gr-lfs-project-info.js
deleted file mode 100644
index 8eff229..0000000
--- a/src/main/resources/static/gr-lfs-project-info.js
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright (C) 2019 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.
-
-(function () {
-  'use strict';
-
-  Polymer({
-    is: 'gr-lfs-project-info',
-
-    properties: {
-      repoName: String,
-      _appliedConfig: Object,
-    },
-
-    attached() {
-      this._getPreferences()
-    },
-
-    _getPreferences() {
-      let encodedRepoName = encodeURIComponent(this.repoName);
-      return this.plugin.restApi('/projects/')
-        .get(`${encodedRepoName}/${this.plugin.getPluginName()}~lfs:config-project`)
-        .then(config => {
-          if (!config || Object.entries(config).length === 0) {
-            this.$.lfsProjectInfo.hidden = true;
-            return;
-          }
-
-          this._appliedConfig = config
-        })
-    },
-  });
-})();
diff --git a/src/main/resources/static/gr-lfs.html b/src/main/resources/static/gr-lfs.html
deleted file mode 100644
index 1a82aa8..0000000
--- a/src/main/resources/static/gr-lfs.html
+++ /dev/null
@@ -1,26 +0,0 @@
-<!--
-@license
-Copyright (C) 2019 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.
--->
-
-<link rel="import" href="./gr-lfs-project-info.html">
-
-<dom-module id="gr-lfs">
-  <script>
-    Gerrit.install(plugin => {
-      plugin.registerCustomComponent('repo-config', 'gr-lfs-project-info');
-    });
-  </script>
-</dom-module>