mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 06:17:44 +00:00
[i802] working on eclipse mars support; this needs a few updates to integration with patcher.
This commit is contained in:
1 parent
7707140b6c
commit
e45b492bb0
7 files changed
+87
-37
No files matched your search
@@ -190,6 +190,11 @@ the common tasks and can be called on to run the main aspects of all the sub-scr
|
||||
<src path="build/transformedSources" />
|
||||
</ivy:compile>
|
||||
|
||||
<ivy:compile destdir="build/lombok/Class50" source="1.4" target="1.6" includeantruntime="false">
|
||||
<compilerarg value="-Xbootclasspath/p:build/stubs${path.separator}lib/openJDK6Environment/rt-openjdk6.jar" />
|
||||
<src path="build/transformedSources" />
|
||||
</ivy:compile>
|
||||
|
||||
<ivy:compile destdir="build/lombok" source="1.5" target="1.5" includeantruntime="false">
|
||||
<compilerarg value="-Xbootclasspath/p:build/stubs${path.separator}lib/openJDK6Environment/rt-openjdk6.jar" />
|
||||
<src path="src/launch" />
|
||||
@@ -202,6 +207,14 @@ the common tasks and can be called on to run the main aspects of all the sub-scr
|
||||
<classpath refid="build.path" />
|
||||
</ivy:compile>
|
||||
|
||||
<ivy:compile destdir="build/lombok/Class50" source="1.5" target="1.6" includeantruntime="false">
|
||||
<compilerarg value="-Xbootclasspath/p:build/stubs${path.separator}lib/openJDK6Environment/rt-openjdk6.jar" />
|
||||
<src path="src/eclipseAgent" />
|
||||
<include name="lombok/launch/PatchFixesHider.java" />
|
||||
<classpath location="build/lombok" />
|
||||
<classpath refid="build.path" />
|
||||
</ivy:compile>
|
||||
|
||||
<ivy:compile destdir="build/lombok" source="1.6" target="1.6" includeantruntime="false">
|
||||
<compilerarg value="-Xbootclasspath/p:build/stubs${path.separator}lib/openJDK6Environment/rt-openjdk6.jar" />
|
||||
<src path="src/core" />
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<ivy-module version="2.0">
|
||||
<info organisation="org.projectlombok" module="lombok.patcher" revision="0.18" publication="20150402000000">
|
||||
<license name="MIT License" url="http://www.opensource.org/licenses/mit-license.php" />
|
||||
<ivyauthor name="rzwitserloot" url="http://zwitserloot.com/" />
|
||||
<ivyauthor name="rspilker" url="http://github.com/rspilker" />
|
||||
<description homepage="http://projectlombok.org/" />
|
||||
</info>
|
||||
<configurations>
|
||||
<conf name="default" />
|
||||
</configurations>
|
||||
<publications>
|
||||
<artifact conf="default" url="http://projectlombok.org/downloads/lombok.patcher-0.18.jar" />
|
||||
</publications>
|
||||
</ivy-module>
|
||||
@@ -15,7 +15,7 @@
|
||||
<conf name="javac7" />
|
||||
</configurations>
|
||||
<dependencies>
|
||||
<dependency org="org.projectlombok" name="lombok.patcher" rev="0.16" conf="buildBase->default; runtime->default" />
|
||||
<dependency org="org.projectlombok" name="lombok.patcher" rev="0.18" conf="buildBase->default; runtime->default" />
|
||||
<dependency org="zwitserloot.com" name="cmdreader" rev="1.2" conf="buildBase->runtime; runtime" />
|
||||
|
||||
<dependency org="junit" name="junit" rev="4.8.2" conf="test->default; contrib->sources" />
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -79,6 +79,8 @@ import java.util.jar.JarFile;
|
||||
*/
|
||||
class ShadowClassLoader extends ClassLoader {
|
||||
private static final String SELF_NAME = "lombok/launch/ShadowClassLoader.class";
|
||||
private volatile static Class<?> lombokPatcherSymbols;
|
||||
|
||||
private final String SELF_BASE;
|
||||
private final File SELF_BASE_FILE;
|
||||
private final int SELF_BASE_LENGTH;
|
||||
@@ -360,6 +362,7 @@ class ShadowClassLoader extends ClassLoader {
|
||||
if (alreadyLoaded != null) return alreadyLoaded;
|
||||
}
|
||||
|
||||
if (lombokPatcherSymbols != null && name.equals("lombok.patcher.Symbols")) return lombokPatcherSymbols;
|
||||
String fileNameOfClass = name.replace(".", "/") + ".class";
|
||||
URL res = getResource_(fileNameOfClass, true);
|
||||
if (res == null) {
|
||||
@@ -392,6 +395,7 @@ class ShadowClassLoader extends ClassLoader {
|
||||
}
|
||||
|
||||
Class<?> c = defineClass(name, b, 0, p);
|
||||
if (name.equals("lombok.patcher.Symbols")) lombokPatcherSymbols = c;
|
||||
if (resolve) resolveClass(c);
|
||||
return c;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user