Question

Imagine that we have a grails plugin (that we're developing) and also a test app that we're using to test the grails plugin. I'm trying to test the _Install.groovy script of the plugin, but it's quite a process each time.

Can anyone please recommend way using gant or bash to automate the process of:

  1. Increment the version of the plugin
  2. Package the plugin
  3. Check if the plugin is already installed in the test app and if it is, remove it.
  4. Re-install the plugin.

Much appreciated,

Was it helpful?

Solution

The answer for me was to create a groovy/GANT script and execute it via the command line.

In my plugin, I have a scripts directory and in there I created a script called Deploy.groovy.

Running the command

grails deploy

Automatically executes this script. The script packages the plugin using built in grails targets, then executes grails commands via the commandline.

plugin-home/scripts/Deploy.groovy

includeTargets << grailsScript("PackagePlugin_")
includeTool << gant.tools.Execute


target(main: "This is the script that tries to test what's going on...") {

    println ("1. Package the plugin")
    packagePlugin()

    println ("2. Confirm the directory")
    execute.shell("cd ~/quirk-projects/admin-cms-plugin-test && pwd")

    println ("3. Remove the plugin ")
    execute.shell("cd ~/quirk-projects/admin-cms-plugin-test && grails uninstall-plugin grails-admin-cms-plugin")

    println ("4. Install the plugin ")
    execute.shell("cd ~/quirk-projects/admin-cms-plugin-test && grails install-plugin ../admin-cms-plugin/grails-admin-cms-plugin-0.1.zip")

    println ("5. Run Application")
    execute.shell("cd ~/quirk-projects/admin-cms-plugin-test && grails run-app")

    println ("6. Your plugin is ready for testing...")

}

setDefaultTarget(main)

To increment, I wrote a script that simply edits the source file and increments the version number:

plugin-home/scripts/_Events.groovy

eventCompileStart = { kind ->

    println("Incrementing Version Number for next time")

    def version = metadata.'version'

    if (!version) {
        version = '1'
    } else {
        version = version.toInteger() + 1
    }
    metadata.'version' = version.toString()
    metadata.persist()

    def file = new File("${basedir}/AdminCmsPluginGrailsPlugin.groovy")
    def script = file.text
    def array = script.split("\n")
    for (int i = 0 ; i < array.length; i++) {
        if (array[i].indexOf("def version") > -1) {
            array[i] = "    def version = 0." + version
        }
    }

    def newScript = array.join(System.getProperty("line.separator"))

    file.text = newScript


}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top