public class Main
extends java.lang.Object
Clients can handle all messages by registering a holder:
Main main = new Main(); IMessageHolder holder = new MessageHandler(); main.setHolder(holder);Clients can get control after each command completes by installing a Runnable:
main.setCompletionRunner(new Runnable() {..});
Modifier and Type | Class and Description |
---|---|
static class |
Main.CommandController
controller for repeatable command delays until input or file changed or removed
|
static class |
Main.LogModeMessagePrinter |
static class |
Main.MessagePrinter
interceptor IMessageHandler to print as we go.
|
Modifier and Type | Field and Description |
---|---|
protected ICommand |
command |
protected java.lang.String |
commandName
ReflectionFactory identifier for command (compiler)
|
protected Main.CommandController |
controller
control iteration/continuation for command (compiler)
|
protected MessageHandler |
ourHandler
internally-set message sink
|
static java.lang.String |
THROWN_PREFIX
Header used when rendering exceptions for users
|
Constructor and Description |
---|
Main() |
Modifier and Type | Method and Description |
---|---|
static int |
bareMain(java.lang.String[] args,
boolean useSystemExit,
java.util.List fails,
java.util.List errors,
java.util.List warnings,
java.util.List infos)
Convenience method to run ajc and collect String lists of messages.
|
protected static void |
fail(IMessageHandler handler,
java.lang.String message,
java.lang.Throwable thrown)
convenience API to make fail messages (without MessageUtils's fail prefix)
|
IMessageHolder |
getHolder() |
MessageHandler |
getMessageHandler() |
static void |
main(java.lang.String[] args) |
protected void |
outMessage(java.lang.String message)
Messages to the user
|
void |
quit()
call this to stop after the next iteration of incremental compile
|
static java.lang.String |
renderExceptionForUser(java.lang.Throwable thrown) |
protected boolean |
report(boolean pass,
IMessageHolder holder)
Report results from a (possibly-incremental) compile run.
|
void |
run(java.lang.String[] args,
IMessageHolder holder)
Run without using System.exit(..), putting all messages in holder:
ERROR: compiler error
WARNING: compiler warning
FAIL: command error (bad arguments, exception thrown)
This handles incremental behavior:
If args include "-incremental", repeat for every input char until 'q' is entered.
|
void |
runMain(java.lang.String[] args,
boolean useSystemExit)
Run without throwing exceptions but optionally using System.exit(..).
|
void |
setCommand(ICommand command) |
void |
setCompletionRunner(java.lang.Runnable runner)
Install a Runnable to be invoked synchronously after each compile completes.
|
void |
setHolder(IMessageHolder holder)
Set holder to be passed all messages.
|
protected void |
systemExit(IMessageHolder messages)
Call System.exit(int) with values derived from the number of failures/aborts or errors in messages.
|
public static final java.lang.String THROWN_PREFIX
protected Main.CommandController controller
protected java.lang.String commandName
protected ICommand command
protected final MessageHandler ourHandler
public static void main(java.lang.String[] args) throws java.io.IOException
args
- the String[] of command-line argumentsjava.io.IOException
public static int bareMain(java.lang.String[] args, boolean useSystemExit, java.util.List fails, java.util.List errors, java.util.List warnings, java.util.List infos)
args
- the String[] args to pass to the compileruseSystemExit
- if true and errors, return System.exit(errs)fails
- the List sink, if any, for String failure (or worse) messageserrors
- the List sink, if any, for String error messageswarnings
- the List sink, if any, for String warning messagesinfo
- the List sink, if any, for String info messagesany
- unchecked exceptions the compiler doespublic static java.lang.String renderExceptionForUser(java.lang.Throwable thrown)
java.lang.NullPointerException
- if thrown is nullpublic MessageHandler getMessageHandler()
public void setCommand(ICommand command)
public void runMain(java.lang.String[] args, boolean useSystemExit)
args
- the String[] command line for the compileruseSystemExit
- if true, use System.exit(int) to complete unless one of the args is -noExit. and signal result (0 no
exceptions/error, <0 exceptions, >0 compiler errors).public void run(java.lang.String[] args, IMessageHolder holder)
args
- the String[] command line for the compilerholder
- the MessageHandler sink for messages.public void quit()
public void setHolder(IMessageHolder holder)
holder
- the IMessageHolder sink for all messages (use null to restore default behavior)public IMessageHolder getHolder()
public void setCompletionRunner(java.lang.Runnable runner)
runner
- the Runnable to invoke - null to disableprotected void systemExit(IMessageHolder messages)
messages
- the IMessageHolder to interrogate.messages
- protected void outMessage(java.lang.String message)
protected boolean report(boolean pass, IMessageHolder holder)
pass
- true result of the commandholder
- IMessageHolder with messages from the commandreportCommandResults(IMessageHolder)
protected static void fail(IMessageHandler handler, java.lang.String message, java.lang.Throwable thrown)