Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

IDE support

Michael Rüegg edited this page Oct 19, 2016 · 5 revisions

To write your DSL scripts, you probably want to have an IDE that supports Groovy because the DSL scripts are basically just Groovy code. Beside the basic Groovy support, if you are using IntelliJ, then you can additionally have syntax highlighting, code completion and documentation for the DSL elements. This is possible thanks to the GroovyDSL scripting framework IntelliJ offers. To make this work, you have to put the following file into your IntelliJ project:

def dslPath = /.*\/dsls\/.*\.groovy/
contributor(context(pathRegexp: dslPath), {
    delegatesTo(findClass('ch.mibex.bamboo.plandsl.dsl.DslFactory'))
})

In order to have access to the DSL elements, you need to add our DSL library to your project. In the following snippet, we show how you can achieve this with Gradle. Just put the following content into a file called build.gradle in your project:

apply plugin: 'groovy'

sourceSets {
    dsls {
        groovy {
            srcDirs 'dsls'
            compileClasspath += main.compileClasspath
        }
    }
}

repositories {
    mavenCentral()
    maven { url "https://jitpack.io" }
}

dependencies {
    compile 'com.github.mibexsoftware:bamboo-plan-dsl-plugin:1.2.0'
    compile group: 'org.apache.ant', name: 'ant', version: '1.8.2'
    testCompile('org.spockframework:spock-core:1.0-groovy-2.4')
}

test {
    inputs.files sourceSets.dsls.groovy.srcDirs
}

Beside the reference to our DSL library, this file also makes it possible to test your DSL scripts for compatibility with a specific version of the DSL library (in this example, version 1.2.0; change this if necessary). A Groovy Spock test to check all your DSL scripts in the directory dsls for syntax issues looks like follows:

import ch.mibex.bamboo.plandsl.dsl.DslScriptContext
import ch.mibex.bamboo.plandsl.dsl.DslScriptParserImpl
import spock.lang.Specification
import spock.lang.Unroll

class DslScriptSpec extends Specification {

    @Unroll
    def 'test DSL script #file.name'(File file) {
        given:

        when:
        def loader = new DslScriptParserImpl()
        loader.parse(new DslScriptContext(file.text))

        then:
        noExceptionThrown()

        where:
        file << findDslFiles()
    }

    private static def findDslFiles() {
        List<File> dslFiles = []
        new File('dsls').eachFileRecurse {
            if (it.name.endsWith('.groovy')) {
                dslFiles << it
            }
        }
        dslFiles
    }
}

If you don't want to copy&paste all this code, we provide a sample repository which contains all these files.

Clone this wiki locally