Skip to content

Commit 4cc254e

Browse files
authored
[MNG-8550] Update JLine3 to 3.29.0 (#2074)
Update to 3.29.0 --- https://issues.apache.org/jira/browse/MNG-8550
1 parent 4dfffae commit 4cc254e

File tree

4 files changed

+115
-126
lines changed

4 files changed

+115
-126
lines changed

impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,27 @@ public int invoke(InvokerRequest invokerRequest) throws InvokerException {
139139
}
140140

141141
protected int doInvoke(C context) throws Exception {
142-
pushCoreProperties(context);
143-
pushUserProperties(context);
144-
configureLogging(context);
145-
createTerminal(context);
146-
activateLogging(context);
147-
helpOrVersionAndMayExit(context);
148-
preCommands(context);
149-
container(context);
150-
postContainer(context);
151-
pushUserProperties(context); // after PropertyContributor SPI
152-
lookup(context);
153-
init(context);
154-
postCommands(context);
155-
settings(context);
156-
return execute(context);
142+
try {
143+
pushCoreProperties(context);
144+
pushUserProperties(context);
145+
configureLogging(context);
146+
createTerminal(context);
147+
activateLogging(context);
148+
helpOrVersionAndMayExit(context);
149+
preCommands(context);
150+
container(context);
151+
postContainer(context);
152+
pushUserProperties(context); // after PropertyContributor SPI
153+
lookup(context);
154+
init(context);
155+
postCommands(context);
156+
settings(context);
157+
return execute(context);
158+
} finally {
159+
if (context.terminal != null) {
160+
context.terminal.writer().flush();
161+
}
162+
}
157163
}
158164

159165
protected InvokerException handleException(C context, Exception e) throws InvokerException {

impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnenc/EncryptInvoker.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ protected int execute(EncryptContext context) throws Exception {
107107
context.logger.error(e.getMessage());
108108
}
109109
return ERROR;
110-
} finally {
111-
context.terminal.writer().flush();
112110
}
113111
}
114112

impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnenc/goals/Init.java

Lines changed: 93 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
*/
1919
package org.apache.maven.cling.invoker.mvnenc.goals;
2020

21-
import java.io.IOError;
22-
import java.io.InterruptedIOException;
23-
import java.util.HashMap;
2421
import java.util.List;
2522
import java.util.Map;
2623
import java.util.Objects;
@@ -42,7 +39,6 @@
4239
import org.jline.consoleui.prompt.PromptResultItemIF;
4340
import org.jline.consoleui.prompt.builder.ListPromptBuilder;
4441
import org.jline.consoleui.prompt.builder.PromptBuilder;
45-
import org.jline.reader.UserInterruptException;
4642
import org.jline.utils.Colors;
4743
import org.jline.utils.OSUtils;
4844

