1212
1313@ SuppressWarnings ("unused" )
1414public class RuntimeReflectionRegistrationFeature implements Feature {
15+ private static final String [] SKIP_CLASS_NAMES = {
16+ "oracle.dbtools.util.Closeables" ,
17+ };
1518
16- private static void register (String classNamePrefix , ClassLoader classLoader ) {
17- Reflections reflections = new Reflections (classNamePrefix );
19+ private static void register (String packageName , boolean includeSubPackages , ClassLoader classLoader ) {
20+ Reflections reflections = new Reflections (packageName );
1821 Set <String > allClassNames = reflections .getAll (Scanners .SubTypes );
1922 // allClassNames contains also inner classes
2023 for (String className : allClassNames ) {
21- registerClass (className , classLoader );
24+ if (className .startsWith ((packageName ))) {
25+ if (includeSubPackages || (!className .substring (packageName .length () + 1 ).contains ("." ))) {
26+ if (validClass (className )) {
27+ registerClass (className , classLoader );
28+ }
29+ }
30+ }
31+ }
32+ }
33+
34+ private static boolean validClass (String className ) {
35+ for (String skipClassName : SKIP_CLASS_NAMES ) {
36+ if (className .startsWith (skipClassName )) {
37+ return false ;
38+ }
2239 }
40+ return true ;
2341 }
2442
2543 private static void registerClass (String className , ClassLoader classLoader ) {
2644 try {
27- Class <?> clazz = Class .forName (className ,false , classLoader );
45+ Class <?> clazz = Class .forName (className , false , classLoader );
2846 // calling getClass() on a clazz throws an Exception when not found on the classpath
2947 RuntimeReflection .register (clazz .getClass ());
3048 for (Constructor <?> constructor : clazz .getDeclaredConstructors ()) {
@@ -39,16 +57,15 @@ private static void registerClass(String className, ClassLoader classLoader) {
3957 } catch (Throwable t ) {
4058 // ignore
4159 }
42- }
60+ }
4361
4462 public void beforeAnalysis (BeforeAnalysisAccess access ) {
4563 ClassLoader classLoader = access .getApplicationClassLoader ();
4664 // register all classes in a package
47- register ("oracle.dbtools.app" , classLoader );
48- register ("oracle.dbtools.arbori" , classLoader );
49- register ("oracle.dbtools.parser" , classLoader );
50- register ("oracle.dbtools.raptor.utils" , classLoader );
51- register ("oracle.dbtools.util" , classLoader );
52- register ("oracle.dbtools.scripting" , classLoader );
65+ register ("oracle.dbtools.app" , true , classLoader );
66+ register ("oracle.dbtools.arbori" , true , classLoader );
67+ register ("oracle.dbtools.parser" , true , classLoader );
68+ register ("oracle.dbtools.raptor" , false , classLoader );
69+ register ("oracle.dbtools.util" , true , classLoader );
5370 }
5471}
0 commit comments