Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,27 @@ public int invoke(InvokerRequest invokerRequest) throws InvokerException {
}

protected int doInvoke(C context) throws Exception {
pushCoreProperties(context);
pushUserProperties(context);
configureLogging(context);
createTerminal(context);
activateLogging(context);
helpOrVersionAndMayExit(context);
preCommands(context);
container(context);
postContainer(context);
pushUserProperties(context); // after PropertyContributor SPI
lookup(context);
init(context);
postCommands(context);
settings(context);
return execute(context);
try {
pushCoreProperties(context);
pushUserProperties(context);
configureLogging(context);
createTerminal(context);
activateLogging(context);
helpOrVersionAndMayExit(context);
preCommands(context);
container(context);
postContainer(context);
pushUserProperties(context); // after PropertyContributor SPI
lookup(context);
init(context);
postCommands(context);
settings(context);
return execute(context);
} finally {
if (context.terminal != null) {
context.terminal.writer().flush();
}
}
}

protected InvokerException handleException(C context, Exception e) throws InvokerException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ protected int execute(EncryptContext context) throws Exception {
context.logger.error(e.getMessage());
}
return ERROR;
} finally {
context.terminal.writer().flush();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
*/
package org.apache.maven.cling.invoker.mvnenc.goals;

import java.io.IOError;
import java.io.InterruptedIOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand All @@ -42,7 +39,6 @@
import org.jline.consoleui.prompt.PromptResultItemIF;
import org.jline.consoleui.prompt.builder.ListPromptBuilder;
import org.jline.consoleui.prompt.builder.PromptBuilder;
import org.jline.reader.UserInterruptException;
import org.jline.utils.Colors;
import org.jline.utils.OSUtils;

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

try (ConsolePrompt prompt = new ConsolePrompt(context.reader, context.terminal, promptConfig)) {
Map<String, PromptResultItemIF> dispatcherResult = new HashMap<>();
Map<String, PromptResultItemIF> dispatcherConfigResult = new HashMap<>();
Map<String, PromptResultItemIF> confirmChoice = new HashMap<>();
Map<String, PromptResultItemIF> dispatcherResult;
Map<String, PromptResultItemIF> dispatcherConfigResult;
Map<String, PromptResultItemIF> confirmChoice;
ConsolePrompt prompt = new ConsolePrompt(context.reader, context.terminal, promptConfig);

prompt.prompt(
context.header, dispatcherPrompt(prompt.getPromptBuilder()).build(), dispatcherResult);
if (dispatcherResult.isEmpty()) {
throw new InterruptedException();
}
if (NONE.equals(dispatcherResult.get("defaultDispatcher").getResult())) {
context.terminal
.writer()
.println(messageBuilderFactory
.builder()
.warning(
"Maven4 SecDispatcher disabled; Maven3 fallback may still work, use `mvnenc diag` to check")
.build());
} else {
config.setDefaultDispatcher(
dispatcherResult.get("defaultDispatcher").getResult());
dispatcherResult = prompt.prompt(
context.header, dispatcherPrompt(prompt.getPromptBuilder()).build());
if (dispatcherResult.isEmpty()) {
throw new InterruptedException();
}
if (NONE.equals(dispatcherResult.get("defaultDispatcher").getResult())) {
context.terminal
.writer()
.println(messageBuilderFactory
.builder()
.warning(
"Maven4 SecDispatcher disabled; Maven3 fallback may still work, use `mvnenc diag` to check")
.build());
} else {
config.setDefaultDispatcher(
dispatcherResult.get("defaultDispatcher").getResult());

DispatcherMeta meta = secDispatcher.availableDispatchers().stream()
.filter(d -> Objects.equals(config.getDefaultDispatcher(), d.name()))
.findFirst()
.orElseThrow();
if (!meta.fields().isEmpty()) {
prompt.prompt(
context.header,
configureDispatcher(context, meta, prompt.getPromptBuilder())
.build(),
dispatcherConfigResult);
if (dispatcherConfigResult.isEmpty()) {
throw new InterruptedException();
}
DispatcherMeta meta = secDispatcher.availableDispatchers().stream()
.filter(d -> Objects.equals(config.getDefaultDispatcher(), d.name()))
.findFirst()
.orElseThrow();
if (!meta.fields().isEmpty()) {
dispatcherConfigResult = prompt.prompt(
context.header,
configureDispatcher(context, meta, prompt.getPromptBuilder())
.build());
if (dispatcherConfigResult.isEmpty()) {
throw new InterruptedException();
}

List<Map.Entry<String, PromptResultItemIF>> editables = dispatcherConfigResult.entrySet().stream()
.filter(e -> e.getValue().getResult().contains("$"))
.toList();
if (!editables.isEmpty()) {
context.addInHeader("");
context.addInHeader("Please customize the editable value:");
Map<String, PromptResultItemIF> editMap = new HashMap<>(editables.size());
for (Map.Entry<String, PromptResultItemIF> editable : editables) {
String template = editable.getValue().getResult();
prompt.prompt(
context.header,
prompt.getPromptBuilder()
.createInputPrompt()
.name("edit")
.message(template)
.addPrompt()
.build(),
editMap);
if (editMap.isEmpty()) {
throw new InterruptedException();
}
dispatcherConfigResult.put(editable.getKey(), editMap.get("edit"));
List<Map.Entry<String, PromptResultItemIF>> editables = dispatcherConfigResult.entrySet().stream()
.filter(e -> e.getValue().getResult().contains("$"))
.toList();
if (!editables.isEmpty()) {
context.addInHeader("");
context.addInHeader("Please customize the editable value:");
Map<String, PromptResultItemIF> editMap;
for (Map.Entry<String, PromptResultItemIF> editable : editables) {
String template = editable.getValue().getResult();
editMap = prompt.prompt(
context.header,
prompt.getPromptBuilder()
.createInputPrompt()
.name("edit")
.message(template)
.addPrompt()
.build());
if (editMap.isEmpty()) {
throw new InterruptedException();
}
}

Config dispatcherConfig = new Config();
dispatcherConfig.setName(meta.name());
for (DispatcherMeta.Field field : meta.fields()) {
ConfigProperty property = new ConfigProperty();
property.setName(field.getKey());
property.setValue(
dispatcherConfigResult.get(field.getKey()).getResult());
dispatcherConfig.addProperty(property);
}
if (!dispatcherConfig.getProperties().isEmpty()) {
config.addConfiguration(dispatcherConfig);
dispatcherConfigResult.put(editable.getKey(), editMap.get("edit"));
}
}
}

if (yes) {
secDispatcher.writeConfiguration(config);
} else {
context.addInHeader("");
context.addInHeader("Values set:");
context.addInHeader("defaultDispatcher=" + config.getDefaultDispatcher());
for (Config c : config.getConfigurations()) {
context.addInHeader(" dispatcherName=" + c.getName());
for (ConfigProperty cp : c.getProperties()) {
context.addInHeader(" " + cp.getName() + "=" + cp.getValue());
}
Config dispatcherConfig = new Config();
dispatcherConfig.setName(meta.name());
for (DispatcherMeta.Field field : meta.fields()) {
ConfigProperty property = new ConfigProperty();
property.setName(field.getKey());
property.setValue(dispatcherConfigResult.get(field.getKey()).getResult());
dispatcherConfig.addProperty(property);
}
if (!dispatcherConfig.getProperties().isEmpty()) {
config.addConfiguration(dispatcherConfig);
}
}
}

prompt.prompt(
context.header, confirmPrompt(prompt.getPromptBuilder()).build(), confirmChoice);
ConfirmResult confirm = (ConfirmResult) confirmChoice.get("confirm");
if (confirm.getConfirmed() == ConfirmChoice.ConfirmationValue.YES) {
context.terminal
.writer()
.println(messageBuilderFactory
.builder()
.info("Writing out the configuration...")
.build());
secDispatcher.writeConfiguration(config);
} else {
context.terminal
.writer()
.println(messageBuilderFactory
.builder()
.warning("Values not accepted; not saving configuration.")
.build());
return CANCELED;
if (yes) {
secDispatcher.writeConfiguration(config);
} else {
context.addInHeader("");
context.addInHeader("Values set:");
context.addInHeader("defaultDispatcher=" + config.getDefaultDispatcher());
for (Config c : config.getConfigurations()) {
context.addInHeader(" dispatcherName=" + c.getName());
for (ConfigProperty cp : c.getProperties()) {
context.addInHeader(" " + cp.getName() + "=" + cp.getValue());
}
}
} catch (IOError e) {
// TODO: this should be handled properly in jline3!
if (e.getCause() instanceof InterruptedIOException) {
throw new UserInterruptException(e.getCause());

confirmChoice = prompt.prompt(
context.header, confirmPrompt(prompt.getPromptBuilder()).build());
ConfirmResult confirm = (ConfirmResult) confirmChoice.get("confirm");
if (confirm.getConfirmed() == ConfirmChoice.ConfirmationValue.YES) {
context.terminal
.writer()
.println(messageBuilderFactory
.builder()
.info("Writing out the configuration...")
.build());
secDispatcher.writeConfiguration(config);
} else {
throw e;
context.terminal
.writer()
.println(messageBuilderFactory
.builder()
.warning("Values not accepted; not saving configuration.")
.build());
return CANCELED;
}
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ under the License.
<hamcrestVersion>3.0</hamcrestVersion>
<jakartaInjectApiVersion>2.0.1</jakartaInjectApiVersion>
<javaxAnnotationApiVersion>1.3.2</javaxAnnotationApiVersion>
<jlineVersion>3.28.0</jlineVersion>
<jlineVersion>3.29.0</jlineVersion>
<junitVersion>5.11.4</junitVersion>
<jxpathVersion>1.3</jxpathVersion>
<logbackClassicVersion>1.5.16</logbackClassicVersion>
Expand Down