How to debug embedding groovy with Groovy-Eclipse-Plugin

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

How to debug embedding groovy with Groovy-Eclipse-Plugin

杨冰
If anyone know how to debug embedding groovy with "Groovy Eclipse Plugin"?
This is my case:
I write a main method in a java class in the a groovy project, something like code below.
public static void main(String[] args) {
   // (1) load the groovy source code
   // (2) get a new instance of the groovy class
   // (3) invoke one of it's method
}
I debug as java application,hoping to debug groovy class step by step in  part (3),but eclipse always say "Source not found."
I edit source lookup path,try to add all the possible path into the lookup path ,but no one works.any one know what is wrony? what should i do?

Reply | Threaded
Open this post in threaded view
|

Re: How to debug embedding groovy with Groovy-Eclipse-Plugin

Andrew Eisenberg
I'm guessing that you see the "source not found" messages on stack
frames that relate to Groovy internals, native method calls, and
reflective calls.  Is that right?

As you probably know, Groovy uses a metaobject protocol to dispatch
all method invocations and field accesses.  This means that each
method call or field access will require some reflective calls before
the actual method/field invocation/access.

In plain groovy-eclipse, there is not much you can do to get around
this, but if you download STS and install the grails tooling, then you
get some extra debug support.  Step into and step out will work as you
expect (ie - bypassing all reflective calls and going straight to the
stack frame you are interested in).  This can only be done from within
a Groovy project.



On Tue, Aug 16, 2011 at 3:12 AM, 杨冰 <unique5945@gmailAs .com> wrote:

> If anyone know how to debug embedding groovy with "Groovy Eclipse Plugin"?
> This is my case:
> I write a main method in a java class in the a groovy project, something
> like code below.
> public static void main(String[] args) {
>    // (1) load the groovy source code
>    // (2) get a new instance of the groovy class
>    // (3) invoke one of it's method
> }
> I debug as java application,hoping to debug groovy class step by step in
>  part (3),but eclipse always say "Source not found."
> I edit source lookup path,try to add all the possible path into the lookup
> path ,but no one works.any one know what is wrony? what should i do?
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: How to debug embedding groovy with Groovy-Eclipse-Plugin

杨冰
thank you very much,Andrew.But what i can not see is not only groovy internal but also my own groovy code.In fact i only care about debugging my code.Do you have any idea?


2011/8/17 Andrew Eisenberg <[hidden email]>
I'm guessing that you see the "source not found" messages on stack
frames that relate to Groovy internals, native method calls, and
reflective calls.  Is that right?

As you probably know, Groovy uses a metaobject protocol to dispatch
all method invocations and field accesses.  This means that each
method call or field access will require some reflective calls before
the actual method/field invocation/access.

In plain groovy-eclipse, there is not much you can do to get around
this, but if you download STS and install the grails tooling, then you
get some extra debug support.  Step into and step out will work as you
expect (ie - bypassing all reflective calls and going straight to the
stack frame you are interested in).  This can only be done from within
a Groovy project.



On Tue, Aug 16, 2011 at 3:12 AM, 杨冰 <unique5945@gmailAs .com> wrote:
> If anyone know how to debug embedding groovy with "Groovy Eclipse Plugin"?
> This is my case:
> I write a main method in a java class in the a groovy project, something
> like code below.
> public static void main(String[] args) {
>    // (1) load the groovy source code
>    // (2) get a new instance of the groovy class
>    // (3) invoke one of it's method
> }
> I debug as java application,hoping to debug groovy class step by step in
>  part (3),but eclipse always say "Source not found."
> I edit source lookup path,try to add all the possible path into the lookup
> path ,but no one works.any one know what is wrony? what should i do?
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: How to debug embedding groovy with Groovy-Eclipse-Plugin

Andrew Eisenberg
Is the groovy script on your build path?  If you don't want the script
to be sent to the compiler, then you can go to Preferences -> Groovy
-> Compiler.

You say that you have added the script to the source lookup, but
that's not working for you?  Have you gone to your launch
configuration and looked at the "Source" tab?.

On Tue, Aug 16, 2011 at 10:09 PM, 杨冰 <[hidden email]> wrote:

