grails.build.logging
Class GrailsConsole

java.lang.Object
  extended by grails.build.logging.GrailsConsole
Direct Known Subclasses:
GrailsEclipseConsole

public class GrailsConsole
extends java.lang.Object

Utility class for delivering console output in a nicely formatted way.

Since:
2.0

Field Summary
static java.lang.String CATEGORY_SEPARATOR
           
static java.lang.String ENABLE_INTERACTIVE
           
static java.lang.String ENABLE_TERMINAL
           
static java.lang.String ERROR
           
static java.lang.String HISTORYFILE
           
static java.lang.String LINE_SEPARATOR
           
static java.lang.String PROMPT
           
static java.lang.Character SECURE_MASK_CHAR
           
static java.lang.String SPACE
           
static java.lang.String STACKTRACE_FILTERED_MESSAGE
           
static java.lang.String STACKTRACE_MESSAGE
           
static java.lang.String WARNING
           
 
Constructor Summary
protected GrailsConsole()
           
 
Method Summary
 void addStatus(java.lang.String msg)
          Keeps doesn't replace the status message
protected  java.io.OutputStream ansiWrap(java.io.OutputStream out)
          Hook method that allows controlling whether or not output streams should be wrapped by AnsiConsole.wrapOutputStream.
 void append(java.lang.String msg)
           
protected  jline.ConsoleReader createConsoleReader()
           
static GrailsConsole createInstance()
           
protected  jline.Terminal createTerminal()
          Creates the instance of Terminal used directly in GrailsConsole.
 void echoStatus()
          Replays the last status message
 void error(java.lang.String msg)
          Prints an error message
 void error(java.lang.String label, java.lang.String message)
           
 void error(java.lang.String msg, java.lang.Throwable error)
          Use to log an error
 void error(java.lang.Throwable error)
          Use to log an error
 void flush()
           
 java.util.Stack<java.lang.String> getCategory()
           
 java.io.PrintStream getErr()
           
 java.io.InputStream getInput()
           
static GrailsConsole getInstance()
           
 java.lang.String getLastMessage()
           
 java.io.PrintStream getOut()
           
 jline.ConsoleReader getReader()
           
 jline.Terminal getTerminal()
           
 void indicateProgress()
          Indicates progress with the default progress indicator
 void indicateProgress(int number)
          Indicates progress by number
 void indicateProgress(int number, int total)
          Indicate progress for a number and total
 void indicateProgressPercentage(long number, long total)
          Indicates progress as a percentage for the given number and total
 void info(java.lang.String msg)
          Synonym for #log
 boolean isAnsiEnabled()
           
 boolean isStacktrace()
           
 boolean isVerbose()
           
 boolean isWindows()
           
 void log(java.lang.String msg)
          Logs a message below the current status message
protected  jline.History prepareHistory()
          Prepares a history file to be used by the ConsoleReader.
 java.lang.String secureUserInput(java.lang.String msg)
          Like userInput(String) except that the user's entered characters will be replaced with '*' on the CLI, masking the input (i.e.
 void setAnsiEnabled(boolean ansiEnabled)
           
 void setErr(java.io.PrintStream err)
           
static void setInstance(GrailsConsole newConsole)
           
 void setLastMessage(java.lang.String lastMessage)
           
 void setOut(java.io.PrintStream out)
           
 void setStacktrace(boolean stacktrace)
           
 void setVerbose(boolean verbose)
           
 java.lang.String showPrompt()
          Shows the prompt to request user input
 void updateStatus(java.lang.String msg)
          Updates the current state message
 java.lang.String userInput(java.lang.String msg)
          Replacement for AntBuilder.input() to eliminate dependency of GrailsScriptRunner on the Ant libraries.
 java.lang.String userInput(java.lang.String message, java.util.List<java.lang.String> validResponses)
           
 java.lang.String userInput(java.lang.String message, java.lang.String[] validResponses)
          Replacement for AntBuilder.input() to eliminate dependency of GrailsScriptRunner on the Ant libraries.
 void verbose(java.lang.String msg)
           
 void warn(java.lang.String msg)
          Prints a warn message
 void warning(java.lang.String msg)
          Prints an error message
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENABLE_TERMINAL

public static final java.lang.String ENABLE_TERMINAL
See Also:
Constant Field Values

ENABLE_INTERACTIVE

public static final java.lang.String ENABLE_INTERACTIVE
See Also:
Constant Field Values

LINE_SEPARATOR

public static final java.lang.String LINE_SEPARATOR

CATEGORY_SEPARATOR

public static final java.lang.String CATEGORY_SEPARATOR
See Also:
Constant Field Values

PROMPT

public static final java.lang.String PROMPT
See Also:
Constant Field Values

SPACE

public static final java.lang.String SPACE
See Also:
Constant Field Values

ERROR

public static final java.lang.String ERROR
See Also:
Constant Field Values

WARNING

public static final java.lang.String WARNING
See Also:
Constant Field Values

HISTORYFILE

public static final java.lang.String HISTORYFILE
See Also:
Constant Field Values

STACKTRACE_FILTERED_MESSAGE

public static final java.lang.String STACKTRACE_FILTERED_MESSAGE
See Also:
Constant Field Values

STACKTRACE_MESSAGE

public static final java.lang.String STACKTRACE_MESSAGE
See Also:
Constant Field Values

SECURE_MASK_CHAR

public static final java.lang.Character SECURE_MASK_CHAR
Constructor Detail

GrailsConsole

protected GrailsConsole()
                 throws java.io.IOException
Throws:
java.io.IOException
Method Detail

