This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new f72f4b8  GROOVY-9468: Support running as Java code in the Groovy 
console (refinements for better error messages) (closes #1194)
f72f4b8 is described below

commit f72f4b896f846e976699463688dcf0cba5eeb6f9
Author: Paul King <[email protected]>
AuthorDate: Mon Mar 16 09:59:49 2020 +1000

    GROOVY-9468: Support running as Java code in the Groovy console 
(refinements for better error messages) (closes #1194)
---
 src/main/java/org/apache/groovy/util/JavaShell.java           |  3 +--
 .../org/apache/groovy/util/JavaShellCompilationException.java | 11 +++++++++++
 .../src/main/groovy/groovy/console/ui/Console.groovy          |  2 ++
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/groovy/util/JavaShell.java 
b/src/main/java/org/apache/groovy/util/JavaShell.java
index c797cb7..bf79d07 100644
--- a/src/main/java/org/apache/groovy/util/JavaShell.java
+++ b/src/main/java/org/apache/groovy/util/JavaShell.java
@@ -18,7 +18,6 @@
  */
 package org.apache.groovy.util;
 
-import groovy.lang.GroovyRuntimeException;
 import org.apache.groovy.io.StringBuilderWriter;
 import org.apache.groovy.lang.annotation.Incubating;
 import org.codehaus.groovy.control.CompilerConfiguration;
@@ -150,7 +149,7 @@ public class JavaShell {
             task.call();
 
             if (bjfm.isEmpty()) {
-                throw new GroovyRuntimeException(out.toString());
+                throw new JavaShellCompilationException(out.toString());
             }
 
             final Map<String, byte[]> classMap = bjfm.getClassMap();
diff --git 
a/src/main/java/org/apache/groovy/util/JavaShellCompilationException.java 
b/src/main/java/org/apache/groovy/util/JavaShellCompilationException.java
new file mode 100644
index 0000000..7d23a9e
--- /dev/null
+++ b/src/main/java/org/apache/groovy/util/JavaShellCompilationException.java
@@ -0,0 +1,11 @@
+package org.apache.groovy.util;
+
+import groovy.lang.GroovyRuntimeException;
+
+public class JavaShellCompilationException extends GroovyRuntimeException {
+    private static final long serialVersionUID = 8048143189569571714L;
+
+    public JavaShellCompilationException(String message) {
+        super(message);
+    }
+}
diff --git 
a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy 
b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
index 37ec862..500ba50 100644
--- 
a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
+++ 
b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
@@ -1193,6 +1193,8 @@ class Console implements CaretListener, 
HyperlinkListener, ComponentListener, Fo
             if (optionalPrimaryClassName.isPresent()) {
                 def js = new 
JavaShell(Thread.currentThread().contextClassLoader)
                 js.run(optionalPrimaryClassName.get(), src)
+            } else {
+                System.err.println('Initial parsing successful but no public 
class found. Compile/run will not proceed.')
             }
             return null
         }

Reply via email to