]> source.dussan.org Git - jgit.git/commitdiff
Bazel: Add support for JDK 21 84/204984/10
authorDavid Ostrovsky <david@ostrovsky.org>
Tue, 17 Oct 2023 07:47:35 +0000 (09:47 +0200)
committerDavid Ostrovsky <david@ostrovsky.org>
Thu, 2 May 2024 13:05:22 +0000 (15:05 +0200)
There are two failing tests when switching to JDK 21.

One failure is related to the changed behaviour related to the locale
providers. Adapt `GitDateFormatterTest` to changes in unicode [1].

Second failure related to changed behaviour in URL.openConnection(),
see: [2] for more details.

Before JDK 20, some of the parsing/validation performed by the JDK
built-in URLStreamHander implementations were delayed until
URL::openConnection or URLConnection::connect was called. Starting
JDK 20, some of these parsing/validations are now performed early,
i.e. within URL constructors.

IOW, the assumption made in HttpSupport.TesttestMalformedUri() isn't
met any more: providing mailformed URI to the URL ctor now throws an
exception starting with JDK 20. To rectify the problem, remove the
offending test.

Test plan:

To build with JDK 21 and run the tests locally:

  $> bazel test --config=java21 //...

To build with JDK 21 and run the tests on RBE:

  $> bazel test --config=remote21 --remote_instance_name=$PROJECT //...

[1] https://bugs.openjdk.org/browse/JDK-8304925
[2] https://bugs.openjdk.org/browse/JDK-8293590

Change-Id: I796de67f7945d5f1fa5e8146f4ec8cbe9ac7bd3e

.bazelrc
WORKSPACE
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/GitDateFormatterTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/HttpSupportTest.java
tools/BUILD

index 51be79be289c838514a8a888d4e8e61166ef756e..7c71c4a9d089864df263690df52085a49b2c2b88 100644 (file)
--- a/.bazelrc
+++ b/.bazelrc
@@ -21,7 +21,7 @@ build:remote11 --tool_java_language_version=11
 build:remote11 --tool_java_runtime_version=remotejdk_11
 build:remote11 --config=remote
 
-# Builds using remote_jdk17, executes using remote_jdk11 or local_jdk
+# Builds using remote_jdk17, executes using remote_jdk17 or local_jdk
 build:java17 --java_language_version=17
 build:java17 --java_runtime_version=remotejdk_17
 build:java17 --tool_java_language_version=17
@@ -34,6 +34,19 @@ build:remote17 --tool_java_language_version=17
 build:remote17 --tool_java_runtime_version=remotejdk_17
 build:remote17 --config=remote
 
+# Builds using remote_jdk21, executes using remote_jdk21 or local_jdk
+build:java21 --java_language_version=21
+build:java21 --java_runtime_version=remotejdk_21
+build:java21 --tool_java_language_version=21
+build:java21 --tool_java_runtime_version=remotejdk_21
+
+# Builds and executes on RBE using remotejdk_21
+build:remote21 --java_language_version=21
+build:remote21 --java_runtime_version=remotejdk_21
+build:remote21 --tool_java_language_version=21
+build:remote21 --tool_java_runtime_version=remotejdk_21
+build:remote21 --config=remote
+
 test --build_tests_only
 test --test_output=errors
 test --flaky_test_attempts=3
index b0d0ea01f09bbccdb9437c5eecdada3bccaeba38..07d4d5cd03acae5359ac0cb34eb6b83b83b70032 100644 (file)
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -10,6 +10,18 @@ load(
     "maven_jar",
 )
 
