jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • groovy
  • GROOVY-3644

GroovyConsole should be able to handle multiple classes

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Improvement Improvement
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: 1.7-beta-1
  • Fix Version/s: None
  • Component/s: Groovy Console
  • Labels:
    None
  • Environment:
    Mac OS 10.5.7

Description

I'd like to be able to define multiple classes in GroovyConsole. When I push the "execute" button, GroovyConsole could either look for a runnable class or ask me for a hint. Here is an example:

class Bar {}

class Foo {
  static main(args) {
    println "hi"
  }
}

I can't run this code because GroovyConsole only looks at Bar and determines that it can't be run. I can solve the problem by defining Foo before Bar. However, if Foo inherits from Bar, this trick no longer works, and there is no way to run Foo.

Issue Links

is related to

Bug - A problem which impairs or prevents the functions of the product. GROOVY-1328 cleanup strategy of choosing the class to execute when a file contains multiple classes

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Paul King added a comment - 26/Jul/09 5:09 AM

For this case the workaround is simple. Add the following line:

Foo.main()

Obviously some smarts which avoided the workaround altogether might also be nice but I would give Minor priority.

There is also a related issue (not console specific) from a while back. I'll hunt it down and link it.

Show
Paul King added a comment - 26/Jul/09 5:09 AM For this case the workaround is simple. Add the following line:
Foo.main()
Obviously some smarts which avoided the workaround altogether might also be nice but I would give Minor priority. There is also a related issue (not console specific) from a while back. I'll hunt it down and link it.
Hide
Permalink
Peter Niederwieser added a comment - 26/Jul/09 7:03 AM

You are right, this one is easy. My actual concern was to run a test class that inherits from another test class. If it had not been late in the night, I would have probably tried JUnitCore.runClasses().

Show
Peter Niederwieser added a comment - 26/Jul/09 7:03 AM You are right, this one is easy. My actual concern was to run a test class that inherits from another test class. If it had not been late in the night, I would have probably tried JUnitCore.runClasses().
Hide
Permalink
Hamlet D'Arcy added a comment - 09/Dec/10 2:18 PM

OK, the issue is the GroovyClassLoader. It eventually gets invoked with "parseClass(GroovyCodeSource) : Class"

Added logic in GroovyClassLoader to look for a class with a "main" method would be inappropriate because GCL is much more general than that. However, we could add this method to GCL:

GroovyClassLoader#parseClasses(GroovyCodeSource) : List<Class>

Then GroovyShell (and GroovyConsole) would have all the classes and be able to make a decision about what to do when the primary class is not of type Script.

Show
Hamlet D'Arcy added a comment - 09/Dec/10 2:18 PM OK, the issue is the GroovyClassLoader. It eventually gets invoked with "parseClass(GroovyCodeSource) : Class" Added logic in GroovyClassLoader to look for a class with a "main" method would be inappropriate because GCL is much more general than that. However, we could add this method to GCL:
GroovyClassLoader#parseClasses(GroovyCodeSource) : List<Class>
Then GroovyShell (and GroovyConsole) would have all the classes and be able to make a decision about what to do when the primary class is not of type Script.

People

  • Assignee:
    Hamlet D'Arcy
    Reporter:
    Peter Niederwieser
Vote (0)
Watch (3)

Dates

  • Created:
    25/Jul/09 5:25 PM
    Updated:
    09/Dec/10 2:18 PM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.