better solution for JDT, ECJ, and class loading dynamically to get XQMode working

This commit is contained in:
benfry
2012-10-22 20:15:27 +00:00
parent 66ef6af3b4
commit a468509f14
8 changed files with 46 additions and 10 deletions

View File

@@ -27,9 +27,10 @@ import processing.app.*;
import processing.core.*;
import java.io.*;
import java.lang.reflect.Method;
import org.eclipse.jdt.core.compiler.batch.BatchCompiler;
import org.eclipse.jdt.core.compiler.CompilationProgress;
//import org.eclipse.jdt.core.compiler.batch.BatchCompiler;
//import org.eclipse.jdt.core.compiler.CompilationProgress;
public class Compiler {
@@ -107,10 +108,31 @@ public class Compiler {
PrintWriter writer = new PrintWriter(internalWriter);
//result = com.sun.tools.javac.Main.compile(command, writer);
CompilationProgress progress = null;
PrintWriter outWriter = new PrintWriter(System.out);
success = BatchCompiler.compile(command, outWriter, writer, progress);
// Version that's not dynamically loaded
//CompilationProgress progress = null;
//success = BatchCompiler.compile(command, outWriter, writer, progress);
// Version that *is* dynamically loaded. First gets the mode class loader
// so that it can grab the compiler JAR files from it.
ClassLoader loader = build.mode.getClassLoader();
try {
Class batchClass =
Class.forName("org.eclipse.jdt.core.compiler.batch.BatchCompiler", false, loader);
Class progressClass =
Class.forName("org.eclipse.jdt.core.compiler.CompilationProgress", false, loader);
Class[] compileArgs =
new Class[] { String[].class, PrintWriter.class, PrintWriter.class, progressClass };
Method compileMethod = batchClass.getMethod("compile", compileArgs);
success = (Boolean)
compileMethod.invoke(null, new Object[] { command, outWriter, writer, null });
} catch (Exception e) {
e.printStackTrace();
throw new SketchException("Unknown error inside the compiler.");
}
// Close out the stream for good measure
writer.flush();
writer.close();