Grails Plugins DJUG and Colorado Springs Open Source User's Group 2009

Post on 13-May-2015

723 views 0 download

Tags:

description

An overview of Grails plugin development and specifics on the development and use of the multi tenant plugin

Transcript of Grails Plugins DJUG and Colorado Springs Open Source User's Group 2009

Grails Plugin Magic

Scott RyanSoaring Eagle L.L.C.scott@theryansplace.comMarch 2010Colorado Spring Open Source User Group

Agenda

Grails Overview Plugin Architecture Sample Plugins Other Modification Options Q & A

What do you know?

Grails Java, Groovy Spring, Hibernate Maven , Ivy

Grails Overview

Integrated framework based on Groovy Spring MVC / GSP Spring Hibernate GSP Sitemesh

Grails Overview

Convention over configuration Dynamic framework for ease of development Lots of code generation Plugin Framework allows extension

Grails Benefits

Supports Java Framework Leadership Technologies

Quick development turn-around Good performance Easy extensibility Runs on the JVM

Plugin Functions

Integrate new libraries Add incremental Functionality Exchange Frameworks Inject or Modify behavior Add build support Can include other libraries or plugins

Plugin Development

Uses standard Grails Application grails create-plugin name Update the plugin class Create the plugin grails package-plugin grails release-plugin grails install-plugin (local or repository)

Plugin Integration

Plugins never modify application main source Source is copied to /plugins/-name-/grails-app Static resources are copied to

web-app/plugins/-name-/js etc. Plugins never modify web.xml or application.xml ${pluginContextPath} variable helps locate

resources

What can I do in a Plugin?

Add Basic Artifacts (Controllers, GSP , Services, etc.)

Integrate with build script events Integrate with runtime configuration Add Dynamic Methods Integrate with auto reload events

Adding Basic Artifacts

Domain,Controllers, Services, GSP Follow conventions Try to use unique names (UGH) Use packages for all code Integrate with conf.groovy or provide config

file Remember you are only a guest

Scripts

_Install.groovy Called on installation Can be used to copy or modify files Gant based

_Upgrade.groovy Called on upgraded Gant based

Hooking into Build Events

_Events.groovy One per plugin Per User file in .grails user directory

Open Framework Closures begin with “event” and then the

name of the event Trigger events with event method

event( eventName, message)

Integrating with Runtime

doWithSpring closure Allows you to add to the spring configuration

using spring bean builder syntax doWithWebDescriptor closure

Passes in the xml variable doWithApplicationContext closure

Run after the application context is assembled Passes in the application context

Adding Dynamic Methods

doWithDynamicMethods closure Grails artifacts expose the metaclass via the

expandometaclass to add methods, constructors, etc.

Other classes allow you to use the metaclass to add methods, constructors, etc.

Application context is passed in so you can interact with artifacts within it.

Sample Plugins

Jquery Hibernate Filter Falcone Multi tenant