+http_archive(
+    name = "rules_java",
+    sha256 = "4da3761f6855ad916568e2bfe86213ba6d2637f56b8360538a7fb6125abf6518",
+    urls = [
+        "https://github.com/bazelbuild/rules_java/releases/download/7.5.0/rules_java-7.5.0.tar.gz",
+    ],
+)
+
+load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains")
+
+rules_java_dependencies()
+
 http_archive(
     name = "ubuntu2204_jdk17",
     sha256 = "8ea82b81c9707e535ff93ef5349d11e55b2a23c62bcc3b0faaec052144aed87d",
@@ -24,6 +36,14 @@ register_toolchains("//tools:error_prone_warnings_toolchain_java11_definition")
 
 register_toolchains("//tools:error_prone_warnings_toolchain_java17_definition")
 
+register_toolchains("//tools:error_prone_warnings_toolchain_java21_definition")
+
+# Order of registering toolchains matters. rules_java toolchains take precedence
+# over the custom toolchains, so the default jdk21 toolchain gets picked
+# (one without custom package_config). That's why the `rules_java_toolchains()`
+# must be called after the `register_toolchain()` invocation.
+rules_java_toolchains()
+
 JMH_VERS = "1.37"
 
 maven_jar(
index 0bd7e0bd61ed03797d8ff7d141a35082939c6c5e..6a531fe0e601e8e1700edd7e70cdbf321f2fc764 100644 (file)
@@ -89,15 +89,19 @@ public class GitDateFormatterTest {
        @Test
        public void LOCALE() {
                String date = new GitDateFormatter(Format.LOCALE).formatDate(ident);
+               System.out.println(date);
                assertTrue("Sep 20, 2011 7:09:25 PM -0400".equals(date)
-                               || "Sep 20, 2011, 7:09:25 PM -0400".equals(date)); // JDK-8206961
+                               || "Sep 20, 2011, 7:09:25 PM -0400".equals(date) // JDK-8206961
+                               || "Sep 20, 2011, 7:09:25\u202FPM -0400".equals(date)); // JDK-8304925
        }
 
        @Test
        public void LOCALELOCAL() {
                String date = new GitDateFormatter(Format.LOCALELOCAL)
                                .formatDate(ident);
+               System.out.println(date);
                assertTrue("Sep 20, 2011 7:39:25 PM".equals(date)
-                               || "Sep 20, 2011, 7:39:25 PM".equals(date)); // JDK-8206961
+                               || "Sep 20, 2011, 7:39:25 PM".equals(date) // JDK-8206961
+                               || "Sep 20, 2011, 7:39:25\u202FPM".equals(date)); // JDK-8304925
        }
 }
index cbe4eb2eb014d58701d0ca28a2540682f73c9546..a3a5697ef4f99a24f360f15dee614441fcf675b2 100644 (file)
@@ -46,18 +46,6 @@ public class HttpSupportTest {
                }
        }
 
-       @Test
-       public void testMalformedUri() throws Exception {
-               // Valid URL, but backslash is not allowed in a URI in the userinfo part
-               // per RFC 3986: https://tools.ietf.org/html/rfc3986#section-3.2.1 .
-               // Test that conversion to URI to call the ProxySelector does not throw
-               // an exception.
-               Proxy proxy = HttpSupport.proxyFor(new TestProxySelector(), new URL(
-                               "http://infor\\c.jones@somehost/somewhere/someproject.git"));
-               assertNotNull(proxy);
-               assertEquals(Proxy.Type.HTTP, proxy.type());
-       }
-
        @Test
        public void testCorrectUri() throws Exception {
                // Backslash escaped as %5C is correct.
index 2ad281e64a14dde337e81cc0c95bf905e3eddb30..c7ec6386456fdb47ea50b26f95ae27b4a48ee9b4 100644 (file)
@@ -17,7 +17,7 @@ default_java_toolchain(
 default_java_toolchain(
     name = "error_prone_warnings_toolchain_java17",
     configuration = dict(),
-    java_runtime = "@bazel_tools//tools/jdk:remotejdk_17",
+    java_runtime = "@rules_java//toolchains:remotejdk_17",
     package_configuration = [
         ":error_prone",
     ],
@@ -26,6 +26,18 @@ default_java_toolchain(
     visibility = ["//visibility:public"],
 )
 
+default_java_toolchain(
+    name = "error_prone_warnings_toolchain_java21",
+    configuration = dict(),
+    java_runtime = "@rules_java//toolchains:remotejdk_21",
+    package_configuration = [
+        ":error_prone",
+    ],
+    source_version = "21",
+    target_version = "21",
+    visibility = ["//visibility:public"],
+)
+
 # Error Prone errors enabled by default; see ../.bazelrc for how this is
 # enabled. This warnings list is originally based on:
 # https://github.com/bazelbuild/BUILD_file_generator/blob/master/tools/bazel_defs/java.bzl