Scanning for resources on the user classpath from an annotation processor
Graeme Keith Rocher
graeme.rocher at oracle.com
Wed Aug 4 07:48:41 UTC 2021
Hi all,
Apologies in advance if I am sending this to the wrong place.
We have a requirement in the upcoming CDI lite specification to find “beans.xml” files in the user classpath from an annotation processor (Micronaut).
The issue is that as far as I am aware there is no way to do this from an annotation processor since the “JavaFileManager” interface is inaccessible which provides this functionality via the “getClassLoader” method that accepts a location that can be the user classpath:
https://docs.oracle.com/en/java/javase/11/docs/api/java.compiler/javax/tools/JavaFileManager.html#getClassLoader(javax.tools.JavaFileManager.Location)
We have an experimental and not officially supported hack in the Micronaut annotation processor to attempt to work around this which retrieves the “JavaFileManager” via reflection:
https://github.com/micronaut-projects/micronaut-core/blob/a949a27c69ff00fe50fa751adf0501540aee79b2/inject-java/src/main/java/io/micronaut/annotation/processing/visitor/JavaVisitorContext.java#L123-L142
However clearly this violates the JDKs direction in terms of closing more of the internals.
I would like to request the addition of an officially supported way to do this via the APT API and am happy to contribute a proposal / JEP + PR if it means it can be taken forward since without this functionality it would mean that users will have to unnecessarily pollute the annotation processor classpath with JARs that aren’t required on that classpath.
Thanks in advance for any feedback.
Graeme
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20210804/48502f47/attachment.htm>
More information about the compiler-dev
mailing list