From 593c257e4a3ea17604bf83675285211c5a7cee60 Mon Sep 17 00:00:00 2001 From: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Sat, 16 Dec 2023 19:31:41 -0500 Subject: [PATCH 1/2] check modulePath for plugin --- jsonb-generator/pom.xml | 2 +- .../jsonb/generator/ProcessingContext.java | 21 +++++++------------ .../io/avaje/jsonb/generator/Processor.java | 2 ++ 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/jsonb-generator/pom.xml b/jsonb-generator/pom.xml index 88b003b0..58586134 100644 --- a/jsonb-generator/pom.xml +++ b/jsonb-generator/pom.xml @@ -11,7 +11,7 @@ jsonb generator annotation processor generating source code json adapters for avaje-jsonb - 1.16 + 1.17 diff --git a/jsonb-generator/src/main/java/io/avaje/jsonb/generator/ProcessingContext.java b/jsonb-generator/src/main/java/io/avaje/jsonb/generator/ProcessingContext.java index 90a2498d..b8a0583c 100644 --- a/jsonb-generator/src/main/java/io/avaje/jsonb/generator/ProcessingContext.java +++ b/jsonb-generator/src/main/java/io/avaje/jsonb/generator/ProcessingContext.java @@ -12,7 +12,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.Element; @@ -86,18 +85,14 @@ static void validateModule(String fqn) { try (var reader = getModuleInfoReader()) { - AtomicBoolean noInjectPlugin = new AtomicBoolean(injectPresent); + var moduleInfo = new ModuleInfoReader(module, reader); + + boolean noInjectPlugin = + injectPresent && !moduleInfo.containsOnModulePath("io.avaje.jsonb.plugin"); + var noProvides = - reader - .lines() - .map( - s -> { - if (injectPresent - && (s.contains("io.avaje.jsonb.plugin") || s.contains("io.avaje.nima"))) { - noInjectPlugin.set(false); - } - return s; - }) + moduleInfo.provides().stream() + .flatMap(s -> s.implementations().stream()) .noneMatch(s -> s.contains(fqn)); if (noProvides) { @@ -105,7 +100,7 @@ static void validateModule(String fqn) { module, "Missing `provides io.avaje.jsonb.Jsonb.GeneratedComponent with %s;`", fqn); } - if (noInjectPlugin.get()) { + if (noInjectPlugin) { logWarn( module, "`requires io.avaje.jsonb.plugin` must be explicity added or else avaje-inject may fail to detect and wire the default Jsonb instance", diff --git a/jsonb-generator/src/main/java/io/avaje/jsonb/generator/Processor.java b/jsonb-generator/src/main/java/io/avaje/jsonb/generator/Processor.java index 7cb163de..f8a21bd0 100644 --- a/jsonb-generator/src/main/java/io/avaje/jsonb/generator/Processor.java +++ b/jsonb-generator/src/main/java/io/avaje/jsonb/generator/Processor.java @@ -14,12 +14,14 @@ import javax.lang.model.util.ElementFilter; import io.avaje.prism.GenerateAPContext; +import io.avaje.prism.GenerateModuleInfoReader; import java.io.IOException; import java.util.*; import java.util.function.Predicate; @GenerateAPContext +@GenerateModuleInfoReader @SupportedAnnotationTypes({ CustomAdapterPrism.PRISM_TYPE, JSON, From fc8009b683ea16e5f22f1a6547d7e91356f28e95 Mon Sep 17 00:00:00 2001 From: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Sat, 23 Dec 2023 22:16:43 -0500 Subject: [PATCH 2/2] Update BufferRecycleStrategy.java --- .../io/avaje/jsonb/stream/BufferRecycleStrategy.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/jsonb/src/main/java/io/avaje/jsonb/stream/BufferRecycleStrategy.java b/jsonb/src/main/java/io/avaje/jsonb/stream/BufferRecycleStrategy.java index 28c60eea..9c47eb48 100644 --- a/jsonb/src/main/java/io/avaje/jsonb/stream/BufferRecycleStrategy.java +++ b/jsonb/src/main/java/io/avaje/jsonb/stream/BufferRecycleStrategy.java @@ -2,15 +2,17 @@ import java.util.function.Supplier; -/** - * Strategy for recycling buffers used in parsing and generation. - */ +/** Strategy for recycling buffers used in parsing and generation. */ public enum BufferRecycleStrategy { - HYBRID_POOL(BufferRecycler::hybrid), + /** Do not perform any sort of recycling. */ NO_RECYCLING(BufferRecycler::nonRecyclingPool), + /** A lock free implementation designed for virtual thread use */ LOCK_FREE(BufferRecycler::lockFreePool), - THREAD_LOCAL(BufferRecycler::threadLocalPool); + /** Use Thread Locals for recycling buffers */ + THREAD_LOCAL(BufferRecycler::threadLocalPool), + /** Use 2 recyclers and switch between them depending on the nature of thread (virtual or not) */ + HYBRID_POOL(BufferRecycler::hybrid); private final Supplier supplier;