What is a Grails Plugin? What does it mean to Install a Plugin? - grails

I used Grails recently, and added Grails plugin for JQuery, but I don't think it did anything more than just copy some jQuery files over.
So far, I have seen info only on 'how to install and use' plugins...but I can't find anything that describes the concept of a plugin.
Can somebody please tell me, what is a Grails Plugin? And what does it mean to 'Install' a plugin?

A Grails plugin is (or should be) a self-contained bundle of functionality that can be installed into a Grails application. When a Grails plugin is installed, it can do any of the following:
define additional Spring beans
modify the generated web.xml
add new methods to the application's artefacts (controllers, domain classes, services, etc.)
provide new tag libraries
make additional resources and classes available to the application
provide new Grails commands
For example, when you install the JQuery plugin
the JQuery JavaScript files are added to the application
a new Grails tag <jq:jquery> is added to the application
a new Grails command grails install-plugin jquery is added to the application
When you install a Grails plugin, that plugin's functionality is made available to the installing application. However, the plugin itself is not actually copied into the application, only the plugin name and version is added to the application's application.properties file. The plugin itself is downloaded to $HOME/.grails and the application loads it from there.
The structure of a Grails plugin project is identical to that of a Grails application, with the exception of a configuration file (known as a plugin descriptor) that is included in a plugin's root directory.

Well, a Grails plugin is some piece of software that extends the frameworks funcionalities in some manner. Generally, installing a plugin in Grails means copying it to your Grails folder, so projects can refer to it and Grails will know where to find it.
Grails plugins have this folder structure:
grails-app
controllers
domain
taglib
service
etc
lib
src
java
groovy
web-app
js
css
So anything it has there will also be available to the application that uses it. For example, the Searchable plugin has a service class which you can use to perform advanced searchs in your own domain classes .
The jQuery plugin you mentioned has the jQuery .js file, and a tag to include that file.
For information on creating plugins, see http://grails.org/doc/latest/guide/12.%20Plug-ins.html

A plugin is just a set of functionality around a desired purpose. So the Spring Security plugin provides a way to lock down your app, assign roles to users, restrict access, whatever. The Searchable plugin allows you to integrate advanced searching into your app. There are lots of plugins
The point is to provide useful functionality so that you don't have to implement hard things yourself. Someone did something useful, and they wanted to contribute back to the community, so they organized their functionality and made it available.
A plugin is code and configuration, like any functionality you would implement yourself.
There is some documentation here: http://grails.org/doc/latest/ref/Plug-ins/Usage.html

Related

[grails 3]: Replacement of doWithWebDescriptor on Plugin descriptor?

We are trying to move our existing grails 2.5 application to newer versions of grails. For that adopting strategy to first upgrade to grails 3.3.11 (latest in 3.x releases) and then move to grails 4.
For one of the feature from grails 2.5.6 application, I found that there is nothing documented anywhere or may be I've missed that part on the document! It is about Plugin descriptor's doWithWebDescriptor. With this closure we can able to update web.xml dynamically based on some rules.
After upgrading to grails 3, I found that doWithWebDescriptor is not working. It is not initializing task which it supposed to (as far as grails 2.5 concerned). Later I found that there is nothing documented after grails 3.0 documentation.
If doWithWebDescriptor is removed then what is the best suitable replacement with grails 3 or latest grails 4 edition? If it still working fine and there is some configuration related changes required with grails 3 then kindly point me to that part.
Update:
Reason why we need doWithWebDescriptor is that, we are trying to add servlet based on the plugin. Actually we have several plugins for different modules in the application. Not all plugins included in the project. Based on modules selected we are adding plugin to the application. So if a plugin is included then we need to add servlet and a filter to web.xml.
Thank you.
Reason why we need doWithWebDescriptor is that, we are trying to add
servlet based on the plugin.
You can add a servlet by registering a ServletRegistrationBean in the application context. You can do that in the plugin's doWithSpring method or in the app's resources.groovy. Example:
Closure doWithSpring() {{->
myServlet(ServletRegistrationBean, new MyServlet(), "/myServlet/*") {
loadOnStartup = 2
}
}}
We have documented this in the 18.5 Hooking into Runtime Configuration section at http://docs.grails.org/3.3.11/guide/plugins.html#hookingIntoRuntimeConfiguration.

Include more than one filter from existing JAR into a Grails project

I have a Grails project and want to add existing filters from a JAR file.
I used the WebXmlConfig plugin, mentioned in this answer:
How to add filters to a Grails app
and that worked great for a single filter, but I can't figure out how to extend that to more than one filter.
Do I need to change approach and edit the web.xml template directly?
I'd use the pluginator plugin and put the definitions in doWithWebDescriptor just like you would in a plugin - you can add as many elements as you want. It's a slick plugin that lets apps do things that are generally only supported in plugins, like conveniently editing web.xml (although with a seriously weird DSL) and registering custom artifact types.

Order of Grails Bootstrap classes

On one of our feature branches of our project we have a strange issue with running our grails integration tests. In our application we have the base project and one plugin, which relies on data from the base application. The default data is created in the "Bootstrap" Classes of the project and the plugin.
since yesterday the bootstrap of the plugin is called before the base bootstrap, and fails, because of the missing data from the application. This happens only if we run the integration tests, and only on our buildserver (Windows Server 2012 with Atlassian Bamboo).
test-app -integration --stacktrace -non-interactive
how can we fix this problem?
Grails makes no guarantees about ordering of BootStrap classes so it isn't something that should be relied about in your application.
If you need to control ordering of logic that is run at startup there are better solutions, for example you could use the platform-core plugin's event model to trigger an event in your application that your plugin listens to once the data it needs is in place. See http://grails-plugins.github.io/grails-platform-core/guide/events.html

Customizing new Grails Spring Security Core Plugin login page

I installed Grails Spring Security Core Plugin and it works great, but I can't find the gsp file for the login page. I want to change the login page to match my web theme. Anyone knows how to find the file ? I tried generate-views and also generate-all followed by User, UserRole, and Role domain classes but I didn't see the actual files. Also I can't find the login and logout controllers for the spring security core plugin in my project directories. Any idea what's going on ?
They're in the plugin itself, so it depends on where your plugins get installed. In 2.3 they'll be under target/work/plugins, and in earlier versions they'll be in the .grails folder which is in your home directory, so it'll be something like $HOME/.grails/2.x.x/projects/<projectname>/plugins
I like to keep things simple by deleting the grails.project.class.dir, grails.project.test.class.dir, and grails.project.test.reports.dir settings from BuildConfig.groovy and adding just
grails.project.work.dir = 'target'
so everything is in one place.

Is it possible to add Grails MVC classes at deployment time?

I'm writing a Grails app which I'd like 3rd parties to augment at runtime. Ideally they would be able to add a JAR/WAR to the webapp directory which contains new domain, controller and service classes, new views, and other content.
Is there a simple way to do this within grails? Would it be simplest to create a startup script which copies the new classes etc. into the relevant directories and then updates grails.xml and web.xml?
You will be able to do this in version 2 of grails in which plugins will be also OSGI plugins http://jira.codehaus.org/browse/GRAILS/fixforversion/15421
It seems that the Grails plugins will actually fit quite well for this: http://www.grails.org/Understanding+Plugins
A plugin can do just about anything... One thing a plugin cannot do though is modify the web-app/WEB-INF/web.xml or web-app/WEB-INF/applicationContext.xml files. A plugin can participate in web.xml generation, but not modify the file or provide a replacement. A plugin can NEVER change the applicationContext.xml file, but can provide runtime bean definitions

Resources