Skip to content

Commit

Permalink
Working in general solution
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Bescos Gascon <[email protected]>
  • Loading branch information
jbescos committed Oct 10, 2024
1 parent d248c30 commit bfa8d4b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 23 deletions.
4 changes: 2 additions & 2 deletions dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<version.lib.jakarta.websockets-api>2.1.1</version.lib.jakarta.websockets-api>
<!-- Check Hibernate when upgrading to ensure its supplied jaxb-runtime is compatible. -->
<version.lib.jakarta.xml.bind-api>3.0.1</version.lib.jakarta.xml.bind-api>
<version.lib.jandex>2.4.3.Final</version.lib.jandex>
<version.lib.jandex>3.0.8</version.lib.jandex>
<version.lib.jaxb-core>3.0.2</version.lib.jaxb-core>
<version.lib.jaxb-impl>3.0.2</version.lib.jaxb-impl>
<version.lib.jboss.classfilewriter>1.2.5.Final</version.lib.jboss.classfilewriter>
Expand Down Expand Up @@ -148,7 +148,7 @@
<version.lib.postgresql>42.4.4</version.lib.postgresql>
<version.lib.prometheus>0.9.0</version.lib.prometheus>
<version.lib.slf4j>2.0.9</version.lib.slf4j>
<version.lib.smallrye-openapi>2.1.16</version.lib.smallrye-openapi>
<version.lib.smallrye-openapi>2.1.24</version.lib.smallrye-openapi>
<version.lib.snakeyaml>2.2</version.lib.snakeyaml>
<version.lib.typesafe-config>1.4.2</version.lib.typesafe-config>
<version.lib.tyrus>2.1.5</version.lib.tyrus>
Expand Down
8 changes: 0 additions & 8 deletions microprofile/graphql/server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,6 @@
<plugin>
<groupId>org.jboss.jandex</groupId>
<artifactId>jandex-maven-plugin</artifactId>
<!-- Temporal fix meanwhile there are no newer versions of the plugin -->
<dependencies>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jandex</artifactId>
<version>3.1.8</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>make-index</id>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -155,11 +155,12 @@ Set<AnnotationInstance> lookUpLraAnnotations(Method method) {

Set<AnnotationInstance> lookUpLraAnnotations(MethodInfo methodInfo) {
Map<String, AnnotationInstance> 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<AnnotationInstance> result = new HashSet<>(annotations.values());

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -94,7 +96,8 @@ public class LraCdiExtension implements Extension {

private final Set<Class<?>> beanTypesWithCdiLRAMethods = new HashSet<>();
private final Map<Class<?>, Bean<?>> lraCdiBeanReferences = new HashMap<>();
private final Indexer indexer;
// Do not clear indexes. #index requires a strong reference to these.
private final List<IndexView> indexes = new LinkedList<>();
private final ClassLoader classLoader;
private IndexView index;

Expand All @@ -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,
Expand All @@ -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;
}
Expand All @@ -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()));
Expand Down Expand Up @@ -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 -------------
Expand Down Expand Up @@ -255,13 +261,16 @@ Map<Class<?>, 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);
}
Expand Down Expand Up @@ -313,4 +322,13 @@ static <T> 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());
});
}
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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());
}
Expand Down
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,13 @@
<groupId>org.jboss.jandex</groupId>
<artifactId>jandex-maven-plugin</artifactId>
<version>${version.plugin.jandex}</version>
<dependencies>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jandex</artifactId>
<version>3.1.8</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down

0 comments on commit bfa8d4b

Please sign in to comment.