Building Grails Plugins
tips and tricks from the wild
About Me
• • •
Mike Hugo, Independent Software Developer
• •
http://piragua.com http://WhenWorksForYou.com
Groovy/Grails since2007 Author of several Grails plugins
• • •
code-coverage hibernate-stats test-template
• • •
greenmail build-info ????
• Plugins overview • Build your own plugin • testing •modularization • configuration • events • did I mention testing?
what’s on the menu for tonight?
App
Plugin
a plugin is just another grails application, with a few extra files * GrailsPlugin.groovy *Install, Uninstall and Upgrade scripts
Cool hooks into the runtime environment of a running grails app, plus ability to add new ‘artefacts’ and participate in reloading events
ExistingPlugins
there are a ton of existing plugins from security to Rich UI to searching to...you name it.
common problem - this is one i’ve solved about 6 times. time for a plugin
• grailscreate-plugin build-status • cd build-status • mkdir test/projects • cd test/projects • grails create-app statusapp
gives you a client you can use to test your plugin. why?
development
• make a change tothe plugin • grails package-plugin • cd test/projects/statusapp/ • grails install-plugin ../../../grails-build-status-0.1.zip • grails run-app • wash, rinse, repeat
In Place Plugins
• In theapplication just created, modify
BuildConfig.groovy and add:
• grails.plugin.location."build-status" = "../../.." • TADA! You’re now working with an inplace plugin
Add Controller (test)
importgrails.test.* class BuildInfoControllerTests extends ControllerUnitTestCase { void testIndex() { ! ! ! ! ! ! ! ! } } controller.index() assertEquals('index', renderArgs.view)assertEquals(['app.version'], renderArgs.model.buildInfoProperties)
Add Controller
class BuildInfoController { ! static final List infoProperties = ['app.version'] def index = { ! render view:'index', model:...
Regístrate para leer el documento completo.