Merge branch 'stable-3.2' into stable-3.3

* stable-3.2:
  Add eslint rule

in this branch eslint rule is added to bazlets by referring following
location :

https://gerrit.googlesource.com/gerrit/
    +/refs/heads/stable-3.3/tools/js

Change-Id: I1d7715727f468545ee2f9a3953dc763acb26dc7f
diff --git a/README.md b/README.md
index 725a35d..e74d20a 100644
--- a/README.md
+++ b/README.md
@@ -36,9 +36,9 @@
 
 ```python
 load("@com_googlesource_gerrit_bazlets//:gerrit_api.bzl", "gerrit_api")
-gerrit_api(version = "3.1.6",
-           plugin_api_sha1 = "e57f6465c9805f568082bffffd61a2771f10d68a",
-           acceptance_framework_sha1 = "ebfd50383f8593678b451c81dbc332db8e8da188")
+gerrit_api(version = "3.2.1",
+           plugin_api_sha1 = "47019cf43ef7e6e8d2d5c0aeba0407d23c93699c",
+           acceptance_framework_sha1 = "6252cab6d1f76202e57858fcffb428424e90b128")
 ```
 
 If the version ends in `-SNAPSHOT`, the jars are consumed from the local
@@ -47,7 +47,7 @@
 
 ```python
 load("@com_googlesource_gerrit_bazlets//:gerrit_api.bzl", "gerrit_api")
-gerrit_api(version = "3.1.7-SNAPSHOT")
+gerrit_api(version = "3.3.0-SNAPSHOT")
 ```
 
 <a name="basic-example"></a>
diff --git a/bouncycastle.bzl b/bouncycastle.bzl
index 02960bc..d9025bf 100644
--- a/bouncycastle.bzl
+++ b/bouncycastle.bzl
@@ -5,23 +5,23 @@
 """
 
 # This should be the same version used in Gerrit.
-BC_VERS = "1.60"
+BC_VERS = "1.61"
 
 def bouncycastle_repos():
     maven_jar(
         name = "bouncycastle_bcprov",
         artifact = "org.bouncycastle:bcprov-jdk15on:" + BC_VERS,
-        sha1 = "bd47ad3bd14b8e82595c7adaa143501e60842a84",
+        sha1 = "00df4b474e71be02c1349c3292d98886f888d1f7",
     )
     maven_jar(
         name = "bouncycastle_bcpg",
         artifact = "org.bouncycastle:bcpg-jdk15on:" + BC_VERS,
-        sha1 = "13c7a199c484127daad298996e95818478431a2c",
+        sha1 = "422656435514ab8a28752b117d5d2646660a0ace",
     )
     maven_jar(
         name = "bouncycastle_bcpkix",
         artifact = "org.bouncycastle:bcpkix-jdk15on:" + BC_VERS,
-        sha1 = "d0c46320fbc07be3a24eb13a56cee4e3d38e0c75",
+        sha1 = "89bb3aa5b98b48e584eee2a7401b7682a46779b4",
     )
     native.bind(
         name = "bcprov",
diff --git a/gerrit_api.bzl b/gerrit_api.bzl
index 9d1f943..c307ade 100644
--- a/gerrit_api.bzl
+++ b/gerrit_api.bzl
@@ -7,9 +7,9 @@
 gerrit_api is rule for fetching Gerrit plugin API using Bazel.
 """
 
-def gerrit_api(version = "3.2.10",
-               plugin_api_sha1 = "86ace0ca309f1fc56815535fabe2e0a4073b3c39",
-               acceptance_framework_sha1 = "fd7f6aff9f8301c324c8aafbb3a6543b2708202c"):
+def gerrit_api(version = "3.3.4",
+               plugin_api_sha1 = "3dc1507083f558ddde2c3b1cd1b85efaa6ea9aa2",
+               acceptance_framework_sha1 = "70dce08e44b47630cf8321c8ad2800e87259a223"):
     gerrit_api_version(
         name = "gerrit_api_version",
         version = version,
diff --git a/tools/js.bzl b/tools/js.bzl
index 21cfa73..7bd33da 100644
--- a/tools/js.bzl
+++ b/tools/js.bzl
@@ -1,6 +1,10 @@
 load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_binary", "closure_js_library")
 load("//lib/js:npm.bzl", "NPM_SHA1S", "NPM_VERSIONS")
 
+load("@npm//@bazel/rollup:index.bzl", "rollup_bundle")
+load("@npm//@bazel/terser:index.bzl", "terser_minified")
+load("@com_googlesource_gerrit_bazlets//tools:genrule2.bzl", "genrule2")
+
 NPMJS = "NPMJS"
 
 GERRIT = "GERRIT:"
@@ -519,3 +523,56 @@
         name = name,
         srcs = static_files,
     )
