From 9d0e4288ca223380953d6f27132307021c1fcf39 Mon Sep 17 00:00:00 2001 From: George Gastaldi Date: Fri, 7 Jun 2024 21:59:16 -0300 Subject: [PATCH] Set WindowCache to be initialized during runtime (#124) --- .../quarkus/jgit/deployment/JGitProcessor.java | 3 ++- .../java/io/quarkus/it/jgit/JGitResource.java | 11 +++++++++++ .../test/java/io/quarkus/it/jgit/JGitTest.java | 8 ++++++++ .../graalvm/WindowCacheSubstitution.java | 17 ----------------- 4 files changed, 21 insertions(+), 18 deletions(-) delete mode 100644 runtime/src/main/java/io/quarkus/jgit/runtime/graalvm/WindowCacheSubstitution.java diff --git a/deployment/src/main/java/io/quarkus/jgit/deployment/JGitProcessor.java b/deployment/src/main/java/io/quarkus/jgit/deployment/JGitProcessor.java index adfb892..08d5523 100644 --- a/deployment/src/main/java/io/quarkus/jgit/deployment/JGitProcessor.java +++ b/deployment/src/main/java/io/quarkus/jgit/deployment/JGitProcessor.java @@ -47,8 +47,9 @@ ReflectiveClassBuildItem reflection() { @BuildStep void runtimeInitializedClasses(BuildProducer producer) { - producer.produce(new RuntimeInitializedClassBuildItem("org.eclipse.jgit.transport.HttpAuthMethod$Digest")); + producer.produce(new RuntimeInitializedClassBuildItem("org.eclipse.jgit.internal.storage.file.WindowCache")); producer.produce(new RuntimeInitializedClassBuildItem("org.eclipse.jgit.lib.GpgSigner")); + producer.produce(new RuntimeInitializedClassBuildItem("org.eclipse.jgit.transport.HttpAuthMethod$Digest")); } @BuildStep diff --git a/integration-tests/src/main/java/io/quarkus/it/jgit/JGitResource.java b/integration-tests/src/main/java/io/quarkus/it/jgit/JGitResource.java index dcac526..60fe1de 100644 --- a/integration-tests/src/main/java/io/quarkus/it/jgit/JGitResource.java +++ b/integration-tests/src/main/java/io/quarkus/it/jgit/JGitResource.java @@ -3,6 +3,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.Field; import java.net.URL; import java.nio.file.Files; import java.nio.file.StandardCopyOption; @@ -15,6 +16,7 @@ import org.eclipse.jgit.api.Git; import org.eclipse.jgit.diff.DiffEntry; +import org.eclipse.jgit.internal.storage.file.WindowCache; import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; @@ -43,6 +45,15 @@ public String cloneRepository() throws Exception { } } + @GET + @Path("/windowcache_random_initialized") + @Produces(MediaType.TEXT_PLAIN) + public boolean windowCacheRandomInitialized() throws Exception { + Field field = WindowCache.class.getDeclaredField("rng"); + field.setAccessible(true); + return field.get(WindowCache.getInstance()) != null; + } + @GET @Path("/config") @Produces(MediaType.TEXT_PLAIN) diff --git a/integration-tests/src/test/java/io/quarkus/it/jgit/JGitTest.java b/integration-tests/src/test/java/io/quarkus/it/jgit/JGitTest.java index b4b4fe4..924ea09 100644 --- a/integration-tests/src/test/java/io/quarkus/it/jgit/JGitTest.java +++ b/integration-tests/src/test/java/io/quarkus/it/jgit/JGitTest.java @@ -29,4 +29,12 @@ void shouldDiff() { given().get("/jgit/diff").then().body(is("153")); } + @Test + void shouldRandomBeInitialized() { + given().get("/jgit/windowcache_random_initialized").then() + .log().ifValidationFails() + .statusCode(200) + .body(is("true")); + } + } diff --git a/runtime/src/main/java/io/quarkus/jgit/runtime/graalvm/WindowCacheSubstitution.java b/runtime/src/main/java/io/quarkus/jgit/runtime/graalvm/WindowCacheSubstitution.java deleted file mode 100644 index f149ea2..0000000 --- a/runtime/src/main/java/io/quarkus/jgit/runtime/graalvm/WindowCacheSubstitution.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.quarkus.jgit.runtime.graalvm; - -import java.util.Random; - -import org.eclipse.jgit.internal.storage.file.WindowCache; - -import com.oracle.svm.core.annotate.Alias; -import com.oracle.svm.core.annotate.RecomputeFieldValue; -import com.oracle.svm.core.annotate.TargetClass; - -@TargetClass(WindowCache.class) -final class WindowCacheSubstitution { - @Alias - @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset) - private static Random rng; - -}