Usage
- Type any Groovy command in the console text area, then press "Execute"
- Keyboard Shortcuts:
- Ctrl + Return - Execute
- Esc + Esc - Clear output
- The following implicit variables are available:
- application - grailsApplication instance, e.g.
application.getFlatConfig().each{ k,v ->
println k.padRight(40) + v
}
- context or ctx - Spring ApplicationContext, e.g.
import groovy.sql.Sql
def dataSource = context.getBean('dataSource')
def sql = Sql.newInstance(dataSource)
sql.eachRow("select * from information_schema.system_tables", {
println "${it.TABLE_NAME}"
})
- session - the current HTTP session
session.getAttributeNames().each{ attr ->
println attr.padRight(40) + session.getAttribute(attr)
}
- request - the current HTTP request, e.g.
def params = ['requestURI', 'requestURL', 'forwardURI']
params.each{
println it + "\\t" + request."$it"
}
- shell - the Groovy Shell instance
println shell.'application'
println application
println shell.'application' == application
- defining variables
- The console instance is maintained in session scope.
- similar to normal Groovy Shell, you don't need to use "def" to declare a variable, e.g. the following won't work
def foo = "bar"
(execute)
println foo
(execute)
- but you can use
foo = "bar"
(execute)
println foo
(execute)
- Result Area
- The result area display the output of "println" and the return value of the last line of execute (in blue).
Concepts
- The console plugin relies on Groovy Shell. Lookup Groovy Shell documentation for more information.
- The Groovy Shell uses the root classloader of Grails, so you could access any class as same as any object in the Grails application.
Security Warning
- IMPORTANT In the current version, no security feature is implemented and the '/console' path is accessible from anywhere. You shall have a firewall to protect your console against unauthorized access.
Compatiability
- This plugin is tested with Grails 1.1 RC1
The console doesn't support IE6
Reference
Development
Author Siegfried Puchbauer, Mingfai Ma