grails plugin controlling load order - grails

i've been looking several guidance about this in Grails official documentation site here
but still i couldn't make it runs well.
Supposed i created two plugin. myplugin-a and myplugin-b .
Each plugin had their own bootstrap that will execute when main app which install those plugins runs. I had include this line of code in MypluginBGrailsPlugin.groovy
def loadAfter = ['myplugin-a']
but still the plugin runs the bootstrap on each plugins with the following order :
myplugin-b -> myplugin-a .
Did i miss something here ?
Any help would be appreciated

You need to use the camel-case syntax of the plugin name: def loadAfter = ['mypluginA']. See https://github.com/grails-plugins/grails-hibernate-plugin/blob/master/HibernateGrailsPlugin.groovy for an example in the Hibernate plugin

Related

Dynamic Controller Plugin for grails

I'am new to grails, I wanted to make use of Dynamic Controller Plugin (http://grails.org/plugin/dynamic-controller) in my project.
I am using grails version 3.2.11
I've added the dependency as directed on the page. It downloads the dependency in the form of zip, I can see it in External libraries. But when I am trying to import two classes (as directed on http://burtbeckwith.com/blog/?p=1041 Linking to existing Controller Actions
approach)
import com.burtbeckwith.grails.plugins.dynamiccontroller.ControllerClosureSource
import com.burtbeckwith.grails.plugins.dynamiccontroller.DynamicControllerManager
it gives " unable to resolve class" error. Please suggest what am I doing wrong here. Thanks!
You're trying to install a Grails 2 plugin in a Grails 3+ app, but that's not possible since they're not compatible. Grails 2 plugins must be upgraded and reworked to be used in Grails 3, and there's no plan to do so for this plugin.
I would say take a look at the URL Mappings & Embedded variables in the grails documentation.
https://docs.grails.org/3.2.11/guide/single.html#embeddedVariables
For example:
static mappings = {
"/blog/$topic"(controller: "blog")
}
which gives you a feeling like you are dynamically declaring actions.
And the topic variable is accessible through GrailsParameterMap params object # controller.
With this you can construct url like:
www.mysite.com/blog/football
www.mysite.com/blog/tvshow
www.mysite.com/blog/etc
Edit: you can also take a look at Dynamic Controller and Action Names [https://docs.grails.org/3.2.11/guide/single.html#_dynamic_controller_and_action_names]

default CRUD in vaadin 7 on grails

First of all, I am new to both Grails and Vaadin, I'm trying to make it work according to docs. I am using Grails 2.2.4 and Vaadin 7.1.8.2. I installed the plugin using:
$ grails install-plugin vaadin 7.1.8.2
and put the plugin into BuildConfig.groovy:
compile ':vaadin:7.1.8.2'
I have made a basic Vaadin UI that works (even generated from Eclipse designer - great stuff), I can modify it and it auto-reloads. Fine. I got the URL mapping set in VaadinConfig.groovy so that I can use the traditional Grails CRUD controllers as well as my Vaadin UI:
mapping = [
"/vaadin": "app.MyUI"
]
contextRelativePath = "/vaadin"
I was hoping I could use the Vaadin-style CRUD scaffolding of domain classes as in http://mckenfra.github.io/grails-vaadin-plugin/source-code/docs/ref/Command%20Line/generate-vaadin-all.html but I can't generate it:
$ grails generate-vaadin-all "*"
| Script 'GenerateVaadinAll' not found, did you mean:
1) GenerateAll
2) GenerateViews
3) GenerateController
4) DbmGenerateChangelog
5) DbmGenerateGormChangelog
I'm getting the same if I try generate-vaadin-views or generate-vaadin-controllers. What could I be doing wrong ?
Thanks
You can try RefreshDependencies before GenerateVaadinAll.

Grails Plugin Get Plugin's Root or Installed Directory

I'm writing a plugin and I'm trying to write a file inside of the Plugin's root or installed directory (not sure what to refer to this to). I can't seem to figure out how to get a hold of this value. Doing System.properties['base.dir'] will result in the implementing Grails project's root directory. So right now I have two directories:
C:/PluginProject/
C:/GrailsAppThatUsesPlugin/
It's my understanding that when this becomes a distributed plugin a user will similarly have two directories:
GRAILS_HOME/grails-version/projects/projectName/plugins/myPlugin/
C:/GrailsAppThatUsesPlugin/
Inside of my plugin project I need to create a file. It needs to be inside of my plugin because the file I'm writing needs to reference other files that my plugin provides. The few things that I've tried that haven't worked are:
System.properties['base.dir']
new File("")
In a groovy script within a plugin you can simply refer to pluginNamePluginDir but I'm trying to access this from a POGO.
Looking at all of the System.properties none of them have the plugin directory
grailsApplication doesn't seem to contain this type of information either.
Any help is greatly appreciated.
This worked for me (both in-place and regular plug-ins):
import org.codehaus.groovy.grails.plugins.GrailsPluginUtils
GrailsPluginUtils.pluginInfos.find { it.name == pluginName }.pluginDir
You can use this:
import org.codehaus.groovy.grails.plugins.PluginManagerHolder
def pluginManager = PluginManagerHolder.pluginManager
def plugin = pluginManager.getGrailsPlugin(pluginName)
def pluginDir = plugin.descriptor.file.parentFile
The plugin name has to be of the form 'spring-security-core', not 'springSecurityCore'