> thank you very much,Andrew.But what i can not see is not only groovy
> internal but also my own groovy code.In fact i only care about debugging my
> code.Do you have any idea?
>
> 2011/8/17 Andrew Eisenberg <[hidden email]>
>>
>> I'm guessing that you see the "source not found" messages on stack
>> frames that relate to Groovy internals, native method calls, and
>> reflective calls.  Is that right?
>>
>> As you probably know, Groovy uses a metaobject protocol to dispatch
>> all method invocations and field accesses.  This means that each
>> method call or field access will require some reflective calls before
>> the actual method/field invocation/access.
>>
>> In plain groovy-eclipse, there is not much you can do to get around
>> this, but if you download STS and install the grails tooling, then you
>> get some extra debug support.  Step into and step out will work as you
>> expect (ie - bypassing all reflective calls and going straight to the
>> stack frame you are interested in).  This can only be done from within
>> a Groovy project.
>>
>>
>>
>> On Tue, Aug 16, 2011 at 3:12 AM, 杨冰 <unique5945@gmailAs .com> wrote:
>> > If anyone know how to debug embedding groovy with "Groovy Eclipse
>> > Plugin"?
>> > This is my case:
>> > I write a main method in a java class in the a groovy project, something
>> > like code below.
>> > public static void main(String[] args) {
>> >    // (1) load the groovy source code
>> >    // (2) get a new instance of the groovy class
>> >    // (3) invoke one of it's method
>> > }
>> > I debug as java application,hoping to debug groovy class step by step in
>> >  part (3),but eclipse always say "Source not found."
>> > I edit source lookup path,try to add all the possible path into the
>> > lookup
>> > path ,but no one works.any one know what is wrony? what should i do?
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: How to debug embedding groovy with Groovy-Eclipse-Plugin

杨冰
Thread [main] (Suspended (breakpoint at line 39 in AuditTask))
AuditTask.doGet(ModelMap, WebRequest, HttpServletResponse) line: 39
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]
NativeMethodAccessorImpl.invoke(Object, Object[]) line: not available
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available
Method.invoke(Object, Object...) line: not available
MyTest.test3(File, File, ClassLoader) line: 315
MyTest.main(String[]) line: 262

this is my stack,MyTest.java is in a java project.When i step into AuditTask.groovy,eclipse shows "source not found".i edit source lookup path to add the project into the build path.In fact the project is just the same project where MyTest.java belong to.Here is my project schema:
myproj
  |-src
     |-main
         |-java
             |-com
                 |-test
                     |-MyTest.java
                     |-AuditTask.groovy

you  remind me to check the "Source" tab" in launch configuration,i found it is the same as editing source lookup path to add the project into the build path.i also try three ways to run the embeding grooy script:
//GroovyScriptEngine public static void test1(String scriptLocation,ClassLoader cl) throws Exception { String[] roots = new String[] { scriptLocation }; GroovyScriptEngine gse = new GroovyScriptEngine(roots,cl); Class<?> clz = gse.loadScriptByName("com.test.AuditTask"); Object obj = clz.newInstance(); for(Method m : obj.getClass().getDeclaredMethods()){ if(m.getName().equals("doGet")){ m.invoke(obj, null,null,null); } } } //GroovyClassLoader public static void test2(File file,ClassLoader cl) throws Exception { GroovyClassLoader loader = new GroovyClassLoader(cl); Class<Script> ret = loader.parseClass(file); GroovyObject gobj = ret.newInstance(); Object[] args = {null,null,null}; gobj.invokeMethod("doGet", args); } //CompilerConfiguration public static void test3(File scriptLocation,File scriptPath,ClassLoader cl) throws Exception { // Some variables… // Configure CompilerConfiguration conf = new CompilerConfiguration(); conf.setTargetDirectory(scriptPath.getPath()); // Compile… GroovyClassLoader gcl = new GroovyClassLoader(cl); CompilationUnit cu = new CompilationUnit(gcl); cu.configure(conf); cu.addSources(scriptLocation.listFiles()); // Add more source files to the compilation unit if needed cu.compile(); // Load… URL[] urls = new URL[] { scriptPath.toURL() }; URLClassLoader ucl = new URLClassLoader(urls, cl); gcl = new GroovyClassLoader(ucl, conf); Class clazz = gcl.loadClass("com.test.AuditTask"); Object at = clazz.newInstance(); for(Method m : at.getClass().getDeclaredMethods()){ if(m.getName().equals("doGet")){ m.invoke(at, null,null,null); } } }
None of them can see the source code . 
I also go to the Preferences -> Groovy-> Compiler,and check the "Enable script folder support" and add "src/main/java/**/*.groovy" to the list. i do not know if it is necessary?
I also set  a filter out list below in Preferences -> Groovy-> Debugger.
groovy.lang
groovy.ui
java.lang.reflect
org.codehaus.groovy
sun.misc
sun.reflect

But i still can not see the source code while debugging.

在 2011年8月17日 下午1:35,Andrew Eisenberg <[hidden email]>写道:
Is the groovy script on your build path?  If you don't want the script
to be sent to the compiler, then you can go to Preferences -> Groovy
-> Compiler.

You say that you have added the script to the source lookup, but
that's not working for you?  Have you gone to your launch
configuration and looked at the "Source" tab?.

On Tue, Aug 16, 2011 at 10:09 PM, 杨冰 <[hidden email]> wrote:
> thank you very much,Andrew.But what i can not see is not only groovy
> internal but also my own groovy code.In fact i only care about debugging my
> code.Do you have any idea?
>
> 2011/8/17 Andrew Eisenberg <[hidden email]>
>>
>> I'm guessing that you see the "source not found" messages on stack
>> frames that relate to Groovy internals, native method calls, and
>> reflective calls.  Is that right?
>>
>> As you probably know, Groovy uses a metaobject protocol to dispatch
>> all method invocations and field accesses.  This means that each
>> method call or field access will require some reflective calls before
>> the actual method/field invocation/access.
>>
>> In plain groovy-eclipse, there is not much you can do to get around
>> this, but if you download STS and install the grails tooling, then you
>> get some extra debug support.  Step into and step out will work as you
>> expect (ie - bypassing all reflective calls and going straight to the
>> stack frame you are interested in).  This can only be done from within
>> a Groovy project.
>>
>>
>>
>> On Tue, Aug 16, 2011 at 3:12 AM, 杨冰 <unique5945@gmailAs .com> wrote:
>> > If anyone know how to debug embedding groovy with "Groovy Eclipse
>> > Plugin"?
>> > This is my case:
>> > I write a main method in a java class in the a groovy project, something
>> > like code below.
>> > public static void main(String[] args) {
>> >    // (1) load the groovy source code
>> >    // (2) get a new instance of the groovy class
>> >    // (3) invoke one of it's method
>> > }
>> > I debug as java application,hoping to debug groovy class step by step in
>> >  part (3),but eclipse always say "Source not found."
>> > I edit source lookup path,try to add all the possible path into the
>> > lookup
>> > path ,but no one works.any one know what is wrony? what should i do?
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: How to debug embedding groovy with Groovy-Eclipse-Plugin

杨冰
I found the problem is that i didn't set the Included of "Java Build Path-->Souce" to "**/*.groovy;**/*.java" ,which is set as "**/*.java" by default.
But i found another problem: it is not allowed to use "ctrl+shift+i" to see the value of the variables,i can only check them in "Variables View".Is this a bug of Groovy-Eclipse-Plugin?

2011/8/17 杨冰 <[hidden email]>
Thread [main] (Suspended (breakpoint at line 39 in AuditTask))
AuditTask.doGet(ModelMap, WebRequest, HttpServletResponse) line: 39
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]
NativeMethodAccessorImpl.invoke(Object, Object[]) line: not available
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available
Method.invoke(Object, Object...) line: not available
MyTest.test3(File, File, ClassLoader) line: 315
MyTest.main(String[]) line: 262

this is my stack,MyTest.java is in a java project.When i step into AuditTask.groovy,eclipse shows "source not found".i edit source lookup path to add the project into the build path.In fact the project is just the same project where MyTest.java belong to.Here is my project schema:
myproj
  |-src
     |-main
         |-java
             |-com
                 |-test
                     |-MyTest.java
                     |-AuditTask.groovy

