SlideShare a Scribd company logo
1 of 30
Grails Custom Plugin
Agenda
× What is plugin.
× Creating and Installing plugin
× Plugin Repositories
× Understanding a Plugin’s Structure
× Evaluating Conventions
× Hooking into Build Events
× Hooking into runtime configuration
× Adding methods at compile time
× Adding Dynamic method at runtime
× Understanding Plugin loader
What is Plugin
× A plugin is a software component which adds a specific
feature to an existing software application.
× Very similar to Grails application project
× A plugin descriptor file *GrailsPlugin.groovy
Creating and Installing Plugin
grails create-plugin [plugin-name]
× In grails-3.* you should profile to create a plugin.
× If you want to create web environment then
grails create-plugin [plugin-name] --profile=web-plugin
× If you want to create a plugin which will be used with other profile
grails create-plugin [plugin-name] --profile=plugin
Note*:- Make sure the plugin name does not contain more than one capital letter
in a row, or it won't work. Camel case is fine, though.
× The structure of a Grails plugin is very nearly the same as a Grails application
project's except that in the src/main/groovy directory under the plugin
package structure you will find a plugin descriptor class (a class that ends in
"GrailsPlugin").
× Being a regular Grails project has a number of benefits in that you can
immediately test your plugin by running (if the plugin targets the "web"
profile):
Note*:- Plugin projects don't provide an index.gsp by default since most plugins
don't need it. So, if you try to view the plugin running in a browser right after
creating it, you will receive a page not found error. You can easily create a grails-
app/views/index.gsp for your plugin if you'd like.
Plugin Descriptor
Class CustomGrailsPlugin{
}
This class defines the metadata about the plugin.
× Title:- short one-sentence description of your plugin
× grailsVersion:- The version range of Grails that the plugin supports. eg. "1.2 > *" (indicating 1.2 or
higher)
× Author :- plugin author's name
× authorEmail:- plugin author's contact e-mail
× Description:- full multi-line description of plugin's features
× Documentation:- URL of the plugin's documentation
× License:- License of the plugin
× Issuemanagement:- Issue Tracker of the plugin
× Scm:- Source code management location of the plugin
Installing Local Plugin
× Add plugin path in BuildConfig
× Add plugin in local maven then add in BuildConfig
Plugin Repositories
× The preferred way to distribute plugin is to publish to the official Grails
Central Plugin Repository. This will make your plugin visible to the list-
plugins command:
grails list-plugins
which lists all plugins that are in the central repository.
× Your plugin will also be available to the plugin-info command:
grails plugin-info [plugin-name]
which prints extra information about it, such as its description, who wrote,
etc.
Understanding a Plugin's Structure
➔ grails-app
◆ conf
◆ controller
◆ domain
◆ taglib
➔ lib
➔ src
◆ java
◆ groovy
➔ web-app
◆ js
◆ css
× When plugin installed, will go directly as plugins/custom-plugin/grails-app.
They will not be copied into main source tree.
× When you run the plugin in development mode the link to the resource will
resolve to something like /js/mycode.js. However, when the plugin is installed
into an application the path will automatically change to something like
/plugin/custom-plugin/js/mycode.js and Grails will deal with making sure the
resources are in the right place.
× pluginContextPath is responsible to manage the static resource path.
× At runtime the pluginContextPath variable will either evaluate to an empty
string or /plugins/custom-plugin depending on whether the plugin is running
standalone or has been installed in an application.
× Java and Groovy code that the plugin provides within the lib and src/java and
src/groovy directories will be compiled into the main project's web-app/WEB-
INF/classes directory so that they are made available at runtime.
Providing Basic Artefacts
Adding a new script
Adding a new grails-app artifact (controller, taglib,
service, etc.)
Providing Views, Templates and view resolution.
Excluded Artefacts
Adding a new Script
A plugin can add a new script simply by providing the
relevant Gant script in its scripts directory:
× CustomPlugin
× Grails-app
× scripts <--Add script here
× Grails create-script ShowDetailsScript
Adding a new grails-app artifact (Controller, Tag Library, Service, etc.)
× CustomPlugin
× grails-app
× controllers
× services
× etc.
× lib
× scripts
Providing Views, Templates and View resolution
× When a plugin provides a controller it may also provide default views
to be rendered.
× Grails' view resolution mechanism will first look for the view in the
application it is installed into and if that fails will attempt to look for
the view within the plugin.
× This means that you can override views provided by a plugin by
creating corresponding GSPs in the application's grails-app/views
directory.
× if the view uses templates that are also provided by the plugin then:-
× <g:render template="fooTemplate" plugin="amazon"/>
Excluded Artefacts
By default Grails excludes the following files during the packaging process:
× grails-app/conf/BootStrap.groovy
× grails-app/conf/BuildConfig.groovy (although it is used to generate dependencies.groovy)
× grails-app/conf/Config.groovy
× grails-app/conf/DataSource.groovy (and any other *DataSource.groovy)
× grails-app/conf/UrlMappings.groovy
× grails-app/conf/spring/resources.groovy
× Everything within /web-app/WEB-INF
× Everything within /web-app/plugins/**
× Everything within /test/**
× SCM management files within **/.svn/** and **/CVS/**
If your plugin requires files under the web-app/WEB-INF directory it is recommended that you modify the plugin's
scripts/_Install.groovy Gant script to install these artefacts into the target project's directory tree.
In addition, the default UrlMappings.groovy file is excluded to avoid naming conflicts, however you are free to add a
UrlMappings definition under a different name which will be included. For example a file called grails-
app/conf/BlogUrlMappings.groovy is fine.
The list of excludes is extensible with the pluginExcludes property:
// resources that are excluded from plugin packaging
def pluginExcludes = [
"grails-app/views/error.gsp"
]
Evaluating Conventions
Every plugin has an implicit application variable which is an instance of the GrailsApplication interface.
The GrailsApplication interface provides methods to evaluate the conventions within the project and
internally stores references to all artifact classes within your application.
Artifacts implement the GrailsClass interface, which represents a Grails resource such as a controller or a
tag library. For example to get all GrailsClassinstances you can do:
for (grailsClass in application.allClasses) {
println grailsClass.name
}
for (controllerClass in application.controllerClasses) {
println controllerClass.name
}
The dynamic method conventions are as follows:
× *Classes - Retrieves all the classes for a particular artefact name. For example
application.controllerClasses.
× get*Class - Retrieves a named class for a particular artefact. For example
application.getControllerClass("PersonController")
× is*Class - Returns true if the given class is of the given artefact type. For
example application.isControllerClass(PersonController)
The GrailsClass interface has a number of useful methods that let you further evaluate and work with
the conventions. These include:
× getPropertyValue - Gets the initial value of the given property on the class
× hasProperty - Returns true if the class has the specified property
× newInstance - Creates a new instance of this class.
× getName - Returns the logical name of the class in the application without the trailing
convention part if applicable
× getShortName - Returns the short name of the class without package prefix
× getFullName - Returns the full name of the class in the application with the trailing convention
part and with the package name
× getPropertyName - Returns the name of the class as a property name
× getLogicalPropertyName - Returns the logical property name of the class in the application
Hooking into Build Events
Grails plugins can do post-install configuration. This is achieved using a specially named script
under the scripts directory of the plugin -_Install.groovy.
_Install.groovy is executed after the plugin has been installed.
Below will create a new directory type under the grails-app directory and install a
configuration template:
ant.mkdir(dir: "${basedir}/grails-app/jobs")
ant.copy(file: "${pluginBasedir}/src/samples/SamplePluginConfig.groovy",
todir: "${basedir}/grails-app/conf")
The pluginBasedir variable is not available in custom scripts, but you can use fooPluginDir,
where foo is the name of your plugin.
Hooking into Runtime Configuration
Hooking into the Grails Spring configuration
Participating in web.xml Generation
Doing Post Initialisation Configuration
Hooking into the Grails Spring configuration
you can hook in Grails runtime configuration by
providing a property called doWithSpring which is
assigned a block of code
def doWithSpring = {
customPluginObject(CustomPluginObject) {}
}
Adding Dynamic Methods at Runtime
Grails plugins let you register dynamic methods with any Grails-managed or other
class at runtime. This work is done in a doWithDynamicMethods closure.
For Grails-managed classes like controllers, tag libraries and so forth you can add
methods, constructors etc. using the ExpandoMetaClass mechanism by accessing
each controller's MetaClass:
For more:-
http://docs.grails.org/2.4.4/guide/plugins.html#addingDynamicMethodsAtRuntime
Understanding Plugin Load Order
Controlling Plugin Dependencies
Controlling Load Order
Scopes and Environments
Controlling Plugin Dependencies
Plugins often depend on the presence of other plugins and can adapt depending on the presence of
others. This is implemented with two properties. The first is called dependsOn
def dependsOn = [dataSource: "1.0",
domainClass: "1.0",
i18n: "1.0",
core: "1.0"]
The dependsOn property also supports a mini expression language for specifying version ranges
def dependsOn = [foo: "* > 1.0"]
def dependsOn = [foo: "1.0 > 1.1"]
def dependsOn = [foo: "1.0 > *"]
When the wildcard * character is used it denotes "any" version. The expression syntax also excludes any
suffixes such as -BETA, -ALPHA etc. so for example the expression "1.0 > 1.1" would match any of the
following versions:
Controlling Load Order
Using dependsOn establishes a "hard" dependency in that if the dependency is
not resolved, the plugin will give up and won't load. It is possible though to have a
weaker dependency using the loadAfter and loadBefore properties
def loadAfter = ['otherplugin']
Here the plugin will be loaded after the controllers plugin if it exists, otherwise it
will just be loaded. The plugin can then adapt to the presence of the other plugin.
You can also use the loadBefore property to specify one or more plugins that your
plugin should load before:
def loadBefore = ['rabbitmq']
Scopes and Environments
It's not only plugin load order that you can control. You can also specify which environments your plugin should be
loaded in and which scopes (stages of a build). Simply declare one or both of these properties in your plugin
descriptor:
def environments = ['development', 'test', 'myCustomEnv']
def scopes = [excludes:'war']
the plugin will only load in the 'development' and 'test' environments. Nor will it be packaged into the WAR file,
because it's excluded from the 'war' phase. This allows development-only plugins to not be packaged for
production use.
The full list of available scopes are defined by the enum BuildScope,
Both properties can be one of:
× a string - a sole inclusion
× a list - a list of environments or scopes to include
× a map - for full control, with 'includes' and/or 'excludes' keys that can have string or list values
Register on local
× Comment export = false
× grails compile: to trigger dependency resolution
× grails maven-install: will work once the release plugin in BuildConfig.groovy is installed for
your plugin.
× Note that this isn't plugin installation, it's faking out a plugin release by putting the ZIP
and the POM file in your mavenLocal() repo.
Releasing our plugin
× Register on grails.org
× Fill out this form
× Provide good documentation for the users to get started.
× Once approved, install the release plugin in the plugin application
× grails publish-plugin --stacktrace
× Once successful, the plugin will be published in the grails plugin
repository. Users will be able to install it directly from Grails Plugin
portal by adding the dependency in BuildConfig.groovy
Get code:- https://bitbucket.org/vendetta30/customplugin
For any doubt please contact:- vijay@nexthoughts.com
Thank You

More Related Content

What's hot

Grails beginners workshop
Grails beginners workshopGrails beginners workshop
Grails beginners workshopJacobAae
 
Config BuildConfig
Config BuildConfigConfig BuildConfig
Config BuildConfigVijay Shukla
 
Gradle - the Enterprise Automation Tool
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation ToolIzzet Mustafaiev
 
Idiomatic gradle plugin writing
Idiomatic gradle plugin writingIdiomatic gradle plugin writing
Idiomatic gradle plugin writingSchalk Cronjé
 
Idiomatic Gradle Plugin Writing - GradleSummit 2016
Idiomatic Gradle Plugin Writing - GradleSummit 2016Idiomatic Gradle Plugin Writing - GradleSummit 2016
Idiomatic Gradle Plugin Writing - GradleSummit 2016Schalk Cronjé
 
Gradle - time for a new build
Gradle - time for a new buildGradle - time for a new build
Gradle - time for a new buildIgor Khotin
 
Gradle,the new build system for android
Gradle,the new build system for androidGradle,the new build system for android
Gradle,the new build system for androidzhang ghui
 
The Challenges of Container Configuration
The Challenges of Container ConfigurationThe Challenges of Container Configuration
The Challenges of Container ConfigurationGareth Rushgrove
 
Google App Engine (GAE) 演進史
Google App Engine (GAE) 演進史Google App Engine (GAE) 演進史
Google App Engine (GAE) 演進史Simon Su
 
An Introduction to Gradle for Java Developers
An Introduction to Gradle for Java DevelopersAn Introduction to Gradle for Java Developers
An Introduction to Gradle for Java DevelopersKostas Saidis
 
PROMAND 2014 project structure
PROMAND 2014 project structurePROMAND 2014 project structure
PROMAND 2014 project structureAlexey Buzdin
 
PuppetConf 2016: Running Puppet Software in Docker Containers – Gareth Rushgr...
PuppetConf 2016: Running Puppet Software in Docker Containers – Gareth Rushgr...PuppetConf 2016: Running Puppet Software in Docker Containers – Gareth Rushgr...
PuppetConf 2016: Running Puppet Software in Docker Containers – Gareth Rushgr...Puppet
 
Coscup x ruby conf tw 2021 google cloud buildpacks 剖析與實踐
Coscup x ruby conf tw 2021  google cloud buildpacks 剖析與實踐Coscup x ruby conf tw 2021  google cloud buildpacks 剖析與實踐
Coscup x ruby conf tw 2021 google cloud buildpacks 剖析與實踐KAI CHU CHUNG
 
Google App Engine: Basic
Google App Engine: BasicGoogle App Engine: Basic
Google App Engine: BasicKAI CHU CHUNG
 
Gdg cloud taipei ddt meetup #53 buildpack
Gdg cloud taipei ddt meetup #53 buildpackGdg cloud taipei ddt meetup #53 buildpack
Gdg cloud taipei ddt meetup #53 buildpackKAI CHU CHUNG
 
Building Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And TricksBuilding Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And TricksMike Hugo
 
Creating an nuget package for EPiServer
Creating an nuget package for EPiServerCreating an nuget package for EPiServer
Creating an nuget package for EPiServerPaul Graham
 

What's hot (20)

Grails beginners workshop
Grails beginners workshopGrails beginners workshop
Grails beginners workshop
 
Config BuildConfig
Config BuildConfigConfig BuildConfig
Config BuildConfig
 
Gradle - the Enterprise Automation Tool
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation Tool
 
Idiomatic gradle plugin writing
Idiomatic gradle plugin writingIdiomatic gradle plugin writing
Idiomatic gradle plugin writing
 
Idiomatic Gradle Plugin Writing - GradleSummit 2016
Idiomatic Gradle Plugin Writing - GradleSummit 2016Idiomatic Gradle Plugin Writing - GradleSummit 2016
Idiomatic Gradle Plugin Writing - GradleSummit 2016
 
Gradle - time for a new build
Gradle - time for a new buildGradle - time for a new build
Gradle - time for a new build
 
Introduction to gradle
Introduction to gradleIntroduction to gradle
Introduction to gradle
 
Gradle,the new build system for android
Gradle,the new build system for androidGradle,the new build system for android
Gradle,the new build system for android
 
Gradle : An introduction
Gradle : An introduction Gradle : An introduction
Gradle : An introduction
 
The Challenges of Container Configuration
The Challenges of Container ConfigurationThe Challenges of Container Configuration
The Challenges of Container Configuration
 
Tips & Tricks for Maven Tycho
Tips & Tricks for Maven TychoTips & Tricks for Maven Tycho
Tips & Tricks for Maven Tycho
 
Google App Engine (GAE) 演進史
Google App Engine (GAE) 演進史Google App Engine (GAE) 演進史
Google App Engine (GAE) 演進史
 
An Introduction to Gradle for Java Developers
An Introduction to Gradle for Java DevelopersAn Introduction to Gradle for Java Developers
An Introduction to Gradle for Java Developers
 
PROMAND 2014 project structure
PROMAND 2014 project structurePROMAND 2014 project structure
PROMAND 2014 project structure
 
PuppetConf 2016: Running Puppet Software in Docker Containers – Gareth Rushgr...
PuppetConf 2016: Running Puppet Software in Docker Containers – Gareth Rushgr...PuppetConf 2016: Running Puppet Software in Docker Containers – Gareth Rushgr...
PuppetConf 2016: Running Puppet Software in Docker Containers – Gareth Rushgr...
 
Coscup x ruby conf tw 2021 google cloud buildpacks 剖析與實踐
Coscup x ruby conf tw 2021  google cloud buildpacks 剖析與實踐Coscup x ruby conf tw 2021  google cloud buildpacks 剖析與實踐
Coscup x ruby conf tw 2021 google cloud buildpacks 剖析與實踐
 
Google App Engine: Basic
Google App Engine: BasicGoogle App Engine: Basic
Google App Engine: Basic
 
Gdg cloud taipei ddt meetup #53 buildpack
Gdg cloud taipei ddt meetup #53 buildpackGdg cloud taipei ddt meetup #53 buildpack
Gdg cloud taipei ddt meetup #53 buildpack
 
Building Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And TricksBuilding Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And Tricks
 
Creating an nuget package for EPiServer
Creating an nuget package for EPiServerCreating an nuget package for EPiServer
Creating an nuget package for EPiServer
 

Similar to Custom plugin

How to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular FrameworkHow to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular FrameworkRapidValue
 
Mastering Grails 3 Plugins - GR8Conf US 2016
Mastering Grails 3 Plugins - GR8Conf US 2016Mastering Grails 3 Plugins - GR8Conf US 2016
Mastering Grails 3 Plugins - GR8Conf US 2016Alvaro Sanchez-Mariscal
 
Improving build solutions dependency management with webpack
Improving build solutions  dependency management with webpackImproving build solutions  dependency management with webpack
Improving build solutions dependency management with webpackNodeXperts
 
Config/BuildConfig
Config/BuildConfigConfig/BuildConfig
Config/BuildConfigVijay Shukla
 
Mastering Grails 3 Plugins - Greach 2016
Mastering Grails 3 Plugins - Greach 2016Mastering Grails 3 Plugins - Greach 2016
Mastering Grails 3 Plugins - Greach 2016Alvaro Sanchez-Mariscal
 
Mastering Grails 3 Plugins - GR8Conf EU 2016
Mastering Grails 3 Plugins - GR8Conf EU 2016Mastering Grails 3 Plugins - GR8Conf EU 2016
Mastering Grails 3 Plugins - GR8Conf EU 2016Alvaro Sanchez-Mariscal
 
Cut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature pluginsCut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature pluginsGR8Conf
 
Plugins And Making Your Own
Plugins And Making Your OwnPlugins And Making Your Own
Plugins And Making Your OwnLambert Beekhuis
 
Grails Asset Pipeline Plugin
Grails Asset Pipeline PluginGrails Asset Pipeline Plugin
Grails Asset Pipeline PluginAli Tanwir
 
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
Grails 0.3-SNAPSHOT Presentation WJAX 2006 EnglishGrails 0.3-SNAPSHOT Presentation WJAX 2006 English
Grails 0.3-SNAPSHOT Presentation WJAX 2006 EnglishSven Haiges
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!David Gibbons
 
CommissionCalculationbuildclasses.netbeans_automatic_build.docx
CommissionCalculationbuildclasses.netbeans_automatic_build.docxCommissionCalculationbuildclasses.netbeans_automatic_build.docx
CommissionCalculationbuildclasses.netbeans_automatic_build.docxmonicafrancis71118
 
Grunt training deck
Grunt training deckGrunt training deck
Grunt training deckJames Ford
 
Mastering Grails 3 Plugins - G3 Summit 2016
Mastering Grails 3 Plugins - G3 Summit 2016Mastering Grails 3 Plugins - G3 Summit 2016
Mastering Grails 3 Plugins - G3 Summit 2016Alvaro Sanchez-Mariscal
 
CICON2010: Adam Griffiths - CodeIgniter 2
CICON2010: Adam Griffiths - CodeIgniter 2CICON2010: Adam Griffiths - CodeIgniter 2
CICON2010: Adam Griffiths - CodeIgniter 2CodeIgniter Conference
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress pluginAnthony Montalbano
 

Similar to Custom plugin (20)

How to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular FrameworkHow to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular Framework
 
Mastering Grails 3 Plugins - GR8Conf US 2016
Mastering Grails 3 Plugins - GR8Conf US 2016Mastering Grails 3 Plugins - GR8Conf US 2016
Mastering Grails 3 Plugins - GR8Conf US 2016
 
Improving build solutions dependency management with webpack
Improving build solutions  dependency management with webpackImproving build solutions  dependency management with webpack
Improving build solutions dependency management with webpack
 
Plugin development
Plugin developmentPlugin development
Plugin development
 
Config BuildConfig
Config BuildConfigConfig BuildConfig
Config BuildConfig
 
Config/BuildConfig
Config/BuildConfigConfig/BuildConfig
Config/BuildConfig
 
Mastering Grails 3 Plugins - Greach 2016
Mastering Grails 3 Plugins - Greach 2016Mastering Grails 3 Plugins - Greach 2016
Mastering Grails 3 Plugins - Greach 2016
 
Mastering Grails 3 Plugins - GR8Conf EU 2016
Mastering Grails 3 Plugins - GR8Conf EU 2016Mastering Grails 3 Plugins - GR8Conf EU 2016
Mastering Grails 3 Plugins - GR8Conf EU 2016
 
Cut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature pluginsCut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature plugins
 
Plugins And Making Your Own
Plugins And Making Your OwnPlugins And Making Your Own
Plugins And Making Your Own
 
Grails Asset Pipeline Plugin
Grails Asset Pipeline PluginGrails Asset Pipeline Plugin
Grails Asset Pipeline Plugin
 
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
Grails 0.3-SNAPSHOT Presentation WJAX 2006 EnglishGrails 0.3-SNAPSHOT Presentation WJAX 2006 English
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
 
Grails Advanced
Grails Advanced Grails Advanced
Grails Advanced
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!
 
CommissionCalculationbuildclasses.netbeans_automatic_build.docx
CommissionCalculationbuildclasses.netbeans_automatic_build.docxCommissionCalculationbuildclasses.netbeans_automatic_build.docx
CommissionCalculationbuildclasses.netbeans_automatic_build.docx
 
Grunt training deck
Grunt training deckGrunt training deck
Grunt training deck
 
Pyramid patterns
Pyramid patternsPyramid patterns
Pyramid patterns
 
Mastering Grails 3 Plugins - G3 Summit 2016
Mastering Grails 3 Plugins - G3 Summit 2016Mastering Grails 3 Plugins - G3 Summit 2016
Mastering Grails 3 Plugins - G3 Summit 2016
 
CICON2010: Adam Griffiths - CodeIgniter 2
CICON2010: Adam Griffiths - CodeIgniter 2CICON2010: Adam Griffiths - CodeIgniter 2
CICON2010: Adam Griffiths - CodeIgniter 2
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
 

More from Vijay Shukla (18)

Introduction of webpack 4
Introduction of webpack 4Introduction of webpack 4
Introduction of webpack 4
 
Preview of Groovy 3
Preview of Groovy 3Preview of Groovy 3
Preview of Groovy 3
 
Jython
JythonJython
Jython
 
Groovy closures
Groovy closuresGroovy closures
Groovy closures
 
Groovy
GroovyGroovy
Groovy
 
Grails services
Grails servicesGrails services
Grails services
 
Grails plugin
Grails pluginGrails plugin
Grails plugin
 
Grails domain
Grails domainGrails domain
Grails domain
 
Grails custom tag lib
Grails custom tag libGrails custom tag lib
Grails custom tag lib
 
Grails
GrailsGrails
Grails
 
Gorm
GormGorm
Gorm
 
Controller
ControllerController
Controller
 
Command object
Command objectCommand object
Command object
 
Boot strap.groovy
Boot strap.groovyBoot strap.groovy
Boot strap.groovy
 
Vertx
VertxVertx
Vertx
 
Spring security
Spring securitySpring security
Spring security
 
REST
RESTREST
REST
 
GORM
GORMGORM
GORM
 

Recently uploaded

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 

Recently uploaded (20)

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 

Custom plugin

  • 2. Agenda × What is plugin. × Creating and Installing plugin × Plugin Repositories × Understanding a Plugin’s Structure × Evaluating Conventions × Hooking into Build Events × Hooking into runtime configuration × Adding methods at compile time × Adding Dynamic method at runtime × Understanding Plugin loader
  • 3. What is Plugin × A plugin is a software component which adds a specific feature to an existing software application. × Very similar to Grails application project × A plugin descriptor file *GrailsPlugin.groovy
  • 4. Creating and Installing Plugin grails create-plugin [plugin-name] × In grails-3.* you should profile to create a plugin. × If you want to create web environment then grails create-plugin [plugin-name] --profile=web-plugin × If you want to create a plugin which will be used with other profile grails create-plugin [plugin-name] --profile=plugin Note*:- Make sure the plugin name does not contain more than one capital letter in a row, or it won't work. Camel case is fine, though.
  • 5. × The structure of a Grails plugin is very nearly the same as a Grails application project's except that in the src/main/groovy directory under the plugin package structure you will find a plugin descriptor class (a class that ends in "GrailsPlugin"). × Being a regular Grails project has a number of benefits in that you can immediately test your plugin by running (if the plugin targets the "web" profile): Note*:- Plugin projects don't provide an index.gsp by default since most plugins don't need it. So, if you try to view the plugin running in a browser right after creating it, you will receive a page not found error. You can easily create a grails- app/views/index.gsp for your plugin if you'd like.
  • 6. Plugin Descriptor Class CustomGrailsPlugin{ } This class defines the metadata about the plugin. × Title:- short one-sentence description of your plugin × grailsVersion:- The version range of Grails that the plugin supports. eg. "1.2 > *" (indicating 1.2 or higher) × Author :- plugin author's name × authorEmail:- plugin author's contact e-mail × Description:- full multi-line description of plugin's features × Documentation:- URL of the plugin's documentation × License:- License of the plugin × Issuemanagement:- Issue Tracker of the plugin × Scm:- Source code management location of the plugin
  • 7. Installing Local Plugin × Add plugin path in BuildConfig × Add plugin in local maven then add in BuildConfig
  • 8. Plugin Repositories × The preferred way to distribute plugin is to publish to the official Grails Central Plugin Repository. This will make your plugin visible to the list- plugins command: grails list-plugins which lists all plugins that are in the central repository. × Your plugin will also be available to the plugin-info command: grails plugin-info [plugin-name] which prints extra information about it, such as its description, who wrote, etc.
  • 9. Understanding a Plugin's Structure ➔ grails-app ◆ conf ◆ controller ◆ domain ◆ taglib ➔ lib ➔ src ◆ java ◆ groovy ➔ web-app ◆ js ◆ css
  • 10. × When plugin installed, will go directly as plugins/custom-plugin/grails-app. They will not be copied into main source tree. × When you run the plugin in development mode the link to the resource will resolve to something like /js/mycode.js. However, when the plugin is installed into an application the path will automatically change to something like /plugin/custom-plugin/js/mycode.js and Grails will deal with making sure the resources are in the right place. × pluginContextPath is responsible to manage the static resource path. × At runtime the pluginContextPath variable will either evaluate to an empty string or /plugins/custom-plugin depending on whether the plugin is running standalone or has been installed in an application. × Java and Groovy code that the plugin provides within the lib and src/java and src/groovy directories will be compiled into the main project's web-app/WEB- INF/classes directory so that they are made available at runtime.
  • 11. Providing Basic Artefacts Adding a new script Adding a new grails-app artifact (controller, taglib, service, etc.) Providing Views, Templates and view resolution. Excluded Artefacts
  • 12. Adding a new Script A plugin can add a new script simply by providing the relevant Gant script in its scripts directory: × CustomPlugin × Grails-app × scripts <--Add script here × Grails create-script ShowDetailsScript
  • 13. Adding a new grails-app artifact (Controller, Tag Library, Service, etc.) × CustomPlugin × grails-app × controllers × services × etc. × lib × scripts
  • 14. Providing Views, Templates and View resolution × When a plugin provides a controller it may also provide default views to be rendered. × Grails' view resolution mechanism will first look for the view in the application it is installed into and if that fails will attempt to look for the view within the plugin. × This means that you can override views provided by a plugin by creating corresponding GSPs in the application's grails-app/views directory. × if the view uses templates that are also provided by the plugin then:- × <g:render template="fooTemplate" plugin="amazon"/>
  • 15. Excluded Artefacts By default Grails excludes the following files during the packaging process: × grails-app/conf/BootStrap.groovy × grails-app/conf/BuildConfig.groovy (although it is used to generate dependencies.groovy) × grails-app/conf/Config.groovy × grails-app/conf/DataSource.groovy (and any other *DataSource.groovy) × grails-app/conf/UrlMappings.groovy × grails-app/conf/spring/resources.groovy × Everything within /web-app/WEB-INF × Everything within /web-app/plugins/** × Everything within /test/** × SCM management files within **/.svn/** and **/CVS/** If your plugin requires files under the web-app/WEB-INF directory it is recommended that you modify the plugin's scripts/_Install.groovy Gant script to install these artefacts into the target project's directory tree. In addition, the default UrlMappings.groovy file is excluded to avoid naming conflicts, however you are free to add a UrlMappings definition under a different name which will be included. For example a file called grails- app/conf/BlogUrlMappings.groovy is fine. The list of excludes is extensible with the pluginExcludes property: // resources that are excluded from plugin packaging def pluginExcludes = [ "grails-app/views/error.gsp" ]
  • 16. Evaluating Conventions Every plugin has an implicit application variable which is an instance of the GrailsApplication interface. The GrailsApplication interface provides methods to evaluate the conventions within the project and internally stores references to all artifact classes within your application. Artifacts implement the GrailsClass interface, which represents a Grails resource such as a controller or a tag library. For example to get all GrailsClassinstances you can do: for (grailsClass in application.allClasses) { println grailsClass.name } for (controllerClass in application.controllerClasses) { println controllerClass.name }
  • 17. The dynamic method conventions are as follows: × *Classes - Retrieves all the classes for a particular artefact name. For example application.controllerClasses. × get*Class - Retrieves a named class for a particular artefact. For example application.getControllerClass("PersonController") × is*Class - Returns true if the given class is of the given artefact type. For example application.isControllerClass(PersonController)
  • 18. The GrailsClass interface has a number of useful methods that let you further evaluate and work with the conventions. These include: × getPropertyValue - Gets the initial value of the given property on the class × hasProperty - Returns true if the class has the specified property × newInstance - Creates a new instance of this class. × getName - Returns the logical name of the class in the application without the trailing convention part if applicable × getShortName - Returns the short name of the class without package prefix × getFullName - Returns the full name of the class in the application with the trailing convention part and with the package name × getPropertyName - Returns the name of the class as a property name × getLogicalPropertyName - Returns the logical property name of the class in the application
  • 19. Hooking into Build Events Grails plugins can do post-install configuration. This is achieved using a specially named script under the scripts directory of the plugin -_Install.groovy. _Install.groovy is executed after the plugin has been installed. Below will create a new directory type under the grails-app directory and install a configuration template: ant.mkdir(dir: "${basedir}/grails-app/jobs") ant.copy(file: "${pluginBasedir}/src/samples/SamplePluginConfig.groovy", todir: "${basedir}/grails-app/conf") The pluginBasedir variable is not available in custom scripts, but you can use fooPluginDir, where foo is the name of your plugin.
  • 20. Hooking into Runtime Configuration Hooking into the Grails Spring configuration Participating in web.xml Generation Doing Post Initialisation Configuration
  • 21. Hooking into the Grails Spring configuration you can hook in Grails runtime configuration by providing a property called doWithSpring which is assigned a block of code def doWithSpring = { customPluginObject(CustomPluginObject) {} }
  • 22. Adding Dynamic Methods at Runtime Grails plugins let you register dynamic methods with any Grails-managed or other class at runtime. This work is done in a doWithDynamicMethods closure. For Grails-managed classes like controllers, tag libraries and so forth you can add methods, constructors etc. using the ExpandoMetaClass mechanism by accessing each controller's MetaClass: For more:- http://docs.grails.org/2.4.4/guide/plugins.html#addingDynamicMethodsAtRuntime
  • 23. Understanding Plugin Load Order Controlling Plugin Dependencies Controlling Load Order Scopes and Environments
  • 24. Controlling Plugin Dependencies Plugins often depend on the presence of other plugins and can adapt depending on the presence of others. This is implemented with two properties. The first is called dependsOn def dependsOn = [dataSource: "1.0", domainClass: "1.0", i18n: "1.0", core: "1.0"] The dependsOn property also supports a mini expression language for specifying version ranges def dependsOn = [foo: "* > 1.0"] def dependsOn = [foo: "1.0 > 1.1"] def dependsOn = [foo: "1.0 > *"] When the wildcard * character is used it denotes "any" version. The expression syntax also excludes any suffixes such as -BETA, -ALPHA etc. so for example the expression "1.0 > 1.1" would match any of the following versions:
  • 25. Controlling Load Order Using dependsOn establishes a "hard" dependency in that if the dependency is not resolved, the plugin will give up and won't load. It is possible though to have a weaker dependency using the loadAfter and loadBefore properties def loadAfter = ['otherplugin'] Here the plugin will be loaded after the controllers plugin if it exists, otherwise it will just be loaded. The plugin can then adapt to the presence of the other plugin. You can also use the loadBefore property to specify one or more plugins that your plugin should load before: def loadBefore = ['rabbitmq']
  • 26. Scopes and Environments It's not only plugin load order that you can control. You can also specify which environments your plugin should be loaded in and which scopes (stages of a build). Simply declare one or both of these properties in your plugin descriptor: def environments = ['development', 'test', 'myCustomEnv'] def scopes = [excludes:'war'] the plugin will only load in the 'development' and 'test' environments. Nor will it be packaged into the WAR file, because it's excluded from the 'war' phase. This allows development-only plugins to not be packaged for production use. The full list of available scopes are defined by the enum BuildScope, Both properties can be one of: × a string - a sole inclusion × a list - a list of environments or scopes to include × a map - for full control, with 'includes' and/or 'excludes' keys that can have string or list values
  • 27. Register on local × Comment export = false × grails compile: to trigger dependency resolution × grails maven-install: will work once the release plugin in BuildConfig.groovy is installed for your plugin. × Note that this isn't plugin installation, it's faking out a plugin release by putting the ZIP and the POM file in your mavenLocal() repo.
  • 28. Releasing our plugin × Register on grails.org × Fill out this form × Provide good documentation for the users to get started. × Once approved, install the release plugin in the plugin application × grails publish-plugin --stacktrace × Once successful, the plugin will be published in the grails plugin repository. Users will be able to install it directly from Grails Plugin portal by adding the dependency in BuildConfig.groovy
  • 29. Get code:- https://bitbucket.org/vendetta30/customplugin For any doubt please contact:- vijay@nexthoughts.com