Grails Events: Copying directories around at Build time to get a clean 'multi-tenant' deployment effect

I'm working on a sort of 'multi-tenant' grails app that will be used as a 'platform' upon which quick sites will be developed.
A 'site' will include a layout, images, and page gsps.
Right now, these are spread across the project in their normal locations, eg:
/grails-app/views/layout
/grails-app/views/<site>
/web-app/images/
Ideally, they'd all be in one place, centralized by site, like
/sites/<site>/layout
/sites/<site>/pages/
/sites/<site>/imagtes
My current thinking is this could be accomplished with a Build.groovy script and doing some ant trickery at build time.
But I'm not sure if it's possible to do this copying-by-convention - ie I don't know the directories that are present until it runs. (I'm also no ant guru)
Any ideas/suggestions? Thanks!
I have used the following script, named _Events.groovy and located in a scripts folder under your grails application, to copy files before my build:
includeTargets << grailsScript("_GrailsEvents")
eventSetClasspath = { msg ->
println "Custom Configuration"
ant.copy(todir:classesDirPath) {
fileset(dir:"${basedir}/config")
}
}
And I suppose you could use something very similar.
Relevant grails documentation is here

one-off grails script for populating database

Update: as of Grails 1.3.6 one has access to the full domain from Gant scripts.
From the Grails 1.3.6 release notes:
You can now run one or more Groovy scripts from the commandline using the run-script command, e.g.
grails run-script [path-to-script-1] [path-to-script-2]...[path-to-script-n]
This works around the issue in Gant scripts where you can't conveniently access application classes since they're not available in the classpath when the scripts start.
Hi all,
I am new to using Grails (in a real project) and I have a one-off script I need to execute that reads a file and then populates my database.
I wanted the script to run in the context of my grails app, so I used the create-script command. I now understand that makes it a 'Gant' script. The reason for doing so was that I thought it would allow me easy access to all the grails domain good-ness, so that i would be able to do something like this easily:
Car car = new Car(model: 'bar', brand: 'Ford')
car.save()
Here, Car is one of my domain classes and the strings 'bar' and 'Ford' I have retrieved from my file.
The start of my script looks like this:
import com.foo.Car
grailsHome = Ant.project.properties."environment.GRAILS_HOME"
includeTargets << new File ( "${grailsHome}/scripts/Bootstrap.groovy" )
target(main: "a script for storing cars") {
depends(bootstrap, classpath) // code dealing with the file with cars follows
Surprisingly, groovy gives me a java.lang.NoClassDefFoundError: com.foo.Car when I execute the script with the command grails LoadCars
Am I taking the wrong approach, or is there something more simple I am doing wrong?
Any help is appreciated
i know the scripts are useful, and I will probably get hate mail for even suggesting it, but I have just incorporating this kinda of stuff directly into my application in the past.
I have a flag set in my configuration which indicates if the data should be bootstrapped, if so, the bootstrap code looks for a comma delimited file at startup and calls a service method to load up the data.
I've updated the grails run-script Gant script (referred to by Jared above) to work with grails 1.3.5. I'd been meaning to do it for a while, but this question nudged me into finally getting around to it).
Just download the script described in the post, save it in your grails "scripts" directory and you can then run your own groovy script to bootstrap data with:
grails run-script script-path/boostrapMyDataIntoApp.groovy
I've had to do this and you have to create a special script to allow you to access GORM from a standard grails script. See this question for more info. I'm not sure what the current status of the script is under grails 1.3 but the author of the script posted in the comments.
Hans, there are several choices here, assuming you are not out to polish the GANT scripting chops 8^)
So assume that you are doing some integration-mode TDD, correct?
Have you looked into the db-stuff plugin? Actually that one leverages the open source package (extension of the JUnit project) called dbUnit, which is also an outstanding choice, for both Java and Groovy projects.
*db-stuff <0.3.0> -- db schema managment and data import/export. Generate generic schema files and import or export base/seed/test data into your database.
I have traditionally done this as well in the BootStrap depending on the environment - and I try to never let those domain assumptions / constraints get too far out of synch. with my schema.
Here's the canon I'm talking about :
class BootStrap {
def init = { servletContext ->
if (GrailsUtil.environment.equals( GrailsApplication.ENV_DEVELOPMENT )) {
log.info( "Loading sample data for 2010 models..." );
new Car( manufacturer: new Manufacturer( name: "Toyota" ), model: "Prius" )
new Car( manufacturer: new Manufacturer( name: "GM" ), model: "Volt" )
//...

Resources