getErr

public java.io.PrintStream getErr()

setErr

public void setErr(java.io.PrintStream err)

setOut

public void setOut(java.io.PrintStream out)

createConsoleReader

protected jline.ConsoleReader createConsoleReader()
                                           throws java.io.IOException
Throws:
java.io.IOException

createTerminal

protected jline.Terminal createTerminal()
Creates the instance of Terminal used directly in GrailsConsole. Note that there is also another terminal instance created implicitly inside of ConsoleReader. That instance is controlled by the jline.terminal system property.


prepareHistory

protected jline.History prepareHistory()
                                throws java.io.IOException
Prepares a history file to be used by the ConsoleReader. This file will live in the home directory of the user.

Throws:
java.io.IOException

ansiWrap

protected java.io.OutputStream ansiWrap(java.io.OutputStream out)
Hook method that allows controlling whether or not output streams should be wrapped by AnsiConsole.wrapOutputStream. Unfortunately, Eclipse consoles will look to the AnsiWrap like they do not understand ansi, even if we were to implement support in Eclipse to' handle it and the wrapped stream will not pass the ansi chars on to Eclipse).


isWindows

public boolean isWindows()

getInstance

public static GrailsConsole getInstance()

setInstance

public static void setInstance(GrailsConsole newConsole)

createInstance

public static GrailsConsole createInstance()
                                    throws java.io.IOException
Throws:
java.io.IOException

setAnsiEnabled

public void setAnsiEnabled(boolean ansiEnabled)

setVerbose

public void setVerbose(boolean verbose)
Parameters:
verbose - Sets whether verbose output should be used

setStacktrace

public void setStacktrace(boolean stacktrace)
Parameters:
stacktrace - Sets whether to show stack traces on errors

isVerbose

public boolean isVerbose()
Returns:
Whether verbose output is being used

isStacktrace

public boolean isStacktrace()
Returns:
Whether to show stack traces

getInput

public java.io.InputStream getInput()
Returns:
The input stream being read from

getLastMessage

public java.lang.String getLastMessage()
Returns:
The last message logged

setLastMessage

public void setLastMessage(java.lang.String lastMessage)

getReader

public jline.ConsoleReader getReader()

getTerminal

public jline.Terminal getTerminal()

getOut

public java.io.PrintStream getOut()

getCategory

public java.util.Stack<java.lang.String> getCategory()

indicateProgress

public void indicateProgress()
Indicates progress with the default progress indicator


indicateProgress

public void indicateProgress(int number,
                             int total)
Indicate progress for a number and total

Parameters:
number - The current number
total - The total number

indicateProgressPercentage

public void indicateProgressPercentage(long number,
                                       long total)
Indicates progress as a percentage for the given number and total

Parameters:
number - The number
total - The total

indicateProgress

public void indicateProgress(int number)
Indicates progress by number

Parameters:
number - The number

updateStatus

public void updateStatus(java.lang.String msg)
Updates the current state message

Parameters:
msg - The message

addStatus

public void addStatus(java.lang.String msg)
Keeps doesn't replace the status message

Parameters:
msg - The message

error

public void error(java.lang.String msg)
Prints an error message

Parameters:
msg - The error message

warning

public void warning(java.lang.String msg)
Prints an error message

Parameters:
msg - The error message

warn

public void warn(java.lang.String msg)
Prints a warn message

Parameters:
msg - The message

isAnsiEnabled

public boolean isAnsiEnabled()

error

public void error(java.lang.String msg,
                  java.lang.Throwable error)
Use to log an error

Parameters:
msg - The message
error - The error

error

public void error(java.lang.Throwable error)
Use to log an error

Parameters:
error - The error

log

public void log(java.lang.String msg)
Logs a message below the current status message

Parameters:
msg - The message to log

append

public void append(java.lang.String msg)

info

public void info(java.lang.String msg)
Synonym for #log

Parameters:
msg - The message to log

verbose

public void verbose(java.lang.String msg)

echoStatus

public void echoStatus()
Replays the last status message


userInput

public java.lang.String userInput(java.lang.String msg)
Replacement for AntBuilder.input() to eliminate dependency of GrailsScriptRunner on the Ant libraries. Prints a message and returns whatever the user enters (once they press <return>).

Parameters:
msg - The message/question to display.
Returns:
The line of text entered by the user. May be a blank string.

secureUserInput

public java.lang.String secureUserInput(java.lang.String msg)
Like userInput(String) except that the user's entered characters will be replaced with '*' on the CLI, masking the input (i.e. suitable for capturing passwords etc.).

Parameters:
msg - The message/question to display.
Returns:
The line of text entered by the user. May be a blank string.

showPrompt

public java.lang.String showPrompt()
Shows the prompt to request user input

Returns:
The user input prompt

userInput

public java.lang.String userInput(java.lang.String message,
                                  java.util.List<java.lang.String> validResponses)

userInput

public java.lang.String userInput(java.lang.String message,
                                  java.lang.String[] validResponses)
Replacement for AntBuilder.input() to eliminate dependency of GrailsScriptRunner on the Ant libraries. Prints a message and list of valid responses, then returns whatever the user enters (once they press <return>). If the user enters something that is not in the array of valid responses, the message is displayed again and the method waits for more input. It will display the message a maximum of three times before it gives up and returns null.

Parameters:
message - The message/question to display.
validResponses - An array of responses that the user is allowed to enter. Displayed after the message.
Returns:
The line of text entered by the user, or null if the user never entered a valid string.

error

public void error(java.lang.String label,
                  java.lang.String message)

flush

public void flush()