This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Created attachment 124888 [details] Groovy vs. Java Groovy scripts doesn't have "Play" icon even though they can be executed the same way as Java classes.
Wow, nice catch :]
Btw: In which cases do you think we should have "Play" icon shown? I mean, it's hard to figure out if the code is just a script or whether it's a full class. In Java there is a Play icon only if corresponding public static main(String[] args) method exists, but I'm not sure what should be the entry point in groovy. Maybe I can look at the code and say if there is "something" outside of the class declaration, show the "Play" icon? What do you think?
This is tricky question. According to documentation: http://groovy.codehaus.org/Running Script must be: "- Classes with a main method of course, - Classes extending GroovyTestCase are run with JUnit's test runner, - Classes implementing the Runnable interface are instanciated either with a constructor with String[] as argument, or with a no-args constructor, then their run() method is called." Typically, when you write simple shell scripts, it is enough to have at least one command outside type definition. e.g. #!/usr/bin/env groovy println("Hello world") Or something like this: class HelloWorld { def greet( name ){ "Hello ${name}!" } } def hw = new HelloWorld(); But, there is a clue in file: src/main/groovy/lang/GroovyShell.java#200 (http://dist.groovy.codehaus.org/distributions/groovy-src-2.0.5.zip) from Groovy source distribution. Here, you can see what Groovy does to determine whether script can be executed or not. try { // let's find a main method scriptClass.getMethod("main", new Class[]{String[].class}); // if that main method exist, invoke it return InvokerHelper.invokeMethod(scriptClass, "main", new Object[]{args}); } catch (NoSuchMethodException e) { // if it implements Runnable, try to instantiate it if (Runnable.class.isAssignableFrom(scriptClass)) { return runRunnable(scriptClass, args); } // if it's a JUnit 3.8.x test, run it with an appropriate runner if (isJUnit3Test(scriptClass)) { return runJUnit3Test(scriptClass); } // if it's a JUnit 3.8.x test suite, run it with an appropriate runner if (isJUnit3TestSuite(scriptClass)) { return runJUnit3TestSuite(scriptClass); } // if it's a JUnit 4.x test, run it with an appropriate runner if (isJUnit4Test(scriptClass)) { return runJUnit4Test(scriptClass); } for (Map.Entry<String, GroovyRunner> entry : GroovySystem.RUNNER_REGISTRY.entrySet()) { GroovyRunner runner = entry.getValue(); if (runner != null && runner.canRun(scriptClass, this.loader)) { return runner.run(scriptClass, this.loader); } } Cheers
Thanks a lot for a detailed explanation! I'll try to use GroovyShell for recognition..
Changing to enhancement, setting TM = TBD