refactor(common-logging): remove `Reflections` library, replace with `classgraph` library.
Reflections library was causing various issues, varying from incompatibilities with newer versions
of Java, through to silent errors in the case of certain exceptions (which was breaking logging
discovery).
MODIFY
common/logging/core/pom.xml
common/logging/core/pom.xml
<dependencies>
<dependency>
- <groupId>org.reflections</groupId>
- <artifactId>reflections</artifactId>
+ <groupId>io.github.classgraph</groupId>
+ <artifactId>classgraph</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>

MODIFY
common/logging/core/src/main/java/io/apiman/common/logging/ApimanLoggerFactoryRegistry.java
common/logging/core/src/main/java/io/apiman/common/logging/ApimanLoggerFactoryRegistry.java
@@ -20,9 +20,11 @@ import io.apiman.common.logging.impl.SoutDelegateFactory;
import java.util.HashMap;
import java.util.Map;
-import java.util.Set;
-import org.reflections.Reflections;
+import io.github.classgraph.AnnotationInfo;
+import io.github.classgraph.ClassGraph;
+import io.github.classgraph.ClassInfo;
+import io.github.classgraph.ScanResult;
/**
* Registry of Apiman Logger Factories.
@@ -48,20 +50,23 @@ public class ApimanLoggerFactoryRegistry {
}
private static void resolveAllImplementations() {
- Reflections reflection = new Reflections("io.apiman.common.logging");
- Set<Class<?>> loggerFactories = reflection.getTypesAnnotatedWith(ApimanLoggerFactory.class);
-
- for (Class<?> loggerFactory : loggerFactories) {
+ try (ScanResult scanResult = new ClassGraph()
+ .enableAnnotationInfo()
+ .enableClassInfo()
+ .acceptPackages("io.apiman.common.logging")
+ .scan()) {
+ for (ClassInfo loggerFactoryKlazz : scanResult.getClassesWithAnnotation(ApimanLoggerFactory.class)) {
+ AnnotationInfo loggerFactoryAnno = loggerFactoryKlazz.getAnnotationInfo(ApimanLoggerFactory.class);
+ // Only have 1 required param.
+ String name = (String) loggerFactoryAnno.getParameterValues().get(0).getValue();
try {
- IDelegateFactory instance = (IDelegateFactory) loggerFactory.newInstance();
- String name = loggerFactory.getAnnotation(ApimanLoggerFactory.class).value();
- DELEGATE_FACTORY_MAP.put(name, instance);
- // System.err.println("Logger registered: " + name);
+ DELEGATE_FACTORY_MAP.put(name, (IDelegateFactory) loggerFactoryKlazz.loadClass().newInstance());
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
+ }
/**
* Register a logger factory implementation. Last in wins in case of collision.

MODIFY
parent/pom.xml
parent/pom.xml
<version.org.mapstruct>1.4.2.Final</version.org.mapstruct>
<version.org.mvel>2.4.12.Final</version.org.mvel>
<version.org.picketbox>5.1.0.Final</version.org.picketbox>
- <version.org.reflections>0.9.11</version.org.reflections>
+ <version.io.github.classgraph>4.8.149</version.io.github.classgraph>
<version.org.slf4j>1.7.36</version.org.slf4j>
<version.org.testcontainers>1.17.3</version.org.testcontainers>
<version.io.apicurio>1.1.26</version.io.apicurio>
<artifactId>commons-codec</artifactId>
<version>${version.commons-codec}</version>
</dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>${version.org.slf4j}</version>
- </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${version.com.jcbai}</version>
</dependency>
<dependency>
- <groupId>org.reflections</groupId>
- <artifactId>reflections</artifactId>
- <version>${version.org.reflections}</version>
+ <groupId>io.github.classgraph</groupId>
+ <artifactId>classgraph</artifactId>
+ <version>${version.io.github.classgraph}</version>
</dependency>
<dependency>
<groupId>com.github.seancfoley</groupId>

refactor(common-logging): remove `Reflections` library, replace with `classgraph` library.

Reflections library was causing various issues, varying from incompatibilities with newer versions
of Java, through to silent errors in the case of certain exceptions (which was breaking logging
discovery).