-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix build-time Refaster template loading #121
Conversation
@@ -195,7 +195,7 @@ private static ImmutableListMultimap<String, CodeTransformer> loadAllCodeTransfo | |||
|
|||
private static ImmutableSet<ResourceInfo> getClassPathResources() { | |||
try { | |||
return ClassPath.from(ClassLoader.getSystemClassLoader()).getResources(); | |||
return ClassPath.from(RefasterCheck.class.getClassLoader()).getResources(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also impacts #43, and that PR doesn't actually apply the templates at build time for a second reason; will also push a commit to that branch.
742e21c
to
c6daede
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code changes LGTM.
I have one question as I fail to understand why. Why does this (not) happen?
However, when during a build the Java compiler loads
RefasterCheck
, the templates on the annotation processor classpath are
not exposed through the system classloader.
When using the system classloader, `RefasterCheckTest` is able to successfully load the Refaster templates from the classpath, causing the tests to pass. However, when during a build the Java compiler loads `RefasterCheck`, the templates on the annotation processor classpath are _not_ exposed through the system classloader.
c6daede
to
81f6180
Compare
There are short and long, simple and complex answers to this question, but the key point (IIUC) is that the system classloader loads only classes and resources on the "regular" classpath of the Java process. I think (but did not check) that this works at test time because Surefire creates new JVM processes with a classpath that matches the Maven test classpath. On the other hand, the annotation processor classpath is a special construct understood (and defined) only by the Maven Compiler Plugin, implemented using a custom classloader implementation; the system classloader is oblivious to that logic. |
Suggested commit message:
To see the issue for yourself, apply the following patch and observe how before this change the redundant negations aren't flagged: