Add Bazel build

This change adds Bazel build. Frontend build is not addressed in this
change.

One complication is the usage of lombok library, that has a known issue
with bazel Turbine processor.  Add a workaround to disable running
Turbine processor for related dependencies.

The plugin is split in two different artifacts: github-oauth library
and github-plugin.

TEST PLAN:

Clone the plugin into gerrit's plugins directory.

Copy plugin's own external_plugin_deps.bzl into gerrit's plugins
directory.

To build the github-oauth library run:

  $> bazel build \
     plugins/github/github-oauth:github-oauth_deploy.jar

To build the github-plugin run:

  $> bazel build plugins/github/github-plugin

To run the tests:

  $> bazel test plugins/github/...

Feature: Issue 10271
Change-Id: I21e90d50f0a4db36a74a0c34123b3da6c0ec28da
diff --git a/BUILD b/BUILD
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/BUILD
diff --git a/external_plugin_deps.bzl b/external_plugin_deps.bzl
new file mode 100644
index 0000000..5282ce4
--- /dev/null
+++ b/external_plugin_deps.bzl
@@ -0,0 +1,115 @@
+load("@bazel_tools//tools/build_defs/repo:java.bzl", "java_import_external")
+load("//tools/bzl:maven_jar.bzl", "maven_jar")
+
+JENKINS = "JENKINS:"
+ECLIPSE_EGIT = "ECLIPSE_EGIT:"
+
+def external_plugin_deps():
+    maven_jar(
+        name = "github-api",
+        artifact = "org.kohsuke:github-api:1.316",
+        sha1 = "90ea530f3aeceb46be27b924ae25b4b7b2388c9d",
+    )
+
+    maven_jar(
+        name = "axis",
+        artifact = "org.apache.axis:axis:1.4",
+        sha1 = "94a9ce681a42d0352b3ad22659f67835e560d107",
+        attach_source = False,
+    )
+
+    maven_jar(
+        name = "axis-jaxrpc",
+        artifact = "org.apache.axis:axis-jaxrpc:1.4",
+        sha1 = "b393f1f0c0d95b68c86d0b1ab2e687bb71f3c075",
+        attach_source = False,
+    )
+
+    maven_jar(
+        name = "eclipse-mylyn-github",
+        artifact = "org.eclipse.mylyn.github:org.eclipse.egit.github.core:6.1.0.202203080745-r",
+        repository = ECLIPSE_EGIT,
+        sha1 = "a0bc7ce9f17e2d41bbfbf08e4bc63c3ae0ec15b7",
+        attach_source = False,
+    )
+
+    maven_jar(
+        name = "commons-discovery",
+        artifact = "commons-discovery:commons-discovery:0.5",
+        sha1 = "3a8ac816bbe02d2f88523ef22cbf2c4abd71d6a8",
+        attach_source = False,
+    )
+
+    maven_jar(
+        name = "velocity",
+        artifact = "org.apache.velocity:velocity-engine-core:2.3",
+        sha1 = "e2133b723d0e42be74880d34de6bf6538ea7f915",
+    )
+
+    maven_jar(
+        name = "lombok",
+        artifact = "org.projectlombok:lombok:1.18.32",
+        sha1 = "17d46b3e205515e1e8efd3ee4d57ce8018914163",
+    )
+
+    maven_jar(
+        name = "com-sun-mail",
+        artifact = "com.sun.mail:javax.mail:1.6.2",
+        sha1 = "935151eb71beff17a2ffac15dd80184a99a0514f",
+    )
+
+    maven_jar(
+        name = "javax-activation",
+        artifact = "javax.activation:activation:1.1",
+        sha1 = "e6cb541461c2834bdea3eb920f1884d1eb508b50",
+    )
+
+    maven_jar(
+        name = "jackson-core",
+        artifact = "com.fasterxml.jackson.core:jackson-core:2.15.2",
+        sha1 = "a6fe1836469a69b3ff66037c324d75fc66ef137c",
+    )
+
+    maven_jar(
+        name = "jackson-databind",
+        artifact = "com.fasterxml.jackson.core:jackson-databind:2.15.2",
+        sha1 = "9353b021f10c307c00328f52090de2bdb4b6ff9c",
+    )
+
+    maven_jar(
+        name = "jackson-annotations",
+        artifact = "com.fasterxml.jackson.core:jackson-annotations:2.15.2",
+        sha1 = "4724a65ac8e8d156a24898d50fd5dbd3642870b8",
+    )
+
+    maven_jar(
+        name = "org-ow2-asm",
+        artifact = "org.ow2.asm:asm:9.6",
+        sha1 = "aa205cf0a06dbd8e04ece91c0b37c3f5d567546a",
+    )
+
+    maven_jar(
+        name = "org-ow2-asm-tree",
+        artifact = "org.ow2.asm:asm-tree:9.6",
+        sha1 = "c0cdda9d211e965d2a4448aa3fd86110f2f8c2de",
+    )
+
+    maven_jar(
+        name = "org-ow2-asm-commons",
+        artifact = "org.ow2.asm:asm-commons:9.6",
+        sha1 = "f1a9e5508eff490744144565c47326c8648be309",
+    )
+
+    maven_jar(
+        name = "bridge-method-injector",
+        artifact = "com.infradna.tool:bridge-method-injector:1.29",
+        repository = JENKINS,
+        sha1 = "5b6c616c7a6e04beb4178327d616af4f1bbe88da",
+    )
+
+    maven_jar(
+        name = "bridge-method-annotation",
+        artifact = "com.infradna.tool:bridge-method-annotation:1.29",
+        repository = JENKINS,
+        sha1 = "55dd67d0578d107697803a95cb9c235a9bd83ec1",
+    )
diff --git a/github-oauth/BUILD b/github-oauth/BUILD
new file mode 100644
index 0000000..05e694b
--- /dev/null
+++ b/github-oauth/BUILD
@@ -0,0 +1,36 @@
+load("//tools/bzl:junit.bzl", "junit_tests")
+load("//tools/bzl:plugin.bzl", "PLUGIN_DEPS", "PLUGIN_DEPS_NEVERLINK")
+
+java_binary(
+    name = "github-oauth",
+    main_class = "Dummy",
+    runtime_deps = [":github-oauth-lib"],
+)
+
+java_library(
+    name = "github-oauth-lib",
+    srcs = glob(["src/main/java/**/*.java"]),
+    visibility = ["//visibility:public"],
+    deps = PLUGIN_DEPS_NEVERLINK + [
+        "//lib:servlet-api",
+        "@bridge-method-annotation//jar",
+        "@bridge-method-injector//jar",
+        "@commons-io//jar",
+        "@github-api//jar",
+        "@jackson-annotations//jar",
+        "@jackson-core//jar",
+        "@jackson-databind//jar",
+        "@org-ow2-asm-commons//jar",
+        "@org-ow2-asm-tree//jar",
+        "@org-ow2-asm//jar",
+    ],
+)
+
+junit_tests(
+    name = "github-oauth_tests",
+    srcs = glob(["src/test/java/**/*.java"]),
+    tags = ["github"],
+    deps = PLUGIN_DEPS + [
+        ":github-oauth-lib",
+    ],
+)
diff --git a/github-plugin/BUILD b/github-plugin/BUILD
new file mode 100644
index 0000000..589f7c6
--- /dev/null
+++ b/github-plugin/BUILD
@@ -0,0 +1,95 @@
+load(
+    "//plugins/github:java_library_without_header_compilation.bzl",
+    "java_library_without_header_compilation",
+)
+load("//tools/bzl:junit.bzl", "junit_tests")
+load("//tools/bzl:plugin.bzl", "PLUGIN_DEPS", "PLUGIN_DEPS_NEVERLINK", "PLUGIN_TEST_DEPS", "gerrit_plugin")
+
+SOURCES_WITH_LOMBOK_USAGE = [
+    "src/main/java/com/googlesource/gerrit/plugins/github/git/GitHubRepository.java",
+    "src/main/java/com/googlesource/gerrit/plugins/github/GitHubURL.java",
+]
+
+gerrit_plugin(
+    name = "github-plugin",
+    srcs = glob(
+        ["src/main/java/**/*.java"],
+        exclude = SOURCES_WITH_LOMBOK_USAGE,
+    ),
+    dir_name = "github",
+    manifest_entries = [
+        "Gerrit-PluginName: github-plugin",
+        "Gerrit-Module: com.googlesource.gerrit.plugins.github.GuiceModule",
+        "Gerrit-HttpModule: com.googlesource.gerrit.plugins.github.GuiceHttpModule",
+        "Gerrit-InitStep: com.googlesource.gerrit.plugins.github.InitGitHub",
+        "Implementation-Title: GitHub plugin",
+        "Implementation-Vendor: GerritForge",
+        "Implementation-URL: http://www.gerritforge.com",
+    ],
+    resource_jars = ["//plugins/github/github-plugin/web:github-plugin"],
+    resources = glob(["src/main/resources/**/*"]),
+    deps = [
+        ":github-plugin-lib",
+        "//plugins/github/github-oauth:github-oauth-lib",
+        "@axis-jaxrpc//jar",
+        "@axis//jar",
+        "@com-sun-mail//jar",
+        "@commons-codec//jar",
+        "@commons-discovery//jar",
+        "@commons-io//jar",
+        "@eclipse-mylyn-github//jar",
+        "@github-api//jar",
+        "@javax-activation//jar",
+        "@velocity//jar",
+    ],
+)
+
+java_library_without_header_compilation(
+    name = "github-plugin-lib",
+    dep = ":github-plugin-lib_impl",
+    visibility = ["//visibility:public"],
+)
+
+java_library(
+    name = "github-plugin-lib_impl",
+    srcs = SOURCES_WITH_LOMBOK_USAGE,
+    deps = PLUGIN_DEPS_NEVERLINK + [
+        ":lombok",
+        "//plugins/github/github-oauth:github-oauth-lib",
+        "@axis-jaxrpc//jar",
+        "@axis//jar",
+        "@commons-codec//jar",
+        "@commons-discovery//jar",
+        "@commons-io//jar",
+        "@eclipse-mylyn-github//jar",
+        "@github-api//jar",
+        "@velocity//jar",
+    ],
+)
+
+junit_tests(
+    name = "github-plugin_tests",
+    srcs = glob(["src/test/java/**/*.java"]),
+    tags = ["github"],
+    deps = PLUGIN_DEPS + PLUGIN_TEST_DEPS + [
+        ":github-plugin-lib",
+        ":github-plugin__plugin",
+        "//javatests/com/google/gerrit/util/http/testutil",
+        "//plugins/github/github-oauth:github-oauth-lib",
+        "@commons-io//jar",
+    ],
+)
+
+java_plugin(
+    name = "lombok_plugin",
+    generates_api = True,
+    processor_class = "lombok.launch.AnnotationProcessorHider$AnnotationProcessor",
+    deps = ["@lombok//jar"],
+)
+
+java_library(
+    name = "lombok",
+    exported_plugins = [":lombok_plugin"],
+    neverlink = True,
+    exports = ["@lombok//jar"],
+)
diff --git a/github-plugin/src/test/java/com/googlesource/gerrit/plugins/github/FakeHttpSession.java b/github-plugin/src/test/java/com/googlesource/gerrit/plugins/github/FakeHttpSession.java
index 6a820e7..b24efba 100644
--- a/github-plugin/src/test/java/com/googlesource/gerrit/plugins/github/FakeHttpSession.java
+++ b/github-plugin/src/test/java/com/googlesource/gerrit/plugins/github/FakeHttpSession.java
@@ -19,7 +19,9 @@
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpSession;
 import javax.servlet.http.HttpSessionContext;
