SlideShare a Scribd company logo
Grails Plugins

                                         Modularizing your application with
                                                      Plugins




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




Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   2
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
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
The Plugin Architecture




Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   5
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
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
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
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
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
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
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
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
Demo

                                                      Building a Functional Plugin




Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
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
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
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
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
What plugins enable...




Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   19
What plugins enable...

                • Test Grails: selenium,
                  fitnesse, code coverage etc.




Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   19
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
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
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
The Plugin Portal
                     • http://grails.org/




Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   20
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
Q&A




Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.

More Related Content

PDF
Running Spring Boot Applications as GraalVM Native Images
PPT
Extend your CMS Investment to Video Content
PPTX
Mobile Application Testing in the Cloud - Oct 2012
PPT
Pinax Long Tutorial Slides
PDF
Intro to Pinax: Kickstarting Your Django Apps
PPTX
Maven
PDF
Next Generation Development Infrastructure: Maven, m2eclipse, Nexus & Hudson ...
PPTX
Running Spring Boot Applications as GraalVM Native Images
Extend your CMS Investment to Video Content
Mobile Application Testing in the Cloud - Oct 2012
Pinax Long Tutorial Slides
Intro to Pinax: Kickstarting Your Django Apps
Maven
Next Generation Development Infrastructure: Maven, m2eclipse, Nexus & Hudson ...

What's hot (19)

PDF
Flex Continuous Quality Builds Flex & (Ant || Maven)
PDF
Mobile developments at eXo
PPTX
Webex Teams Widgets Technical Drill down - Cisco Live Orlando 2018 - DEVNET-3891
PPTX
Chatbots 101: design, code, deploy - Cisco Live Orlando 2018 - DEVNET-2896
KEY
OSGi, Eclipse and API Tooling
PDF
Basics About Git & GitHub
PDF
GR8Conf 2011: Groovy Maven Builds
PDF
Seven Simple Reasons to Use AppFuse
PDF
Spring Native and Spring AOT
PDF
Eclipse vs Netbean vs Railo
PDF
Enterprise Maven Repository BOF
KEY
Tycho - good, bad or ugly ?
KEY
Magnolia CMS 5.0 - Architecture
PDF
Resource Handling in Spring MVC 4.1
KEY
How to be effective with JBoss Developer Studio
PDF
Groovy for Java Devs
PPTX
What's new in Spring Boot 2.0
PDF
Build system
PDF
Perspectives on Cloud COmputing - Google
Flex Continuous Quality Builds Flex & (Ant || Maven)
Mobile developments at eXo
Webex Teams Widgets Technical Drill down - Cisco Live Orlando 2018 - DEVNET-3891
Chatbots 101: design, code, deploy - Cisco Live Orlando 2018 - DEVNET-2896
OSGi, Eclipse and API Tooling
Basics About Git & GitHub
GR8Conf 2011: Groovy Maven Builds
Seven Simple Reasons to Use AppFuse
Spring Native and Spring AOT
Eclipse vs Netbean vs Railo
Enterprise Maven Repository BOF
Tycho - good, bad or ugly ?
Magnolia CMS 5.0 - Architecture
Resource Handling in Spring MVC 4.1
How to be effective with JBoss Developer Studio
Groovy for Java Devs
What's new in Spring Boot 2.0
Build system
Perspectives on Cloud COmputing - Google
Ad

Similar to GR8Conf 2009. The Grails Plugin System by Graeme Rocher (20)

PDF
Gradle - Build System
PPTX
Custom Runtimes for the Cloud
PDF
Introduction To Groovy And Grails - SpringPeople
PPTX
Setting Up Development Environment For Google App Engine & Python | Talentica
PDF
Keeping your build tool updated in a multi repository world
PPTX
Flask and Introduction to web frameworks
PPTX
Gradle,the new build system for android
PPTX
Drupal Solutions Comparison For Multiple Sites With Related Content - Acquia ...
PPTX
Advanced angular
PPT
Open up your platform with Open Source and GitHub
PDF
Building GPE: What We Learned
PDF
UnBBayes Plugin Framework
PPTX
Apigee deploy grunt plugin.1.0
PDF
Cut your Grails application to pieces - build feature plugins
PPTX
Ways to Level Up Your Java Application with GraalVM.pptx
PDF
Self Hosted Web-based GIT Repository Managers
PPT
Moving the Guidewire platform to OSGi - Paul D'Albora
PPTX
Alfresco DevCon 2018: SDK 3 Multi Module project using Nexus 3 for releases a...
PDF
ICONUK 2015 - Gradle Up!
PDF
Operations and Monitoring with Spring
Gradle - Build System
Custom Runtimes for the Cloud
Introduction To Groovy And Grails - SpringPeople
Setting Up Development Environment For Google App Engine & Python | Talentica
Keeping your build tool updated in a multi repository world
Flask and Introduction to web frameworks
Gradle,the new build system for android
Drupal Solutions Comparison For Multiple Sites With Related Content - Acquia ...
Advanced angular
Open up your platform with Open Source and GitHub
Building GPE: What We Learned
UnBBayes Plugin Framework
Apigee deploy grunt plugin.1.0
Cut your Grails application to pieces - build feature plugins
Ways to Level Up Your Java Application with GraalVM.pptx
Self Hosted Web-based GIT Repository Managers
Moving the Guidewire platform to OSGi - Paul D'Albora
Alfresco DevCon 2018: SDK 3 Multi Module project using Nexus 3 for releases a...
ICONUK 2015 - Gradle Up!
Operations and Monitoring with Spring
Ad

