diff --git a/extensions/vertx/deployment/src/main/java/io/quarkus/vertx/deployment/VertxBuildConfig.java b/extensions/vertx/deployment/src/main/java/io/quarkus/vertx/deployment/VertxBuildConfig.java new file mode 100644 index 00000000000000..b2c13043ae9712 --- /dev/null +++ b/extensions/vertx/deployment/src/main/java/io/quarkus/vertx/deployment/VertxBuildConfig.java @@ -0,0 +1,17 @@ +package io.quarkus.vertx.deployment; + +import io.quarkus.runtime.annotations.ConfigItem; +import io.quarkus.runtime.annotations.ConfigPhase; +import io.quarkus.runtime.annotations.ConfigRoot; + +@ConfigRoot(name = "vertx", phase = ConfigPhase.BUILD_TIME) +public class VertxBuildConfig { + + /** + * If set to {@code true} then a customized current context factory (backed by a Vert.x duplicated local context) is used + * for normal scopes in ArC. + */ + @ConfigItem(generateDocumentation = false, defaultValue = "true") + public boolean customizeArcContext; + +} diff --git a/extensions/vertx/deployment/src/main/java/io/quarkus/vertx/deployment/VertxProcessor.java b/extensions/vertx/deployment/src/main/java/io/quarkus/vertx/deployment/VertxProcessor.java index e90ce7c644bd01..43b5c21d711564 100644 --- a/extensions/vertx/deployment/src/main/java/io/quarkus/vertx/deployment/VertxProcessor.java +++ b/extensions/vertx/deployment/src/main/java/io/quarkus/vertx/deployment/VertxProcessor.java @@ -101,8 +101,11 @@ VertxBuildItem build(CoreVertxBuildItem vertx, VertxRecorder recorder, @BuildStep @Record(ExecutionTime.STATIC_INIT) - CurrentContextFactoryBuildItem currentContextFactory(VertxRecorder recorder) { - return new CurrentContextFactoryBuildItem(recorder.currentContextFactory()); + void currentContextFactory(BuildProducer currentContextFactory, + VertxBuildConfig buildConfig, VertxRecorder recorder) { + if (buildConfig.customizeArcContext) { + currentContextFactory.produce(new CurrentContextFactoryBuildItem(recorder.currentContextFactory())); + } } @BuildStep diff --git a/extensions/vertx/deployment/src/test/java/io/quarkus/vertx/deployment/currentcontextfactory/VertxCurrentContextFactoryDisabledTest.java b/extensions/vertx/deployment/src/test/java/io/quarkus/vertx/deployment/currentcontextfactory/VertxCurrentContextFactoryDisabledTest.java new file mode 100644 index 00000000000000..4f17aed87680ba --- /dev/null +++ b/extensions/vertx/deployment/src/test/java/io/quarkus/vertx/deployment/currentcontextfactory/VertxCurrentContextFactoryDisabledTest.java @@ -0,0 +1,23 @@ +package io.quarkus.vertx.deployment.currentcontextfactory; + +import static org.junit.jupiter.api.Assertions.assertFalse; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.arc.Arc; +import io.quarkus.test.QuarkusUnitTest; +import io.quarkus.vertx.runtime.VertxCurrentContextFactory; + +public class VertxCurrentContextFactoryDisabledTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .overrideConfigKey("quarkus.vertx.customize-arc-context", "false"); + + @Test + public void testCustomizedFactoryNotUsed() { + assertFalse(Arc.container().getCurrentContextFactory() instanceof VertxCurrentContextFactory); + } + +}