groovy

cleanup strategy of choosing the class to execute when a file contains multiple classes

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0-JSR-5
  • Fix Version/s: 1.7.6, 1.8.0
  • Component/s: None
  • Labels:
    None
  • Number of attachments :
    1

Description

> Doit.groovy
> ----
> class Helper {...}
> class Doit { ... }
> ----
>
> Should it really make a difference whether Helper is
> declared before or after Doit?

Yes, I think that is buggy. There is also another problem if additional
to these two classes is a script iside... you would get an error saying
something about defining two classes of the same name. Anyway... can you
fill a jira issue and assign it to me? I will fix that as soon as I have
fixed my classloader problem here.

bye blackdrag

Issue Links

Activity

Hide
Olivier Mengué added a comment -

Here is a test case : the attached is both a valid Java source and a valid Groovy source.
However, Groovy 1.5.6 is not able to run it.

The strategy to implement could be:

  • the default scope for the class which has the script name is 'public' (this is different from Java where it has the 'package' scope)
  • the default scope for any other class is private (not sure about the exact scope, but it should be the same as an inner class in Java)
  • run the class named after the script
Show
Olivier Mengué added a comment - Here is a test case : the attached is both a valid Java source and a valid Groovy source. However, Groovy 1.5.6 is not able to run it. The strategy to implement could be:
  • the default scope for the class which has the script name is 'public' (this is different from Java where it has the 'package' scope)
  • the default scope for any other class is private (not sure about the exact scope, but it should be the same as an inner class in Java)
  • run the class named after the script
Hide
Olivier Mengué added a comment -
The 1.5.6 output of MultipleClasses.groovy
$ groovy MultipleClasses.groovy
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.
Show
Olivier Mengué added a comment -
The 1.5.6 output of MultipleClasses.groovy
$ groovy MultipleClasses.groovy
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.
Hide
Olivier Mengué added a comment -
MultipleClasses.java/MultipleClasses.groovy
class Helper {
    public static void run() {
        System.out.println("Hello, world!");
    }
}

class MultipleClasses {
    public static void main(String[] args) {
        Helper.run();
    }
}
Show
Olivier Mengué added a comment -
MultipleClasses.java/MultipleClasses.groovy
class Helper {
    public static void run() {
        System.out.println("Hello, world!");
    }
}

class MultipleClasses {
    public static void main(String[] args) {
        Helper.run();
    }
}
Hide
Olivier Mengué added a comment -

GROOVY-763 (implement java parts) should depend on this issue and be reopened.

Show
Olivier Mengué added a comment - GROOVY-763 (implement java parts) should depend on this issue and be reopened.
Hide
Olivier Mengué added a comment -

Workaround: put the class to run at the top. It appears that Groovy tries to run only the first class defined.

Show
Olivier Mengué added a comment - Workaround: put the class to run at the top. It appears that Groovy tries to run only the first class defined.
Hide
blackdrag blackdrag added a comment -

this issue is an ordering issue, not a naming or visibility issue as you found out by yourself. GROOVY-763 was a collection task I used to get a better overview of missing parts, no need to reopen that one.

Show
blackdrag blackdrag added a comment - this issue is an ordering issue, not a naming or visibility issue as you found out by yourself. GROOVY-763 was a collection task I used to get a better overview of missing parts, no need to reopen that one.
Hide
Paul King added a comment -

After GROOVY-4624 has been resolved, it isn't clear to me what problems remain for this issue.

Show
Paul King added a comment - After GROOVY-4624 has been resolved, it isn't clear to me what problems remain for this issue.

People

Vote (2)
Watch (4)

Dates

  • Created:
    Updated:
    Resolved: