GRECLIPSE
  1. GRECLIPSE
  2. GRECLIPSE-560

Groovy script launcher not behaving quite right

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0.0m1
    • Fix Version/s: 2.0.0m2
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Define a groovy project.

      Create this java type MyHelper.java:

      import groovy.lang.Closure;

      public class MyHelper {

      public void someMethod(int i,Closure c) {
      for (int j=0;j<i;j++)

      { c.call(j); }

      }
      }

      Define a script demoscript.groovy:

      mh =new MyHelper()

      mh.someMethod(4) {
      println "$

      {it}

      "
      }

      In the script editor window, RunAs>JavaApplication - works
      RunAs>GroovyScript:
      Caught: groovy.lang.MissingMethodException: No signature of method: MyHelper.someMethod() is applicable for argument types: (java.lang.Integer, demoscript$_run_closure1) values: [4, demoscript$_run_closure1@16d835f]
      Possible solutions: someMethod(int, groovy.lang.Closure)
      at demoscript.run(demoscript.groovy:3)

      it is as if the classpath for the script launch is not including the path to the compiled MyHelper, however, there must be slightly more to it because it doesn't complain it can't find MyHelper, it complains it can't find the method within MyHelper.

        Activity

        Hide
        Andrew Eisenberg added a comment -

        I've known there were some problems with run as groovy script, but I haven't had a chance to really look at it. I guess this is a good opportunity to.

        Show
        Andrew Eisenberg added a comment - I've known there were some problems with run as groovy script, but I haven't had a chance to really look at it. I guess this is a good opportunity to.
        Hide
        Andy Clement added a comment -

        Recreated on the command line using what that launcher is trying to do:

        set CLASSPATH=bin;%CLASSPATH%

        N:\workspaces\groovy_dev_workspace\TestProject>java -Dgroovy.starter.conf="/N:/workspaces/groovy35/org.codehaus.groovy/conf/groovy-starter.conf" -Dgroovy.home="N:\workspaces\groovy35\org.codehaus.groovy" org.codehaus.groovy.tools.GroovyStarter --main groovy.ui.GroovyMain src\demoscript.groovy

        Caught: groovy.lang.MissingMethodException: No signature of method: MyHelper.someMethod() is applicable for argument types: (java.lang.Integer, demoscript$run
        closure1) values: [4, demoscript$_run_closure1@cbd8dc]
        Possible solutions: someMethod(int, groovy.lang.Closure)
        at demoscript.run(demoscript.groovy:3)

        Show
        Andy Clement added a comment - Recreated on the command line using what that launcher is trying to do: set CLASSPATH=bin;%CLASSPATH% N:\workspaces\groovy_dev_workspace\TestProject>java -Dgroovy.starter.conf="/N:/workspaces/groovy35/org.codehaus.groovy/conf/groovy-starter.conf" -Dgroovy.home="N:\workspaces\groovy35\org.codehaus.groovy" org.codehaus.groovy.tools.GroovyStarter --main groovy.ui.GroovyMain src\demoscript.groovy Caught: groovy.lang.MissingMethodException: No signature of method: MyHelper.someMethod() is applicable for argument types: (java.lang.Integer, demoscript$ run closure1) values: [4, demoscript$_run_closure1@cbd8dc] Possible solutions: someMethod(int, groovy.lang.Closure) at demoscript.run(demoscript.groovy:3)
        Hide
        Andrew Eisenberg added a comment -

        This is looking like a classloader problem.

        MyHelper is being loaded by a sun.misc.Launcher$AppClassLoader and demoscript is being loaded by a org.codehaus.groovy.tools.RootLoader. One of the checks to see if a method is callable with the current args is it sees if the types of the args at the call site can be assigned to the formal parameters where the method is called. Since the classloader hierarchy does not match, even though MyHelper.someMethod takes a closure and the argument passed in a sub-class of closure, the arg type is not assignable to the param type and the method cannot be called.

        I need to add the bin folder to the script's classpath and probably remove it from the eclipse launch classpath. There is probably an argument somewhere to do that.

        Show
        Andrew Eisenberg added a comment - This is looking like a classloader problem. MyHelper is being loaded by a sun.misc.Launcher$AppClassLoader and demoscript is being loaded by a org.codehaus.groovy.tools.RootLoader. One of the checks to see if a method is callable with the current args is it sees if the types of the args at the call site can be assigned to the formal parameters where the method is called. Since the classloader hierarchy does not match, even though MyHelper.someMethod takes a closure and the argument passed in a sub-class of closure, the arg type is not assignable to the param type and the method cannot be called. I need to add the bin folder to the script's classpath and probably remove it from the eclipse launch classpath. There is probably an argument somewhere to do that.
        Hide
        Andrew Eisenberg added a comment -

        Need to include the --classpath <bin_folders> argument in the launcher.

        Show
        Andrew Eisenberg added a comment - Need to include the --classpath <bin_folders> argument in the launcher.
        Hide
        Andrew Eisenberg added a comment -

        In the short term to get this working, open up your launch config and in the program arguments text box, add at the beginning:

        --classpath "src:bin"
        

        Replace src with all of your source folders (':' separated) and bin with all of your out folders (':' separated).

        Show
        Andrew Eisenberg added a comment - In the short term to get this working, open up your launch config and in the program arguments text box, add at the beginning: --classpath "src:bin" Replace src with all of your source folders (':' separated) and bin with all of your out folders (':' separated).
        Hide
        Andrew Eisenberg added a comment -

        Fix has been committed.

        Show
        Andrew Eisenberg added a comment - Fix has been committed.

          People

          • Assignee:
            Andrew Eisenberg
            Reporter:
            Andy Clement
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: