You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2025/08/05 11:29:23 UTC
(groovy) branch master updated (01c368398f -> 23af6c6270)
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
from 01c368398f GROOVY-8162: Update Groovysh to JLine3 (additional /slurp details)
new e319e6acbc GROOVY-8162: Update Groovysh to JLine3 (document exception handling)
new b5622c64ab GROOVY-8162: Update Groovysh to JLine3 (fix /!ls handling regression)
new 23af6c6270 GROOVY-8162: Update Groovysh to JLine3 (clarify duplicate method handling)
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../apache/groovy/groovysh/jline/GroovyEngine.java | 15 ++++++++++----
.../groovysh/jline/GroovySystemRegistry.groovy | 2 +-
.../src/spec/doc/assets/img/repl_exceptions.png | Bin 0 -> 437859 bytes
.../groovy-groovysh/src/spec/doc/groovysh.adoc | 22 +++++++++++++++++----
4 files changed, 30 insertions(+), 9 deletions(-)
create mode 100644 subprojects/groovy-groovysh/src/spec/doc/assets/img/repl_exceptions.png
(groovy) 03/03: GROOVY-8162: Update Groovysh to JLine3 (clarify duplicate method handling)
Posted by pa...@apache.org.
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
commit 23af6c6270c9794550e58a74be6e0113a73ffa9c
Author: Paul King <pa...@asert.com.au>
AuthorDate: Tue Aug 5 21:29:13 2025 +1000
GROOVY-8162: Update Groovysh to JLine3 (clarify duplicate method handling)
---
.../org/apache/groovy/groovysh/jline/GroovyEngine.java | 15 +++++++++++----
subprojects/groovy-groovysh/src/spec/doc/groovysh.adoc | 14 ++++++++++----
2 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyEngine.java b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyEngine.java
index 91714c7917..3338b020c2 100644
--- a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyEngine.java
+++ b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyEngine.java
@@ -164,7 +164,7 @@ public class GroovyEngine implements ScriptEngine {
public GroovyEngine() {
sharedData = new Binding();
// for debugging
-// sharedData.setVariable("engine", this);
+ sharedData.setVariable("engine", this);
classLoader = new EngineClassLoader();
shell = new GroovyShell(classLoader, sharedData);
for (String s : DEFAULT_IMPORTS) {
@@ -577,7 +577,12 @@ public class GroovyEngine implements ScriptEngine {
methodNames.add(m.group(3));
if (isInterpreterMode()) {
String code = removeTrailingSemi(m.group(0));
- methods.put(m.group(2), addSnippet(SnippetType.METHOD, code));
+ Integer existing = methods.get(m.group(2));
+ if (existing != null) {
+ snippets.get(existing).setSnippet(code);
+ } else {
+ methods.put(m.group(2), addSnippet(SnippetType.METHOD, code));
+ }
} else {
String body = m.group(5).substring(1);
put(m.group(3), execute("{" + m.group(4) + "->" + body));
@@ -654,8 +659,10 @@ public class GroovyEngine implements ScriptEngine {
String k = it.next();
if (k.equals(name) || k.startsWith(name + "(")) {
Integer gone = methods.get(k);
- if (gone != null) snippets.set(gone, null);
- it.remove();
+ if (gone != null) {
+ snippets.set(gone, null);
+ it.remove();
+ }
}
}
}
diff --git a/subprojects/groovy-groovysh/src/spec/doc/groovysh.adoc b/subprojects/groovy-groovysh/src/spec/doc/groovysh.adoc
index ba2dd49304..e094a7c994 100644
--- a/subprojects/groovy-groovysh/src/spec/doc/groovysh.adoc
+++ b/subprojects/groovy-groovysh/src/spec/doc/groovysh.adoc
@@ -248,7 +248,7 @@ This behavior can be changed by activating <<GroovyShell-InterpreterMode,interpr
Methods can be defined in the shell, and will be saved for later use.
-Defining a function is easy:
+Defining a method is easy:
[source,jshell]
----------------------------------
@@ -265,9 +265,15 @@ groovy> hello "Jason"
Hello Jason
--------------
-Internally the shell creates a closure to encapsulate the function and
-then binds the closure to a variable. So variables and functions share
-the same namespace.
+If a method definition has the same signature as an existing definition,
+the old definition will be replaced with the new one.
+
+When in _interpreterMode_, methods are remembered and given as extra statements
+when executing the next input.
+
+When not in _interpreterMode_, the shell internally creates a closure to encapsulate
+the method and stores it in the shared variables.
+In this case, variables and methods share the same namespace.
[[GroovyShell-Exceptions]]
==== Exceptions
(groovy) 02/03: GROOVY-8162: Update Groovysh to JLine3 (fix /!ls handling regression)
Posted by pa...@apache.org.
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
commit b5622c64ab49f0e356c33fee51144bc42e2fe8ba
Author: Paul King <pa...@asert.com.au>
AuthorDate: Tue Aug 5 21:28:49 2025 +1000
GROOVY-8162: Update Groovysh to JLine3 (fix /!ls handling regression)
---
.../groovy/org/apache/groovy/groovysh/jline/GroovySystemRegistry.groovy | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovySystemRegistry.groovy b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovySystemRegistry.groovy
index 8bfb7277d2..e3b0350823 100644
--- a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovySystemRegistry.groovy
+++ b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovySystemRegistry.groovy
@@ -36,6 +36,7 @@ class GroovySystemRegistry extends SystemRegistryImpl {
// workaround for: https://github.com/jline/jline3/issues/1361
@Override
Object execute(String line) throws Exception {
+ line = line.startsWith("/!") ? line.replaceFirst("/!", "/! ") : line
def m = line =~ /([a-zA-Z][a-zA-Z0-9_]*)(\s*)=(\s*)(\/?)(\S.*)/
def target = null
if (m.matches()) {
@@ -43,7 +44,6 @@ class GroovySystemRegistry extends SystemRegistryImpl {
if (slash) {
target = variable
line = slash + rhs
- line = line.startsWith("/!") ? line.replaceFirst("/!", "/! ") : line
} else {
space1 = space1.size() == 0 ? ' ' : space1
space2 = space2.size() == 0 ? ' ' : space2
(groovy) 01/03: GROOVY-8162: Update Groovysh to JLine3 (document exception handling)
Posted by pa...@apache.org.
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
commit e319e6acbc6457e798651b65d265655851e22214
Author: Paul King <pa...@asert.com.au>
AuthorDate: Tue Aug 5 21:23:58 2025 +1000
GROOVY-8162: Update Groovysh to JLine3 (document exception handling)
---
.../src/spec/doc/assets/img/repl_exceptions.png | Bin 0 -> 437859 bytes
subprojects/groovy-groovysh/src/spec/doc/groovysh.adoc | 8 ++++++++
2 files changed, 8 insertions(+)
diff --git a/subprojects/groovy-groovysh/src/spec/doc/assets/img/repl_exceptions.png b/subprojects/groovy-groovysh/src/spec/doc/assets/img/repl_exceptions.png
new file mode 100644
index 0000000000..53e9350f9b
Binary files /dev/null and b/subprojects/groovy-groovysh/src/spec/doc/assets/img/repl_exceptions.png differ
diff --git a/subprojects/groovy-groovysh/src/spec/doc/groovysh.adoc b/subprojects/groovy-groovysh/src/spec/doc/groovysh.adoc
index 8bf02ce850..ba2dd49304 100644
--- a/subprojects/groovy-groovysh/src/spec/doc/groovysh.adoc
+++ b/subprojects/groovy-groovysh/src/spec/doc/groovysh.adoc
@@ -269,6 +269,14 @@ Internally the shell creates a closure to encapsulate the function and
then binds the closure to a variable. So variables and functions share
the same namespace.
+[[GroovyShell-Exceptions]]
+==== Exceptions
+
+If an exception is thrown, the shell will print the exception message
+and set a special `exception` shared variable.
+
+image:assets/img/repl_exceptions.png[Exception, width=80%]
+
[[GroovyShell-Commands]]
=== Commands