com.stanfy.helium.handler.ScriptExtender.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of helium Show documentation
Show all versions of helium Show documentation
DSL and Java API for REST API specification
package com.stanfy.helium.handler
import com.stanfy.helium.dsl.HeliumScript
import com.stanfy.helium.dsl.ProjectDsl
import com.stanfy.helium.model.Project
import org.codehaus.groovy.control.CompilerConfiguration
/**
* Extends project with script.
*/
class ScriptExtender implements Handler {
/** Closure. */
private final HeliumScript script
public ScriptExtender(final HeliumScript script) {
this.script = script
}
public ScriptExtender(final Reader scriptReader, final String name, final String path) {
CompilerConfiguration config = new CompilerConfiguration()
config.scriptBaseClass = HeliumScript.canonicalName
GroovyCodeSource source = new GroovyCodeSource(scriptReader, name, path)
this.script = new GroovyShell(HeliumScript.classLoader, new Binding(), config).parse(source) as HeliumScript
}
@Override
public void handle(final Project project) {
script.setProject((ProjectDsl)project)
script.run()
}
}