more flexible scalac logging

the custom scalac Reporter now delegates to an instance of
  an sbt interface called xsbti.Reporter
handling compilation logging is now mainly done on the sbt-side of the
  compiler interface
the xsbti.Reporter interface provides access to richer information
  about errors and warnings, including source file, line, and offset
xsbti.Reporter can be implemented by users to get access to
  detailed information without needing to parse the logging output
the CompileFailed exception that is thrown when compilation fails now
  includes an array of the problems, providing detailed
  error and warning information that can, for example, be consumed
  by doing a mapFailure on 'compile' and using 'Compile.allProblems'
This commit is contained in:
Mark Harrah 2010-10-23 16:34:22 -04:00
parent 7dca038bde
commit 6402a766b5
6 changed files with 89 additions and 0 deletions

View File

@ -3,4 +3,5 @@ package xsbti;
public abstract class CompileFailed extends RuntimeException
{
public abstract String[] arguments();
public abstract Problem[] problems();
}

View File

@ -0,0 +1,30 @@
/* sbt -- Simple Build Tool
* Copyright 2008, 2009, 2010 Mark Harrah
*/
package xsbti;
/** Intended as a lightweight carrier for scala.Option. */
public abstract class Maybe<t>
{
// private pending Scala bug #3642
protected Maybe() {}
public static <s> Maybe<s> just(final s v)
{
return new Maybe<s>() {
public boolean isDefined() { return true; }
public s get() { return v; }
};
}
public static <s> Maybe<s> nothing()
{
return new Maybe<s>() {
public boolean isDefined() { return false; }
public s get() { throw new UnsupportedOperationException("nothing.get"); }
};
}
public final boolean isEmpty() { return !isDefined(); }
public abstract boolean isDefined();
public abstract t get();
}

View File

@ -0,0 +1,18 @@
/* sbt -- Simple Build Tool
* Copyright 2008, 2009, 2010 Mark Harrah
*/
package xsbti;
public interface Position
{
Maybe<Integer> line();
String lineContent();
Maybe<Integer> offset();
// pointer to the column position of the error/warning
Maybe<Integer> pointer();
Maybe<String> pointerSpace();
Maybe<String> sourcePath();
Maybe<java.io.File> sourceFile();
}

View File

@ -0,0 +1,11 @@
/* sbt -- Simple Build Tool
* Copyright 2008, 2009, 2010 Mark Harrah
*/
package xsbti;
public interface Problem
{
Severity severity();
String message();
Position position();
}

View File

@ -0,0 +1,20 @@
/* sbt -- Simple Build Tool
* Copyright 2008, 2009, 2010 Mark Harrah
*/
package xsbti;
public interface Reporter
{
/** Resets logging, including any accumulated errors, warnings, messages, and counts.*/
public void reset();
/** Returns true if this logger has seen any errors since the last call to reset.*/
public boolean hasErrors();
/** Returns true if this logger has seen any warnings since the last call to reset.*/
public boolean hasWarnings();
/** Logs a summary of logging since the last reset.*/
public void printSummary();
/** Returns a list of warnings and errors since the last reset.*/
public Problem[] problems();
/** Logs a message.*/
public void log(Position pos, String msg, Severity sev);
}

View File

@ -0,0 +1,9 @@
/* sbt -- Simple Build Tool
* Copyright 2008, 2009, 2010 Mark Harrah
*/
package xsbti;
public enum Severity
{
Info, Warn, Error
}