You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Theodor Tolstoy (JIRA)" <ji...@apache.org> on 2015/10/23 10:55:27 UTC

[jira] [Commented] (GROOVY-5194) ConfigSluper cannot re-parse a file written by itself.

    [ https://issues.apache.org/jira/browse/GROOVY-5194?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14970668#comment-14970668 ] 

Theodor Tolstoy commented on GROOVY-5194:
-----------------------------------------

Frustrating.
I want to filter my configuration by environment and then save the resulting configuration to the war file. I had the same problem.
My workaround is to use the prettyPrint() on the ConfigSlurtper when saving the configuration to file. The object is not as pretty, but it works for my transforming purpuses.

This is my Gradle method :
def loadConfiguration() {
    def environment = hasProperty('env') ? env : 'dev'
    project.ext.environment = environment
    def configFile = file('configValues.groovy')
    def config = new ConfigSlurper(environment).parse(configFile.toURI().toURL())
    config.mode = ext.environment
    config.buildTimeStamp = (new Date()).format('yyyy-MM-dd HH:mm:ss')
    file('./src/main/resources/config.groovy').text = config.prettyPrint()
}


> ConfigSluper cannot re-parse a file written by itself.
> ------------------------------------------------------
>
>                 Key: GROOVY-5194
>                 URL: https://issues.apache.org/jira/browse/GROOVY-5194
>             Project: Groovy
>          Issue Type: Sub-task
>          Components: groovy-jdk
>    Affects Versions: 1.8.3
>         Environment: winxp, jdk6
>            Reporter: Chenyang XING
>            Priority: Minor
>              Labels: exception
>         Attachments: Config.groovy, TestConfigSlurper.groovy, config.txt
>
>
> config file is as below:
> list('XX') {
>     one {
>         a = 100
>         b = 200
>         c {
>             x1 = "x1"
>             x2 {
>                 y1 = 1
>             }
>         }
>     }
>     two = "2000"
> }
> ConfigSlurper can parse correctly. But when call its writeTo method to a file, the file like this:
> list="XX"
> one."list.a"=100
> one."list.b"=200
> one"list.x1"="x1"
> onex2."list.y1"=1
> "list.two"="2000"
> This output file cannot be re-parsed.
> The error message in stdout as below:
> [list:XX, one:[list.a:100, list.b:200, c:[list.x1:x1, x2:[list.y1:1]]], list.two:2000]
> XX
> 2000
> 2000
> 100
> x1
> x1
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> script13238783009061342328505.groovy: 4: 
> [list.x1] is a constant expression, but it should be a variable expression at line: 4 column: 13. File: script13238783009061342328505.groovy @ line 4, column 13.
>    one"list.x1"="x1"
>                ^
> 1 error



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)