Skip to content

Commit 8b5e1b9

Browse files
committed
8350749: Upgrade JLine to 3.29.0
Reviewed-by: liach
1 parent c5aaa76 commit 8b5e1b9

18 files changed

+174
-50
lines changed

src/jdk.internal.le/share/classes/jdk/internal/org/jline/reader/LineReader.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import java.io.File;
1212
import java.io.InputStream;
13+
import java.nio.file.Path;
1314
import java.util.Collection;
1415
import java.util.Map;
1516
import java.util.function.IntConsumer;
@@ -766,7 +767,11 @@ String readLine(String prompt, String rightPrompt, MaskingCallback maskingCallba
766767

767768
void addCommandsInBuffer(Collection<String> commands);
768769

769-
void editAndAddInBuffer(File file) throws Exception;
770+
default void editAndAddInBuffer(File file) throws Exception {
771+
editAndAddInBuffer(file != null ? file.toPath() : null);
772+
}
773+
774+
void editAndAddInBuffer(Path file) throws Exception;
770775

771776
String getLastBinding();
772777

src/jdk.internal.le/share/classes/jdk/internal/org/jline/reader/UserInterruptException.java

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public class UserInterruptException extends RuntimeException {
1919

2020
private final String partialLine;
2121

22+
public UserInterruptException(Throwable cause) {
23+
super(cause);
24+
this.partialLine = null;
25+
}
26+
2227
public UserInterruptException(String partialLine) {
2328
this.partialLine = partialLine;
2429
}

src/jdk.internal.le/share/classes/jdk/internal/org/jline/reader/impl/DefaultHighlighter.java

+8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public AttributedString highlight(LineReader reader, String buffer) {
3838
int underlineEnd = -1;
3939
int negativeStart = -1;
4040
int negativeEnd = -1;
41+
boolean first = true;
4142
String search = reader.getSearchTerm();
4243
if (search != null && search.length() > 0) {
4344
underlineStart = buffer.indexOf(search);
@@ -65,6 +66,7 @@ public AttributedString highlight(LineReader reader, String buffer) {
6566
}
6667

6768
AttributedStringBuilder sb = new AttributedStringBuilder();
69+
commandStyle(reader, sb, true);
6870
for (int i = 0; i < buffer.length(); i++) {
6971
if (i == underlineStart) {
7072
sb.style(AttributedStyle::underline);
@@ -77,6 +79,10 @@ public AttributedString highlight(LineReader reader, String buffer) {
7779
}
7880

7981
char c = buffer.charAt(i);
82+
if (first && Character.isSpaceChar(c)) {
83+
first = false;
84+
commandStyle(reader, sb, false);
85+
}
8086
if (c == '\t' || c == '\n') {
8187
sb.append(c);
8288
} else if (c < 32) {
@@ -105,4 +111,6 @@ public AttributedString highlight(LineReader reader, String buffer) {
105111
}
106112
return sb.toAttributedString();
107113
}
114+
115+
protected void commandStyle(LineReader reader, AttributedStringBuilder sb, boolean enable) {}
108116
}

src/jdk.internal.le/share/classes/jdk/internal/org/jline/reader/impl/LineReaderImpl.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import java.io.BufferedReader;
1212
import java.io.File;
13-
import java.io.FileReader;
1413
import java.io.FileWriter;
1514
import java.io.Flushable;
1615
import java.io.IOError;
@@ -1131,16 +1130,16 @@ public void addCommandsInBuffer(Collection<String> commands) {
11311130
}
11321131

11331132
@Override
1134-
public void editAndAddInBuffer(File file) throws Exception {
1133+
public void editAndAddInBuffer(Path file) throws Exception {
11351134
if (isSet(Option.BRACKETED_PASTE)) {
11361135
terminal.writer().write(BRACKETED_PASTE_OFF);
11371136
}
1138-
Constructor<?> ctor = Class.forName("org.jline.builtins.Nano").getConstructor(Terminal.class, File.class);
1139-
Editor editor = (Editor) ctor.newInstance(terminal, new File(file.getParent()));
1137+
Constructor<?> ctor = Class.forName("org.jline.builtins.Nano").getConstructor(Terminal.class, Path.class);
1138+
Editor editor = (Editor) ctor.newInstance(terminal, file.getParent());
11401139
editor.setRestricted(true);
1141-
editor.open(Collections.singletonList(file.getName()));
1140+
editor.open(Collections.singletonList(file.getFileName().toString()));
11421141
editor.run();
1143-
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
1142+
try (BufferedReader br = Files.newBufferedReader(file)) {
11441143
String line;
11451144
commandsBuffer.clear();
11461145
while ((line = br.readLine()) != null) {
@@ -3529,7 +3528,7 @@ protected boolean viPutAfter() {
35293528
buf.move(1);
35303529
putString(yankBuffer);
35313530
buf.move(-yankBuffer.length());
3532-
} else if (yankBuffer.length() != 0) {
3531+
} else if (!yankBuffer.isEmpty()) {
35333532
if (buf.cursor() < buf.length()) {
35343533
buf.move(1);
35353534
}
@@ -3547,7 +3546,7 @@ protected boolean viPutBefore() {
35473546
;
35483547
putString(yankBuffer);
35493548
buf.move(-yankBuffer.length());
3550-
} else if (yankBuffer.length() != 0) {
3549+
} else if (!yankBuffer.isEmpty()) {
35513550
if (buf.cursor() > 0) {
35523551
buf.move(-1);
35533552
}

src/jdk.internal.le/share/classes/jdk/internal/org/jline/reader/impl/completer/SystemCompleter.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
package jdk.internal.org.jline.reader.impl.completer;
1010

1111
import java.util.*;
12+
import java.util.function.Function;
13+
import java.util.stream.Collectors;
1214

1315
import jdk.internal.org.jline.reader.Candidate;
1416
import jdk.internal.org.jline.reader.Completer;
@@ -24,6 +26,7 @@
2426
public class SystemCompleter implements Completer {
2527
private Map<String, List<Completer>> completers = new HashMap<>();
2628
private Map<String, String> aliasCommand = new HashMap<>();
29+
private Map<String, String> descriptions = new HashMap<>();
2730
private StringsCompleter commands;
2831
private boolean compiled = false;
2932

@@ -124,6 +127,10 @@ private Map<String, String> getAliases() {
124127
}
125128

126129
public void compile() {
130+
compile(s -> new Candidate(AttributedString.stripAnsi(s), s, null, null, null, null, true));
131+
}
132+
133+
public void compile(Function<String, Candidate> candidateBuilder) {
127134
if (compiled) {
128135
return;
129136
}
@@ -139,7 +146,7 @@ public void compile() {
139146
completers = compiledCompleters;
140147
Set<String> cmds = new HashSet<>(completers.keySet());
141148
cmds.addAll(aliasCommand.keySet());
142-
commands = new StringsCompleter(cmds);
149+
commands = new StringsCompleter(cmds.stream().map(candidateBuilder).collect(Collectors.toList()));
143150
compiled = true;
144151
}
145152

src/jdk.internal.le/share/classes/jdk/internal/org/jline/reader/impl/history/DefaultHistory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public void purge() throws IOException {
200200
public void write(Path file, boolean incremental) throws IOException {
201201
Path path = file != null ? file : getPath();
202202
if (path != null && Files.exists(path)) {
203-
path.toFile().delete();
203+
Files.deleteIfExists(path);
204204
}
205205
internalWrite(path, incremental ? getLastLoaded(path) : 0);
206206
}

src/jdk.internal.le/share/classes/jdk/internal/org/jline/terminal/TerminalBuilder.java

+44
Original file line numberDiff line numberDiff line change
@@ -209,41 +209,85 @@ public TerminalBuilder systemOutput(SystemOutput systemOutput) {
209209
return this;
210210
}
211211

212+
/**
213+
* Forces the usage of the give terminal provider.
214+
*
215+
* @param provider The {@link TerminalProvider}'s name to use when creating the Terminal.
216+
* @return The builder.
217+
*/
212218
public TerminalBuilder provider(String provider) {
213219
this.provider = provider;
214220
return this;
215221
}
216222

223+
/**
224+
* Sets the list of providers to try when creating the terminal.
225+
* If not specified, the system property {@link #PROP_PROVIDERS} will be used if set.
226+
* Else, the value {@link #PROP_PROVIDERS_DEFAULT} will be used.
227+
*
228+
* @param providers The list of {@link TerminalProvider}'s names to check when creating the Terminal.
229+
* @return The builder.
230+
*/
217231
public TerminalBuilder providers(String providers) {
218232
this.providers = providers;
219233
return this;
220234
}
221235

236+
/**
237+
* Enables or disables the {@link #PROP_PROVIDER_JNA}/{@code jna} terminal provider.
238+
* If not specified, the system property {@link #PROP_JNA} will be used if set.
239+
* If not specified, the provider will be checked.
240+
*/
222241
public TerminalBuilder jna(boolean jna) {
223242
this.jna = jna;
224243
return this;
225244
}
226245

246+
/**
247+
* Enables or disables the {@link #PROP_PROVIDER_JANSI}/{@code jansi} terminal provider.
248+
* If not specified, the system property {@link #PROP_JANSI} will be used if set.
249+
* If not specified, the provider will be checked.
250+
*/
227251
public TerminalBuilder jansi(boolean jansi) {
228252
this.jansi = jansi;
229253
return this;
230254
}
231255

256+
/**
257+
* Enables or disables the {@link #PROP_PROVIDER_JNI}/{@code jni} terminal provider.
258+
* If not specified, the system property {@link #PROP_JNI} will be used if set.
259+
* If not specified, the provider will be checked.
260+
*/
232261
public TerminalBuilder jni(boolean jni) {
233262
this.jni = jni;
234263
return this;
235264
}
236265

266+
/**
267+
* Enables or disables the {@link #PROP_PROVIDER_EXEC}/{@code exec} terminal provider.
268+
* If not specified, the system property {@link #PROP_EXEC} will be used if set.
269+
* If not specified, the provider will be checked.
270+
*/
237271
public TerminalBuilder exec(boolean exec) {
238272
this.exec = exec;
239273
return this;
240274
}
241275

276+
/**
277+
* Enables or disables the {@link #PROP_PROVIDER_FFM}/{@code ffm} terminal provider.
278+
* If not specified, the system property {@link #PROP_FFM} will be used if set.
279+
* If not specified, the provider will be checked.
280+
*/
242281
public TerminalBuilder ffm(boolean ffm) {
243282
this.ffm = ffm;
244283
return this;
245284
}
246285

286+
/**
287+
* Enables or disables the {@link #PROP_PROVIDER_DUMB}/{@code dumb} terminal provider.
288+
* If not specified, the system property {@link #PROP_DUMB} will be used if set.
289+
* If not specified, the provider will be checked.
290+
*/
247291
public TerminalBuilder dumb(boolean dumb) {
248292
this.dumb = dumb;
249293
return this;

src/jdk.internal.le/share/classes/jdk/internal/org/jline/terminal/impl/AbstractPosixTerminal.java

+9
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,13 @@ public TerminalProvider getProvider() {
9494
public SystemStream getSystemStream() {
9595
return getPty().getSystemStream();
9696
}
97+
98+
@Override
99+
public String toString() {
100+
return getKind() + "[" + "name='"
101+
+ name + '\'' + ", pty='"
102+
+ pty + '\'' + ", type='"
103+
+ type + '\'' + ", size='"
104+
+ getSize() + '\'' + ']';
105+
}
97106
}

src/jdk.internal.le/share/classes/jdk/internal/org/jline/terminal/impl/AbstractTerminal.java

+8
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,12 @@ public boolean paused() {
287287
public ColorPalette getPalette() {
288288
return palette;
289289
}
290+
291+
@Override
292+
public String toString() {
293+
return getKind() + "[" + "name='"
294+
+ name + '\'' + ", type='"
295+
+ type + '\'' + ", size='"
296+
+ getSize() + '\'' + ']';
297+
}
290298
}

0 commit comments

Comments
 (0)