Details

    • Type: Sub-task Sub-task
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.7.4, 1.8-beta-1
    • Fix Version/s: 1.7.4, 1.8-beta-1
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      1

      Description

      Test.groovy
      class B extends A {
           static main(args){}
      }
      
      class A {}
      

      fails with

      Caught: groovy.lang.GroovyRuntimeException: This script or class could not be run.
      It should either: 
      - have a main method, 
      - be a JUnit test, TestNG test or extend GroovyTestCase, 
      - or implement the Runnable interface.
      

        Issue Links

          Activity

          Hide
          Paul King added a comment -

          So you are talking about a user supplied annotation rather than an 'internal system' annotation, e.g. for the first example, the compiler could internally add a @GroovyMain onto class B since it was originally first in the file. Then it could find it later even if sorting changed the order. I guess an annotation is just one way to remember that fact. And I suspect this isn't what you meant but just thinking through all possibilities ...

          Show
          Paul King added a comment - So you are talking about a user supplied annotation rather than an 'internal system' annotation, e.g. for the first example, the compiler could internally add a @GroovyMain onto class B since it was originally first in the file. Then it could find it later even if sorting changed the order. I guess an annotation is just one way to remember that fact. And I suspect this isn't what you meant but just thinking through all possibilities ...
          Hide
          Roshan Dawrani added a comment - - edited

          A groovy defined annotation @GroovyMain that is not automatically added by groovy compiler, but explicitly by user. That way even if you write as below, you are fine

          class A {}
          @GroovyMain
          class B extends A {
             static void main(args){}
          }
          

          In the example here, @GroovyMain makes B as the class to be executed although the usual sorting says it should be A.

          Show
          Roshan Dawrani added a comment - - edited A groovy defined annotation @GroovyMain that is not automatically added by groovy compiler, but explicitly by user. That way even if you write as below, you are fine class A {} @GroovyMain class B extends A { static void main(args){} } In the example here, @GroovyMain makes B as the class to be executed although the usual sorting says it should be A.
          Hide
          blackdrag blackdrag added a comment -

          I think we should simply save the first class (beware scripts! they are included in that) and save it as being first. Then we should add a method that allows anything using hte CompilationUnit to get this first class. This way we are independend of the sorting output and can say the output of the classes given by CompilationUnit is undefined, and this method should instead be used.

          Show
          blackdrag blackdrag added a comment - I think we should simply save the first class (beware scripts! they are included in that) and save it as being first. Then we should add a method that allows anything using hte CompilationUnit to get this first class. This way we are independend of the sorting output and can say the output of the classes given by CompilationUnit is undefined, and this method should instead be used.
          Hide
          Roshan Dawrani added a comment -

          Attaching a patch for review. Fixes the issue by executing the first class in the file even in case of inheritance.

          Show
          Roshan Dawrani added a comment - Attaching a patch for review. Fixes the issue by executing the first class in the file even in case of inheritance.
          Hide
          Roshan Dawrani added a comment -

          Fixed.

          Show
          Roshan Dawrani added a comment - Fixed.

            People

            • Assignee:
              Roshan Dawrani
              Reporter:
              Roshan Dawrani
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: