From 749377f5866c7d12c12dedfee5d4399dd418bf3a Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Wed, 29 Mar 2023 09:53:14 +0200 Subject: [PATCH 1/6] ArC - remove the usage of the deprecated ClientProxyUnwrapper - fix and deprecate ProxyUnwrapperBuildItem --- .../deployment/builditem/ProxyUnwrapperBuildItem.java | 5 ++++- .../io/quarkus/arc/deployment/ProxyUnwrapProcessor.java | 5 +++-- .../mongodb/DefaultAndNamedMongoClientConfigTest.java | 6 ++---- .../java/io/quarkus/mongodb/MongoClientConfigTest.java | 8 +++----- .../mongodb/NamedReactiveMongoClientConfigTest.java | 6 ++---- .../resteasy/common/runtime/QuarkusInjectorFactory.java | 8 +++----- .../mockito/internal/CreateMockitoSpiesCallback.java | 4 ++-- 7 files changed, 19 insertions(+), 23 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/builditem/ProxyUnwrapperBuildItem.java b/core/deployment/src/main/java/io/quarkus/deployment/builditem/ProxyUnwrapperBuildItem.java index d18fcfd6c23d6..e4d858dda7530 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/builditem/ProxyUnwrapperBuildItem.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/builditem/ProxyUnwrapperBuildItem.java @@ -5,8 +5,11 @@ import io.quarkus.builder.item.MultiBuildItem; /** - * A build item that can be used to unwrap CDI or other proxies + * A build item that can be used to unwrap CDI or other proxies. + * + * @deprecated Use {@code io.quarkus.arc.ClientProxy.unwrap(T)} instead. */ +@Deprecated(since = "3.0.0", forRemoval = true) public final class ProxyUnwrapperBuildItem extends MultiBuildItem { private final Function unwrapper; diff --git a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ProxyUnwrapProcessor.java b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ProxyUnwrapProcessor.java index 88a046c30d61d..74c4095f9281c 100644 --- a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ProxyUnwrapProcessor.java +++ b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ProxyUnwrapProcessor.java @@ -1,6 +1,6 @@ package io.quarkus.arc.deployment; -import io.quarkus.arc.ClientProxy; +import io.quarkus.arc.runtime.ClientProxyUnwrapper; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.builditem.ProxyUnwrapperBuildItem; @@ -8,6 +8,7 @@ public class ProxyUnwrapProcessor { @BuildStep ProxyUnwrapperBuildItem wrapper() { - return new ProxyUnwrapperBuildItem(ClientProxy::unwrap); + // ClientProxy::unwrap cannot be used because we need to serialize the unwrapper through a recorder method + return new ProxyUnwrapperBuildItem(new ClientProxyUnwrapper()); } } diff --git a/extensions/mongodb-client/deployment/src/test/java/io/quarkus/mongodb/DefaultAndNamedMongoClientConfigTest.java b/extensions/mongodb-client/deployment/src/test/java/io/quarkus/mongodb/DefaultAndNamedMongoClientConfigTest.java index 9cc7fc2d834ad..9c8d367e1bc4a 100644 --- a/extensions/mongodb-client/deployment/src/test/java/io/quarkus/mongodb/DefaultAndNamedMongoClientConfigTest.java +++ b/extensions/mongodb-client/deployment/src/test/java/io/quarkus/mongodb/DefaultAndNamedMongoClientConfigTest.java @@ -17,7 +17,7 @@ import com.mongodb.client.internal.MongoClientImpl; import io.quarkus.arc.Arc; -import io.quarkus.arc.runtime.ClientProxyUnwrapper; +import io.quarkus.arc.ClientProxy; import io.quarkus.mongodb.health.MongoHealthCheck; import io.quarkus.test.QuarkusUnitTest; @@ -39,8 +39,6 @@ public class DefaultAndNamedMongoClientConfigTest extends MongoWithReplicasTestB @Any MongoHealthCheck health; - private final ClientProxyUnwrapper unwrapper = new ClientProxyUnwrapper(); - @AfterEach void cleanup() { if (client != null) { @@ -74,7 +72,7 @@ public void testNamedDataSourceInjection() { } private void assertProperConnection(MongoClient client, int expectedPort) { - assertThat(unwrapper.apply(client)).isInstanceOfSatisfying(MongoClientImpl.class, c -> { + assertThat(ClientProxy.unwrap(client)).isInstanceOfSatisfying(MongoClientImpl.class, c -> { assertThat(c.getCluster().getSettings().getHosts()).singleElement().satisfies(sa -> { assertThat(sa.getPort()).isEqualTo(expectedPort); }); diff --git a/extensions/mongodb-client/deployment/src/test/java/io/quarkus/mongodb/MongoClientConfigTest.java b/extensions/mongodb-client/deployment/src/test/java/io/quarkus/mongodb/MongoClientConfigTest.java index b4f546107c2af..3708be970d06e 100644 --- a/extensions/mongodb-client/deployment/src/test/java/io/quarkus/mongodb/MongoClientConfigTest.java +++ b/extensions/mongodb-client/deployment/src/test/java/io/quarkus/mongodb/MongoClientConfigTest.java @@ -16,7 +16,7 @@ import com.mongodb.client.MongoClient; import com.mongodb.client.internal.MongoClientImpl; -import io.quarkus.arc.runtime.ClientProxyUnwrapper; +import io.quarkus.arc.ClientProxy; import io.quarkus.mongodb.impl.ReactiveMongoClientImpl; import io.quarkus.mongodb.reactive.ReactiveMongoClient; import io.quarkus.test.QuarkusUnitTest; @@ -34,8 +34,6 @@ public class MongoClientConfigTest extends MongoWithReplicasTestBase { @Inject ReactiveMongoClient reactiveClient; - private final ClientProxyUnwrapper unwrapper = new ClientProxyUnwrapper(); - @AfterEach void cleanup() { if (reactiveClient != null) { @@ -48,7 +46,7 @@ void cleanup() { @Test public void testClientConfiguration() { - MongoClientImpl clientImpl = (MongoClientImpl) unwrapper.apply(client); + MongoClientImpl clientImpl = (MongoClientImpl) ClientProxy.unwrap(client); assertThat(clientImpl.getSettings().getConnectionPoolSettings().getMaxSize()).isEqualTo(2); assertThat(clientImpl.getSettings().getConnectionPoolSettings().getMinSize()).isEqualTo(1); assertThat(clientImpl.getSettings().getConnectionPoolSettings().getMaxConnectionIdleTime(TimeUnit.SECONDS)) @@ -73,7 +71,7 @@ public void testClientConfiguration() { @Test public void testReactiveClientConfiuration() { - ReactiveMongoClientImpl reactiveMongoClientImpl = (ReactiveMongoClientImpl) unwrapper.apply(reactiveClient); + ReactiveMongoClientImpl reactiveMongoClientImpl = (ReactiveMongoClientImpl) ClientProxy.unwrap(reactiveClient); com.mongodb.reactivestreams.client.internal.MongoClientImpl clientImpl = (com.mongodb.reactivestreams.client.internal.MongoClientImpl) reactiveMongoClientImpl .unwrap(); assertThat(clientImpl.getSettings().getConnectionPoolSettings().getMaxSize()).isEqualTo(2); diff --git a/extensions/mongodb-client/deployment/src/test/java/io/quarkus/mongodb/NamedReactiveMongoClientConfigTest.java b/extensions/mongodb-client/deployment/src/test/java/io/quarkus/mongodb/NamedReactiveMongoClientConfigTest.java index 9b4cb46ed77a7..a5b2909d53d1d 100644 --- a/extensions/mongodb-client/deployment/src/test/java/io/quarkus/mongodb/NamedReactiveMongoClientConfigTest.java +++ b/extensions/mongodb-client/deployment/src/test/java/io/quarkus/mongodb/NamedReactiveMongoClientConfigTest.java @@ -20,9 +20,9 @@ import com.mongodb.reactivestreams.client.internal.MongoClientImpl; import io.quarkus.arc.Arc; +import io.quarkus.arc.ClientProxy; import io.quarkus.arc.InjectableBean; import io.quarkus.arc.InstanceHandle; -import io.quarkus.arc.runtime.ClientProxyUnwrapper; import io.quarkus.mongodb.health.MongoHealthCheck; import io.quarkus.mongodb.impl.ReactiveMongoClientImpl; import io.quarkus.mongodb.reactive.ReactiveMongoClient; @@ -47,8 +47,6 @@ public class NamedReactiveMongoClientConfigTest extends MongoWithReplicasTestBas @Any MongoHealthCheck health; - private final ClientProxyUnwrapper unwrapper = new ClientProxyUnwrapper(); - @AfterEach void cleanup() { if (client != null) { @@ -80,7 +78,7 @@ public void checkHealth() { } private void assertProperConnection(ReactiveMongoClient client, int expectedPort) { - assertThat(unwrapper.apply(client)).isInstanceOfSatisfying(ReactiveMongoClientImpl.class, rc -> { + assertThat(ClientProxy.unwrap(client)).isInstanceOfSatisfying(ReactiveMongoClientImpl.class, rc -> { Field mongoClientField; try { mongoClientField = ReactiveMongoClientImpl.class.getDeclaredField("client"); diff --git a/extensions/resteasy-classic/resteasy-common/runtime/src/main/java/io/quarkus/resteasy/common/runtime/QuarkusInjectorFactory.java b/extensions/resteasy-classic/resteasy-common/runtime/src/main/java/io/quarkus/resteasy/common/runtime/QuarkusInjectorFactory.java index 67c923e299653..287130c569257 100644 --- a/extensions/resteasy-classic/resteasy-common/runtime/src/main/java/io/quarkus/resteasy/common/runtime/QuarkusInjectorFactory.java +++ b/extensions/resteasy-classic/resteasy-common/runtime/src/main/java/io/quarkus/resteasy/common/runtime/QuarkusInjectorFactory.java @@ -2,7 +2,6 @@ import java.lang.reflect.Constructor; import java.util.concurrent.CompletionStage; -import java.util.function.Function; import jakarta.ws.rs.WebApplicationException; @@ -18,12 +17,11 @@ import org.jboss.resteasy.spi.metadata.ResourceClass; import org.jboss.resteasy.spi.metadata.ResourceConstructor; -import io.quarkus.arc.runtime.ClientProxyUnwrapper; +import io.quarkus.arc.ClientProxy; public class QuarkusInjectorFactory extends InjectorFactoryImpl { private static final Logger log = Logger.getLogger("io.quarkus.resteasy.runtime"); - static final Function PROXY_UNWRAPPER = new ClientProxyUnwrapper(); @SuppressWarnings("rawtypes") @Override @@ -65,13 +63,13 @@ public UnwrappingPropertyInjector(PropertyInjector delegate) { @Override public CompletionStage inject(Object target, boolean unwrapAsync) { - return delegate.inject(PROXY_UNWRAPPER.apply(target), unwrapAsync); + return delegate.inject(ClientProxy.unwrap(target), unwrapAsync); } @Override public CompletionStage inject(HttpRequest request, HttpResponse response, Object target, boolean unwrapAsync) throws Failure, WebApplicationException, ApplicationException { - return delegate.inject(request, response, PROXY_UNWRAPPER.apply(target), unwrapAsync); + return delegate.inject(request, response, ClientProxy.unwrap(target), unwrapAsync); } } } diff --git a/test-framework/junit5-mockito/src/main/java/io/quarkus/test/junit/mockito/internal/CreateMockitoSpiesCallback.java b/test-framework/junit5-mockito/src/main/java/io/quarkus/test/junit/mockito/internal/CreateMockitoSpiesCallback.java index c4a62cc5143cd..5d04c06905835 100644 --- a/test-framework/junit5-mockito/src/main/java/io/quarkus/test/junit/mockito/internal/CreateMockitoSpiesCallback.java +++ b/test-framework/junit5-mockito/src/main/java/io/quarkus/test/junit/mockito/internal/CreateMockitoSpiesCallback.java @@ -5,7 +5,7 @@ import org.mockito.AdditionalAnswers; import org.mockito.Mockito; -import io.quarkus.arc.runtime.ClientProxyUnwrapper; +import io.quarkus.arc.ClientProxy; import io.quarkus.test.junit.callback.QuarkusTestAfterConstructCallback; import io.quarkus.test.junit.mockito.InjectSpy; @@ -28,7 +28,7 @@ public void afterConstruct(Object testInstance) { } private Object createSpyAndSetTestField(Object testInstance, Field field, Object beanInstance, boolean delegate) { - Object unwrapped = new ClientProxyUnwrapper().apply(beanInstance); + Object unwrapped = ClientProxy.unwrap(beanInstance); Object spy = delegate ? Mockito.mock(unwrapped.getClass(), AdditionalAnswers.delegatesTo(unwrapped)) : Mockito.spy(unwrapped); field.setAccessible(true); From 0c781bbbe2da43e49bec03340f3082902a83bca3 Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Wed, 29 Mar 2023 11:48:58 +0200 Subject: [PATCH 2/6] ArC - reduce the visibility of BeanContainerImpl --- .../java/io/quarkus/arc/runtime/BeanContainerImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/BeanContainerImpl.java b/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/BeanContainerImpl.java index de4a28e5c11df..8f93f767bcadb 100644 --- a/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/BeanContainerImpl.java +++ b/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/BeanContainerImpl.java @@ -11,13 +11,13 @@ import io.quarkus.arc.InstanceHandle; import io.quarkus.arc.ManagedContext; -public class BeanContainerImpl implements BeanContainer { +class BeanContainerImpl implements BeanContainer { private static final Logger LOGGER = Logger.getLogger(BeanContainerImpl.class.getName()); private final ArcContainer container; - public BeanContainerImpl(ArcContainer container) { + BeanContainerImpl(ArcContainer container) { this.container = container; } @@ -64,9 +64,9 @@ public ManagedContext requestContext() { return container.requestContext(); } - static final class DefaultInstanceFactory implements BeanContainer.Factory { + private static final class DefaultInstanceFactory implements BeanContainer.Factory { - final Class type; + private final Class type; DefaultInstanceFactory(Class type) { this.type = type; From 5f7d0799dea3bdb9f2c96c2ffa66fe3674067ba0 Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Wed, 29 Mar 2023 11:51:46 +0200 Subject: [PATCH 3/6] ArC - fix typo in the InitializationTaskProcessor class name --- ...ztionTaskProcessor.java => InitializationTaskProcessor.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/init/{InitializtionTaskProcessor.java => InitializationTaskProcessor.java} (95%) diff --git a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/init/InitializtionTaskProcessor.java b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/init/InitializationTaskProcessor.java similarity index 95% rename from extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/init/InitializtionTaskProcessor.java rename to extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/init/InitializationTaskProcessor.java index b7aa22aa8bf58..194ad9ba1e73a 100644 --- a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/init/InitializtionTaskProcessor.java +++ b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/init/InitializationTaskProcessor.java @@ -15,7 +15,7 @@ * once they are completed if * needed. */ -public class InitializtionTaskProcessor { +public class InitializationTaskProcessor { @BuildStep @Consume(SyntheticBeansRuntimeInitBuildItem.class) From 19083b72a993a4406892dfd2887a12a2da99234e Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Wed, 29 Mar 2023 13:03:38 +0200 Subject: [PATCH 4/6] ArC - improve the javadoc of deprecated RecorderBeanInitializedBuildItem Co-authored-by: Matej Novotny --- .../deployment/RecorderBeanInitializedBuildItem.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/RecorderBeanInitializedBuildItem.java b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/RecorderBeanInitializedBuildItem.java index a1133a36da5c9..1bdc5c1d95d91 100644 --- a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/RecorderBeanInitializedBuildItem.java +++ b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/RecorderBeanInitializedBuildItem.java @@ -4,7 +4,17 @@ /** * Marker build item to indicate that a build step initializes a CDI bean "manually" through a - * {@link io.quarkus.runtime.annotations.Recorder} + * {@link io.quarkus.runtime.annotations.Recorder}. + *

+ * A build step does not necessarily need to create an instance of this build item, declaring a + * {@code BuildProducer} parameter is enough. + *

+ * If a build step consumes a {@code List} parameter then it will be executed after all build + * steps that produce this build item. + *

+ * This build item is deprecated because initialization of a bean via a recorder method is considered a bad practice. Extension + * authors are encouraged to use {@link SyntheticBeanBuildItem} instead. See https://github.com/quarkusio/quarkus/issues/24441 + * for more information. * * @deprecated use synthetic beans for bean initialization instead */ From 2f14cb51b9c49e8a98f31349de7498fe0b32e8ab Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Wed, 29 Mar 2023 13:30:07 +0200 Subject: [PATCH 5/6] ArC - make io.quarkus.arc.runtime.InterceptorBindings final --- .../java/io/quarkus/arc/runtime/InterceptorBindings.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/InterceptorBindings.java b/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/InterceptorBindings.java index 4ace62d76588f..012fc84763859 100644 --- a/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/InterceptorBindings.java +++ b/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/InterceptorBindings.java @@ -8,7 +8,11 @@ import io.quarkus.arc.AbstractAnnotationLiteral; import io.quarkus.arc.ArcInvocationContext; -public class InterceptorBindings { +/** + * + * @see ArcInvocationContext#getInterceptorBindings() + */ +public final class InterceptorBindings { @SuppressWarnings("unchecked") public static Set getInterceptorBindings(InvocationContext invocationContext) { From 06852267003826526f03eca14d9e3143f6274493 Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Wed, 29 Mar 2023 13:31:06 +0200 Subject: [PATCH 6/6] ArC - reduce the visibility of ArcContextProvider.NOOP_CONTROLLER --- .../main/java/io/quarkus/arc/runtime/InterceptorBindings.java | 2 +- .../java/io/quarkus/arc/runtime/context/ArcContextProvider.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/InterceptorBindings.java b/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/InterceptorBindings.java index 012fc84763859..6802e44cead31 100644 --- a/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/InterceptorBindings.java +++ b/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/InterceptorBindings.java @@ -9,7 +9,7 @@ import io.quarkus.arc.ArcInvocationContext; /** - * + * * @see ArcInvocationContext#getInterceptorBindings() */ public final class InterceptorBindings { diff --git a/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/context/ArcContextProvider.java b/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/context/ArcContextProvider.java index 21ee7c15e25a8..d4e5c63003aba 100644 --- a/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/context/ArcContextProvider.java +++ b/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/context/ArcContextProvider.java @@ -20,7 +20,7 @@ */ public class ArcContextProvider implements ThreadContextProvider { - protected static final ThreadContextController NOOP_CONTROLLER = new ThreadContextController() { + private static final ThreadContextController NOOP_CONTROLLER = new ThreadContextController() { @Override public void endContext() throws IllegalStateException { }