diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2015-04-01 05:34:56 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2015-04-02 02:06:30 +0200 |
commit | e45b492bb007af43301799f2e338a509a6389888 (patch) | |
tree | ab109e294a8667043445b31446648ba2ffdc23a4 /src/eclipseAgent/lombok | |
parent | 7707140b6c86bd34801f3fd29092be06e2cee3cf (diff) | |
download | lombok-e45b492bb007af43301799f2e338a509a6389888.tar.gz lombok-e45b492bb007af43301799f2e338a509a6389888.tar.bz2 lombok-e45b492bb007af43301799f2e338a509a6389888.zip |
[i802] working on eclipse mars support; this needs a few updates to integration with patcher.
Diffstat (limited to 'src/eclipseAgent/lombok')
3 files changed, 55 insertions, 36 deletions
diff --git a/src/eclipseAgent/lombok/eclipse/agent/EclipseLoaderPatcher.java b/src/eclipseAgent/lombok/eclipse/agent/EclipseLoaderPatcher.java index c137cb46..aa01c13d 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/EclipseLoaderPatcher.java +++ b/src/eclipseAgent/lombok/eclipse/agent/EclipseLoaderPatcher.java @@ -52,6 +52,14 @@ public class EclipseLoaderPatcher { .targetClass("org.eclipse.osgi.internal.loader.ModuleClassLoader") .build()); + sm.addScript(ScriptBuilder.addField().setPublic().setVolatile().setStatic() + .fieldType("Ljava/lang/Class;") + .fieldName("lombok$shadowLoaderClass") + .targetClass("org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader") + .targetClass("org.eclipse.osgi.framework.adapter.core.AbstractClassLoader") + .targetClass("org.eclipse.osgi.internal.loader.ModuleClassLoader") + .build()); + sm.addScript(ScriptBuilder.addField().setPublic().setStatic().setFinal() .fieldType("Ljava/lang/String;") .fieldName("lombok$location") diff --git a/src/eclipseAgent/lombok/eclipse/agent/EclipseLoaderPatcherTransplants.java b/src/eclipseAgent/lombok/eclipse/agent/EclipseLoaderPatcherTransplants.java index b7268e01..b1327216 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/EclipseLoaderPatcherTransplants.java +++ b/src/eclipseAgent/lombok/eclipse/agent/EclipseLoaderPatcherTransplants.java @@ -58,45 +58,49 @@ public class EclipseLoaderPatcherTransplants { synchronized ("lombok$shadowLoader$globalLock".intern()) { shadowLoader = (ClassLoader) shadowLoaderField.get(original); if (shadowLoader == null) { + Class shadowClassLoaderClass = (Class) original.getClass().getField("lombok$shadowLoaderClass").get(null); + Class classLoaderClass = Class.forName("java.lang.ClassLoader"); String jarLoc = (String) original.getClass().getField("lombok$location").get(null); - JarFile jf = new JarFile(jarLoc); - InputStream in = null; - try { - ZipEntry entry = jf.getEntry("lombok/launch/ShadowClassLoader.class"); - in = jf.getInputStream(entry); - byte[] bytes = new byte[65536]; - int len = 0; - while (true) { - int r = in.read(bytes, len, bytes.length - len); - if (r == -1) break; - len += r; - if (len == bytes.length) throw new IllegalStateException("lombok.launch.ShadowClassLoader too large."); + if (shadowClassLoaderClass == null) { + JarFile jf = new JarFile(jarLoc); + InputStream in = null; + try { + ZipEntry entry = jf.getEntry("lombok/launch/ShadowClassLoader.class"); + in = jf.getInputStream(entry); + byte[] bytes = new byte[65536]; + int len = 0; + while (true) { + int r = in.read(bytes, len, bytes.length - len); + if (r == -1) break; + len += r; + if (len == bytes.length) throw new IllegalStateException("lombok.launch.ShadowClassLoader too large."); + } + in.close(); + { + Class[] paramTypes = new Class[4]; + paramTypes[0] = "".getClass(); + paramTypes[1] = new byte[0].getClass(); + paramTypes[2] = Integer.TYPE; + paramTypes[3] = paramTypes[2]; + Method defineClassMethod = classLoaderClass.getDeclaredMethod("defineClass", paramTypes); + defineClassMethod.setAccessible(true); + shadowClassLoaderClass = (Class) defineClassMethod.invoke(original, new Object[] {"lombok.launch.ShadowClassLoader", bytes, new Integer(0), new Integer(len)}); + original.getClass().getField("lombok$shadowLoaderClass").set(null, shadowClassLoaderClass); + } + } finally { + if (in != null) in.close(); + jf.close(); } - in.close(); - Class classLoaderClass = Class.forName("java.lang.ClassLoader"); - Class shadowClassLoaderClass; { - Class[] paramTypes = new Class[4]; - paramTypes[0] = "".getClass(); - paramTypes[1] = new byte[0].getClass(); - paramTypes[2] = Integer.TYPE; - paramTypes[3] = paramTypes[2]; - Method defineClassMethod = classLoaderClass.getDeclaredMethod("defineClass", paramTypes); - defineClassMethod.setAccessible(true); - shadowClassLoaderClass = (Class) defineClassMethod.invoke(original, new Object[] {"lombok.launch.ShadowClassLoader", bytes, new Integer(0), new Integer(len)}); - } - Class[] paramTypes = new Class[4]; - paramTypes[0] = classLoaderClass; - paramTypes[1] = "".getClass(); - paramTypes[2] = paramTypes[1]; - paramTypes[3] = new String[0].getClass(); - Constructor constructor = shadowClassLoaderClass.getDeclaredConstructor(paramTypes); - constructor.setAccessible(true); - shadowLoader = (ClassLoader) constructor.newInstance(new Object[] {original, "lombok", jarLoc, new String[] {"lombok."}}); - shadowLoaderField.set(original, shadowLoader); - } finally { - if (in != null) in.close(); - jf.close(); } + Class[] paramTypes = new Class[4]; + paramTypes[0] = classLoaderClass; + paramTypes[1] = "".getClass(); + paramTypes[2] = paramTypes[1]; + paramTypes[3] = new String[0].getClass(); + Constructor constructor = shadowClassLoaderClass.getDeclaredConstructor(paramTypes); + constructor.setAccessible(true); + shadowLoader = (ClassLoader) constructor.newInstance(new Object[] {original, "lombok", jarLoc, new String[] {"lombok."}}); + shadowLoaderField.set(original, shadowLoader); } } } diff --git a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java index b8e3a955..9906c4d4 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java +++ b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java @@ -34,6 +34,7 @@ import lombok.patcher.MethodTarget; import lombok.patcher.ScriptManager; import lombok.patcher.StackRequest; import lombok.patcher.TargetMatcher; +import lombok.patcher.TransplantMapper; import lombok.patcher.scripts.ScriptBuilder; /** @@ -73,6 +74,12 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { private static void registerPatchScripts(Instrumentation instrumentation, boolean reloadExistingClasses, boolean ecjOnly, Class<?> launchingContext) { ScriptManager sm = new ScriptManager(); sm.registerTransformer(instrumentation); + sm.setTransplantMapper(new TransplantMapper() { + public String getPrefixFor(int classFileFormatVersion) { + return classFileFormatVersion > 49 ? "Class50/" : ""; + } + }); + if (!ecjOnly) { EclipseLoaderPatcher.patchEquinoxLoaders(sm, launchingContext); patchCatchReparse(sm); |