+
+def gerrit_js_bundle(name, srcs, entry_point):
+    """Produces a Gerrit JavaScript bundle archive.
+
+    This rule bundles and minifies the javascript files of a frontend plugin and
+    produces a file archive.
+    Output of this rule is an archive with "${name}.jar" with specific layout for
+    Gerrit frontend plugins. That archive should be provided to gerrit_plugin
+    rule as resource_jars attribute.
+
+    Args:
+      name: Plugin name.
+      srcs: Plugin sources.
+      entry_point: Plugin entry_point.
+    """
+
+    bundle = name + "-bundle"
+    minified = name + ".min"
+    main = name + ".js"
+
+    rollup_bundle(
+        name = bundle,
+        srcs = srcs,
+        entry_point = entry_point,
+        format = "iife",
+        sourcemap = "hidden",
+    )
+
+    terser_minified(
+        name = minified,
+        sourcemap = False,
+        src = bundle,
+    )
+
+    native.genrule(
+        name = name + "_rename_js",
+        srcs = [minified],
+        outs = [main],
+        cmd = "cp $< $@",
+        output_to_bindir = True,
+    )
+
+    genrule2(
+        name = name,
+        srcs = [main],
+        outs = [name + ".jar"],
+        cmd = " && ".join([
+            "mkdir $$TMP/static",
+            "cp $(SRCS) $$TMP/static",
+            "cd $$TMP",
+            "zip -Drq $$ROOT/$@ -g .",
+        ]),
+    )
diff --git a/tools/js/eslint-rules/BUILD b/tools/js/eslint-rules/BUILD
new file mode 100644
index 0000000..476c4ff
--- /dev/null
+++ b/tools/js/eslint-rules/BUILD
@@ -0,0 +1,11 @@
+package(default_visibility = ["//visibility:public"])
+
+# To load eslint rules from a directory, we must pass a directory
+# name to it. We can't get the directory name in bazel, but we can calculate
+# use a file from this directory. We are using README.md for it.
+exports_files(["README.md"])
+
+filegroup(
+    name = "eslint-rules-srcs",
+    srcs = glob(["**/*.js"]),
+)
diff --git a/tools/js/eslint-rules/README.md b/tools/js/eslint-rules/README.md
new file mode 100644
index 0000000..b425d74
--- /dev/null
+++ b/tools/js/eslint-rules/README.md
@@ -0,0 +1,74 @@
+# Eslint rules for polygerrit
+This directory contains custom eslint rules for polygerrit.
+
+## ts-imports-js
+This rule must be used only for `.ts` files.
+The rule ensures that:
+* All import paths either a relative paths or module imports.
+```typescript
+// Correct imports
+import './file1'; // relative path
+import '../abc/file2'; // relative path
+import 'module_name/xyz'; // import from the module_name
+
+// Incorrect imports
+import '/usr/home/file3'; // absolute path
+```
+* All *relative* import paths has a short form (i.e. don't include extension):
+```typescript
+// Correct imports
+import './file1'; // relative path without extension
+import data from 'module_name/file2.json'; // file in a module, can be anything
+
+// Incorrect imports
+import './file1.js'; // relative path with extension
+```
+
+* Imported `.js` and `.d.ts` files both exists (only for a relative import path):
+
+Example:
+```
+polygerrit-ui/app
+ |- ex.ts
+ |- abc
+     |- correct_ts.ts
+     |- correct_js.js
+     |- correct_js.d.ts
+     |- incorrect_1.js
+     |- incorrect_2.d.ts
+```
+```typescript
+// The ex.ts file:
+// Correct imports
+import {x} from './abc/correct_js'; // correct_js.js and correct_js.d.ts exist
+import {x} from './abc/correct_ts'; // import from .ts - d.ts is not required
+
+// Incorrect imports
+import {x} from './abc/incorrect_1'; // incorrect_1.d.ts doesn't exist
+import {x} from './abc/incorrect_2'; // incorrect_2.js doesn't exist
+```
+
+To fix the last two imports 2 files must be added: `incorrect_1.d.ts` and
+`incorrect_2.js`.
+
+## goog-module-id
+Enforce correct usage of goog.declareModuleId:
+* The goog.declareModuleId must be used only in `.js` files which have
+associated `.d.ts` files.
+* The module name is correct. The correct module name is constructed from the
+file path using the folowing rules
+rules:
+  1. Get part of the path after the '/polygerrit-ui/app/':
+    `/usr/home/gerrit/polygerrit-ui/app/elements/shared/x/y.js` ->
+    `elements/shared/x/y.js`
+  2. Discard `.js` extension and replace all `/` with `.`:
+    `elements/shared/x/y.js` -> `elements.shared.x.y`
+  3. Add `polygerrit.` prefix:
+    `elements.shared.x.y` -> `polygerrit.elements.shared.x.y`
+    The last string is a module name.
+
+Example:
+```javascript
+// polygerrit-ui/app/elements/shared/x/y.js
+goog.declareModuleId('polygerrit.elements.shared.x.y');
+```
diff --git a/tools/js/eslint.bzl b/tools/js/eslint.bzl
index 33b5a69..9633dd7 100644
--- a/tools/js/eslint.bzl
+++ b/tools/js/eslint.bzl
@@ -40,10 +40,24 @@
             bazel run {name}_test -- --fix $(pwd)/polygerrit-ui/app
     """
     entry_point = "@npm//:node_modules/eslint/bin/eslint.js"
+
+    # There are custom eslint rules in eslint-rules directory. Eslint loads
+    # custom rules from a directory specified with the --rulesdir argument.
+    # When bazel runs eslint, it places the eslint-rules directory into
+    # some location in the filesystem, and the location is not known in advance.
+    # It is not possible to get the directory location in bazel directly.
+    # Instead, we can use dirname to get a directory for a file in the
+    # eslint-rules directory.
+    # README.md is the most "stable" file in the eslint-rules directory
+    # (i.e. it is unlikely will be removed), and we are using it to calculate
+    # exact directory path in bazel.
+    eslint_rules_toplevel_file = "@com_googlesource_gerrit_bazlets//tools/js/eslint-rules:README.md"
     bin_data = [
         "@npm//eslint:eslint",
         config,
         ignore,
+         "@com_googlesource_gerrit_bazlets//tools/js/eslint-rules:eslint-rules-srcs",
+        eslint_rules_toplevel_file,
     ] + plugins + data
     common_templated_args = [
         "--ext",
@@ -55,6 +69,9 @@
         "$$(rlocation $(rootpath {}))".format(config),
         "--ignore-path",
         "$$(rlocation $(rootpath {}))".format(ignore),
+        # Load custom rules from eslint-rules directory
+        "--rulesdir",
+        "$$(dirname $$(rlocation $(rootpath {})))".format(eslint_rules_toplevel_file),
     ]
     nodejs_test(
         name = name + "_test",
diff --git a/tools/maven_jar.bzl b/tools/maven_jar.bzl
index 46aa4c1..fec3ea7 100644
--- a/tools/maven_jar.bzl
+++ b/tools/maven_jar.bzl
@@ -15,6 +15,8 @@
 # Port of Buck native gwt_binary() rule. See discussion in context of
 # https://github.com/facebook/buck/issues/109
 
+ECLIPSE = "ECLIPSE:"
+
 GERRIT = "GERRIT:"
 
 GERRIT_API = "GERRIT_API:"
diff --git a/tools/pkg_war.bzl b/tools/pkg_war.bzl
index 931450b..2952a03 100644
--- a/tools/pkg_war.bzl
+++ b/tools/pkg_war.bzl
@@ -67,7 +67,7 @@
         inputs.append(dep)
 
     if ctx.attr.web_xml:
-        for web_xml in ctx.attr.web_xml.files:
+        for web_xml in ctx.attr.web_xml.files.to_list():
             inputs.append(web_xml)
             cmd = cmd + _add_file(ctx.attr.name, web_xml, build_output + "/WEB-INF/")
 
diff --git a/tools/util.py b/tools/util.py
index 1d92528..5b9d455 100644
--- a/tools/util.py
+++ b/tools/util.py
@@ -15,6 +15,7 @@
 from os import path
 
 REPO_ROOTS = {
+  'ECLIPSE': 'https://repo.eclipse.org/content/groups/releases',
   'GERRIT': 'https://gerrit-maven.storage.googleapis.com',
   'GERRIT_API': 'https://gerrit-api.commondatastorage.googleapis.com/release',
   'MAVEN_CENTRAL': 'https://repo1.maven.org/maven2',