About Hubert Ikkink

My name is Hubert A. Klein Ikkink also known as mrhaki. I work at the great IT company JDriven. Here I work on projects with Groovy & Grails, Gradle and Spring. At JDriven we focus on SpringSource technologies. All colleagues want to learn new technologies, support craftmanship and are very eager to learn. This is truly a great environment to work in.

Grails Goodness: Extending IntegrateWith Command

We can extend the integrate-with command in Grails to generate files for a custom IDE or build system. We must add a _Events.groovy file to our Grails projects and then write an implementation for the eventIntegrateWithStart event. Inside the event we must define a new closure with our code to generate files. The name of the closure must have the following pattern: binding.integrateCustomIdentifier. The value for CustomIdentifier can be used as an argument for the integrate-with command.

Suppose we want to extend integrate-with to generate a simple Sublime Text project file. First we create a template Sublime Text project file where we define folders for a Grails application. We create the folder src/ide-support/sublimetext and add the file grailsProject.sublimetext-project with the following contents:

{
    "folders": [
        {
            "name": "Domain classes",
            "path": "grails-app/domain"
        },
        {
            "name": "Controllers",
            "path": "grails-app/controllers"
        },
        {
            "name": "Taglibs",
            "path": "grails-app/taglib"
        },
        {
            "name": "Views",
            "path": "grails-app/views"
        },
        {
            "name": "Services",
            "path": "grails-app/services"
        },
        {
            "name": "Configuration",
            "path": "grails-app/conf"
        },
        {
            "name": "grails-app/i18n",
            "path": "grails-app/i18n"
        },
        {
            "name": "grails-app/utils",
            "path": "grails-app/utils"
        },
        {
            "name": "grails-app/migrations",
            "path": "grails-app/migrations"
        },
        {
            "name": "web-app",
            "path": "web-app"
        },
        {
            "name": "Scripts",
            "path": "scripts"
        },
        {
            "name": "Sources:groovy",
            "path": "src/groovy"
        },
        {
            "name": "Sources:java",
            "path": "src/java"
        },
        {
            "name": "Tests:integration",
            "path": "test/integration"
        },
        {
            "name": "Tests:unit",
            "path": "test/unit"
        },
        {
            "name": "All files",
            "follow_symlinks": true,
            "path": "."
        }
    ]
}

Next we create the file scripts/_Events.groovy:

includeTargets << grailsScript("_GrailsInit")

eventIntegrateWithStart = {

    // Usage: integrate-with --sublimeText
    binding.integrateSublimeText = {

        // Copy template file.
        ant.copy(todir: basedir) {
            fileset(dir: "src/ide-support/sublimetext/")
        }

        // Move template file to real project file with name of Grails application.
        ant.move(file: "$basedir/grailsProject.sublime-project", 
                 tofile: "$basedir/${grailsAppName}.sublime-project", 
                 overwrite: true)

        grailsConsole.updateStatus "Created SublimeText project file"
    }
}

We are done and can now run the integrate-with command with the new argument sublimeText:

$ grails integrate-with --sublimeText
| Created SublimeText project file.
$

If we open the project in Sublime Text we see our folder structure for a Grails application:

integrate-with-st

Code written with Grails 2.3.7.

Reference: Grails Goodness: Extending IntegrateWith Command from our JCG partner Hubert Ikkink at the JDriven blog.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

Leave a Reply


9 + = sixteen



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close