The ClassHunter: in depth look to and configuration guide

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.


Search configuration components


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.

Flexible

It’s possible to search classes by every criteria that your imagination can make by using lambda expressions

Optimized

Scan engine is highly optimized using direct allocated ByteBuffers to avoid heap saturation

Open

Burningwave core is an advanced free and open source Java library