Skip to content

Commit

Permalink
[i802] working on eclipse mars support; this needs a few updates to i…
Browse files Browse the repository at this point in the history
…ntegration with patcher.
  • Loading branch information
rzwitserloot committed Apr 2, 2015
1 parent 7707140 commit e45b492
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 37 deletions.
13 changes: 13 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand All @@ -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" />
Expand Down
14 changes: 14 additions & 0 deletions buildScripts/ivy-repo/org.projectlombok-lombok.patcher-0.18.xml
Original file line number Diff line number Diff line change
@@ -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>
2 changes: 1 addition & 1 deletion buildScripts/ivy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ public static void patchEquinoxLoaders(ScriptManager sm, Class<?> launchingConte
.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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,45 +58,49 @@ public static Class overrideLoadResult(ClassLoader original, String name, boolea
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);
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import lombok.patcher.ScriptManager;
import lombok.patcher.StackRequest;
import lombok.patcher.TargetMatcher;
import lombok.patcher.TransplantMapper;
import lombok.patcher.scripts.ScriptBuilder;

/**
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/launch/lombok/launch/ShadowClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
*/
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;
Expand Down Expand Up @@ -360,6 +362,7 @@ private URL getResourceSkippingSelf(String name) throws IOException {
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) {
Expand Down Expand Up @@ -392,6 +395,7 @@ private URL getResourceSkippingSelf(String name) throws IOException {
}

Class<?> c = defineClass(name, b, 0, p);
if (name.equals("lombok.patcher.Symbols")) lombokPatcherSymbols = c;
if (resolve) resolveClass(c);
return c;
}
Expand Down

0 comments on commit e45b492

Please sign in to comment.