Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions java/src/processing/mode/java/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,9 @@ static public boolean compile(JavaBuild build) throws SketchException {
"-nowarn", // we're not currently interested in warnings (works in ecj)
"-d", build.getBinFolder().getAbsolutePath() // output the classes in the buildPath
};
//PApplet.println(baseCommand);

String[] sourceFiles = Util.listFiles(build.getSrcFolder(), false, ".java");
String[] command = PApplet.concat(baseCommand, sourceFiles);
//PApplet.println(command);

try {
// Load errors into a local StringBuilder
Expand Down Expand Up @@ -107,6 +105,7 @@ public void close() { }
// 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);
Expand All @@ -117,6 +116,7 @@ public void close() { }
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.");
Expand All @@ -128,17 +128,14 @@ public void close() { }

BufferedReader reader =
new BufferedReader(new StringReader(errorBuffer.toString()));
//System.err.println(errorBuffer.toString());

String line = null;
while ((line = reader.readLine()) != null) {
//System.out.println("got line " + line); // debug

// get first line, which contains file name, line number,
// and at least the first line of the error message
String errorFormat = "([\\w\\d_]+.java):(\\d+):\\s*(.*):\\s*(.*)\\s*";
String[] pieces = PApplet.match(line, errorFormat);
//PApplet.println(pieces);

// if it's something unexpected, die and print the mess to the console
if (pieces == null) {
Expand All @@ -159,9 +156,24 @@ public void close() { }
int dotJavaLineIndex = PApplet.parseInt(pieces[2]) - 1;
String errorMessage = pieces[4];

// extended error message or certain error message

if (!errorMessage.matches("([\\w\\d_]+.java):(\\d+):\\s*(.*):\\s*(.*)\\s*")) {
switch (errorMessage) {
case "23)": // cast error: int -> boolean
errorMessage = "int constant cannot be casted into boolean";
break;
default:
errorMessage = pieces[3] + " " + errorMessage;
break;
}
}


exception = build.placeException(errorMessage,
dotJavaFilename,
dotJavaLineIndex);


if (exception == null) {
exception = new SketchException(errorMessage);
Expand All @@ -177,7 +189,6 @@ public void close() { }
String[] m = PApplet.match(errorMessage, "The import (.*) cannot be resolved");
//what = what.substring(0, what.indexOf(' '));
if (m != null) {
// System.out.println("'" + m[1] + "'");
if (m[1].equals("processing.xml")) {
exception.setMessage("processing.xml no longer exists, this code needs to be updated for 2.0.");
System.err.println("The processing.xml library has been replaced " +
Expand Down Expand Up @@ -221,9 +232,7 @@ public void close() { }
}

} else if (errorMessage.endsWith("cannot be resolved")) {
// xxx cannot be resolved
//println(xxx);


String what = errorMessage.substring(0, errorMessage.indexOf(' '));

if (what.equals("LINE_LOOP") ||
Expand Down Expand Up @@ -304,6 +313,8 @@ public void close() { }
break;
}
}

// System.out.printf("DEBUG: class Compiler -- end of first try -- compile(...) exception=%s\n",exception); // DEBUG
} catch (IOException e) {
String bigSigh = "Error while compiling. (" + e.getMessage() + ")";
exception = new SketchException(bigSigh);
Expand All @@ -313,6 +324,8 @@ public void close() { }
// In case there was something else.
if (exception != null) throw exception;

// System.out.printf("DEBUG: class Compiler -- END of compile(...)\n"); // DEBUG

return success;
}

Expand Down