Skip to content

Commit 064a892

Browse files
author
Stefan Kapferer
authored
Update reflections library (#15)
1 parent 5c82823 commit 064a892

File tree

2 files changed

+13
-30
lines changed

2 files changed

+13
-30
lines changed

gradle.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ ossReleaseStagingRepository=https://oss.sonatype.org/service/local/staging/deplo
44

55
# dependency versions
66
jUnitVersion=5.5.2
7-
cmlVersion=6.3.0
8-
reflectionsVersion=0.9.12
9-
springBootVersion=2.2.0.RELEASE
10-
springWebVersion=5.2.0.RELEASE
7+
cmlVersion=6.6.1
8+
reflectionsVersion=0.10.2
9+
springBootVersion=2.6.4
10+
springWebVersion=5.3.16
1111
commonsLangVersion=3.9
1212
commonsIOVersion=2.6
1313
snakeYMLVersion=1.25

src/main/java/org/contextmapper/discovery/strategies/helper/AnnotationScanner.java

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,18 @@
1515
*/
1616
package org.contextmapper.discovery.strategies.helper;
1717

18-
import org.reflections.Configuration;
1918
import org.reflections.Reflections;
20-
import org.reflections.ReflectionsException;
21-
import org.reflections.Store;
22-
import org.reflections.scanners.MethodAnnotationsScanner;
23-
import org.reflections.scanners.Scanner;
24-
import org.reflections.scanners.SubTypesScanner;
25-
import org.reflections.scanners.TypeAnnotationsScanner;
2619
import org.reflections.util.ClasspathHelper;
2720
import org.reflections.util.ConfigurationBuilder;
2821
import org.reflections.util.FilterBuilder;
29-
import org.slf4j.Logger;
3022

3123
import java.lang.annotation.Annotation;
3224
import java.lang.reflect.Method;
3325
import java.util.HashSet;
3426
import java.util.Set;
3527
import java.util.stream.Collectors;
3628

37-
import static org.reflections.util.Utils.findLogger;
29+
import static org.reflections.scanners.Scanners.*;
3830

3931
/**
4032
* Provides methods for annotation scanning.
@@ -43,8 +35,6 @@
4335
*/
4436
public class AnnotationScanner {
4537

46-
public static Logger log = findLogger(AnnotationScanner.class);
47-
4838
/**
4939
* Finds all types within a package annotated with a given annotation.
5040
*
@@ -53,7 +43,7 @@ public class AnnotationScanner {
5343
* @return the set of types within the given package which are annotated with the given annotation
5444
*/
5545
public Set<Class<?>> scanForAnnotatedType(String packageName, Class<? extends Annotation> annotation) {
56-
Reflections reflections = new Reflections(packageName, new SubTypesScanner(false), new TypeAnnotationsScanner());
46+
Reflections reflections = new Reflections(packageName);
5747
return reflections.getTypesAnnotatedWith(annotation);
5848
}
5949

@@ -66,20 +56,13 @@ public Set<Class<?>> scanForAnnotatedType(String packageName, Class<? extends An
6656
*/
6757
public Set<Method> scanForAnnotatedMethods(Class<?> type, Class<? extends Annotation>... annotations) {
6858
Set<Method> methods = new HashSet<>();
69-
try {
70-
Reflections reflections = new Reflections(new ConfigurationBuilder()
71-
.setUrls(ClasspathHelper.forClass(type))
72-
.setScanners(new SubTypesScanner(), new TypeAnnotationsScanner(), new MethodAnnotationsScanner())
73-
.filterInputsBy(new FilterBuilder().includePackage(type))
74-
);
75-
for (Class<? extends Annotation> annotation : annotations) {
76-
methods.addAll(reflections.getMethodsAnnotatedWith(annotation));
77-
}
78-
} catch (ReflectionsException e) {
79-
// unfortunately the reflections library in version 0.9.12 (needed for Java 11) throws an exception if nothing is found
80-
// just log errors here for now; should no longer be needed to catch this when the following issue is fixed:
81-
// https://github.com/ronmamo/reflections/issues/273
82-
log.error(e.getMessage());
59+
Reflections reflections = new Reflections(new ConfigurationBuilder()
60+
.setUrls(ClasspathHelper.forClass(type))
61+
.setScanners(TypesAnnotated, MethodsAnnotated, MethodsReturn)
62+
.filterInputsBy(new FilterBuilder().includePackage(type.getPackageName()))
63+
);
64+
for (Class<? extends Annotation> annotation : annotations) {
65+
methods.addAll(reflections.getMethodsAnnotatedWith(annotation));
8366
}
8467
return methods.stream().filter(m -> m.getDeclaringClass().equals(type)).collect(Collectors.toSet());
8568
}

0 commit comments

Comments
 (0)