Hello all,

I am using `GroovyClassLoader` to execute groovy scripts at runtime and I want 
modifications to the script text (stored on the filesystem) to be picked up on 
subsequent execution of the script but I don't want the script to be 
re-compiled each time.  From my understanding, creating a `GroovyClassLoader` 
with a `CompilerConfiguration` where `recompileGroovySource` is set to true 
should give this outcome, but it does not seems to work the way I am using it.

I expect the following script to pass, but the second assert fails, anybody can 
tell me what I am doing wrong (or why my assumptions on how this is supposed to 
work are false) ?


----
import org.codehaus.groovy.control.CompilerConfiguration
import org.codehaus.groovy.runtime.InvokerHelper
class MyGcl {

    public static void main(String[] args) {
        CompilerConfiguration config
        config = new CompilerConfiguration()
        config.setRecompileGroovySource(true)
        GroovyClassLoader gcl = new GroovyClassLoader(getClassLoader(), config)
        Binding binding = new Binding()

        File fooFile = new File("foo.groovy")
        fooFile.text = '''
alpha='abc'
num='123'
alpha
'''
        def result = InvokerHelper.createScript(gcl.parseClass(fooFile), 
binding).run()
        assert 'abc' == result

        fooFile.text = fooFile.text + '''
num
'''
        result = InvokerHelper.createScript(gcl.parseClass(fooFile), 
binding).run()
        assert '123' == result
    }
}
----

Thanks in advance,
Marc

Reply via email to