diff options
author | Reinier Zwitserloot <r.zwitserloot@projectlombok.org> | 2020-10-30 04:48:03 +0100 |
---|---|---|
committer | Reinier Zwitserloot <r.zwitserloot@projectlombok.org> | 2020-10-30 04:48:52 +0100 |
commit | 28fbff467b3f3f3f5a4128313de02c9b1b2cb41d (patch) | |
tree | b7f674e9e3f6b2dfe24ef85a1179051dceedfd43 /src/launch/lombok | |
parent | 647c36f01619d10bd88ec86f05f9833b08d8a371 (diff) | |
download | lombok-28fbff467b3f3f3f5a4128313de02c9b1b2cb41d.tar.gz lombok-28fbff467b3f3f3f5a4128313de02c9b1b2cb41d.tar.bz2 lombok-28fbff467b3f3f3f5a4128313de02c9b1b2cb41d.zip |
[issue #285] Compiling with Maven+Tycho should now work
Diffstat (limited to 'src/launch/lombok')
-rw-r--r-- | src/launch/lombok/launch/Main.java | 5 | ||||
-rw-r--r-- | src/launch/lombok/launch/ShadowClassLoader.java | 24 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/launch/lombok/launch/Main.java b/src/launch/lombok/launch/Main.java index 08298cc2..ff539704 100644 --- a/src/launch/lombok/launch/Main.java +++ b/src/launch/lombok/launch/Main.java @@ -34,6 +34,11 @@ class Main { return classLoader; } + static synchronized void prependClassLoader(ClassLoader loader) { + getShadowClassLoader(); + classLoader.prepend(loader); + } + public static void main(String[] args) throws Throwable { ClassLoader cl = getShadowClassLoader(); Class<?> mc = cl.loadClass("lombok.core.Main"); diff --git a/src/launch/lombok/launch/ShadowClassLoader.java b/src/launch/lombok/launch/ShadowClassLoader.java index da377ae4..e75c300e 100644 --- a/src/launch/lombok/launch/ShadowClassLoader.java +++ b/src/launch/lombok/launch/ShadowClassLoader.java @@ -102,6 +102,16 @@ class ShadowClassLoader extends ClassLoader { private final List<String> parentExclusion = new ArrayList<String>(); private final List<String> highlanders = new ArrayList<String>(); + private final List<ClassLoader> prependedLoaders = new ArrayList<ClassLoader>(); + + public void prepend(ClassLoader loader) { + if (loader == null) return; + for (ClassLoader cl : prependedLoaders) { + if (cl == loader) return; + } + prependedLoaders.add(loader); + } + /** * @param source The 'parent' classloader. * @param sclSuffix The suffix of the shadowed class files in our own jar. For example, if this is {@code lombok}, then the class files in your jar should be {@code foo/Bar.SCL.lombok} and not {@code foo/Bar.class}. @@ -529,6 +539,16 @@ class ShadowClassLoader extends ClassLoader { } String fileNameOfClass = name.replace(".", "/") + ".class"; + for (ClassLoader pre : prependedLoaders) { + try { + URL res = pre.getResource(fileNameOfClass); + if (res == null) continue; + return urlToDefineClass(name, res, resolve); + } catch (Exception e) { + continue; + } + } + URL res = getResource_(fileNameOfClass, true); if (res == null) { if (!exclusionListMatch(fileNameOfClass)) try { @@ -540,6 +560,10 @@ class ShadowClassLoader extends ClassLoader { } if (res == null) throw new ClassNotFoundException(name); + return urlToDefineClass(name, res, resolve); + } + + private Class<?> urlToDefineClass(String name, URL res, boolean resolve) throws ClassNotFoundException { byte[] b; int p = 0; try { |