|
27 | 27 | import processing.core.*; |
28 | 28 |
|
29 | 29 | import java.io.*; |
| 30 | +import java.lang.reflect.Method; |
30 | 31 |
|
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; |
33 | 34 |
|
34 | 35 |
|
35 | 36 | public class Compiler { |
@@ -107,10 +108,31 @@ public void close() { } |
107 | 108 | PrintWriter writer = new PrintWriter(internalWriter); |
108 | 109 |
|
109 | 110 | //result = com.sun.tools.javac.Main.compile(command, writer); |
110 | | - |
111 | | - CompilationProgress progress = null; |
| 111 | + |
112 | 112 | 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 | + |
114 | 136 | // Close out the stream for good measure |
115 | 137 | writer.flush(); |
116 | 138 | writer.close(); |
|
0 commit comments