Skip to content

Commit

Permalink
Printing cause of compilation failure - System.exit() is not ideal bu…
Browse files Browse the repository at this point in the history
…t it avoids printing the Truncate Class File error that run.sh has after a compilation failure and run.sh fails to dynamically reload after that anyway
  • Loading branch information
David Reed committed Aug 17, 2012
1 parent 7d8d79a commit befebb1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
15 changes: 10 additions & 5 deletions koans-lib/src/com/sandwich/util/io/CompilationFailureLogger.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package com.sandwich.util.io;

import java.io.File;
import java.util.Arrays;

import com.sandwich.koan.ui.SuitePresenter;
import com.sandwich.koan.util.ApplicationUtils;

import java.io.File;
import java.util.Arrays;
import java.util.Scanner;

public class CompilationFailureLogger implements CompilationListener {
public void compilationFailed(File src, String[] command, Process p, Throwable x) {
public void compilationFailed(File src, String[] command, Process p, Throwable x) {
SuitePresenter presenter = ApplicationUtils.getPresenter();
presenter.displayError("\n*****************************************************************");
presenter.displayError("COMPILE FAILED! Exit status was: " + p.exitValue());
presenter.displayError("\nCompile Output:");
presenter.displayError(StreamUtils.convertStreamToString(p.getErrorStream()));
presenter.displayError("Compile Command:");
presenter.displayError(Arrays.toString(command));
presenter.displayError(src.getAbsolutePath() + " does not compile. exit status was: " + p.exitValue());
presenter.displayError("*****************************************************************\n");
System.exit(1);
}
public void compilationSucceeded(File src, String[] command, Process p, Throwable x) { }
}
15 changes: 15 additions & 0 deletions koans-lib/src/com/sandwich/util/io/StreamUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.sandwich.util.io;

import java.io.InputStream;

public class StreamUtils {

public static String convertStreamToString(InputStream stream) {
try {
return new java.util.Scanner(stream).useDelimiter("\\A").next();
} catch (java.util.NoSuchElementException e) {
return "";
}
}

}
Binary file modified koans/lib/koans.jar
100755 → 100644
Binary file not shown.

0 comments on commit befebb1

Please sign in to comment.