Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 0 additions & 12 deletions maven-cli/src/main/java/org/apache/maven/cling/MavenCling.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.maven.cling.invoker.mvn.DefaultMavenParser;
import org.apache.maven.cling.invoker.mvn.local.DefaultLocalMavenInvoker;
import org.apache.maven.jline.JLineMessageBuilderFactory;
import org.apache.maven.jline.MessageUtils;
import org.codehaus.plexus.classworlds.ClassWorld;

/**
Expand Down Expand Up @@ -60,17 +59,6 @@ public MavenCling(ClassWorld classWorld) {
super(classWorld);
}

@Override
public int run(String[] args) throws IOException {
MessageUtils.systemInstall();
MessageUtils.registerShutdownHook();
try {
return super.run(args);
} finally {
MessageUtils.systemUninstall();
}
}

@Override
protected Invoker<MavenInvokerRequest<MavenOptions>> createInvoker() {
return new DefaultLocalMavenInvoker(
Expand Down
23 changes: 2 additions & 21 deletions maven-cli/src/main/java/org/apache/maven/cling/MavenEncCling.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@
import org.apache.maven.cling.invoker.mvnenc.DefaultEncryptInvoker;
import org.apache.maven.cling.invoker.mvnenc.DefaultEncryptParser;
import org.apache.maven.jline.JLineMessageBuilderFactory;
import org.apache.maven.jline.MessageUtils;
import org.codehaus.plexus.classworlds.ClassWorld;
import org.jline.terminal.Terminal;
import org.jline.terminal.TerminalBuilder;

/**
* Maven encrypt CLI "new-gen".
Expand All @@ -55,8 +52,6 @@ public static int main(String[] args, ClassWorld world) throws IOException {
return new MavenEncCling(world).run(args);
}

private Terminal terminal;

public MavenEncCling() {
super();
}
Expand All @@ -65,24 +60,10 @@ public MavenEncCling(ClassWorld classWorld) {
super(classWorld);
}

@Override
public int run(String[] args) throws IOException {
terminal = TerminalBuilder.builder().build();
MessageUtils.systemInstall(terminal);
MessageUtils.registerShutdownHook();
try {
return super.run(args);
} finally {
MessageUtils.systemUninstall();
}
}

@Override
protected Invoker<EncryptInvokerRequest> createInvoker() {
return new DefaultEncryptInvoker(ProtoLookup.builder()
.addMapping(ClassWorld.class, classWorld)
.addMapping(Terminal.class, terminal)
.build());
return new DefaultEncryptInvoker(
ProtoLookup.builder().addMapping(ClassWorld.class, classWorld).build());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ protected void helpOrVersionAndMayExit(C context) throws Exception {
} else {
context.terminal.writer().println(CLIReportingUtils.showVersion());
}
context.terminal.writer().flush();
throw new ExitException(0);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,8 @@ public void addInHeader(AttributedStyle style, String text) {
}
}

private final Terminal terminal;

public DefaultEncryptInvoker(ProtoLookup protoLookup) {
super(protoLookup);
this.terminal = protoLookup.lookup(Terminal.class);
}

@Override
Expand Down Expand Up @@ -119,11 +116,11 @@ protected int doExecute(LocalContext context) throws Exception {
context.addInHeader("");
try {
Thread executeThread = Thread.currentThread();
terminal.handle(Terminal.Signal.INT, signal -> executeThread.interrupt());
context.terminal.handle(Terminal.Signal.INT, signal -> executeThread.interrupt());
ConsolePrompt.UiConfig config;
if (terminal.getType().equals(Terminal.TYPE_DUMB)
|| terminal.getType().equals(Terminal.TYPE_DUMB_COLOR)) {
System.out.println(terminal.getName() + ": " + terminal.getType());
if (context.terminal.getType().equals(Terminal.TYPE_DUMB)
|| context.terminal.getType().equals(Terminal.TYPE_DUMB_COLOR)) {
System.out.println(context.terminal.getName() + ": " + context.terminal.getType());
throw new IllegalStateException("Dumb terminal detected.\nThis tool requires real terminal to work!\n"
+ "Note: On Windows Jansi or JNA library must be included in classpath.");
} else if (OSUtils.IS_WINDOWS) {
Expand All @@ -133,8 +130,9 @@ protected int doExecute(LocalContext context) throws Exception {
}
config.setCancellableFirstPrompt(true);

context.reader = LineReaderBuilder.builder().terminal(terminal).build();
context.prompt = new ConsolePrompt(context.reader, terminal, config);
context.reader =
LineReaderBuilder.builder().terminal(context.terminal).build();
context.prompt = new ConsolePrompt(context.reader, context.terminal, config);

if (context.invokerRequest.options().goals().isEmpty()
|| context.invokerRequest.options().goals().get().size() != 1) {
Expand Down