Implement loading ClassLoaderHandler from Java’s ServiceLoader.#266
Conversation
This commit adds loading of additional ClassLoaderHandler from Java’s Serviceloader SPI. The default list of handlers is now created in a static initializer block and than supplemented by a list of dynamically loaded handlers. To use the the handlers from the SPI, ClassLoaderHandlerRegistryEntry had to have a new constructor, taking, taking in the pre populated handler.
|
Great contribution, thanks! Looks good to me. Yes, it looks like the ability to register custom What I just barely pushed out a new version of ClassGraph an hour ago, so I might wait to push this out as a new version until I have some other things to release as well, but let me know if you need a release with any urgency. Glad to know Neo4j-OGM is getting some good use out of FastClasspathScanner/ClassGraph! The upgrade to ClassGraph will be worth the effort, it is significantly more robust, capable, optimized, and futureproof (e.g. supporting JPMS) compared to FCS. |
|
Wow, that was fast! Thanks a lot! And yes, I'd like to see another class loader handler, for Spring Boots Devtools (See RestartClassLoader and [https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html](Spring Boot Devtools)). Our current branch using ClassGraph fails in Spring Boot Apps running Devtools when loading classes to ClassGraph. |
|
ClassGraph has support for different delegation modes (parent first or child first), but every classloader I have ever come across uses parent first delegation (for the same reason that you should never have the current directory "." in your commandline path before "/bin", "/usr/local/bin", etc.). It's possible there's some other weird or complex ordering bug in ClassGraph too -- I tried to guess the correct order for pulling paths from classloaders, but I'm sure it's not correct for every situation. It's a very simple task to write a new I know next to nothing about Spring Boot, so can't help much with the specifics of |
The
ClassLoaderHandlerpromises in it's JavaDoc that additional handlers can be loaded through the standard Java SPI. That's not the case.This PR add this feature and additionally fixes the doc. Please see the single commit message for more detail (quoted below).
All the standard handlers could maybe be loaded through the SPI as well, but to keep the order one would have to add one additional interface method and I understand ClassGraph should still support Java 7, so I didn't add a default interface method.
Also, thanks for your work on ClassGraph, we are using it in Neo4j-OGM and are currently in the process of upgrading from FastClasspathScanner code.