Console Plugin

11 votes

4% of Grails users

Dependency :
compile ":console:1.2"

Documentation Source Issues

Summary

A web-based Groovy console for interactive runtime application management and debugging

Installation

Installation

  • in command prompt, under your project directory
    grails install-plugin console
  • access the console under ${contextPath}/console, e.g. http://localhost:8080/consoleDemo/console

Description

Usage

  • Run your web application using grails run-app, then use a browser to navigate to the /console page of your app - most likely http://localhost:8080/<app-name>/console
  • Type any Groovy commands in the console text area, then press "Execute"
  • Keyboard Shortcuts:
    • Ctrl + Enter - Execute
    • Esc - Clear output
  • The following implicit variables are available:
grailsApplication.domainClasses.each {
   println "There are ${it.clazz.count()} instances of $it.clazz.simpleName"
}
import groovy.sql.Sql

def dataSource = ctx.dataSource def sql = Sql.newInstance(dataSource) sql.eachRow("select * from information_schema.system_tables", { println it.TABLE_NAME })

session.attributeNames.each { name ->
   println name.padRight(40) + session.getAttribute(name)
}
def params = ['requestURI', 'requestURL', 'forwardURI']
params.each {
   println it + "\t" + request."$it"
}
    • config - the current Grails config, e.g.
config.flatten().each { name, value ->
   println name.padRight(40) + value
}
  • Result Area
    • The results area displays the output of println statements and the return value of the last line executed (in blue).
    • Exceptions are also shown in the results area but with a red background
    • Additionally the execution time of your script is shown along with the output or exception

Concepts

  • The console plugin relies on Groovy Shell. Lookup Groovy Shell documentation for more information.
  • The Groovy Shell uses the Grails classloader, so you can access any class or artifact (e.g. domain classes, services, etc.) just like in your application code.

Security Warning

  • IMPORTANT In the current version, no security feature is implemented and the '/console' path is accessible from anywhere. You're strongly encouraged to guard access to the console using a security plugin, for example Spring Security Core or Shiro.

Reference

Development

Questions, issues, etc.

  • If have questions or suggestions about the plugin, ask on the Grails User mailing list. Report bugs in JIRA.

Authors

  • Siegfried Puchbauer
  • Mingfai Ma
  • Burt Beckwith
  • Matt Sheehan
  • Mike Hugo