diff --git a/dependencies/pom.xml b/dependencies/pom.xml index ce2b686630e..b70fb91d890 100644 --- a/dependencies/pom.xml +++ b/dependencies/pom.xml @@ -106,9 +106,10 @@ 2.10 1.13.4 1.13.4 - 3.8.7 - 3.4.3 - 4.8.0 + 4.2.2 + 4.2.0 + 4.4.1 + 5.4.0 3.1 4.0.2 @@ -1083,45 +1084,22 @@ io.micronaut micronaut-inject ${version.lib.micronaut} - - - javax.annotation - javax.annotation-api - - - javax.inject - javax.inject - - io.micronaut micronaut-core ${version.lib.micronaut} - - - javax.annotation - javax.annotation-api - - - javax.inject - javax.inject - - - com.github.spotbugs - spotbugs-annotations - - - com.google.code.findbugs - jsr305 - - io.micronaut micronaut-aop ${version.lib.micronaut} + + io.micronaut + micronaut-core-processor + ${version.lib.micronaut} + org.neo4j.driver @@ -1158,20 +1136,19 @@ ${version.lib.activemq} - io.micronaut + io.micronaut.validation micronaut-validation - ${version.lib.micronaut} + ${version.lib.micronaut.validation} + + + io.micronaut.validation + micronaut-validation-processor + ${version.lib.micronaut.validation} io.micronaut micronaut-runtime ${version.lib.micronaut} - - - javax.validation - validation-api - - io.micronaut.sql diff --git a/integrations/micronaut/cdi-processor/pom.xml b/integrations/micronaut/cdi-processor/pom.xml index 77b27d0a0bc..04b66f38ac7 100644 --- a/integrations/micronaut/cdi-processor/pom.xml +++ b/integrations/micronaut/cdi-processor/pom.xml @@ -34,22 +34,32 @@ io.micronaut micronaut-inject-java + provided io.micronaut micronaut-inject + provided io.micronaut micronaut-core + provided + + + io.micronaut + micronaut-core-processor + provided jakarta.inject jakarta.inject-api + provided jakarta.annotation jakarta.annotation-api + provided @@ -62,6 +72,14 @@ -proc:none + + + io.helidon.build-tools + helidon-services-plugin + + false + + diff --git a/integrations/micronaut/cdi-processor/src/main/java/module-info.java b/integrations/micronaut/cdi-processor/src/main/java/module-info.java deleted file mode 100644 index 5086cbd01b8..00000000000 --- a/integrations/micronaut/cdi-processor/src/main/java/module-info.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2020, 2023 Oracle and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Micronaut integration with CDI - annotation processor for Micronaut. - */ -@SuppressWarnings({ "requires-automatic", "requires-transitive-automatic" }) -module io.helidon.integrations.micronaut.cdi.processor { - - requires jakarta.inject; - - requires transitive io.micronaut.core; - requires transitive io.micronaut.inject; - - provides io.micronaut.inject.annotation.AnnotationTransformer with - io.helidon.integrations.micronaut.cdi.processor.ApplicationScopedTransformer, - io.helidon.integrations.micronaut.cdi.processor.RequestScopedTransformer, - io.helidon.integrations.micronaut.cdi.processor.DependentTransformer; - -} diff --git a/integrations/micronaut/cdi-processor/src/main/resources/META-INF/services/io.micronaut.inject.annotation.AnnotationTransformer b/integrations/micronaut/cdi-processor/src/main/resources/META-INF/services/io.micronaut.inject.annotation.AnnotationTransformer new file mode 100644 index 00000000000..d2052b72ba4 --- /dev/null +++ b/integrations/micronaut/cdi-processor/src/main/resources/META-INF/services/io.micronaut.inject.annotation.AnnotationTransformer @@ -0,0 +1,19 @@ +# +# Copyright (c) 2024, 2025 Oracle and/or its affiliates. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +io.helidon.integrations.micronaut.cdi.processor.ApplicationScopedTransformer +io.helidon.integrations.micronaut.cdi.processor.RequestScopedTransformer +io.helidon.integrations.micronaut.cdi.processor.DependentTransformer \ No newline at end of file diff --git a/integrations/micronaut/cdi/pom.xml b/integrations/micronaut/cdi/pom.xml index c14b9ba3997..e89f1342d18 100644 --- a/integrations/micronaut/cdi/pom.xml +++ b/integrations/micronaut/cdi/pom.xml @@ -35,10 +35,6 @@ jakarta.enterprise jakarta.enterprise.cdi-api - - io.micronaut - micronaut-inject-java - io.micronaut micronaut-inject @@ -116,9 +112,14 @@ io.micronaut - micronaut-validation + micronaut-core-processor ${version.lib.micronaut} + + io.micronaut.validation + micronaut-validation-processor + ${version.lib.micronaut.validation} + io.micronaut.data micronaut-data-processor @@ -140,9 +141,9 @@ ${version.lib.micronaut} - io.micronaut - micronaut-validation - ${version.lib.micronaut} + io.micronaut.validation + micronaut-validation-processor + ${version.lib.micronaut.validation} io.micronaut.data diff --git a/integrations/micronaut/cdi/src/main/java/io/helidon/integrations/micronaut/cdi/CdiExecutableMethod.java b/integrations/micronaut/cdi/src/main/java/io/helidon/integrations/micronaut/cdi/CdiExecutableMethod.java index 7f9a702c5f8..9793a90639e 100644 --- a/integrations/micronaut/cdi/src/main/java/io/helidon/integrations/micronaut/cdi/CdiExecutableMethod.java +++ b/integrations/micronaut/cdi/src/main/java/io/helidon/integrations/micronaut/cdi/CdiExecutableMethod.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021 Oracle and/or its affiliates. + * Copyright (c) 2020, 2025 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ import java.lang.annotation.Annotation; import java.lang.annotation.Documented; -import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.Target; import java.lang.reflect.Array; @@ -208,11 +207,6 @@ private static void processAnnotations(Map, Annotati Map, Annotation> stereotypeMap, Map> annotationsByStereotype) { for (var entry : declaredAnnotations.entrySet()) { - if (stereotypeMap.containsKey(Repeatable.class)) { - // I need to ignore this (used only when there is just one repetition) - // this gets processed as part of the Repeatable container - continue; - } String annotName = entry.getKey().getName(); miAnnotations.put(annotName, annotationValues(entry.getValue())); Set stereotypes = getStereotypes(entry.getValue()); diff --git a/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/CounterCdiIntercepted.java b/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/CounterCdiIntercepted.java new file mode 100644 index 00000000000..041cbd99cea --- /dev/null +++ b/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/CounterCdiIntercepted.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024, 2025 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.helidon.integrations.micronaut.cdi; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import jakarta.interceptor.InterceptorBinding; + +@InterceptorBinding +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD}) +@Repeatable(CounterCdiIntercepted.List.class) +public @interface CounterCdiIntercepted { + + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.TYPE, ElementType.METHOD}) + public @interface List { + CounterCdiIntercepted[] value(); + } + +} diff --git a/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/CounterCdiInterceptor.java b/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/CounterCdiInterceptor.java new file mode 100644 index 00000000000..e2d26e53ca2 --- /dev/null +++ b/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/CounterCdiInterceptor.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024, 2025 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.helidon.integrations.micronaut.cdi; + +import java.util.concurrent.atomic.AtomicInteger; + +import jakarta.enterprise.context.Dependent; +import jakarta.interceptor.AroundInvoke; +import jakarta.interceptor.Interceptor; +import jakarta.interceptor.InvocationContext; + +@Interceptor +@CounterCdiIntercepted +@Dependent +public class CounterCdiInterceptor { + + static final AtomicInteger counter = new AtomicInteger(0); + + @AroundInvoke + private Object aroundMethod(InvocationContext context) throws Exception { + counter.incrementAndGet(); + return context.proceed(); + } +} \ No newline at end of file diff --git a/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/CounterMicronautIntercepted.java b/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/CounterMicronautIntercepted.java new file mode 100644 index 00000000000..49a7cd019cf --- /dev/null +++ b/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/CounterMicronautIntercepted.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024, 2025 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.helidon.integrations.micronaut.cdi; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import io.micronaut.aop.Around; +import io.micronaut.context.annotation.Type; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD}) +@Around +@Type(CounterMicronautInterceptor.class) +@Repeatable(CounterMicronautIntercepted.List.class) +public @interface CounterMicronautIntercepted { + + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.TYPE, ElementType.METHOD}) + public @interface List { + CounterMicronautIntercepted[] value(); + } + +} diff --git a/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/CounterMicronautInterceptor.java b/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/CounterMicronautInterceptor.java new file mode 100644 index 00000000000..d411d87c097 --- /dev/null +++ b/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/CounterMicronautInterceptor.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024, 2025 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.helidon.integrations.micronaut.cdi; + +import java.util.concurrent.atomic.AtomicInteger; + +import io.micronaut.aop.MethodInterceptor; +import io.micronaut.aop.MethodInvocationContext; +import jakarta.inject.Singleton; + +@Singleton +public class CounterMicronautInterceptor implements MethodInterceptor { + + static final AtomicInteger counter = new AtomicInteger(0); + + @Override + public Object intercept(MethodInvocationContext context) { + counter.incrementAndGet(); + return context.proceed(); + } +} \ No newline at end of file diff --git a/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/RepeatableCdiBean.java b/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/RepeatableCdiBean.java new file mode 100644 index 00000000000..7d98c89a863 --- /dev/null +++ b/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/RepeatableCdiBean.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024, 2025 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.helidon.integrations.micronaut.cdi; + +import jakarta.enterprise.context.ApplicationScoped; + +@ApplicationScoped +public class RepeatableCdiBean { + + @CounterCdiIntercepted + public String get() { + return "whatever"; + } + +} diff --git a/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/RepeatableMicronautBean.java b/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/RepeatableMicronautBean.java new file mode 100644 index 00000000000..3255a2a3727 --- /dev/null +++ b/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/RepeatableMicronautBean.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024, 2025 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.helidon.integrations.micronaut.cdi; + +@MicronautBeanDef +public class RepeatableMicronautBean { + + @CounterMicronautIntercepted + public String get() { + return "whatever"; + } + +} diff --git a/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/RepeatableTest.java b/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/RepeatableTest.java new file mode 100644 index 00000000000..6cba3251a37 --- /dev/null +++ b/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/RepeatableTest.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024, 2025 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.helidon.integrations.micronaut.cdi; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +import io.helidon.microprofile.testing.junit5.HelidonTest; + +import jakarta.inject.Inject; +import org.junit.jupiter.api.Test; + +@HelidonTest +class RepeatableTest { + + @Inject + private RepeatableCdiBean repeatableCdiBean; + @Inject + private RepeatableMicronautBean repeatableMicronautBean; + + @Test + void testCdiInvocationCounter() { + repeatableCdiBean.get(); + // Verify it is not invoked more than 1 time + assertThat(CounterCdiInterceptor.counter.get(), is(1)); + } + + @Test + void testMicronautInvocationCounter() { + repeatableMicronautBean.get(); + // Verify it is not invoked more than 1 time + assertThat(CounterCdiInterceptor.counter.get(), is(1)); + } +} diff --git a/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/TestBothBean.java b/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/TestBothBean.java index 6f6227ada22..8655628fe56 100644 --- a/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/TestBothBean.java +++ b/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/TestBothBean.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021 Oracle and/or its affiliates. + * Copyright (c) 2020, 2025 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,28 @@ @ApplicationScoped @MicronautBeanDef public class TestBothBean implements TestBean { + @Override public String name() { return "BothBean"; } + + @CdiIntercepted + @Override + public String cdiAnnotated() { + return TestBean.super.cdiAnnotated(); + } + + @MicroIntercepted + @Override + public String µAnnotated() { + return TestBean.super.µAnnotated(); + } + + @CdiIntercepted + @MicroIntercepted + @Override + public String bothAnnotated() { + return TestBean.super.bothAnnotated(); + } } diff --git a/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/TestCdiBean.java b/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/TestCdiBean.java index de472b8517f..b6f58cddfb4 100644 --- a/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/TestCdiBean.java +++ b/integrations/micronaut/cdi/src/test/java/io/helidon/integrations/micronaut/cdi/TestCdiBean.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021 Oracle and/or its affiliates. + * Copyright (c) 2020, 2025 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,25 @@ @ApplicationScoped public class TestCdiBean implements TestBean { + @CdiIntercepted + @Override + public String cdiAnnotated() { + return TestBean.super.cdiAnnotated(); + } + + @MicroIntercepted + @Override + public String µAnnotated() { + return TestBean.super.µAnnotated(); + } + + @CdiIntercepted + @MicroIntercepted + @Override + public String bothAnnotated() { + return TestBean.super.bothAnnotated(); + } + @Override public String name() { return "CdiBean"; diff --git a/integrations/micronaut/cdi/src/test/resources/META-INF/beans.xml b/integrations/micronaut/cdi/src/test/resources/META-INF/beans.xml index eb02f0d1c2b..f52bbbd1bc7 100644 --- a/integrations/micronaut/cdi/src/test/resources/META-INF/beans.xml +++ b/integrations/micronaut/cdi/src/test/resources/META-INF/beans.xml @@ -1,7 +1,7 @@