mirror of
https://github.com/processing/processing4.git
synced 2026-02-08 08:09:32 +01:00
working on including external code
This commit is contained in:
@@ -34,14 +34,15 @@ public class PdeCompiler implements PdeMessageConsumer {
|
||||
|
||||
String buildPath;
|
||||
String className;
|
||||
File includeFolder;
|
||||
PdeException exception;
|
||||
PdeEditor editor;
|
||||
|
||||
String additional;
|
||||
|
||||
|
||||
public PdeCompiler(String buildPath, String className, PdeEditor editor) {
|
||||
public PdeCompiler(String buildPath, String className,
|
||||
File includeFolder, PdeEditor editor) {
|
||||
this.buildPath = buildPath;
|
||||
this.includeFolder = includeFolder;
|
||||
this.className = className;
|
||||
this.editor = editor;
|
||||
}
|
||||
@@ -53,6 +54,7 @@ public class PdeCompiler implements PdeMessageConsumer {
|
||||
|
||||
String userdir = System.getProperty("user.dir") + File.separator;
|
||||
|
||||
/*
|
||||
if (additional == null) {
|
||||
#ifndef MACOS
|
||||
additional = "";
|
||||
@@ -65,8 +67,8 @@ public class PdeCompiler implements PdeMessageConsumer {
|
||||
|
||||
String list[] = new File("/System/Library/Java/Extensions").list();
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
if (list[i].endsWith(".class") || list[i].endsWith(".jar") ||
|
||||
list[i].endsWith(".zip")) {
|
||||
if (list[i].toLowerCase().endsWith(".jar") ||
|
||||
list[i].toLowerCase().endsWith(".zip")) {
|
||||
//abuffer.append(System.getProperty("path.separator"));
|
||||
abuffer.append(":/System/Library/Java/Extensions/" + list[i]);
|
||||
}
|
||||
@@ -74,6 +76,7 @@ public class PdeCompiler implements PdeMessageConsumer {
|
||||
additional = abuffer.toString();
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
|
||||
//System.out.println(userdir + "jikes");
|
||||
//System.out.println(System.getProperty("sun.boot.class.path"));
|
||||
@@ -94,13 +97,15 @@ public class PdeCompiler implements PdeMessageConsumer {
|
||||
|
||||
// used when run without a vm ("expert" mode)
|
||||
"-bootclasspath",
|
||||
System.getProperty("sun.boot.class.path") + additional,
|
||||
calcBootClassPath(),
|
||||
//System.getProperty("sun.boot.class.path") + additional,
|
||||
|
||||
// needed for macosx so that the classpath is set properly
|
||||
// also for windows because qtjava will most likely be here
|
||||
// and for linux, it just doesn't hurt
|
||||
"-classpath",
|
||||
System.getProperty("java.class.path"),
|
||||
//System.getProperty("java.class.path"),
|
||||
calcClassPath(includeFolder),
|
||||
|
||||
"-nowarn", // we're not currently interested in warnings
|
||||
"+E", // output errors in machine-parsable format
|
||||
@@ -238,4 +243,73 @@ public class PdeCompiler implements PdeMessageConsumer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static String additional;
|
||||
|
||||
static public String calcBootClassPath() {
|
||||
if (additional == null) {
|
||||
#ifdef MACOS
|
||||
additional =
|
||||
includeFolder(new File("/System/Library/Java/Extensions/"));
|
||||
/*
|
||||
// for macosx only, doesn't work on macos9
|
||||
StringBuffer abuffer = new StringBuffer();
|
||||
|
||||
// add the build folder.. why isn't it already there?
|
||||
//abuffer.append(":" + userdir + "lib/build");
|
||||
|
||||
String list[] = new File("/System/Library/Java/Extensions").list();
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
if (list[i].endsWith(".class") || list[i].endsWith(".jar") ||
|
||||
list[i].endsWith(".zip")) {
|
||||
//abuffer.append(System.getProperty("path.separator"));
|
||||
abuffer.append(":/System/Library/Java/Extensions/" + list[i]);
|
||||
}
|
||||
}
|
||||
additional = abuffer.toString();
|
||||
*/
|
||||
#else
|
||||
additional = "";
|
||||
#endif
|
||||
}
|
||||
return System.getProperty("sun.boot.class.path") + additional;
|
||||
}
|
||||
|
||||
|
||||
static public String calcClassPath(File include) {
|
||||
return System.getProperty("java.class.path") + includeFolder(include);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the path for a folder, with appended paths to
|
||||
* any .jar or .zip files inside that folder.
|
||||
*/
|
||||
static protected String includeFolder(File folder) {
|
||||
if (folder == null) return "";
|
||||
|
||||
StringBuffer abuffer = new StringBuffer();
|
||||
String sep = System.getProperty("path.separator");
|
||||
|
||||
try {
|
||||
// add the folder itself in case any unzipped files
|
||||
String path = folder.getCanonicalPath();
|
||||
abuffer.append(sep);
|
||||
abuffer.append(path);
|
||||
|
||||
String list[] = folder.list();
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
if (list[i].toLowerCase().endsWith(".jar") ||
|
||||
list[i].toLowerCase().endsWith(".zip")) {
|
||||
abuffer.append(sep);
|
||||
abuffer.append(path);
|
||||
abuffer.append(list[i]);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(); // this would be odd
|
||||
}
|
||||
return abuffer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,9 +42,9 @@ import java.io.*;
|
||||
|
||||
public class PdeCompilerJavac extends PdeCompiler {
|
||||
|
||||
public PdeCompilerJavac(String buildPath,
|
||||
String className, PdeEditor editor) {
|
||||
super(buildPath, className, editor);
|
||||
public PdeCompilerJavac(String buildPath, String className,
|
||||
File includeFolder, PdeEditor editor) {
|
||||
super(buildPath, className, includeFolder, editor);
|
||||
}
|
||||
|
||||
public boolean compileJava(PrintStream leechErr) {
|
||||
|
||||
@@ -28,12 +28,12 @@ import java.io.*;
|
||||
|
||||
public class PdeCompilerKjc extends PdeCompiler {
|
||||
|
||||
public PdeCompilerKjc(String buildPath, String className, PdeEditor editor) {
|
||||
super(buildPath, className, editor);
|
||||
public PdeCompilerKjc(String buildPath, String className,
|
||||
File includeFolder, PdeEditor editor) {
|
||||
super(buildPath, className, includeFolder, editor);
|
||||
}
|
||||
|
||||
public boolean compileJava(PrintStream leechErr) {
|
||||
|
||||
System.setErr(leechErr); // redirect stderr to our leech filter
|
||||
|
||||
String args[] = new String[2];
|
||||
|
||||
@@ -98,7 +98,9 @@ public class PdeEditor extends JPanel {
|
||||
|
||||
RunButtonWatcher watcher;
|
||||
|
||||
PdeRuntime pdeRuntime;
|
||||
PdeRuntime runtime;
|
||||
boolean externalRuntime;
|
||||
File externalCode;
|
||||
|
||||
static final int GRID_SIZE = 33;
|
||||
static final int INSET_SIZE = 5;
|
||||
@@ -238,7 +240,7 @@ public class PdeEditor extends JPanel {
|
||||
if (presenting == true) {
|
||||
try {
|
||||
presentationWindow.toFront();
|
||||
pdeRuntime.applet.requestFocus();
|
||||
runtime.applet.requestFocus();
|
||||
} catch (Exception ex) { }
|
||||
}
|
||||
}
|
||||
@@ -249,7 +251,7 @@ public class PdeEditor extends JPanel {
|
||||
if (presenting == true) {
|
||||
try {
|
||||
presentationWindow.toFront();
|
||||
pdeRuntime.applet.requestFocus();
|
||||
runtime.applet.requestFocus();
|
||||
} catch (Exception ex) { }
|
||||
}
|
||||
}
|
||||
@@ -261,11 +263,11 @@ public class PdeEditor extends JPanel {
|
||||
public void keyPressed(KeyEvent e) {
|
||||
//System.out.println("window got " + e);
|
||||
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
|
||||
pdeRuntime.stop();
|
||||
runtime.stop();
|
||||
doClose();
|
||||
} else {
|
||||
// pass on the event to the applet [toxi 030903]
|
||||
pdeRuntime.applet.keyPressed(e);
|
||||
runtime.applet.keyPressed(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -571,10 +573,23 @@ public class PdeEditor extends JPanel {
|
||||
preprocessor.writeJava(className, extendsNormal, false);
|
||||
}
|
||||
|
||||
externalRuntime = false;
|
||||
if (PdePreprocessor.programType == PdePreprocessor.ADVANCED) {
|
||||
externalRuntime = true; // we in advanced mode now, boy
|
||||
}
|
||||
|
||||
externalCode = new File(sketchDir, "code");
|
||||
if (externalCode.exists()) {
|
||||
externalRuntime = true;
|
||||
} else {
|
||||
externalCode = null;
|
||||
}
|
||||
|
||||
// compile the program
|
||||
//
|
||||
File includeFolder = null;
|
||||
PdeCompiler compiler =
|
||||
new PdeCompiler(buildPath, className, this);
|
||||
new PdeCompiler(buildPath, className, includeFolder, this);
|
||||
// macos9 now officially broken.. see PdeCompilerJavac
|
||||
//PdeCompiler compiler =
|
||||
// ((PdeBase.platform == PdeBase.MACOS9) ?
|
||||
@@ -683,15 +698,22 @@ public class PdeEditor extends JPanel {
|
||||
if (className != null) {
|
||||
|
||||
// create a runtime object
|
||||
pdeRuntime = new PdeRuntime(this, className);
|
||||
runtime = new PdeRuntime(this, className);
|
||||
|
||||
// if programType is ADVANCED
|
||||
// or the code/ folder is not empty -> or just exists (simpler)
|
||||
// then set boolean for external to true
|
||||
// include path to build in front, then path for code folder
|
||||
// when passing the classpath through
|
||||
// actually, build will already be in there, just prepend code
|
||||
|
||||
// use the runtime object to consume the errors now
|
||||
//messageStream.setMessageConsumer(pdeRuntime);
|
||||
//messageStream.setMessageConsumer(runtime);
|
||||
// no need to bother recycling the old guy
|
||||
PdeMessageStream messageStream = new PdeMessageStream(pdeRuntime);
|
||||
PdeMessageStream messageStream = new PdeMessageStream(runtime);
|
||||
|
||||
// start the applet
|
||||
pdeRuntime.start(presenting ? presentLocation : appletLocation,
|
||||
runtime.start(presenting ? presentLocation : appletLocation,
|
||||
new PrintStream(messageStream));
|
||||
//leechErr);
|
||||
|
||||
@@ -705,7 +727,7 @@ public class PdeEditor extends JPanel {
|
||||
}
|
||||
} catch (PdeException e) {
|
||||
// if we made it to the runtime stage, unwind that thread
|
||||
if (pdeRuntime != null) pdeRuntime.stop();
|
||||
if (runtime != null) runtime.stop();
|
||||
cleanTempFiles(); //tempBuildPath);
|
||||
|
||||
// printing the stack trace may be overkill since it happens
|
||||
@@ -718,7 +740,7 @@ public class PdeEditor extends JPanel {
|
||||
e.printStackTrace();
|
||||
|
||||
// if we made it to the runtime stage, unwind that thread
|
||||
if (pdeRuntime != null) pdeRuntime.stop();
|
||||
if (runtime != null) runtime.stop();
|
||||
|
||||
cleanTempFiles(); //tempBuildPath);
|
||||
}
|
||||
@@ -740,9 +762,9 @@ public class PdeEditor extends JPanel {
|
||||
|
||||
public void run() {
|
||||
while (Thread.currentThread() == thread) {
|
||||
if ((pdeRuntime != null) && (pdeRuntime.applet != null)) {
|
||||
//System.out.println(pdeRuntime.applet.finished);
|
||||
buttons.running(!pdeRuntime.applet.finished);
|
||||
if ((runtime != null) && (runtime.applet != null)) {
|
||||
//System.out.println(runtime.applet.finished);
|
||||
buttons.running(!runtime.applet.finished);
|
||||
//} else {
|
||||
//System.out.println("still pooping");
|
||||
}
|
||||
@@ -759,7 +781,7 @@ public class PdeEditor extends JPanel {
|
||||
|
||||
|
||||
public void doStop() {
|
||||
if (pdeRuntime != null) pdeRuntime.stop();
|
||||
if (runtime != null) runtime.stop();
|
||||
if (watcher != null) watcher.stop();
|
||||
//System.out.println("stop2");
|
||||
message(EMPTY);
|
||||
@@ -784,7 +806,7 @@ public class PdeEditor extends JPanel {
|
||||
|
||||
} else {
|
||||
try {
|
||||
appletLocation = pdeRuntime.window.getLocation();
|
||||
appletLocation = runtime.window.getLocation();
|
||||
} catch (NullPointerException e) { }
|
||||
}
|
||||
//System.out.println("doclose2");
|
||||
@@ -796,9 +818,9 @@ public class PdeEditor extends JPanel {
|
||||
|
||||
//System.out.println("doclose3");
|
||||
try {
|
||||
if (pdeRuntime != null) {
|
||||
pdeRuntime.close(); // kills the window
|
||||
pdeRuntime = null; // will this help?
|
||||
if (runtime != null) {
|
||||
runtime.close(); // kills the window
|
||||
runtime = null; // will this help?
|
||||
}
|
||||
} catch (Exception e) { }
|
||||
//System.out.println("doclose4");
|
||||
|
||||
Reference in New Issue
Block a user