More from GR8Conf (20)

PDF
DevOps Enabling Your Team
PDF
Creating and testing REST contracts with Accurest Gradle
PDF
Mum, I want to be a Groovy full-stack developer
PDF
Metaprogramming with Groovy
PDF
Scraping with Geb
PDF
How to create a conference android app with Groovy and Android
PDF
Ratpack On the Docks
PDF
Groovy Powered Clean Code
PDF
Performance tuning Grails applications
PDF
Ratpack and Grails 3
PDF
Grails & DevOps: continuous integration and delivery in the cloud
PDF
Functional testing your Grails app with GEB
PDF
Deploying, Scaling, and Running Grails on AWS and VPC
PDF
The Grails introduction workshop
PDF
Idiomatic spock
PDF
The Groovy Ecosystem Revisited
PDF
Groovy 3 and the new Groovy Meta Object Protocol in examples
PDF
Integration using Apache Camel and Groovy
PDF
CRaSH the shell for the Java Virtual Machine
PDF
Grooscript gr8conf
DevOps Enabling Your Team
Creating and testing REST contracts with Accurest Gradle
Mum, I want to be a Groovy full-stack developer
Metaprogramming with Groovy
Scraping with Geb
How to create a conference android app with Groovy and Android
Ratpack On the Docks
Groovy Powered Clean Code
Performance tuning Grails applications
Ratpack and Grails 3
Grails & DevOps: continuous integration and delivery in the cloud
Functional testing your Grails app with GEB
Deploying, Scaling, and Running Grails on AWS and VPC
The Grails introduction workshop
Idiomatic spock
The Groovy Ecosystem Revisited
Groovy 3 and the new Groovy Meta Object Protocol in examples
Integration using Apache Camel and Groovy
CRaSH the shell for the Java Virtual Machine
Grooscript gr8conf

Recently uploaded (20)

PDF
TUTI FRUTI RECETA RÁPIDA Y DIVERTIDA PARA TODOS
PDF
the saint and devil who dominated the outcasts
PPTX
VAD - Acute and chronic disorders of mesenteric.pptx
PPTX
Technical-Codes-presentation-G-12Student
PPTX
G10 HOMEROOM PARENT-TEACHER ASSOCIATION MEETING SATURDAY.pptx
PDF
Close Enough S3 E7 "Bridgette the Brain"
PPTX
Visual-Arts.pptx power point elements of art the line, shape, form
PDF
DPSR MUN'25 (U).pdf hhhhhhhhhhhhhbbnhhhh
PPTX
Green and Orange Illustration Understanding Climate Change Presentation.pptx
PPTX
vsfbvefbegbefvsegbthnmthndgbdfvbrsjmrysnedgbdzndhzmsr
PPTX
Lesson 1-Principles of Indigenous Creative Crafts.pptx
PPTX
400kV_Switchyard_Training_with_Diagrams.pptx
PPTX
65bc3704-6ed1-4724-977d-a70f145d40da.pptx
PPTX
MUSIC-W1-Q1-1.pptxL;ML;MLNL;NL;NL;N;LNL;NL;N
PPTX
CPAR7 ARTS GRADE 112 LITERARY ARTS OR LI
PPTX
Callie Slide Show Slide Show Slide Show S
PPTX
SlideEgg_21518-Company Presentation.pptx
PPTX
Socio ch 1 characteristics characteristics
PDF
Ricardo Salinas Pliego Accused of Acting as A Narcotics Kingpin
PPTX
EJ Wedding 520 It's official! We went to Xinyi District to do the documents
TUTI FRUTI RECETA RÁPIDA Y DIVERTIDA PARA TODOS
the saint and devil who dominated the outcasts
VAD - Acute and chronic disorders of mesenteric.pptx
Technical-Codes-presentation-G-12Student
G10 HOMEROOM PARENT-TEACHER ASSOCIATION MEETING SATURDAY.pptx
Close Enough S3 E7 "Bridgette the Brain"
Visual-Arts.pptx power point elements of art the line, shape, form
DPSR MUN'25 (U).pdf hhhhhhhhhhhhhbbnhhhh
Green and Orange Illustration Understanding Climate Change Presentation.pptx
vsfbvefbegbefvsegbthnmthndgbdfvbrsjmrysnedgbdzndhzmsr
Lesson 1-Principles of Indigenous Creative Crafts.pptx
400kV_Switchyard_Training_with_Diagrams.pptx
65bc3704-6ed1-4724-977d-a70f145d40da.pptx
MUSIC-W1-Q1-1.pptxL;ML;MLNL;NL;NL;N;LNL;NL;N
CPAR7 ARTS GRADE 112 LITERARY ARTS OR LI
Callie Slide Show Slide Show Slide Show S
SlideEgg_21518-Company Presentation.pptx
Socio ch 1 characteristics characteristics
Ricardo Salinas Pliego Accused of Acting as A Narcotics Kingpin
EJ Wedding 520 It's official! We went to Xinyi District to do the documents

GR8Conf 2009. The Grails Plugin System by Graeme Rocher

  • 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.