From bfa8d4b920fd3f8317a280dd25235c5435c33ec3 Mon Sep 17 00:00:00 2001 From: Jorge Bescos Gascon Date: Thu, 10 Oct 2024 10:24:39 +0200 Subject: [PATCH] Working in general solution Signed-off-by: Jorge Bescos Gascon --- dependencies/pom.xml | 4 +-- microprofile/graphql/server/pom.xml | 8 ----- .../microprofile/lra/InspectionService.java | 5 +-- .../microprofile/lra/LraCdiExtension.java | 36 ++++++++++++++----- .../lra/ParticipantValidationModel.java | 4 +-- pom.xml | 7 ++++ 6 files changed, 41 insertions(+), 23 deletions(-) diff --git a/dependencies/pom.xml b/dependencies/pom.xml index 095d2a904c3..cd83e9b9d24 100644 --- a/dependencies/pom.xml +++ b/dependencies/pom.xml @@ -87,7 +87,7 @@ 2.1.1 3.0.1 - 2.4.3.Final + 3.0.8 3.0.2 3.0.2 1.2.5.Final @@ -148,7 +148,7 @@ 42.4.4 0.9.0 2.0.9 - 2.1.16 + 2.1.24 2.2 1.4.2 2.1.5 diff --git a/microprofile/graphql/server/pom.xml b/microprofile/graphql/server/pom.xml index bc63e63a975..95b0c30d001 100644 --- a/microprofile/graphql/server/pom.xml +++ b/microprofile/graphql/server/pom.xml @@ -82,14 +82,6 @@ org.jboss.jandex jandex-maven-plugin - - - - org.jboss - jandex - 3.1.8 - - make-index diff --git a/microprofile/lra/jax-rs/src/main/java/io/helidon/microprofile/lra/InspectionService.java b/microprofile/lra/jax-rs/src/main/java/io/helidon/microprofile/lra/InspectionService.java index 8c8803b11d9..e0ae1bb2612 100644 --- a/microprofile/lra/jax-rs/src/main/java/io/helidon/microprofile/lra/InspectionService.java +++ b/microprofile/lra/jax-rs/src/main/java/io/helidon/microprofile/lra/InspectionService.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Oracle and/or its affiliates. + * Copyright (c) 2022, 2024 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. @@ -155,11 +155,12 @@ Set lookUpLraAnnotations(Method method) { Set lookUpLraAnnotations(MethodInfo methodInfo) { Map annotations = new HashMap<>(); + Type[] types = methodInfo.parameters().stream().map(param -> param.type()).toArray(Type[]::new); deepScanLraMethod( methodInfo.declaringClass(), annotations, methodInfo.name(), - methodInfo.parameters().toArray(new Type[0]) + types ); HashSet result = new HashSet<>(annotations.values()); diff --git a/microprofile/lra/jax-rs/src/main/java/io/helidon/microprofile/lra/LraCdiExtension.java b/microprofile/lra/jax-rs/src/main/java/io/helidon/microprofile/lra/LraCdiExtension.java index 34f389dc771..4ea2956cfcf 100644 --- a/microprofile/lra/jax-rs/src/main/java/io/helidon/microprofile/lra/LraCdiExtension.java +++ b/microprofile/lra/jax-rs/src/main/java/io/helidon/microprofile/lra/LraCdiExtension.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Oracle and/or its affiliates. + * Copyright (c) 2021, 2024 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. @@ -25,6 +25,7 @@ import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -69,6 +70,7 @@ import org.jboss.jandex.ClassInfo; import org.jboss.jandex.CompositeIndex; import org.jboss.jandex.DotName; +import org.jboss.jandex.Index; import org.jboss.jandex.IndexReader; import org.jboss.jandex.IndexView; import org.jboss.jandex.Indexer; @@ -94,7 +96,8 @@ public class LraCdiExtension implements Extension { private final Set> beanTypesWithCdiLRAMethods = new HashSet<>(); private final Map, Bean> lraCdiBeanReferences = new HashMap<>(); - private final Indexer indexer; + // Do not clear indexes. #index requires a strong reference to these. + private final List indexes = new LinkedList<>(); private final ClassLoader classLoader; private IndexView index; @@ -103,7 +106,6 @@ public class LraCdiExtension implements Extension { * Initialize MicroProfile Long Running Actions CDI extension. */ public LraCdiExtension() { - indexer = new Indexer(); classLoader = Thread.currentThread().getContextClassLoader(); // Needs to be always indexed Set.of(LRA.class, @@ -119,7 +121,9 @@ public LraCdiExtension() { try { indexFiles = findIndexFiles("META-INF/jandex.idx"); if (!indexFiles.isEmpty()) { - index = CompositeIndex.create(indexer.complete(), existingIndexFileReader(indexFiles)); + indexes.add(existingIndexFileReader(indexFiles)); + index = CompositeIndex.create(indexes); + logIndexedClasses(index); } else { index = null; } @@ -137,7 +141,8 @@ private void index( LRA.class, AfterLRA.class, Compensate.class, Complete.class, Forget.class, Status.class }) ProcessAnnotatedType pat) { - // compile time bilt index + // compile time built index + // If META-INF/jandex.idx exists we don't explore more if (index != null) return; // create runtime index when pre-built index is not available runtimeIndex(DotName.createSimple(pat.getAnnotatedType().getJavaClass().getName())); @@ -227,7 +232,8 @@ private void ready( if (index == null) { // compile time built index - index = indexer.complete(); + index = CompositeIndex.create(indexes); + logIndexedClasses(index); } // ------------- Validate LRA participant methods ------------- @@ -255,13 +261,16 @@ Map, Bean> lraCdiBeanReferences() { void runtimeIndex(DotName fqdn) { if (fqdn == null) return; LOGGER.fine("Indexing " + fqdn); - ClassInfo classInfo; try { - classInfo = indexer.index(classLoader.getResourceAsStream(fqdn.toString().replace('.', '/') + ".class")); + Indexer newIndexer = new Indexer(); + newIndexer.index(classLoader.getResourceAsStream(fqdn.toString().replace('.', '/') + ".class")); + Index index = newIndexer.complete(); + indexes.add(index); + ClassInfo classInfo = index.getClassByName(fqdn); // look also for extended classes runtimeIndex(classInfo.superName()); // and implemented interfaces - classInfo.interfaceNames().forEach(this::runtimeIndex); + classInfo.interfaceNames().forEach(dotName -> runtimeIndex(dotName)); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Unable to index referenced class.", e); } @@ -313,4 +322,13 @@ static T lookup(Bean bean, BeanManager beanManager) { } return (T) instance; } + + private void logIndexedClasses(IndexView index) { + if (LOGGER.isLoggable(Level.FINE)) { + LOGGER.fine(index.getKnownClasses().size()+ " indexed classes."); + index.getKnownClasses().forEach(classInfo -> { + LOGGER.fine("Indexed class - " + classInfo.name().toString()); + }); + } + } } diff --git a/microprofile/lra/jax-rs/src/main/java/io/helidon/microprofile/lra/ParticipantValidationModel.java b/microprofile/lra/jax-rs/src/main/java/io/helidon/microprofile/lra/ParticipantValidationModel.java index 6ce5637f939..f5263454dc7 100644 --- a/microprofile/lra/jax-rs/src/main/java/io/helidon/microprofile/lra/ParticipantValidationModel.java +++ b/microprofile/lra/jax-rs/src/main/java/io/helidon/microprofile/lra/ParticipantValidationModel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Oracle and/or its affiliates. + * Copyright (c) 2021, 2024 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. @@ -155,7 +155,7 @@ private static class ParticipantMethod { String nameWithParams() { return methodInfo.name() + methodInfo.parameters().stream() - .map(Type::name) + .map(paramInfo -> paramInfo.type().name()) .map(DotName::toString) .collect(Collectors.joining()); } diff --git a/pom.xml b/pom.xml index 683d5a2515c..10c4222f143 100644 --- a/pom.xml +++ b/pom.xml @@ -465,6 +465,13 @@ org.jboss.jandex jandex-maven-plugin ${version.plugin.jandex} + + + org.jboss + jandex + 3.1.8 + + org.apache.maven.plugins