aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoel Spilker <r.spilker@gmail.com>2011-02-21 21:53:47 +0100
committerRoel Spilker <r.spilker@gmail.com>2011-02-21 21:53:47 +0100
commit35e18b9332a909aac013697c90d8240826953caf (patch)
tree46f15d23400b0f289f38915cf64dee3568cbea23 /src
parenta79ca059e93b3f32e285e1c9655159c6868e0db2 (diff)
downloadlombok-35e18b9332a909aac013697c90d8240826953caf.tar.gz
lombok-35e18b9332a909aac013697c90d8240826953caf.tar.bz2
lombok-35e18b9332a909aac013697c90d8240826953caf.zip
Issue 194: Javac gives and error when lombok.jar is on the classpath
Diffstat (limited to 'src')
-rw-r--r--src/core/lombok/core/AnnotationProcessor.java27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/core/lombok/core/AnnotationProcessor.java b/src/core/lombok/core/AnnotationProcessor.java
index ad7c58b9..5fd13581 100644
--- a/src/core/lombok/core/AnnotationProcessor.java
+++ b/src/core/lombok/core/AnnotationProcessor.java
@@ -78,15 +78,8 @@ public class AnnotationProcessor extends AbstractProcessor {
if (!procEnv.getClass().getName().equals("com.sun.tools.javac.processing.JavacProcessingEnvironment")) return false;
try {
- ClassLoader toFix = procEnv.getClass().getClassLoader();
- if (toFix.getClass().getCanonicalName().equals("org.codehaus.plexus.compiler.javac.IsolatedClassLoader")) {
- if (lombokAlreadyAddedTo.put(toFix, true) == null) {
- Method m = toFix.getClass().getDeclaredMethod("addURL", URL.class);
- URL selfUrl = new File(LiveInjector.findPathJar(AnnotationProcessor.class)).toURI().toURL();
- m.invoke(toFix, selfUrl);
- }
- }
- processor = (Processor)Class.forName("lombok.javac.apt.Processor", false, procEnv.getClass().getClassLoader()).newInstance();
+ ClassLoader classLoader = findAndPatchClassLoader(procEnv);
+ processor = (Processor)Class.forName("lombok.javac.apt.Processor", false, classLoader).newInstance();
} catch (Exception e) {
delayedWarnings.add("You found a bug in lombok; lombok.javac.apt.Processor is not available. Lombok will not run during this compilation: " + trace(e));
return false;
@@ -106,6 +99,22 @@ public class AnnotationProcessor extends AbstractProcessor {
return true;
}
+ private ClassLoader findAndPatchClassLoader(ProcessingEnvironment procEnv) throws Exception {
+ ClassLoader environmentClassLoader = procEnv.getClass().getClassLoader();
+ if (environmentClassLoader != null && environmentClassLoader.getClass().getCanonicalName().equals("org.codehaus.plexus.compiler.javac.IsolatedClassLoader")) {
+ if (lombokAlreadyAddedTo.put(environmentClassLoader, true) == null) {
+ Method m = environmentClassLoader.getClass().getDeclaredMethod("addURL", URL.class);
+ URL selfUrl = new File(LiveInjector.findPathJar(AnnotationProcessor.class)).toURI().toURL();
+ m.invoke(environmentClassLoader, selfUrl);
+ }
+ return environmentClassLoader;
+ }
+
+ ClassLoader ourClassLoader = JavacDescriptor.class.getClassLoader();
+ if (ourClassLoader == null) return ClassLoader.getSystemClassLoader();
+ return ourClassLoader;
+ }
+
@Override boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
return processor.process(annotations, roundEnv);
}