+import org.junit.Ignore;
 
+@Ignore
 public class FakeHttpSession implements HttpSession {
   private final HashMap<String, Object> attributes;
 
diff --git a/github-plugin/web/.eslintrc.js b/github-plugin/web/.eslintrc.js
new file mode 100644
index 0000000..db4adcd
--- /dev/null
+++ b/github-plugin/web/.eslintrc.js
@@ -0,0 +1,9 @@
+/**
+ * @license
+ * Copyright 2022 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+__plugindir = "github/github-plugin/web";
+module.exports = {
+  extends: "../../../.eslintrc.js",
+};
\ No newline at end of file
diff --git a/github-plugin/web/BUILD b/github-plugin/web/BUILD
new file mode 100644
index 0000000..035d999
--- /dev/null
+++ b/github-plugin/web/BUILD
@@ -0,0 +1,42 @@
+load("//tools/js:eslint.bzl", "plugin_eslint")
+load("//tools/bzl:js.bzl", "gerrit_js_bundle")
+load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_project")
+
+package_group(
+    name = "visibility",
+    packages = ["//plugins/github/github-plugin/..."],
+)
+
+package(default_visibility = [":visibility"])
+
+ts_config(
+    name = "tsconfig",
+    src = "tsconfig.json",
+    deps = [
+        "//plugins:tsconfig-plugins-base.json",
+    ],
+)
+
+ts_project(
+    name = "github-plugin-ts",
+    srcs = glob(
+        ["**/*.ts"],
+    ),
+    incremental = True,
+    out_dir = "_bazel_ts_out",
+    tsc = "//tools/node_tools:tsc-bin",
+    tsconfig = ":tsconfig",
+    deps = [
+        "@plugins_npm//@gerritcodereview/typescript-api",
+        "@plugins_npm//lit",
+        "@plugins_npm//rxjs",
+    ],
+)
+
+gerrit_js_bundle(
+    name = "github-plugin",
+    srcs = [":github-plugin-ts"],
+    entry_point = "_bazel_ts_out/main.js",
+)
+
+plugin_eslint()
diff --git a/github-plugin/src/main/ts/gr-github-oauth-progress.ts b/github-plugin/web/gr-github-oauth-progress.ts
similarity index 100%
rename from github-plugin/src/main/ts/gr-github-oauth-progress.ts
rename to github-plugin/web/gr-github-oauth-progress.ts
diff --git a/github-plugin/src/main/ts/main.ts b/github-plugin/web/main.ts
similarity index 100%
rename from github-plugin/src/main/ts/main.ts
rename to github-plugin/web/main.ts
diff --git a/github-plugin/web/tsconfig.json b/github-plugin/web/tsconfig.json
new file mode 100644
index 0000000..c2dd829
--- /dev/null
+++ b/github-plugin/web/tsconfig.json
@@ -0,0 +1,11 @@
+{
+  "extends": "../../../tsconfig-plugins-base.json",
+  "compilerOptions": {
+    "experimentalDecorators": true,
+    /* outDir for IDE (overridden by Bazel rule arg) */
+    "outDir": "../../../../.ts-out/plugins/github-plugin/ui",
+  },
+  "include": [
+    "**/*",
+  ],
+}
\ No newline at end of file
diff --git a/java_library_without_header_compilation.bzl b/java_library_without_header_compilation.bzl
new file mode 100644
index 0000000..a1250d0
--- /dev/null
+++ b/java_library_without_header_compilation.bzl
@@ -0,0 +1,30 @@
+# See https://github.com/bazelbuild/bazel/issues/12837
+# for workaround suggestion for incompatibility between
+# Bazel Turbine processor and Lombok library.
+
+def _java_header_compilation_transition(settings, attr):
+    _ignore = (settings, attr)
+    return {"//command_line_option:java_header_compilation": "False"}
+
+java_header_compilation_transition = transition(
+    implementation = _java_header_compilation_transition,
+    inputs = [],
+    outputs = ["//command_line_option:java_header_compilation"],
+)
+
+def _java_library_without_header_compilation(ctx):
+    return [java_common.merge([d[JavaInfo] for d in ctx.attr.dep])]
+
+java_library_without_header_compilation = rule(
+    implementation = _java_library_without_header_compilation,
+    attrs = {
+        "dep": attr.label(
+            providers = [JavaInfo],
+            mandatory = True,
+            cfg = java_header_compilation_transition,
+        ),
+        "_allowlist_function_transition": attr.label(
+            default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
+        ),
+    },
+)