mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
better solution for JDT, ECJ, and class loading dynamically to get XQMode working
This commit is contained in:
@@ -51,6 +51,12 @@ public abstract class Mode {
|
||||
|
||||
/** Library folder for core. (Used for OpenGL in particular.) */
|
||||
protected Library coreLibrary;
|
||||
|
||||
/**
|
||||
* ClassLoader used to retrieve classes for this mode. Useful if you want
|
||||
* to grab any additional classes that subclass what's in the mode folder.
|
||||
*/
|
||||
protected ClassLoader classLoader;
|
||||
|
||||
|
||||
// public Mode(Base base, File folder) {
|
||||
@@ -71,6 +77,16 @@ public abstract class Mode {
|
||||
rebuildLibraryList();
|
||||
// rebuildExamplesMenu();
|
||||
}
|
||||
|
||||
|
||||
public void setClassLoader(ClassLoader loader) {
|
||||
this.classLoader = loader;
|
||||
}
|
||||
|
||||
|
||||
public ClassLoader getClassLoader() {
|
||||
return classLoader;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -96,6 +96,7 @@ public class ModeContribution extends InstalledContribution {
|
||||
Class<?> modeClass = loader.loadClass(className);
|
||||
Constructor con = modeClass.getConstructor(Base.class, File.class);
|
||||
mode = (Mode) con.newInstance(base, folder);
|
||||
mode.setClassLoader(loader);
|
||||
mode.setupGUI();
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,6 @@ public class InstallCommander implements Tool {
|
||||
String[] jarList = new String[] {
|
||||
"pde.jar",
|
||||
"antlr.jar",
|
||||
"jdt-core.jar",
|
||||
"jna.jar",
|
||||
"ant.jar",
|
||||
"ant-launcher.jar",
|
||||
|
||||
@@ -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();
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@
|
||||
<fileset dir=".." id="runtime.jars">
|
||||
<include name="app/pde.jar" />
|
||||
<include name="app/lib/antlr.jar" />
|
||||
<include name="app/lib/jdt-core.jar" />
|
||||
<!-- <include name="app/lib/jdt-core.jar" />-->
|
||||
<include name="app/lib/jna.jar" />
|
||||
<include name="app/lib/ant.jar" />
|
||||
<include name="app/lib/ant-launcher.jar" />
|
||||
|
||||
@@ -81,7 +81,7 @@
|
||||
<!-- In 0149, removed /System/Library/Java from the CLASSPATH because
|
||||
it can cause problems if users have installed weird files there.
|
||||
http://dev.processing.org/bugs/show_bug.cgi?id=1045 -->
|
||||
<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>
|
||||
<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>
|
||||
|
||||
<!-- 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 -->
|
||||
<key>Properties</key>
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
<cp>lib/pde.jar</cp>
|
||||
<cp>core/library/core.jar</cp>
|
||||
<cp>lib/jna.jar</cp>
|
||||
<cp>lib/jdt-core.jar</cp>
|
||||
<cp>lib/antlr.jar</cp>
|
||||
<cp>lib/ant.jar</cp>
|
||||
<cp>lib/ant-launcher.jar</cp>
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
<cp>lib/pde.jar</cp>
|
||||
<cp>core/library/core.jar</cp>
|
||||
<cp>lib/jna.jar</cp>
|
||||
<cp>lib/jdt-core.jar</cp>
|
||||
<cp>lib/antlr.jar</cp>
|
||||
<cp>lib/ant.jar</cp>
|
||||
<cp>lib/ant-launcher.jar</cp>
|
||||
|
||||
Reference in New Issue
Block a user