As I am trying to write a Grails Plugin, I stumbled upon two problems:
- how do I modify one of the configuration files like
Config.groovyorDataSource.groovyfrom witin the_install.groovyscript? It is easy to append something to those files, but how do I modify it in a clean way?text.replaceAll()? Or should I create a new config file? - how do I get the name of the current application into which the plugin will be installed? I tried to use
app.nameandappNamebut both do not work.
Is there maybe somewhere a good tutorial on creating plugins which I haven’t found yet?
Here is an example of editing configuration files from
scripts/_Install.groovy.My plugin copies three files to the target directory.
.hgignoreis used for version control,DataSource.groovyreplaces the default version, andSecurityConfig.groovycontains extra settings.I prefer to edit the application’s files as little as possible, especially because I expect to change the security setup a few years down the road. I also need to use properties from a
jcc-server-config.propertiesfile which is customized for each application server in our system.Copying the files is easy.
The hard part is getting Grails to pick up the new configuration file. To do this, I have to edit the application’s
grails-app/conf/Config.groovy. I will add two configuration files to be found on the classpath.The only problem is adding
SecurityConfig.groovyto the classpath. I found that you can do that by creating the following event in the plugin’s/scripts/Events.groovy.Ed.