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 476925a157 GROOVY-8162: Update Groovysh to JLine3 (avoid hang for
simple cases)
476925a157 is described below
commit 476925a157152b5a028231f3a5e15f926de8ceaa
Author: Paul King <[email protected]>
AuthorDate: Mon Jul 28 22:10:09 2025 +1000
GROOVY-8162: Update Groovysh to JLine3 (avoid hang for simple cases)
---
subprojects/groovy-groovysh/build.gradle | 6 +++---
.../groovy/org/apache/groovy/groovysh/Main.groovy | 20 ++++++++++----------
.../groovy/groovysh/jline/GroovyCommands.groovy | 4 ++--
3 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/subprojects/groovy-groovysh/build.gradle
b/subprojects/groovy-groovysh/build.gradle
index 2d36e10a3c..4e423cbb04 100644
--- a/subprojects/groovy-groovysh/build.gradle
+++ b/subprojects/groovy-groovysh/build.gradle
@@ -33,15 +33,15 @@ dependencies {
implementation projects.groovyJson
implementation projects.groovyNio
testImplementation projects.groovyTest
- implementation 'net.java.dev.jna:jna:5.17.0'
+// implementation 'net.java.dev.jna:jna:5.17.0'
implementation "org.jline:jansi:${versions.jline}"
implementation "org.jline:jline-reader:${versions.jline}"
implementation "org.jline:jline-console:${versions.jline}"
- implementation "org.jline:jline-terminal-jni:${versions.jline}"
+// implementation "org.jline:jline-terminal-jni:${versions.jline}"
implementation("org.jline:jline-terminal-jansi:${versions.jline}") {
exclude(group: 'org.fusesource.jansi', module: 'jansi')
}
- implementation "org.jline:jline-terminal-jna:${versions.jline}"
+// implementation "org.jline:jline-terminal-jna:${versions.jline}"
implementation("org.jline:jline-terminal:${versions.jline}") {
// exclude(group: 'junit', module: 'junit')
}
diff --git
a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Main.groovy
b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Main.groovy
index 7059374a09..abeaf83ad7 100644
---
a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Main.groovy
+++
b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Main.groovy
@@ -57,6 +57,7 @@ import org.jline.widget.TailTipWidgets
import org.jline.widget.TailTipWidgets.TipType
import org.jline.widget.Widgets
+import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.util.function.Function
@@ -169,10 +170,12 @@ class Main {
}
-
- static String getUserStateDirectory() {
- def userHome = new File(System.getProperty('user.home'))
- new File(userHome, '.groovy').canonicalPath
+ static Path getUserStateDirectory() {
+ Path.of(System.getProperty('user.home'), '.groovy').tap { groovyHome ->
+ if (!groovyHome) {
+ Files.createDirectories(groovyHome)
+ }
+ }
}
static void main(String[] args) {
@@ -195,7 +198,7 @@ class Main {
def rootURL = Main.getResource('/nanorc')
Path root = ClasspathResourceUtil.getResourcePath(rootURL)
- ConfigurationPath configPath = new ConfigurationPath(root,
Path.of(userStateDirectory))
+ ConfigurationPath configPath = new ConfigurationPath(root,
userStateDirectory)
// ScriptEngine and command registries
GroovyEngine scriptEngine = new GroovyEngine()
@@ -270,10 +273,7 @@ class Main {
LineReader.BLINK_MATCHING_PAREN, 0) // if enabled cursor
remains in begin parenthesis (gitbash)
}
- // complete command registries
- consoleEngine.setLineReader(reader)
- builtins.setLineReader(reader)
- extra.setLineReader(reader)
+ [consoleEngine, builtins, extra]*.setLineReader(reader)
// widgets and console initialization
new TailTipWidgets(reader, systemRegistry::commandDescription, 5,
TipType.COMPLETER)
@@ -306,7 +306,7 @@ class Main {
s.endsWith(' \\') ? s[0..-3] : s
}.collect {s ->
// repl command parsing assumes no whitespace around
'='
- s.matches(/[a-zA-Z][a-zA-Z0-9_]* = \S.*/) ?
s.replaceFirst(' = ', '=') : s
+ s.matches(/[a-zA-Z][a-zA-Z0-9_]*\s*=\s*\/\S.*/) ?
s.replaceFirst(/\s*=\s*/, '=') : s
}.join('\n')
line = parser.getCommand(line).startsWith("/!") ?
line.replaceFirst("/!", "/! ") : line
if (line.startsWith(':')) {
diff --git
a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyCommands.groovy
b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyCommands.groovy
index 35b1a953b9..85ba419d79 100644
---
a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyCommands.groovy
+++
b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyCommands.groovy
@@ -188,7 +188,7 @@ class GroovyCommands extends JlineCommandRegistry
implements CommandRegistry {
checkArgCount(input, [0, 1, 2])
if (maybePrintHelp(input, '/save')) return
if (input.args().length == 0) {
- def out = new File(Main.userStateDirectory, 'groovysh.ser')
+ def out = Main.userStateDirectory.resolve('groovysh.ser')
out.text = engine.toJson(engine.sharedData)
return
}
@@ -216,7 +216,7 @@ class GroovyCommands extends JlineCommandRegistry
implements CommandRegistry {
checkArgCount(input, [0, 1, 2])
if (maybePrintHelp(input, '/load')) return
if (input.args().length == 0) {
- def ser = new File(Main.userStateDirectory, 'groovysh.ser')
+ def ser = Main.userStateDirectory.resolve('groovysh.ser')
def map = engine.sharedData.variables
map.clear()
map.putAll(engine.deserialize(ser.text).variables)