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

16
Grails Plugin Magic Scott Ryan Soaring Eagle L.L.C. [email protected] March 2010 Colorado Spring Open Source User Group

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

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

Grails Plugin Magic

Scott RyanSoaring Eagle [email protected] 2010Colorado Spring Open Source User Group

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

Agenda

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

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

What do you know?

Grails Java, Groovy Spring, Hibernate Maven , Ivy

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

Grails Overview

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

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

Grails Overview

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

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

Grails Benefits

Supports Java Framework Leadership Technologies

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

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

Plugin Functions

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

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

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)

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

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

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

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

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

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

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

Scripts

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

_Upgrade.groovy Called on upgraded Gant based

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

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)

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

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

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

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.

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

Sample Plugins

Jquery Hibernate Filter Falcone Multi tenant