GR8Conf 2009. The Grails Plugin System by Graeme Rocher

  • 3,189 views
Uploaded on

Graeme Rocher, Grails project lead, presents the Grails plugin system.

Graeme Rocher, Grails project lead, presents the Grails plugin system.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
3,189
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
129
Comments
0
Likes
4

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Grails Plugins Modularizing your application with Plugins Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 2. Objectives • Understand the basics of the Grails plugin system • Explore how to create modular applications through plugins • Unlock the potential of Convention over Configuration Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 2
  • 3. Agenda • Plugin basics • Creating, packaging and installing plugins • Building functional plugins • Automating configuration • Enhancing behavior Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 3
  • 4. 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 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 4
  • 5. The Plugin Architecture Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 5
  • 6. The Extension Points • Build System • Spring Application Context • Dynamic method registration • Auto Reloading • Container Config (web.xml) • Adding new Artefacts Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 6
  • 7. 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! Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 7
  • 8. 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 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 8
  • 9. A Plugin Project A Plugin project is the same as a regular Grails project except it has a special plugin Groovy Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 9
  • 10. The Plugin Descriptor class LoggingGrailsPlugin { def version = 0.4 def dependsOn = [core:"1.0 > *"] ... Plug-in Dependencies The Plugin Version } Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 10
  • 11. 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 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 11
  • 12. Plugins & Application Modularity Messaging Security Search Plugin Plugin Plugin Grails Application Blog Wiki Maps Plugin Plugin Plugin Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 12
  • 13. 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! Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 13
  • 14. Demo Building a Functional Plugin Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 15. Automating Configuration import org.springframework.cache.ehcache.* import grails.util.* Implement ‘doWithSpring’ to modify Spring context def doWithSpring = { blogCache(EhCacheFactoryBean) { if(Environment.current == Environment.PRODUCTION) { timeToLive = 2400 } Sets the “timeToLive” of } the cache for Configures a Spring production only bean called “blogCache” Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 15
  • 16. 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) Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 16
  • 17. Enhancing Behavior def doWithDynamicMethods = { ApplicationContext ctx -> application.domainClasses.each { domainClass -> domainClass.metaClass.constructor = {-> ctx.getBean("Bookmark") } Support auto-wiring from Spring in regular constructors! // 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) } } } Interact with the Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Hibernate session!17
  • 18. 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 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 18
  • 19. What plugins enable... Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 19
  • 20. What plugins enable... • Test Grails: selenium, fitnesse, code coverage etc. Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 19
  • 21. What plugins enable... • Test Grails: selenium, fitnesse, code coverage etc. • Rich Grails: Flex, GWT, GrailsUI (YahooUI) etc. Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 19
  • 22. What plugins enable... • Test Grails: selenium, fitnesse, code coverage etc. • Rich Grails: Flex, GWT, GrailsUI (YahooUI) etc. • Secure Grails: Spring Security, JSecurity, OpenID etc. Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 19
  • 23. 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, Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 19
  • 24. The Plugin Portal • http://grails.org/ Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 20
  • 25. 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 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 21
  • 26. Q&A Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.