Download - Grails 3 Inside and Out
![Page 1: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/1.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
SPRINGONE2GXWASHINGTON, DC
Grails 3 Inside & OutBy Graeme Rocher
@graemerocher
![Page 2: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/2.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Who we are?
Jeff Scott Brown Object Computing Inc. @jeffscottbrown [email protected]
2
Graeme Rocher Object Computing Inc. @graemerocher [email protected]
![Page 3: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/3.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Grails + OCI• OCI focused on Grails• Full service support
– Consulting– Training– Support
• Commitment to engineering • Grails team at OCI growing
– Come speak to us!
3
![Page 4: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/4.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/ 4
More at ociweb.com/grails
Visit the OCI’s Table #2 to meet our Grails Team!
Graeme Rocher Jeff Brown
Dave Klein Colin Harrington
![Page 5: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/5.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Agenda• Plugins & Traits• Plugins & Events• Configuration API• Code Generation API• Gradle & The Shell
5
![Page 6: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/6.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
The Example• Build a Mail Sender Plugin
• Trait• Events• Configuration• Code Generation
6
![Page 7: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/7.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
SPRINGONE2GXWASHINGTON, DC
Plugins & Traits
![Page 8: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/8.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Adding Behaviour with Traits• Use Enhances to add behaviour
8
importgrails.artefact.*
@Enhances('Controller')traitMyTrait{voidmyNewMethod(){…}}
![Page 9: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/9.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Core Grails Traits• Controller - implemented by all controllers• DomainClass - implemented by all domain classes
• GormEntity - implemented by all GORM entities• Service - implemented by all services• TagLibrary - implemented by all tag libraries• Interceptor - all Grails interceptors• Events - Any object that wants to send events
9
![Page 10: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/10.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
SPRINGONE2GXWASHINGTON, DC
Events
![Page 11: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/11.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Events• Any class that implements the Events trait can send and receive events• Controllers and services implement the trait by default• You can effectively decouple systems using an event driven approach• Fits nicely with reactive programming• Events are built on the Reactor framework
• http://projectreactor.io
11
![Page 12: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/12.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Events• Use on to listen and notify to send or combine with sendAndReceive
12
notify('mail:sent',eventFor(message))
on('mail:sent'){Event<TYPE>event->//dostuff}
![Page 13: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/13.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Events• The Consumer and Selector annotations from Spring Reactor work too!
13
@ConsumerclassMyService{
@Selector('mail:sent')voidmailEventListener(MailMessagemsg){//dostuff}}
![Page 14: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/14.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
SPRINGONE2GXWASHINGTON, DC
Configuration API
![Page 15: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/15.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Configuration API
15
booleanisFooEnabled=config.getProperty('foo.bar',Boolean,true)
//or
@Value('foo.bar')booleanisFooEnabled
![Page 16: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/16.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Plugins & Configuration• Applications inherit plugin configuration• You should keep your plugin configuration minimal• Plugin configuration defines the default values• Applications can override any plugin provided value
16
![Page 17: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/17.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
SPRINGONE2GXWASHINGTON, DC
Code Generation & Grails
![Page 18: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/18.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Code Generation Scripts• Go in src/main/scripts in plugins or applications• All scripts subclass the GroovyScriptCommand class• Some handy properties
• gradle - for invoking Gradle• ant - for invoking Ant• methodMissing - for invoking other code gen commands
• Useful traits• TemplateRenderer - for rendering templates• FileSystemInteraction - for interacting with the file system
18
![Page 19: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/19.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Code Generation Scripts• The model method exposes a Model interface for introspecting conventions
19
interfaceModel{StringgetClassName()StringgetFullName()StringgetPackageName()…StringgetLowerCaseName()Stringconvention(StringconventionName)Map<String,Object>asMap()}
![Page 20: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/20.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
DSL for Code Generation Scripts
20
description("Createsaservicethatsendsamail"){usage"Thisdoescoolsstuff"}
defmodel=model(args[0])
rendertemplate:template('MailService.groovy'),destination:file("grails-app/services/${model.packagePath}/${model.convention('Service')}.groovy"),model:model
![Page 21: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/21.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
SPRINGONE2GXWASHINGTON, DC
Gradle & The Shell
![Page 22: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/22.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Gradle & The Shell• Create Gradle tasks that invoke your app
• Without knowing any Gradle! ;-)
22
classMailBatcherCommandimplementsApplicationCommand{booleanhandle(ExecutionContextcontext){//DOSTUFFreturntrue}}
![Page 23: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/23.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Gradle & The Shell• Just add to build.gradle build class path and run the command
23
classpath'org.grails.plugins:mailSender:0.1-SNAPSHOT'
gradlebatchSendMailgrailsbatch-send-mail
![Page 24: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/24.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Summary• Grails 3 provides powerful techniques to build plugins that empower your
application• The core philosophy of plugins and modular applications continues• Through traits and events Grails 3 is more powerful that ever before!• Grails’ internals are all based on the described techniques
24
![Page 25: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/25.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Q & A
25
![Page 26: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/26.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/ 26
More at ociweb.com/grails
The OCI Grails Team is growing — will You join us?
![Page 27: Grails 3 Inside and Out](https://reader034.vdocuments.site/reader034/viewer/2022051404/587759021a28ab4e4f8b4e75/html5/thumbnails/27.jpg)
Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Stay Connected.
Web: grails.orgStackOverflow: http://stackoverflow.com/tags/grails Slack: http://slack-signup.grails.org Twitter: twitter.com/grailsframeworkLinkedIn: http://linkedin.com/groups/Grails-User-Group-39757
27
More at ociweb.com/grails