GR8Conf 2009. The Grails Plugin System by Graeme Rocher
-
Upload
gr8conf -
Category
Art & Photos
-
view
3.260 -
download
2
description
Transcript of GR8Conf 2009. The Grails Plugin System by Graeme Rocher
![Page 1: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/1.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Modularizing your application with Plugins
Grails Plugins
![Page 2: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/2.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Objectives
• Understand the basics of the Grails plugin system
• Explore how to create modular applications through plugins
• Unlock the potential of Convention over Configuration
2
![Page 3: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/3.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Agenda
• Plugin basics• Creating, packaging and installing plugins• Building functional plugins• Automating configuration• Enhancing behavior
3
![Page 4: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/4.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
The Background
• Grails is designed to wire together different libraries and make them easy to use
• In this sense it can be seen as a "platform for runtime configuration"
• De-coupling those components was hard without a well defined system
4
![Page 5: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/5.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
The Plugin Architecture
5
![Page 6: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/6.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
The Extension Points
• Build System• Spring Application Context• Dynamic method
registration• Auto Reloading• Container Config (web.xml)• Adding new Artefacts
6
![Page 7: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/7.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
What is a Plugin?
• Just like a normal Grails project!
• The only difference is the presence of a *GrailsPlugin.groovy file
• Use grails create-plugin to create one!
7
![Page 8: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/8.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Creating and Running a Plugin
• A plugin is just a regular Grails project and can be developed like one:
$ grails create-plugin blog
$ cd ../blog
$ grails run-app
8
![Page 9: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/9.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
A Plugin Project
A Plugin project is the same as a regular Grails project except it has a special plugin Groovy
9
![Page 10: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/10.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
The Plugin Descriptor
The Plugin Version
10
class LoggingGrailsPlugin {
def version = 0.4 def dependsOn = [core:"1.0 > *"]
...
}
Plug-in Dependencies
![Page 11: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/11.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Packaging & Installation
• Installation of Grails plugins can then be achieved with a few simple commands:
$ grails package-plugin
$ cd ../my-project$ grails install-plugin ../logging/grails-blog-0.4.zip// or remotely$ grails install-plugin http://myserver/grails-blog-0.4.zip
11
![Page 12: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/12.jpg)
Grails
Application
Search Plugin
Security Plugin
Messaging Plugin
Blog Plugin
Wiki Plugin
MapsPlugin
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Plugins & Application Modularity
12
![Page 13: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/13.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Adding Basic Artefacts
• A Plugin can add new tag libraries, controllers and services simply by creating them in the plugin project
• Since a plugin project is just like any project you can run and debug a plugin in its own project before distributing it
• Once you're done package and distribute it!
13
![Page 14: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/14.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Demo
Building a Functional Plugin
![Page 15: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/15.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Automating Configuration
import org.springframework.cache.ehcache.*import grails.util.*
def doWithSpring = {
blogCache(EhCacheFactoryBean) { if(Environment.current == Environment.PRODUCTION) { timeToLive = 2400 } }
15
Configures a Spring bean called “blogCache”
Sets the “timeToLive” of the cache for production only
Implement ‘doWithSpring’ to modify Spring context
![Page 16: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/16.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Automating Configuration
• Plugins allow you to manipulate the underlying Spring context based on:– The Environment– The Conventions– The State of other Plugins
• Simply implement the doWithSpring plugin hook
• See the user guide for a description of the Spring Domain Specific Langauge (DSL)
16
![Page 17: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/17.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Enhancing Behaviordef doWithDynamicMethods = { ApplicationContext ctx ->
application.domainClasses.each { domainClass -> domainClass.metaClass.constructor = {->
ctx.getBean("Bookmark") }
// adds a new Foo.load(21) method
def template = new HibernateTemplate(ctx.getBean("sessionFactory"))
domainClass.metaClass.static.load = {Long id-> template.load(delegate.getClass(), id)
} }
}
Support auto-wiring from Spring in regular constructors!
Interact with the Hibernate session!17
![Page 18: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/18.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Enhancing Behavior
• Plugins can add new methods and APIs using metaprogramming techniques
• Simply implement the doWithSpring plugin hook
• See the metaprogramming guide on Groovy’s website: http://groovy.codehaus.org/Dynamic+Groovy
• Huge number of possibilities are opened up via plugins
18
![Page 19: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/19.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
What plugins enable...
19
![Page 20: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/20.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
What plugins enable...
• Test Grails: selenium, fitnesse, code coverage etc.
19
![Page 21: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/21.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
What plugins enable...
• Test Grails: selenium, fitnesse, code coverage etc.
• Rich Grails: Flex, GWT, GrailsUI (YahooUI) etc.
19
![Page 22: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/22.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
What plugins enable...
• Test Grails: selenium, fitnesse, code coverage etc.
• Rich Grails: Flex, GWT, GrailsUI (YahooUI) etc.
• Secure Grails: Spring Security, JSecurity, OpenID etc.
19
![Page 23: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/23.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
What plugins enable...
• Test Grails: selenium, fitnesse, code coverage etc.
• Rich Grails: Flex, GWT, GrailsUI (YahooUI) etc.
• Secure Grails: Spring Security, JSecurity, OpenID etc.
• Integrate Grails: Search, Jasper Reports, JMS etc,
19
![Page 24: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/24.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
The Plugin Portal• http://grails.org/
20
![Page 25: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/25.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Summary
• Plugins are crucial the the Grails story• Everyone is a plugin developer, not just
the gurus• Plugins help create modular applications• Plugin automate configuration through
Convention over Configuration
21
![Page 26: GR8Conf 2009. The Grails Plugin System by Graeme Rocher](https://reader033.fdocuments.us/reader033/viewer/2022052823/554ff28ab4c905bc138b4a26/html5/thumbnails/26.jpg)
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Q & A