@@ -94,122 +90,111 @@ public int doExecute(EncryptContext context) throws Exception {
9490
config.setDefaultDispatcher(null);
9591
config.getConfigurations().clear();
9692

97-
try (ConsolePrompt prompt = new ConsolePrompt(context.reader, context.terminal, promptConfig)) {
98-
Map<String, PromptResultItemIF> dispatcherResult = new HashMap<>();
99-
Map<String, PromptResultItemIF> dispatcherConfigResult = new HashMap<>();
100-
Map<String, PromptResultItemIF> confirmChoice = new HashMap<>();
93+
Map<String, PromptResultItemIF> dispatcherResult;
94+
Map<String, PromptResultItemIF> dispatcherConfigResult;
95+
Map<String, PromptResultItemIF> confirmChoice;
96+
ConsolePrompt prompt = new ConsolePrompt(context.reader, context.terminal, promptConfig);
10197

102-
prompt.prompt(
103-
context.header, dispatcherPrompt(prompt.getPromptBuilder()).build(), dispatcherResult);
104-
if (dispatcherResult.isEmpty()) {
105-
throw new InterruptedException();
106-
}
107-
if (NONE.equals(dispatcherResult.get("defaultDispatcher").getResult())) {
108-
context.terminal
109-
.writer()
110-
.println(messageBuilderFactory
111-
.builder()
112-
.warning(
113-
"Maven4 SecDispatcher disabled; Maven3 fallback may still work, use `mvnenc diag` to check")
114-
.build());
115-
} else {
116-
config.setDefaultDispatcher(
117-
dispatcherResult.get("defaultDispatcher").getResult());
98+
dispatcherResult = prompt.prompt(
99+
context.header, dispatcherPrompt(prompt.getPromptBuilder()).build());
100+
if (dispatcherResult.isEmpty()) {
101+
throw new InterruptedException();
102+
}
103+
if (NONE.equals(dispatcherResult.get("defaultDispatcher").getResult())) {
104+
context.terminal
105+
.writer()
106+
.println(messageBuilderFactory
107+
.builder()
108+
.warning(
109+
"Maven4 SecDispatcher disabled; Maven3 fallback may still work, use `mvnenc diag` to check")
110+
.build());
111+
} else {
112+
config.setDefaultDispatcher(
113+
dispatcherResult.get("defaultDispatcher").getResult());
118114

119-
DispatcherMeta meta = secDispatcher.availableDispatchers().stream()
120-
.filter(d -> Objects.equals(config.getDefaultDispatcher(), d.name()))
121-
.findFirst()
122-
.orElseThrow();
123-
if (!meta.fields().isEmpty()) {
124-
prompt.prompt(
125-
context.header,
126-
configureDispatcher(context, meta, prompt.getPromptBuilder())
127-
.build(),
128-
dispatcherConfigResult);
129-
if (dispatcherConfigResult.isEmpty()) {
130-
throw new InterruptedException();
131-
}
115+
DispatcherMeta meta = secDispatcher.availableDispatchers().stream()
116+
.filter(d -> Objects.equals(config.getDefaultDispatcher(), d.name()))
117+
.findFirst()
118+
.orElseThrow();
119+
if (!meta.fields().isEmpty()) {
120+
dispatcherConfigResult = prompt.prompt(
121+
context.header,
122+
configureDispatcher(context, meta, prompt.getPromptBuilder())
123+
.build());
124+
if (dispatcherConfigResult.isEmpty()) {
125+
throw new InterruptedException();
126+
}
132127

133-
List<Map.Entry<String, PromptResultItemIF>> editables = dispatcherConfigResult.entrySet().stream()
134-
.filter(e -> e.getValue().getResult().contains("$"))
135-
.toList();
136-
if (!editables.isEmpty()) {
137-
context.addInHeader("");
138-
context.addInHeader("Please customize the editable value:");
139-
Map<String, PromptResultItemIF> editMap = new HashMap<>(editables.size());
140-
for (Map.Entry<String, PromptResultItemIF> editable : editables) {
141-
String template = editable.getValue().getResult();
142-
prompt.prompt(
143-
context.header,
144-
prompt.getPromptBuilder()
145-
.createInputPrompt()
146-
.name("edit")
147-
.message(template)
148-
.addPrompt()
149-
.build(),
150-
editMap);
151-
if (editMap.isEmpty()) {
152-
throw new InterruptedException();
153-
}
154-
dispatcherConfigResult.put(editable.getKey(), editMap.get("edit"));
128+
List<Map.Entry<String, PromptResultItemIF>> editables = dispatcherConfigResult.entrySet().stream()
129+
.filter(e -> e.getValue().getResult().contains("$"))
130+
.toList();
131+
if (!editables.isEmpty()) {
132+
context.addInHeader("");
133+
context.addInHeader("Please customize the editable value:");
134+
Map<String, PromptResultItemIF> editMap;
135+
for (Map.Entry<String, PromptResultItemIF> editable : editables) {
136+
String template = editable.getValue().getResult();
137+
editMap = prompt.prompt(
138+
context.header,
139+
prompt.getPromptBuilder()
140+
.createInputPrompt()
141+
.name("edit")
142+
.message(template)
143+
.addPrompt()
144+
.build());
145+
if (editMap.isEmpty()) {
146+
throw new InterruptedException();
155147
}
156-
}
157-
158-
Config dispatcherConfig = new Config();
159-
dispatcherConfig.setName(meta.name());
160-
for (DispatcherMeta.Field field : meta.fields()) {
161-
ConfigProperty property = new ConfigProperty();
162-
property.setName(field.getKey());
163-
property.setValue(
164-
dispatcherConfigResult.get(field.getKey()).getResult());
165-
dispatcherConfig.addProperty(property);
166-
}
167-
if (!dispatcherConfig.getProperties().isEmpty()) {
168-
config.addConfiguration(dispatcherConfig);
148+
dispatcherConfigResult.put(editable.getKey(), editMap.get("edit"));
169149
}
170150
}
171-
}
172151

173-
if (yes) {
174-
secDispatcher.writeConfiguration(config);
175-
} else {
176-
context.addInHeader("");
177-
context.addInHeader("Values set:");
178-
context.addInHeader("defaultDispatcher=" + config.getDefaultDispatcher());
179-
for (Config c : config.getConfigurations()) {
180-
context.addInHeader(" dispatcherName=" + c.getName());
181-
for (ConfigProperty cp : c.getProperties()) {
182-
context.addInHeader(" " + cp.getName() + "=" + cp.getValue());
183-
}
152+
Config dispatcherConfig = new Config();
153+
dispatcherConfig.setName(meta.name());
154+
for (DispatcherMeta.Field field : meta.fields()) {
155+
ConfigProperty property = new ConfigProperty();
156+
property.setName(field.getKey());
157+
property.setValue(dispatcherConfigResult.get(field.getKey()).getResult());
158+
dispatcherConfig.addProperty(property);
159+
}
160+
if (!dispatcherConfig.getProperties().isEmpty()) {
161+
config.addConfiguration(dispatcherConfig);
184162
}
163+
}
164+
}
185165

186-
prompt.prompt(
187-
context.header, confirmPrompt(prompt.getPromptBuilder()).build(), confirmChoice);
188-
ConfirmResult confirm = (ConfirmResult) confirmChoice.get("confirm");
189-
if (confirm.getConfirmed() == ConfirmChoice.ConfirmationValue.YES) {
190-
context.terminal
191-
.writer()
192-
.println(messageBuilderFactory
193-
.builder()
194-
.info("Writing out the configuration...")
195-
.build());
196-
secDispatcher.writeConfiguration(config);
197-
} else {
198-
context.terminal
199-
.writer()
200-
.println(messageBuilderFactory
201-
.builder()
202-
.warning("Values not accepted; not saving configuration.")
203-
.build());
204-
return CANCELED;
166+
if (yes) {
167+
secDispatcher.writeConfiguration(config);
168+
} else {
169+
context.addInHeader("");
170+
context.addInHeader("Values set:");
171+
context.addInHeader("defaultDispatcher=" + config.getDefaultDispatcher());
172+
for (Config c : config.getConfigurations()) {
173+
context.addInHeader(" dispatcherName=" + c.getName());
174+
for (ConfigProperty cp : c.getProperties()) {
175+
context.addInHeader(" " + cp.getName() + "=" + cp.getValue());
205176
}
206177
}
207-
} catch (IOError e) {
208-
// TODO: this should be handled properly in jline3!
209-
if (e.getCause() instanceof InterruptedIOException) {
210-
throw new UserInterruptException(e.getCause());
178+
179+
confirmChoice = prompt.prompt(
180+
context.header, confirmPrompt(prompt.getPromptBuilder()).build());
181+
ConfirmResult confirm = (ConfirmResult) confirmChoice.get("confirm");
182+
if (confirm.getConfirmed() == ConfirmChoice.ConfirmationValue.YES) {
183+
context.terminal
184+
.writer()
185+
.println(messageBuilderFactory
186+
.builder()
187+
.info("Writing out the configuration...")
188+
.build());
189+
secDispatcher.writeConfiguration(config);
211190
} else {
212-
throw e;
191+
context.terminal
192+
.writer()
193+
.println(messageBuilderFactory
194+
.builder()
195+
.warning("Values not accepted; not saving configuration.")
196+
.build());
197+
return CANCELED;
213198
}
214199
}
215200

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ under the License.
153153
<hamcrestVersion>3.0</hamcrestVersion>
154154
<jakartaInjectApiVersion>2.0.1</jakartaInjectApiVersion>
155155
<javaxAnnotationApiVersion>1.3.2</javaxAnnotationApiVersion>
156-
<jlineVersion>3.28.0</jlineVersion>
156+
<jlineVersion>3.29.0</jlineVersion>
157157
<junitVersion>5.11.4</junitVersion>
158158
<jxpathVersion>1.3</jxpathVersion>
159159
<logbackClassicVersion>1.5.16</logbackClassicVersion>

0 commit comments

Comments
 (0)