ConfigSlurper

Holger Buhr February 28, 2016

Hi,

I try to use the ConfigSlurper but got a ton of exceptions, can I use it with Script Runner?

 

def config = new ConfigSlurper()

config.parse('''
app.age = 42
app {
name = "343"
}
''')

2016-02-29 11:22:11,860 http-nio-8080-exec-22 ERROR 682x15586x1 14b7680 127.0.0.1 /rest/api/2/issue/10103/comment [c.o.scriptrunner.runner.AbstractScriptListener] *************************************************************************************

2016-02-29 11:22:11,860 http-nio-8080-exec-22 ERROR 682x15586x1 14b7680 127.0.0.1 /rest/api/2/issue/10103/comment [c.o.scriptrunner.runner.AbstractScriptListener] Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: JSDIssueCommented

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:

General error during class generation: java.lang.NoClassDefFoundError: groovy/lang/Script

 

The problem seems to be the parse(), log.debug shows me "groovy.util.ConfigSlurper@278dab4c" on config var

1 answer

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 29, 2016

ConfigSlurper is a bit mad, I try to avoid it. The following seems to work but there are better ways:

str = ...
def script = new GroovyShell().parse(str)
log.debug config.parse(script)
Holger Buhr February 29, 2016

Ah, great, works! Thank you!

I´m eager to learn, so what are the better ways?

What I want to do:
Have 2 config scripts, one for development and one for production. Our build server decides which gets delivered based on the environment. Maybe some file exist voodoo to have some sane production defaults and if development file exists then it´s overriding the production values.

This works so far:

ConfigSlurper configSlurper = new ConfigSlurper()
ConfigObject config = configSlurper.parse(new GroovyShell().parse(this.class.getResource("config/production.groovy").text))
URL developmentUrl = this.class.getResource("config/development.groovy")

if (developmentUrl) {
config.merge(configSlurper.parse(new GroovyShell().parse(developmentUrl.text)))

log.debug config.teams.packers
}
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 1, 2016

That seems reasonable... the problem with the method I gave you is because it creates a new shell, the compiled script is not cached. The better way would be to reuse the shell and classloader from the plugin, which would allow caching. But I couldn't do that quickly... we use a similar technique for a project here. Can't remember the details but I think a system property points to the location of the config, which differs for differing environments.

Holger Buhr March 1, 2016

I´m not that deep into groovy, yet. But good to know, thank you.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events