From 0cfb90e48db89c6e39729f621f7c0a46e895d58d Mon Sep 17 00:00:00 2001 From: Alexey Loubyansky Date: Thu, 26 Aug 2021 21:46:57 +0200 Subject: [PATCH] Fix dev mode launch on Windows, replace jline with Aesh in the quarkus-maven-plugin --- build-parent/pom.xml | 4 -- devtools/maven/pom.xml | 28 +++++++++ .../io/quarkus/maven/CreateExtensionMojo.java | 11 ++-- .../io/quarkus/maven/CreateProjectMojo.java | 30 ++++----- .../io/quarkus/maven/components/Prompter.java | 62 +++++++++++++++++-- independent-projects/arc/pom.xml | 4 -- independent-projects/bootstrap/pom.xml | 4 -- independent-projects/qute/pom.xml | 4 -- .../resteasy-reactive/pom.xml | 4 -- .../tools/devtools-common/pom.xml | 5 -- .../io/quarkus/devtools/utils/Prompter.java | 57 ----------------- independent-projects/tools/pom.xml | 10 --- 12 files changed, 102 insertions(+), 121 deletions(-) delete mode 100644 independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/utils/Prompter.java diff --git a/build-parent/pom.xml b/build-parent/pom.xml index aad128cd70f44..e7c6e7f70fe40 100644 --- a/build-parent/pom.xml +++ b/build-parent/pom.xml @@ -512,10 +512,6 @@ org.jboss.resteasy:resteasy-context-propagation com.google.android:annotations org.codehaus.mojo:animal-sniffer-annotations - - jline:jline diff --git a/devtools/maven/pom.xml b/devtools/maven/pom.xml index e5a95f0cc207b..1d0114205c70e 100644 --- a/devtools/maven/pom.xml +++ b/devtools/maven/pom.xml @@ -191,6 +191,34 @@ + + + org.apache.maven.plugins + maven-shade-plugin + + + package + + shade + + + + + org.fusesource.jansi:jansi + + + + + *:* + + META-INF/MANIFEST.MF + + + + + + + org.codehaus.plexus plexus-component-metadata diff --git a/devtools/maven/src/main/java/io/quarkus/maven/CreateExtensionMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/CreateExtensionMojo.java index 337156b17c661..564ca4749b409 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/CreateExtensionMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/CreateExtensionMojo.java @@ -12,7 +12,6 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; @@ -193,9 +192,6 @@ public class CreateExtensionMojo extends AbstractMojo { @Parameter(property = "artifactId") String artifactId; - @Component - private Prompter prompter; - @Parameter(defaultValue = "${project}") protected MavenProject project; @@ -267,19 +263,20 @@ private void promptValues() throws MojoExecutionException { return; } try { - + final Prompter prompter = new Prompter(); if (project == null || !project.getArtifactId().endsWith("quarkus-parent")) { if (isBlank(quarkusVersion)) { quarkusVersion = getPluginVersion(); } if (isBlank(groupId)) { - groupId = prompter.promptWithDefaultValue("Set the extension groupId", "org.acme"); + prompter.addPrompt("Set the extension groupId: ", "org.acme", input -> groupId = input); } } autoComputeQuarkiverseExtensionId(); if (isBlank(extensionId)) { - extensionId = prompter.prompt("Set the extension id"); + prompter.addPrompt("Set the extension id: ", input -> extensionId = input); } + prompter.collectInput(); } catch (IOException e) { throw new MojoExecutionException("Unable to get user input", e); } diff --git a/devtools/maven/src/main/java/io/quarkus/maven/CreateProjectMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/CreateProjectMojo.java index 61fe889f04f58..e5e6a77cd8117 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/CreateProjectMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/CreateProjectMojo.java @@ -166,9 +166,6 @@ public class CreateProjectMojo extends AbstractMojo { @Parameter(defaultValue = "${repositorySystemSession}", readonly = true) private RepositorySystemSession repoSession; - @Component - private Prompter prompter; - @Component private MavenVersionEnforcer mavenVersionEnforcer; @@ -405,33 +402,30 @@ private void askTheUserForMissingValues() throws MojoExecutionException { } try { + final Prompter prompter = new Prompter(); if (isBlank(projectGroupId)) { - projectGroupId = prompter.promptWithDefaultValue("Set the project groupId", - DEFAULT_GROUP_ID); + prompter.addPrompt("Set the project groupId: ", DEFAULT_GROUP_ID, input -> projectGroupId = input); } if (isBlank(projectArtifactId)) { - projectArtifactId = prompter.promptWithDefaultValue("Set the project artifactId", - DEFAULT_ARTIFACT_ID); + prompter.addPrompt("Set the project artifactId: ", DEFAULT_ARTIFACT_ID, input -> projectArtifactId = input); } if (isBlank(projectVersion)) { - projectVersion = prompter.promptWithDefaultValue("Set the project version", - DEFAULT_VERSION); + prompter.addPrompt("Set the project version: ", DEFAULT_VERSION, input -> projectVersion = input); } if (!noCode && isBlank(example)) { if (extensions.isEmpty()) { - extensions = Arrays - .stream(prompter - .promptWithDefaultValue("What extensions do you wish to add (comma separated list)", - DEFAULT_EXTENSIONS) - .split(",")) - .map(String::trim).filter(Predicate.not(String::isEmpty)).collect(Collectors.toSet()); + prompter.addPrompt("What extensions do you wish to add (comma separated list): ", DEFAULT_EXTENSIONS, + input -> extensions = Arrays + .stream(input.split(",")) + .map(String::trim).filter(Predicate.not(String::isEmpty)).collect(Collectors.toSet())); } - String answer = prompter.promptWithDefaultValue( - "Would you like some code to start (yes), or just an empty Quarkus project (no)", "yes"); - noCode = answer.startsWith("n"); + prompter.addPrompt("Would you like some code to start (yes), or just an empty Quarkus project (no): ", "yes", + input -> noCode = input.startsWith("n")); + + prompter.collectInput(); } } catch (IOException e) { throw new MojoExecutionException("Unable to get user input", e); diff --git a/devtools/maven/src/main/java/io/quarkus/maven/components/Prompter.java b/devtools/maven/src/main/java/io/quarkus/maven/components/Prompter.java index 793fb32c3552b..b648bb65fe609 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/components/Prompter.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/components/Prompter.java @@ -1,18 +1,72 @@ package io.quarkus.maven.components; import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.function.Consumer; -import org.codehaus.plexus.component.annotations.Component; +import org.aesh.readline.Readline; +import org.aesh.readline.ReadlineBuilder; +import org.aesh.readline.tty.terminal.TerminalConnection; /** * Prompt implementation. * * @author Clement Escoffier */ -@Component(role = Prompter.class, instantiationStrategy = "per-lookup") -public class Prompter extends io.quarkus.devtools.utils.Prompter { +public class Prompter { + + private static class Prompt { + private final String prompt; + private final String defaultValue; + private final Consumer inputConsumer; + + public Prompt(String prompt, String defaultValue, Consumer inputConsumer) { + this.prompt = prompt; + this.defaultValue = defaultValue; + this.inputConsumer = inputConsumer; + } + } + + private final List prompts = new ArrayList<>(); + public Prompter() throws IOException { - super(); } + public Prompter addPrompt(String prompt, Consumer inputConsumer) { + prompts.add(new Prompt(prompt, null, inputConsumer)); + return this; + } + + public Prompter addPrompt(String prompt, String defaultValue, Consumer inputConsumer) { + prompts.add(new Prompt(prompt, defaultValue, inputConsumer)); + return this; + } + + public void collectInput() throws IOException { + if (prompts.isEmpty()) { + return; + } + final TerminalConnection connection = new TerminalConnection(); + try { + read(connection, ReadlineBuilder.builder().enableHistory(false).build(), prompts.iterator()); + connection.openBlocking(); + } finally { + connection.close(); + } + } + + private static void read(TerminalConnection connection, Readline readline, Iterator prompts) { + final Prompt prompt = prompts.next(); + readline.readline(connection, prompt.prompt, input -> { + prompt.inputConsumer.accept( + (input == null || input.isBlank()) && prompt.defaultValue != null ? prompt.defaultValue : input); + if (!prompts.hasNext()) { + connection.close(); + } else { + read(connection, readline, prompts); + } + }); + } } diff --git a/independent-projects/arc/pom.xml b/independent-projects/arc/pom.xml index 64b4303472564..4ac3b17b0ea46 100644 --- a/independent-projects/arc/pom.xml +++ b/independent-projects/arc/pom.xml @@ -245,10 +245,6 @@ org.slf4j:slf4j-jdk14 org.slf4j:slf4j-log4j12 org.slf4j:slf4j-log4j13 - - jline:jline diff --git a/independent-projects/bootstrap/pom.xml b/independent-projects/bootstrap/pom.xml index d34feb7869fc5..e88e34e25dcb3 100644 --- a/independent-projects/bootstrap/pom.xml +++ b/independent-projects/bootstrap/pom.xml @@ -134,10 +134,6 @@ org.slf4j:slf4j-jdk14 org.slf4j:slf4j-log4j12 org.slf4j:slf4j-log4j13 - - jline:jline diff --git a/independent-projects/qute/pom.xml b/independent-projects/qute/pom.xml index ea14cf36cd96f..4dbe21e14ad3f 100644 --- a/independent-projects/qute/pom.xml +++ b/independent-projects/qute/pom.xml @@ -173,10 +173,6 @@ org.slf4j:slf4j-jdk14 org.slf4j:slf4j-log4j12 org.slf4j:slf4j-log4j13 - - jline:jline diff --git a/independent-projects/resteasy-reactive/pom.xml b/independent-projects/resteasy-reactive/pom.xml index 253b2fdddcefb..2aed06eaa2350 100644 --- a/independent-projects/resteasy-reactive/pom.xml +++ b/independent-projects/resteasy-reactive/pom.xml @@ -364,10 +364,6 @@ org.slf4j:slf4j-jdk14 org.slf4j:slf4j-log4j12 org.slf4j:slf4j-log4j13 - - jline:jline diff --git a/independent-projects/tools/devtools-common/pom.xml b/independent-projects/tools/devtools-common/pom.xml index 44f78ef114811..72d8674decb47 100644 --- a/independent-projects/tools/devtools-common/pom.xml +++ b/independent-projects/tools/devtools-common/pom.xml @@ -42,11 +42,6 @@ io.quarkus quarkus-devtools-codestarts - - - org.jline - jline - org.apache.commons commons-compress diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/utils/Prompter.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/utils/Prompter.java deleted file mode 100644 index 530db55b12027..0000000000000 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/utils/Prompter.java +++ /dev/null @@ -1,57 +0,0 @@ -package io.quarkus.devtools.utils; - -import java.io.IOException; -import java.util.Objects; -import org.apache.commons.lang3.StringUtils; -import org.jline.reader.LineReader; -import org.jline.reader.LineReaderBuilder; -import org.jline.terminal.Terminal; -import org.jline.terminal.TerminalBuilder; - -/** - * Prompt implementation. - * - * @author Clement Escoffier - */ -public class Prompter { - - private final LineReader lineReader; - - public Prompter() throws IOException { - // we set dumb to "true" only to prevent any warning when a proper terminal cannot be detected. - // If a proper terminal is detected by JLine then that terminal will be used and setting dumb=true - // won't force a dumb terminal. - // (https://github.com/jline/jline3/issues/291) - final Terminal terminal = TerminalBuilder.builder().dumb(true).build(); - this.lineReader = LineReaderBuilder.builder().terminal(terminal).build(); - } - - public String prompt(final String message, final Character mask) throws IOException { - Objects.requireNonNull(message); - - final String prompt = String.format("%s: ", message); - String value; - do { - value = lineReader.readLine(prompt, mask); - } while (StringUtils.isBlank(value)); - return value; - } - - public String prompt(final String message) throws IOException { - Objects.requireNonNull(message); - return prompt(message, null); - } - - public String promptWithDefaultValue(final String message, final String defaultValue) throws IOException { - Objects.requireNonNull(message); - Objects.requireNonNull(defaultValue); - - final String prompt = String.format("%s [%s]: ", message, defaultValue); - String value = lineReader.readLine(prompt); - if (StringUtils.isBlank(value)) { - return defaultValue; - } - return value; - } - -} diff --git a/independent-projects/tools/pom.xml b/independent-projects/tools/pom.xml index 833fb108012fb..5b5fc826e20ef 100644 --- a/independent-projects/tools/pom.xml +++ b/independent-projects/tools/pom.xml @@ -38,7 +38,6 @@ 4.4.0 - 3.20.0 3.20.2 2.12.5 2.0.2 @@ -130,11 +129,6 @@ quarkus-devtools-common ${project.version} - - org.jline - jline - ${jline.version} - commons-io commons-io @@ -310,10 +304,6 @@ org.slf4j:slf4j-jdk14 org.slf4j:slf4j-log4j12 org.slf4j:slf4j-log4j13 - - jline:jline