Skip to content

Commit 65efb16

Browse files
committed
better solution for JDT, ECJ, and class loading dynamically to get XQMode working
1 parent 315c2ca commit 65efb16

File tree

10 files changed

+46
-10
lines changed

10 files changed

+46
-10
lines changed

app/lib/jdt-core.jar

-4.39 MB
Binary file not shown.

app/src/processing/app/Mode.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ public abstract class Mode {
5151

5252
/** Library folder for core. (Used for OpenGL in particular.) */
5353
protected Library coreLibrary;
54+
55+
/**
56+
* ClassLoader used to retrieve classes for this mode. Useful if you want
57+
* to grab any additional classes that subclass what's in the mode folder.
58+
*/
59+
protected ClassLoader classLoader;
5460

5561

5662
// public Mode(Base base, File folder) {
@@ -71,6 +77,16 @@ public Mode(Base base, File folder) {
7177
rebuildLibraryList();
7278
// rebuildExamplesMenu();
7379
}
80+
81+
82+
public void setClassLoader(ClassLoader loader) {
83+
this.classLoader = loader;
84+
}
85+
86+
87+
public ClassLoader getClassLoader() {
88+
return classLoader;
89+
}
7490

7591

7692
/**

app/src/processing/app/contrib/ModeContribution.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ private ModeContribution(Base base, File folder,
9696
Class<?> modeClass = loader.loadClass(className);
9797
Constructor con = modeClass.getConstructor(Base.class, File.class);
9898
mode = (Mode) con.newInstance(base, folder);
99+
mode.setClassLoader(loader);
99100
mode.setupGUI();
100101
}
101102

app/src/processing/app/tools/InstallCommander.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ public void run() {
8282
String[] jarList = new String[] {
8383
"pde.jar",
8484
"antlr.jar",
85-
"jdt-core.jar",
8685
"jna.jar",
8786
"ant.jar",
8887
"ant-launcher.jar",

app/src/processing/mode/java/Compiler.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
import processing.core.*;
2828

2929
import java.io.*;
30+
import java.lang.reflect.Method;
3031

31-
import org.eclipse.jdt.core.compiler.batch.BatchCompiler;
32-
import org.eclipse.jdt.core.compiler.CompilationProgress;
32+
//import org.eclipse.jdt.core.compiler.batch.BatchCompiler;
33+
//import org.eclipse.jdt.core.compiler.CompilationProgress;
3334

3435

3536
public class Compiler {
@@ -107,10 +108,31 @@ public void close() { }
107108
PrintWriter writer = new PrintWriter(internalWriter);
108109

109110
//result = com.sun.tools.javac.Main.compile(command, writer);
110-
111-
CompilationProgress progress = null;
111+
112112
PrintWriter outWriter = new PrintWriter(System.out);
113-
success = BatchCompiler.compile(command, outWriter, writer, progress);
113+
114+
// Version that's not dynamically loaded
115+
//CompilationProgress progress = null;
116+
//success = BatchCompiler.compile(command, outWriter, writer, progress);
117+
118+
// Version that *is* dynamically loaded. First gets the mode class loader
119+
// so that it can grab the compiler JAR files from it.
120+
ClassLoader loader = build.mode.getClassLoader();
121+
try {
122+
Class batchClass =
123+
Class.forName("org.eclipse.jdt.core.compiler.batch.BatchCompiler", false, loader);
124+
Class progressClass =
125+
Class.forName("org.eclipse.jdt.core.compiler.CompilationProgress", false, loader);
126+
Class[] compileArgs =
127+
new Class[] { String[].class, PrintWriter.class, PrintWriter.class, progressClass };
128+
Method compileMethod = batchClass.getMethod("compile", compileArgs);
129+
success = (Boolean)
130+
compileMethod.invoke(null, new Object[] { command, outWriter, writer, null });
131+
} catch (Exception e) {
132+
e.printStackTrace();
133+
throw new SketchException("Unknown error inside the compiler.");
134+
}
135+
114136
// Close out the stream for good measure
115137
writer.flush();
116138
writer.close();

build/build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<fileset dir=".." id="runtime.jars">
3838
<include name="app/pde.jar" />
3939
<include name="app/lib/antlr.jar" />
40-
<include name="app/lib/jdt-core.jar" />
40+
<!-- <include name="app/lib/jdt-core.jar" />-->
4141
<include name="app/lib/jna.jar" />
4242
<include name="app/lib/ant.jar" />
4343
<include name="app/lib/ant-launcher.jar" />

build/macosx/template.app/Contents/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
<!-- In 0149, removed /System/Library/Java from the CLASSPATH because
8282
it can cause problems if users have installed weird files there.
8383
http://dev.processing.org/bugs/show_bug.cgi?id=1045 -->
84-
<string>$JAVAROOT/pde.jar:$JAVAROOT/core/library/core.jar:$JAVAROOT/ant.jar:$JAVAROOT/ant-launcher.jar:$JAVAROOT/antlr.jar:$JAVAROOT/jdt-core.jar:$JAVAROOT/jna.jar:$JAVAROOT/quaqua.jar</string>
84+
<string>$JAVAROOT/pde.jar:$JAVAROOT/core/library/core.jar:$JAVAROOT/ant.jar:$JAVAROOT/ant-launcher.jar:$JAVAROOT/antlr.jar:$JAVAROOT/jna.jar:$JAVAROOT/quaqua.jar</string>
8585

8686
<!-- More properties can be found in http://developer.apple.com/releasenotes/Java/java141/system_properties/chapter_4_section_1.html#//apple_ref/doc/uid/TP30000285 -->
8787
<key>Properties</key>

build/windows/launcher/config-cmd.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
<cp>lib/pde.jar</cp>
1919
<cp>core/library/core.jar</cp>
2020
<cp>lib/jna.jar</cp>
21-
<cp>lib/jdt-core.jar</cp>
2221
<cp>lib/antlr.jar</cp>
2322
<cp>lib/ant.jar</cp>
2423
<cp>lib/ant-launcher.jar</cp>

build/windows/launcher/config.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
<cp>lib/pde.jar</cp>
1919
<cp>core/library/core.jar</cp>
2020
<cp>lib/jna.jar</cp>
21-
<cp>lib/jdt-core.jar</cp>
2221
<cp>lib/antlr.jar</cp>
2322
<cp>lib/ant.jar</cp>
2423
<cp>lib/ant-launcher.jar</cp>

java/mode/ecj.jar

1.57 MB
Binary file not shown.

0 commit comments

Comments
 (0)