diff --git a/processing/app/PdeCompiler.java b/processing/app/PdeCompiler.java index cc45e8614..dbca35fc5 100644 --- a/processing/app/PdeCompiler.java +++ b/processing/app/PdeCompiler.java @@ -20,35 +20,63 @@ public class PdeCompiler implements PdeMessageConsumer{ public boolean compileJava(PrintStream leechErr) { String command[] = new String[] { "jikes", + "-nowarn", // we're not currently interested in warnings "+E", // output errors in machine-parsable format "-d", buildPath, // output the classes in the buildPath buildPath + File.separator + className + ".java" // file to compile }; - int result; - // XXXdmose try/catch should be separate - try { - Process process = Runtime.getRuntime().exec(command); - // XXXdmose race condition? - new PdeMessageSiphon(process.getInputStream(), - process.getErrorStream(), - this); + firstErrorFound = false; // haven't found any errors yet + secondErrorFound = false; + + int result=0; // pre-initialized to quiet a bogus warning from jikes + try { + + // execute the compiler, and create threads to deal with the input + // and error streams + // + Process process = Runtime.getRuntime().exec(command); + new PdeMessageSiphon(process.getInputStream(), this); + new PdeMessageSiphon(process.getErrorStream(), this); + + // wait for the process to finish. if we get interrupted before waitFor + // returns, continue waiting + // + boolean compiling = true; + while (compiling) { + try { + result = process.waitFor(); + compiling = false; + } catch (InterruptedException intExc) { + } + } - result = process.waitFor(); } catch (Exception e) { result = -1; } //System.err.println("result = " + result); + // if we hit either of these conditions, it means that something is + // fairly wrong, one possibility is that jikes has crashed. + // + if (result != 0 && result != 1 ) { + exception = new PdeException("Error while compiling, " + + "please send code to bugs@proce55ing.net"); + editor.error(exception); + } + return result == 0 ? true : false; } + boolean firstErrorFound; + boolean secondErrorFound; + // part of the PdeMessageConsumer interface // public void message(String s) { - // as in: lib\build\Temporary_5476_6442.java:88: caution:Assignment of an expression to itself [KOPI] - if (s.indexOf("caution") != -1) return; + // ignore cautions + if (s.indexOf("Caution") != -1) return; // jikes always uses a forward slash character as its separator, so // we need to replace any platform-specific separator characters before @@ -66,10 +94,21 @@ public class PdeCompiler implements PdeMessageConsumer{ //String s2 = s1.substring(colon + 2); int err = s1.indexOf("Error:"); if (err != -1) { + + // if the first error has already been found, then this must be + // (at least) the second error found + if (firstErrorFound) { + secondErrorFound = true; + return; + } + + // if we're here at all, this is at least the first error + firstErrorFound = true; + //err += "error:".length(); String description = s1.substring(err + "Error:".length()); description = description.trim(); - System.out.println("description = " + description); + //System.out.println("description = " + description); exception = new PdeException(description, lineNumber-1); editor.error(exception); @@ -78,8 +117,18 @@ public class PdeCompiler implements PdeMessageConsumer{ } } else { + // this isn't the start of an error line, so don't attempt to parse - // a line number out of it + // a line number out of it. + + // if we're not yet at the second error, these lines are probably + // associated with the first error message, which is already in the + // status bar, and are likely to be of interest to the user, so + // spit them to the console. + // + if (!secondErrorFound) { + System.err.println(s); + } } } } diff --git a/processing/app/PdeEditor.java b/processing/app/PdeEditor.java index ecdae7951..810c3e24f 100644 --- a/processing/app/PdeEditor.java +++ b/processing/app/PdeEditor.java @@ -649,13 +649,13 @@ afterwards, some of these steps need a cleanup function // compile the program // - PdeCompiler compilerKjc = new PdeCompilerKjc(buildPath, className, this); + PdeCompiler compiler = new PdeCompiler(buildPath, className, this); // this will catch and parse errors during compilation - messageStream = new PdeMessageStream(this, compilerKjc); + messageStream = new PdeMessageStream(this, compiler); leechErr = new PrintStream(messageStream); - boolean result = compilerKjc.compileJava(leechErr); + boolean result = compiler.compileJava(leechErr); // if the compilation worked, run the applet // @@ -1367,17 +1367,18 @@ afterwards, some of these steps need a cleanup function // PdePreprocessor preprocessorOro = new PdePreprocessorOro(program, appletDir.getPath()); + exportSketchName = preprocessorOro.writeJava(exportSketchName, base.normalItem.getState(), true); - PdeCompiler compilerKjc = - new PdeCompilerKjc(appletDir.getPath(), exportSketchName, this); + PdeCompiler compiler = + new PdeCompiler(appletDir.getPath(), exportSketchName, this); // this will catch and parse errors during compilation - messageStream = new PdeMessageStream(this, compilerKjc); + messageStream = new PdeMessageStream(this, compiler); leechErr = new PrintStream(messageStream); - if (!compilerKjc.compileJava(leechErr)) { + if (!compiler.compileJava(leechErr)) { //throw new Exception("error while compiling, couldn't export"); // message() will already have error message in this case return; diff --git a/processing/app/PdeMessageSiphon.java b/processing/app/PdeMessageSiphon.java index fbbf56e0e..d2259dc6e 100644 --- a/processing/app/PdeMessageSiphon.java +++ b/processing/app/PdeMessageSiphon.java @@ -2,21 +2,17 @@ import java.io.*; -// XXXdmose error checking - class PdeMessageSiphon implements Runnable { - BufferedReader stdout, stderr; - PrintStream leechErr; + BufferedReader streamReader; Thread thread; PdeMessageConsumer consumer; - public PdeMessageSiphon(InputStream stdout, InputStream stderr, - PdeMessageConsumer consumer) { + public PdeMessageSiphon(InputStream stream, PdeMessageConsumer consumer) { - // XXXdmose error checking here - - this.stdout = new BufferedReader(new InputStreamReader(stdout)); - this.stderr = new BufferedReader(new InputStreamReader(stderr)); + // we use a BufferedReader in order to be able to read a line + // at a time + // + this.streamReader = new BufferedReader(new InputStreamReader(stream)); this.consumer = consumer; thread = new Thread(this); @@ -27,31 +23,18 @@ class PdeMessageSiphon implements Runnable { String currentLine; - while (Thread.currentThread() == thread) { - - // XXX put back while loops - - try { - if (stderr.ready()) { - currentLine = stderr.readLine(); - System.err.println(currentLine); - consumer.message(currentLine); - } - - if (stdout.ready()) { - currentLine = stdout.readLine(); - System.err.println(currentLine); - consumer.message(currentLine); - } - - Thread.sleep(10); - - } catch (Exception e) { - System.err.println("PdeMessageSiphon err " + e); - - thread.stop(); - thread = null; + try { + // process data until we hit EOF; this may block + // + while ((currentLine = streamReader.readLine()) != null) { + consumer.message(currentLine); + //System.err.println(currentLine); } + } catch (Exception e) { + System.err.println("PdeMessageSiphon err " + e); + thread.stop(); } + + //System.err.println("siphon thread exiting"); } } diff --git a/processing/app/PdeRuntime.java b/processing/app/PdeRuntime.java index c5f3748df..abca038c8 100644 --- a/processing/app/PdeRuntime.java +++ b/processing/app/PdeRuntime.java @@ -44,10 +44,8 @@ public class PdeRuntime implements PdeMessageConsumer { process = Runtime.getRuntime().exec(cmd + " " + className + " " + className + " " + x1 + " " + y1); - new PdeMessageSiphon(process.getInputStream(), - process.getErrorStream(), - this); - + new PdeMessageSiphon(process.getInputStream(), this); + new PdeMessageSiphon(process.getErrorStream(), this); } else { Class c = Class.forName(className); diff --git a/processing/build/linux/dist/Proce55ing b/processing/build/linux/dist/Proce55ing deleted file mode 100755 index 085f70103..000000000 --- a/processing/build/linux/dist/Proce55ing +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -./java/bin/java -cp lib:lib/build:lib/pde.jar:lib/kjc.jar:lib/oro.jar PdeBase diff --git a/processing/build/linux/make.sh b/processing/build/linux/make.sh index 8a1c9ca5f..cda925654 100755 --- a/processing/build/linux/make.sh +++ b/processing/build/linux/make.sh @@ -87,5 +87,5 @@ cd ../.. ### -- BUILD STUB ----------------------------------------------- -gcc -o work/Proce55ing stub.cpp -chmod 777 work/Proce55ing +install -m 755 stub.sh work/Processing + diff --git a/processing/build/linux/stub.cpp b/processing/build/linux/stub.cpp deleted file mode 100644 index af010faa6..000000000 --- a/processing/build/linux/stub.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main() { - system("java/bin/java -cp lib:lib/build:lib/pde.jar:lib/kjc.jar:lib/oro.jar:java/lib/ext/comm.jar PdeBase"); - return 0; -} diff --git a/processing/build/linux/stub.sh b/processing/build/linux/stub.sh new file mode 100644 index 000000000..8257e073f --- /dev/null +++ b/processing/build/linux/stub.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +CLASSPATH=java/lib/rt.jar:lib:lib/build:lib/pde.jar:lib/kjc.jar:lib/oro.jar:java/lib/ext/comm.jar +export CLASSPATH + +exec java/bin/java PdeBase diff --git a/processing/build/windows/dist.sh b/processing/build/windows/dist.sh index 36261424e..8556b2163 100755 --- a/processing/build/windows/dist.sh +++ b/processing/build/windows/dist.sh @@ -48,6 +48,12 @@ cp work/lib/pde.jar processing/lib/ cp -r work/lib/export processing/lib/ rm -rf processing/lib/export/CVS +# get jikes and depedencies +cp /usr/bin/cygwin1.dll processing/ +cp /usr/bin/cygiconv-2.dll processing/ +gunzip < jikes.exe.gz > processing/jikes.exe +chmod +x processing/jikes.exe + # get platform-specific goodies from the dist dir cp dist/Proce55ing.exe processing/ cp dist/run.bat processing/ diff --git a/processing/build/windows/dist/run.bat b/processing/build/windows/dist/run.bat index 6a31a1a4d..5c0e6c8ab 100755 --- a/processing/build/windows/dist/run.bat +++ b/processing/build/windows/dist/run.bat @@ -3,4 +3,9 @@ REM --- if you need more ram, change the 64m (which means REM --- 64 megabytes) to something higher. -java -ms64m -mx64m -cp lib;lib\build;lib\pde.jar;lib\kjc.jar;lib\oro.jar;lib\comm.jar;c:\winnt\system32\qtjava.zip;c:\windows\system32\qtjava.zip PdeBase +set SAVEDCP=%CLASSPATH% +set CLASSPATH=%CLASSPATH%;java\lib\rt.jar;lib;lib\build;lib\pde.jar;lib\kjc.jar;lib\oro.jar;lib\comm.jar;c:\winnt\system32\qtjava.zip;c:\windows\system32\qtjava.zip + +java -ms64m -mx64m PdeBase + +set CLASSPATH=%SAVEDCP% diff --git a/processing/build/windows/run.sh b/processing/build/windows/run.sh index f814a7913..8265a96f2 100644 --- a/processing/build/windows/run.sh +++ b/processing/build/windows/run.sh @@ -12,6 +12,6 @@ fi #QT_JAVA_PATH=..\\build\\shared\\lib\\qtjava.zip -CLASSPATH=lib\;lib\\build\;lib\\pde.jar\;lib\\kjc.jar\;lib\\oro.jar\;java\\lib\\ext\\comm.jar\;${QT_JAVA_PATH} +CLASSPATH=java\\lib\\rt.jar\;lib\;lib\\build\;lib\\pde.jar\;lib\\kjc.jar\;lib\\oro.jar\;java\\lib\\ext\\comm.jar\;${QT_JAVA_PATH} cd work && ./java/bin/java -cp ${CLASSPATH} PdeBase diff --git a/processing/build/windows/srun.sh b/processing/build/windows/srun.sh index 500a94691..17d7cf9fb 100755 --- a/processing/build/windows/srun.sh +++ b/processing/build/windows/srun.sh @@ -1,2 +1,6 @@ #!/bin/sh -cd work && ./java/bin/java -Djava.compiler=NONE -cp lib\;lib\\build\;lib\\pde.jar\;lib\\kjc.jar\;lib\\oro.jar\;java\\lib\\ext\\comm.jar PdeBase + +CLASSPATH=java\\lib\\rt.jar\;lib\;lib\\build\;lib\\pde.jar\;lib\\kjc.jar\;lib\\oro.jar\;java\\lib\\ext\\comm.jar +export CLASSPATH + +cd work && ./java/bin/java -Djava.compiler=NONE PdeBase