you  remind me to check the "Source" tab" in launch configuration,i found it is the same as editing source lookup path to add the project into the build path.i also try three ways to run the embeding grooy script:
//GroovyScriptEngine public static void test1(String scriptLocation,ClassLoader cl) throws Exception { String[] roots = new String[] { scriptLocation }; GroovyScriptEngine gse = new GroovyScriptEngine(roots,cl); Class<?> clz = gse.loadScriptByName("com.test.AuditTask"); Object obj = clz.newInstance(); for(Method m : obj.getClass().getDeclaredMethods()){ if(m.getName().equals("doGet")){ m.invoke(obj, null,null,null); } } } //GroovyClassLoader public static void test2(File file,ClassLoader cl) throws Exception { GroovyClassLoader loader = new GroovyClassLoader(cl); Class<Script> ret = loader.parseClass(file); GroovyObject gobj = ret.newInstance(); Object[] args = {null,null,null}; gobj.invokeMethod("doGet", args); } //CompilerConfiguration public static void test3(File scriptLocation,File scriptPath,ClassLoader cl) throws Exception { // Some variables… // Configure CompilerConfiguration conf = new CompilerConfiguration(); conf.setTargetDirectory(scriptPath.getPath()); // Compile… GroovyClassLoader gcl = new GroovyClassLoader(cl); CompilationUnit cu = new CompilationUnit(gcl); cu.configure(conf); cu.addSources(scriptLocation.listFiles()); // Add more source files to the compilation unit if needed cu.compile(); // Load… URL[] urls = new URL[] { scriptPath.toURL() }; URLClassLoader ucl = new URLClassLoader(urls, cl); gcl = new GroovyClassLoader(ucl, conf); Class clazz = gcl.loadClass("com.test.AuditTask"); Object at = clazz.newInstance(); for(Method m : at.getClass().getDeclaredMethods()){ if(m.getName().equals("doGet")){ m.invoke(at, null,null,null); } } }
None of them can see the source code . 
I also go to the Preferences -> Groovy-> Compiler,and check the "Enable script folder support" and add "src/main/java/**/*.groovy" to the list. i do not know if it is necessary?
I also set  a filter out list below in Preferences -> Groovy-> Debugger.
groovy.lang
groovy.ui
java.lang.reflect
org.codehaus.groovy
sun.misc
sun.reflect

But i still can not see the source code while debugging.

在 2011年8月17日 下午1:35,Andrew Eisenberg <[hidden email]>写道:

Is the groovy script on your build path?  If you don't want the script
to be sent to the compiler, then you can go to Preferences -> Groovy
-> Compiler.

You say that you have added the script to the source lookup, but
that's not working for you?  Have you gone to your launch
configuration and looked at the "Source" tab?.

On Tue, Aug 16, 2011 at 10:09 PM, 杨冰 <[hidden email]> wrote:
> thank you very much,Andrew.But what i can not see is not only groovy
> internal but also my own groovy code.In fact i only care about debugging my
> code.Do you have any idea?
>
> 2011/8/17 Andrew Eisenberg <[hidden email]>
>>
>> I'm guessing that you see the "source not found" messages on stack
>> frames that relate to Groovy internals, native method calls, and
>> reflective calls.  Is that right?
>>
>> As you probably know, Groovy uses a metaobject protocol to dispatch
>> all method invocations and field accesses.  This means that each
>> method call or field access will require some reflective calls before
>> the actual method/field invocation/access.
>>
>> In plain groovy-eclipse, there is not much you can do to get around
>> this, but if you download STS and install the grails tooling, then you
>> get some extra debug support.  Step into and step out will work as you
>> expect (ie - bypassing all reflective calls and going straight to the
>> stack frame you are interested in).  This can only be done from within
>> a Groovy project.
>>
>>
>>
>> On Tue, Aug 16, 2011 at 3:12 AM, 杨冰 <unique5945@gmailAs .com> wrote:
>> > If anyone know how to debug embedding groovy with "Groovy Eclipse
>> > Plugin"?
>> > This is my case:
>> > I write a main method in a java class in the a groovy project, something
>> > like code below.
>> > public static void main(String[] args) {
>> >    // (1) load the groovy source code
>> >    // (2) get a new instance of the groovy class
>> >    // (3) invoke one of it's method
>> > }
>> > I debug as java application,hoping to debug groovy class step by step in
>> >  part (3),but eclipse always say "Source not found."
>> > I edit source lookup path,try to add all the possible path into the
>> > lookup
>> > path ,but no one works.any one know what is wrony? what should i do?
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email




Reply | Threaded
Open this post in threaded view
|

Re: How to debug embedding groovy with Groovy-Eclipse-Plugin

Andrew Eisenberg
> But i found another problem: it is not allowed to use "ctrl+shift+i" to see
> the value of the variables,i can only check them in "Variables View".Is this
> a bug of Groovy-Eclipse-Plugin?

As I mentioned before, this feature is only available in STS.  You can
download it here:
http://www.springsource.com/developer/sts

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: How to debug embedding groovy with Groovy-Eclipse-Plugin

杨冰
STS solved all my problems,and it is real a powerful IDE ,thank you again!!

2011/8/17 Andrew Eisenberg <[hidden email]>
> But i found another problem: it is not allowed to use "ctrl+shift+i" to see
> the value of the variables,i can only check them in "Variables View".Is this
> a bug of Groovy-Eclipse-Plugin?

As I mentioned before, this feature is only available in STS.  You can
download it here:
http://www.springsource.com/developer/sts

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email