Skip to content

Commit

Permalink
4.x: Fix Micronaut integration (helidon-io#8230)
Browse files Browse the repository at this point in the history
Fix Micronaut integration

Signed-off-by: Jorge Bescos Gascon <[email protected]>
  • Loading branch information
jbescos authored Feb 12, 2025
1 parent ffddb31 commit 6528b37
Show file tree
Hide file tree
Showing 18 changed files with 377 additions and 96 deletions.
55 changes: 16 additions & 39 deletions dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@
<version.lib.maven-wagon>2.10</version.lib.maven-wagon>
<version.lib.micrometer>1.13.4</version.lib.micrometer>
<version.lib.micrometer-prometheus>1.13.4</version.lib.micrometer-prometheus>
<version.lib.micronaut>3.8.7</version.lib.micronaut>
<version.lib.micronaut.data>3.4.3</version.lib.micronaut.data>
<version.lib.micronaut.sql>4.8.0</version.lib.micronaut.sql>
<version.lib.micronaut>4.2.2</version.lib.micronaut>
<version.lib.micronaut.validation>4.2.0</version.lib.micronaut.validation>
<version.lib.micronaut.data>4.4.1</version.lib.micronaut.data>
<version.lib.micronaut.sql>5.4.0</version.lib.micronaut.sql>
<version.lib.microprofile-config>3.1</version.lib.microprofile-config>
<!-- FIXME upgrade to 4.1 when it is released in Maven -->
<version.lib.microprofile-fault-tolerance-api>4.0.2</version.lib.microprofile-fault-tolerance-api>
Expand Down Expand Up @@ -1083,45 +1084,22 @@
<groupId>io.micronaut</groupId>
<artifactId>micronaut-inject</artifactId>
<version>${version.lib.micronaut}</version>
<exclusions>
<exclusion>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</exclusion>
<exclusion>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-core</artifactId>
<version>${version.lib.micronaut}</version>
<exclusions>
<exclusion>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</exclusion>
<exclusion>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</exclusion>
<exclusion>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-aop</artifactId>
<version>${version.lib.micronaut}</version>
</dependency>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-core-processor</artifactId>
<version>${version.lib.micronaut}</version>
</dependency>
<!-- Neo4j -->
<dependency>
<groupId>org.neo4j.driver</groupId>
Expand Down Expand Up @@ -1158,20 +1136,19 @@
<version>${version.lib.activemq}</version>
</dependency>
<dependency>
<groupId>io.micronaut</groupId>
<groupId>io.micronaut.validation</groupId>
<artifactId>micronaut-validation</artifactId>
<version>${version.lib.micronaut}</version>
<version>${version.lib.micronaut.validation}</version>
</dependency>
<dependency>
<groupId>io.micronaut.validation</groupId>
<artifactId>micronaut-validation-processor</artifactId>
<version>${version.lib.micronaut.validation}</version>
</dependency>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-runtime</artifactId>
<version>${version.lib.micronaut}</version>
<exclusions>
<exclusion>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.micronaut.sql</groupId>
Expand Down
18 changes: 18 additions & 0 deletions integrations/micronaut/cdi-processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,32 @@
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-inject-java</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-inject</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-core-processor</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

Expand All @@ -62,6 +72,14 @@
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>
<!-- https://github.com/micronaut-projects/micronaut-core/issues/10299 -->
<plugin>
<groupId>io.helidon.build-tools</groupId>
<artifactId>helidon-services-plugin</artifactId>
<configuration>
<failOnMissingModuleInfo>false</failOnMissingModuleInfo>
</configuration>
</plugin>
</plugins>
</build>
</project>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
17 changes: 9 additions & 8 deletions integrations/micronaut/cdi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
</dependency>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-inject-java</artifactId>
</dependency>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-inject</artifactId>
Expand Down Expand Up @@ -116,9 +112,14 @@
</path>
<path>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-validation</artifactId>
<artifactId>micronaut-core-processor</artifactId>
<version>${version.lib.micronaut}</version>
</path>
<path>
<groupId>io.micronaut.validation</groupId>
<artifactId>micronaut-validation-processor</artifactId>
<version>${version.lib.micronaut.validation}</version>
</path>
<path>
<groupId>io.micronaut.data</groupId>
<artifactId>micronaut-data-processor</artifactId>
Expand All @@ -140,9 +141,9 @@
<version>${version.lib.micronaut}</version>
</dependency>
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-validation</artifactId>
<version>${version.lib.micronaut}</version>
<groupId>io.micronaut.validation</groupId>
<artifactId>micronaut-validation-processor</artifactId>
<version>${version.lib.micronaut.validation}</version>
</dependency>
<dependency>
<groupId>io.micronaut.data</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -208,11 +207,6 @@ private static void processAnnotations(Map<Class<? extends Annotation>, Annotati
Map<Class<? extends Annotation>, Annotation> stereotypeMap,
Map<String, Set<String>> 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<Annotation> stereotypes = getStereotypes(entry.getValue());
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}

}
Loading

0 comments on commit 6528b37

Please sign in to comment.