Debugging a compiled Groovy script in Eclipse

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Debugging a compiled Groovy script in Eclipse

Henrik Martin
I'm trying to debug a Groovy script in Eclipse from a JUnit
test. The Groovy code is part of a larger Java application that runs in
Tomcat. For various reasons our system is set up to use compiled JSR223
expressions. Here's the abbreviated code snippet:

GroovyScriptEngineImpl engine = new GroovyScriptEngineImpl();
Resource r =
  new ClassPathResource("groovy/transformations/input/Foo.groovy");
String expression = IOUtils.toString(r.getInputStream());
CompiledScript script = engine.compile(expression);
String result = (String) script.eval(new SimpleBindings(bindings));

The test runs fine, but even though I have a breakpoint set in
Foo.groovy, and the file is on the classpath, the breakpoint never gets
hit when debugging. I'm guessing this doesn't work because there's no
association between the expression in String format and the actual file
that contains it. So is there a way of creating this association between
 the String and its corresponding file name? As mentioned, I need to use
 a CompiledScript. As a side note, I have been able to hit the
breakpoint in the debugger with the same Groovy script when using this
approach:

Resource r =
  new ClassPathResource("groovy/transformations/input/Foo.groovy");
GroovyShell shell = new GroovyShell(new Binding(bindings));
String str = (String) shell.evaluate(r.getFile());

But of course, in this case the Groovy engine loads the file
directly. Any hints as to how to get the first example to work are
greatly appreciated. Also, I have enabled the "Enable script folder support" option
in the Groovy compiler settings in Eclipse. Thanks.

Henrik
Reply | Threaded
Open this post in threaded view
|

Re: Debugging a compiled Groovy script in Eclipse

Andrew Eisenberg
Hi Henrik,

I'm guessing that my answer on StackOverflow is sufficient: http://stackoverflow.com/questions/16307912/debugging-a-compiled-groovy-script-in-eclipse

Let me know if you have any more issues and as I said, this is probably worth an enhancement request for Groovy.


On Wed, May 1, 2013 at 4:28 PM, Henrik Martin <[hidden email]> wrote:
I'm trying to debug a Groovy script in Eclipse from a JUnit
test. The Groovy code is part of a larger Java application that runs in
Tomcat. For various reasons our system is set up to use compiled JSR223
expressions. Here's the abbreviated code snippet:

GroovyScriptEngineImpl engine = new GroovyScriptEngineImpl();
Resource r =
  new ClassPathResource("groovy/transformations/input/Foo.groovy");
String expression = IOUtils.toString(r.getInputStream());
CompiledScript script = engine.compile(expression);
String result = (String) script.eval(new SimpleBindings(bindings));

The test runs fine, but even though I have a breakpoint set in
Foo.groovy, and the file is on the classpath, the breakpoint never gets
hit when debugging. I'm guessing this doesn't work because there's no
association between the expression in String format and the actual file
that contains it. So is there a way of creating this association between
 the String and its corresponding file name? As mentioned, I need to use
 a CompiledScript. As a side note, I have been able to hit the
breakpoint in the debugger with the same Groovy script when using this
approach:

Resource r =
  new ClassPathResource("groovy/transformations/input/Foo.groovy");
GroovyShell shell = new GroovyShell(new Binding(bindings));
String str = (String) shell.evaluate(r.getFile());

But of course, in this case the Groovy engine loads the file
directly. Any hints as to how to get the first example to work are
greatly appreciated. Also, I have enabled the "Enable script folder support" option
in the Groovy compiler settings in Eclipse. Thanks.

Henrik

Reply | Threaded
Open this post in threaded view
|

RE: Debugging a compiled Groovy script in Eclipse

Henrik Martin
Yes, many thanks for your excellent reply Andrew! Major leap forward for me and the team :-)
Cheers,

/H

From: [hidden email] [[hidden email]] on behalf of Andrew Eisenberg [[hidden email]]
Sent: Thursday, May 02, 2013 10:01 AM
To: [hidden email]
Subject: Re: [groovy-user] Debugging a compiled Groovy script in Eclipse

Hi Henrik,

I'm guessing that my answer on StackOverflow is sufficient: http://stackoverflow.com/questions/16307912/debugging-a-compiled-groovy-script-in-eclipse

Let me know if you have any more issues and as I said, this is probably worth an enhancement request for Groovy.


On Wed, May 1, 2013 at 4:28 PM, Henrik Martin <[hidden email]> wrote:
I'm trying to debug a Groovy script in Eclipse from a JUnit
test. The Groovy code is part of a larger Java application that runs in
Tomcat. For various reasons our system is set up to use compiled JSR223
expressions. Here's the abbreviated code snippet:

GroovyScriptEngineImpl engine = new GroovyScriptEngineImpl();
Resource r =
  new ClassPathResource("groovy/transformations/input/Foo.groovy");
String expression = IOUtils.toString(r.getInputStream());
CompiledScript script = engine.compile(expression);
String result = (String) script.eval(new SimpleBindings(bindings));

The test runs fine, but even though I have a breakpoint set in
Foo.groovy, and the file is on the classpath, the breakpoint never gets
hit when debugging. I'm guessing this doesn't work because there's no
association between the expression in String format and the actual file
that contains it. So is there a way of creating this association between
 the String and its corresponding file name? As mentioned, I need to use
 a CompiledScript. As a side note, I have been able to hit the
breakpoint in the debugger with the same Groovy script when using this
approach:

Resource r =
  new ClassPathResource("groovy/transformations/input/Foo.groovy");
GroovyShell shell = new GroovyShell(new Binding(bindings));
String str = (String) shell.evaluate(r.getFile());

But of course, in this case the Groovy engine loads the file
directly. Any hints as to how to get the first example to work are
greatly appreciated. Also, I have enabled the "Enable script folder support" option
in the Groovy compiler settings in Eclipse. Thanks.

Henrik