From 0b458d05147fe788bc730afff50043c15eda15ca Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Mon, 11 Dec 2023 10:03:56 +0100 Subject: [PATCH 1/2] ArC: detect incorrect usage of javax.inject.Singleton - jakarta.inject.Singleton should be used instead --- .../arc/deployment/WrongAnnotationUsageProcessor.java | 1 + .../arc/test/wrongannotations/WrongSingletonTest.java | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/WrongAnnotationUsageProcessor.java b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/WrongAnnotationUsageProcessor.java index 5bbd2bdfcc330..3477a61bf3870 100644 --- a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/WrongAnnotationUsageProcessor.java +++ b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/WrongAnnotationUsageProcessor.java @@ -44,6 +44,7 @@ void detect(ArcConfig config, ApplicationIndexBuildItem applicationIndex, Custom unsupported.add(new UnsupportedAnnotation("com.google.inject.Singleton", correctSingleton)); unsupported.add(new UnsupportedAnnotation("jakarta.ejb.Singleton", correctSingleton)); unsupported.add(new UnsupportedAnnotation("groovy.lang.Singleton", correctSingleton)); + unsupported.add(new UnsupportedAnnotation("javax.inject.Singleton", correctSingleton)); String correctInject = "@jakarta.inject.Inject"; unsupported.add(new UnsupportedAnnotation("javax.inject.Inject", correctInject)); diff --git a/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/wrongannotations/WrongSingletonTest.java b/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/wrongannotations/WrongSingletonTest.java index fa23c3038be6b..04bb22f7ad028 100644 --- a/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/wrongannotations/WrongSingletonTest.java +++ b/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/wrongannotations/WrongSingletonTest.java @@ -21,11 +21,12 @@ public class WrongSingletonTest { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() - .withApplicationRoot((jar) -> jar - .addClasses(EjbSingleton.class)) + .withApplicationRoot(root -> root + .addClasses(EjbSingleton.class, GuiceProducers.class, JavaxSingleton.class)) .assertException(t -> { Throwable rootCause = ExceptionUtil.getRootCause(t); assertTrue(rootCause.getMessage().contains("jakarta.ejb.Singleton"), t.toString()); + assertTrue(rootCause.getMessage().contains("javax.inject.Singleton"), t.toString()); assertTrue(rootCause.getMessage().contains("com.google.inject.Singleton"), t.toString()); }); @@ -55,4 +56,9 @@ List produceEjbSingleton() { } + @javax.inject.Singleton + static class JavaxSingleton { + + } + } From d1b359d2ad000da80134b0ea89610b9b2b139279 Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Mon, 11 Dec 2023 10:57:26 +0100 Subject: [PATCH 2/2] Fix some management tests - use the correct Singleton --- .../vertx/http/management/ManagementAndRootPathTest.java | 3 +-- .../quarkus/vertx/http/management/ManagementWithJksTest.java | 3 +-- .../http/management/ManagementWithMainServerDisabledTest.java | 3 +-- .../quarkus/vertx/http/management/ManagementWithP12Test.java | 3 +-- .../quarkus/vertx/http/management/ManagementWithPemTest.java | 3 +-- 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/management/ManagementAndRootPathTest.java b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/management/ManagementAndRootPathTest.java index 1e9fe401909c9..7fc85520f8fb3 100644 --- a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/management/ManagementAndRootPathTest.java +++ b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/management/ManagementAndRootPathTest.java @@ -2,9 +2,8 @@ import java.util.function.Consumer; -import javax.inject.Singleton; - import jakarta.enterprise.event.Observes; +import jakarta.inject.Singleton; import org.hamcrest.Matchers; import org.jboss.shrinkwrap.api.asset.StringAsset; diff --git a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/management/ManagementWithJksTest.java b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/management/ManagementWithJksTest.java index 580fd44b27066..1a0827d198fb4 100644 --- a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/management/ManagementWithJksTest.java +++ b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/management/ManagementWithJksTest.java @@ -3,9 +3,8 @@ import java.io.File; import java.util.function.Consumer; -import javax.inject.Singleton; - import jakarta.enterprise.event.Observes; +import jakarta.inject.Singleton; import org.assertj.core.api.Assertions; import org.hamcrest.Matchers; diff --git a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/management/ManagementWithMainServerDisabledTest.java b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/management/ManagementWithMainServerDisabledTest.java index 9694283a305a9..13233ae9a8203 100644 --- a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/management/ManagementWithMainServerDisabledTest.java +++ b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/management/ManagementWithMainServerDisabledTest.java @@ -2,9 +2,8 @@ import java.util.function.Consumer; -import javax.inject.Singleton; - import jakarta.enterprise.event.Observes; +import jakarta.inject.Singleton; import org.hamcrest.Matchers; import org.jboss.shrinkwrap.api.asset.StringAsset; diff --git a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/management/ManagementWithP12Test.java b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/management/ManagementWithP12Test.java index 0f730779f0856..a8e55cedb5608 100644 --- a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/management/ManagementWithP12Test.java +++ b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/management/ManagementWithP12Test.java @@ -3,9 +3,8 @@ import java.io.File; import java.util.function.Consumer; -import javax.inject.Singleton; - import jakarta.enterprise.event.Observes; +import jakarta.inject.Singleton; import org.assertj.core.api.Assertions; import org.hamcrest.Matchers; diff --git a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/management/ManagementWithPemTest.java b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/management/ManagementWithPemTest.java index ef4b24d1638a1..bc86379e35909 100644 --- a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/management/ManagementWithPemTest.java +++ b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/management/ManagementWithPemTest.java @@ -3,9 +3,8 @@ import java.io.File; import java.util.function.Consumer; -import javax.inject.Singleton; - import jakarta.enterprise.event.Observes; +import jakarta.inject.Singleton; import org.assertj.core.api.Assertions; import org.hamcrest.Matchers;