In depth look to
The ClassHunter is a component that queries the classes present in the paths received in input and returns only the classes that match a chosen criterion. The searches performed by it are executed in a multithreaded context and recursively through folders and supported compressed files (zip, jar, jmod, war and ear) and even in nested compressed files and folders. This component can cache the classes found in the class paths in order to perform the next searches faster and uses a PathScannerClassLoader which is configurable through the Java coded property ‘class-hunter.default-path-scanner-class-loader‘ of the burningwave.properties file. A Java coded property is a property made of Java code that will be resolved after its compilation at runtime. The default value of the ‘class-hunter.default-path-scanner-class-loader’ property, as you can see in the default burningwave.properties file, is the following:
class-hunter.default-path-scanner-class-loader=\ (Supplier<PathScannerClassLoader>)() -> ((ComponentSupplier)parameter[0]).getPathScannerClassLoader()
… Which means that the default class loader used by the ClassHunter is the class loader supplied by the method ‘getPathScannerClassLoader‘ of ComponentContainer. The parent class loader of this class loader can be indicated through the Java coded property ‘path-scanner-class-loader.parent‘ that has the following default value:
path-scanner-class-loader.parent=Thread.currentThread().getContextClassLoader()
…. Which means that the parent class loader is the context class loader of the current thread: this implies that if you’re scanning a path that is present in the runtime class paths, the classes used for comparison are all the loadable classes of the JVM main class loader, otherwise the classes used for comparison are all the loadable classes of the PathScannerClassLoader.
The main search configuration object is represented by the SearchConfig class to which must be (optionally) passed the paths to be scanned and (optionally too) the query criteria represented by the ClassCriteria. If no path will be passed to SearchConfig, the scan will be executed on the paths indicated by the ‘paths.hunters.default-search-config.paths’ property of the burningwave.properties file that has the following default value:
paths.hunters.default-search-config.paths=\ ${paths.main-class-paths};\ ${paths.main-class-paths.extension};\ ${paths.main-class-repositories};
… And includes the following properties:
paths.main-class-paths=\ ${system.properties:java.class.path} paths.main-class-paths.extension=\ //${system.properties:java.home}/lib//children:.*?\.jar;\ //${system.properties:java.home}/lib/ext//children:.*?\.jar;\ //${system.properties:java.home}/../lib//children:.*?\.jar; paths.main-class-repositories=\ //${system.properties:java.home}/jmods//children:.*?\.jmod;
… Which means that the scan will be executed through:
- the runtime class paths (which is indicated by the system property ‘java.class.path’)
- the direct children of the ‘lib’ folder of the jvm home that have ‘jar’ as extension
- the direct children of the ‘jmods’ folder of the jvm (9 or later) home that have ‘jmod’ as extension
If no ClassCriteria will be passed to SearchConfig object the search will be executed with no filter and all loadable classes of the paths will be returned.
BackgroundExecutor
ClassFactory
ClassHunter
- In depth look to and configuration guide
- USE CASE: how to retrieve all classes of the classpath
- USE CASE: how to retrieve all classes that implement one or more interfaces
- USE CASE: finding all classes that extend a base class
- USE CASE: how to find all classes in a package
- USE CASE: Finding all classes for module name (Java 9 and later)
- USE CASE: finding all annotated classes
- USE CASE: how to scan classes for specific annotations and collect their values
- USE CASE: how to search for all classes with a constructor that takes a specific type as first parameter and with at least 2 methods that begin for a given string
- USE CASE: how to search for all classes with methods whose name begins for a given string and that takes a specific type as its first parameter
- USE CASE: finding all classes that have at least 2 protected fields
ClassPathHunter
CodeExecutor
FileSystemItem
FunctionalInterfaceFactory
IterableObjectHelper
JavaMemoryCompiler
PropertyAccessor
UnitSourceGenerator