Ensure JDK 17 support.

The cache-chroniclemap internals are JDK 17 compatible however JDK,
since that version is more restrictive on which modules are by default
accessible to the third party libraries. Enhance plugin's README.md
and build.md with steps that are necessary to run module in Gerrit
under JDK 17 JVM and call test from IDE (as described in [1]).

In addition JDK 17 modifies the way how annotations have their
`toString` method implemented. In JDK 11 (and older) it used to be:

  @com.google.inject.name.Named(value="accounts")

Whereas in JDK 17 it is:

  @com.google.inject.name.Named("accounts")

Modify MigrateH2CachesLocalDiskIT.isClassBoundWithName(Entry) to be
compatible with both implementations.

[1] https://chronicle.software/chronicle-support-java-17/

Bug: Issue 306464780
Change-Id: I3e201d9638de7007aca2af10796a8ee1deb9d04c
diff --git a/BUILD b/BUILD
index a782456..97158dc 100644
--- a/BUILD
+++ b/BUILD
@@ -46,12 +46,34 @@
         ":chroniclemap-test-lib",
         "@chronicle-bytes//jar",
     ],
+    jvm_flags =[
+        "--add-exports=java.base/sun.nio.ch=ALL-UNNAMED",
+        "--add-exports=java.base/jdk.internal.ref=ALL-UNNAMED",
+        "--add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED",
+        "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
+        "--add-opens=jdk.compiler/com.sun.tools.javac=ALL-UNNAMED",
+        "--add-opens=java.base/java.lang=ALL-UNNAMED",
+        "--add-opens=java.base/java.lang.reflect=ALL-UNNAMED",
+        "--add-opens=java.base/java.io=ALL-UNNAMED",
+        "--add-opens=java.base/java.util=ALL-UNNAMED",
+    ],
 )
 
 [junit_tests(
     name = f[:f.index(".")].replace("/", "_"),
     srcs = [f],
     tags = ["server"],
+    jvm_flags =[
+        "--add-exports=java.base/sun.nio.ch=ALL-UNNAMED",
+        "--add-exports=java.base/jdk.internal.ref=ALL-UNNAMED",
+        "--add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED",
+        "--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
+        "--add-opens=jdk.compiler/com.sun.tools.javac=ALL-UNNAMED",
+        "--add-opens=java.base/java.lang=ALL-UNNAMED",
+        "--add-opens=java.base/java.lang.reflect=ALL-UNNAMED",
+        "--add-opens=java.base/java.io=ALL-UNNAMED",
+        "--add-opens=java.base/java.util=ALL-UNNAMED",
+    ],
     deps = [
         ":cache-chroniclemap__plugin",
         ":chroniclemap-test-lib",
diff --git a/README.md b/README.md
index 870dd90..ded63bf 100644
--- a/README.md
+++ b/README.md
@@ -22,6 +22,22 @@
   installModule = com.googlesource.gerrit.modules.cache.chroniclemap.ChronicleMapCacheModule
 ```
 
+Note that in order to run on JDK 17 (or newer) the following parameters needs to be added
+to `$GERRIT_SITE/etc/gerrit.config`:
+
+```
+[container]
+  javaOptions = --add-exports=java.base/jdk.internal.ref=ALL-UNNAMED
+  javaOptions = --add-exports=java.base/sun.nio.ch=ALL-UNNAMED
+  javaOptions = --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
+  javaOptions = --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
+  javaOptions = --add-opens=jdk.compiler/com.sun.tools.javac=ALL-UNNAMED
+  javaOptions = --add-opens=java.base/java.lang=ALL-UNNAMED
+  javaOptions = --add-opens=java.base/java.lang.reflect=ALL-UNNAMED
+  javaOptions = --add-opens=java.base/java.io=ALL-UNNAMED
+  javaOptions = --add-opens=java.base/java.util=ALL-UNNAMED
+```
+
 For further information and supported options, refer to [config](src/main/resources/Documentation/config.md)
 documentation.
 
diff --git a/src/main/resources/Documentation/build.md b/src/main/resources/Documentation/build.md
index 652b328..f65fe10 100644
--- a/src/main/resources/Documentation/build.md
+++ b/src/main/resources/Documentation/build.md
@@ -34,4 +34,24 @@
 
 ```sh
 bazelisk test plugins/cache-chroniclemap/...
-```
\ No newline at end of file
+```
+
+## Run tests in IDE
+
+The cache-chroniclemap internals are JDK 17 compatible however JDK since that
+version is more restrictive on which modules are by default accessible to the
+third party libraries. Considering that, in order to run tests in IDE (e.g.
+Eclipse), one needs to add the following VM arguments to the particular test's
+_Debug/Run Configuration_:
+
+```
+--add-exports=java.base/sun.nio.ch=ALL-UNNAMED
+--add-exports=java.base/jdk.internal.ref=ALL-UNNAMED
+--add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
+--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
+--add-opens=jdk.compiler/com.sun.tools.javac=ALL-UNNAMED
+--add-opens=java.base/java.lang=ALL-UNNAMED
+--add-opens=java.base/java.lang.reflect=ALL-UNNAMED
+--add-opens=java.base/java.io=ALL-UNNAMED
+--add-opens=java.base/java.util=ALL-UNNAMED
+```
diff --git a/src/test/java/com/googlesource/gerrit/modules/cache/chroniclemap/MigrateH2CachesLocalDiskIT.java b/src/test/java/com/googlesource/gerrit/modules/cache/chroniclemap/MigrateH2CachesLocalDiskIT.java
index 57de6cd..469fcf8 100644
--- a/src/test/java/com/googlesource/gerrit/modules/cache/chroniclemap/MigrateH2CachesLocalDiskIT.java
+++ b/src/test/java/com/googlesource/gerrit/modules/cache/chroniclemap/MigrateH2CachesLocalDiskIT.java
@@ -48,6 +48,7 @@
 import com.google.inject.Inject;
 import com.google.inject.Key;
 import com.google.inject.Module;
+import com.google.inject.name.Named;
 import java.io.IOException;
 import java.lang.annotation.Annotation;
 import java.nio.file.Path;
@@ -305,7 +306,8 @@
     Annotation annotation = entry.getKey().getAnnotation();
     return className.equals(classNameMatch)
         && annotation != null
-        && annotation.toString().endsWith(String.format("Named(value=\"%s\")", named));
+        && annotation instanceof Named
+        && annotation.toString().contains(String.format("\"%s\"", named));
   }
 
   private <K, V> ChronicleMapCacheImpl<K, V> chronicleCacheFor(String cacheName) throws Exception {