diff --git a/plexus-interactivity-api/pom.xml b/plexus-interactivity-api/pom.xml index db04088..96be7c7 100644 --- a/plexus-interactivity-api/pom.xml +++ b/plexus-interactivity-api/pom.xml @@ -18,18 +18,48 @@ plexus-utils 4.0.0 + + + + org.jline + jline + 3.23.0 + true + + + + javax.inject + javax.inject + 1 + provided + + + org.junit.jupiter - junit-jupiter + junit-jupiter-api + test + + + org.eclipse.sisu + org.eclipse.sisu.inject + 0.9.0.M2 test - - javax.annotation - javax.annotation-api - 1.3.2 + com.google.inject + guice + 6.0.0 + test + + + + + org.eclipse.sisu + sisu-maven-plugin + + + diff --git a/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/AbstractInputHandler.java b/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/AbstractInputHandler.java index 2f3bc6f..ada52b0 100644 --- a/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/AbstractInputHandler.java +++ b/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/AbstractInputHandler.java @@ -35,10 +35,11 @@ * @version $Id$ */ public abstract class AbstractInputHandler implements InputHandler { + @Override public List readMultipleLines() throws IOException { List lines = new ArrayList<>(); String line = readLine(); - while (line != null && line.length() > 0) { + while (line != null && !line.isEmpty()) { lines.add(line); line = readLine(); } diff --git a/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/DefaultInputHandler.java b/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/DefaultInputHandler.java index 193431c..6c3fa6b 100644 --- a/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/DefaultInputHandler.java +++ b/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/DefaultInputHandler.java @@ -24,7 +24,7 @@ * SOFTWARE. */ -import javax.annotation.PostConstruct; +import javax.inject.Named; import java.io.BufferedReader; import java.io.IOException; @@ -36,19 +36,17 @@ * @author Brett Porter * @version $Id$ */ +@Named public class DefaultInputHandler extends AbstractInputHandler { - private BufferedReader consoleReader; + private final BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in)); + @Override public String readLine() throws IOException { return consoleReader.readLine(); } + @Override public String readPassword() throws IOException { return consoleReader.readLine(); } - - @PostConstruct - public void initialize() { - consoleReader = new BufferedReader(new InputStreamReader(System.in)); - } } diff --git a/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/DefaultOutputHandler.java b/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/DefaultOutputHandler.java index d0b40ca..19a93be 100644 --- a/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/DefaultOutputHandler.java +++ b/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/DefaultOutputHandler.java @@ -24,9 +24,8 @@ * SOFTWARE. */ -import javax.annotation.PostConstruct; +import javax.inject.Named; -import java.io.IOException; import java.io.PrintWriter; /** @@ -35,20 +34,18 @@ * @author Brett Porter * @version $Id$ */ +@Named public class DefaultOutputHandler implements OutputHandler { - private PrintWriter consoleWriter; + private final PrintWriter consoleWriter = new PrintWriter(System.out); - @PostConstruct - public void initialize() { - consoleWriter = new PrintWriter(System.out); - } - - public void write(String line) throws IOException { + @Override + public void write(String line) { consoleWriter.print(line); consoleWriter.flush(); } - public void writeLine(String line) throws IOException { + @Override + public void writeLine(String line) { consoleWriter.println(); } } diff --git a/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/DefaultPrompter.java b/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/DefaultPrompter.java index a21c2f7..7505923 100644 --- a/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/DefaultPrompter.java +++ b/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/DefaultPrompter.java @@ -24,6 +24,9 @@ * SOFTWARE. */ +import javax.inject.Inject; +import javax.inject.Named; + import java.io.IOException; import java.util.Iterator; import java.util.List; @@ -36,26 +39,19 @@ * @author Brett Porter * @version $Id$ */ +@Named public class DefaultPrompter implements Prompter { - /** - * @requirement - */ - private OutputHandler outputHandler; - - /** - * @requirement - */ - private InputHandler inputHandler; - - public DefaultPrompter() { - super(); - } + private final OutputHandler outputHandler; + + private final InputHandler inputHandler; + @Inject public DefaultPrompter(OutputHandler outputHandler, InputHandler inputHandler) { this.outputHandler = outputHandler; this.inputHandler = inputHandler; } + @Override public String prompt(String message) throws PrompterException { try { writePrompt(message); @@ -70,6 +66,7 @@ public String prompt(String message) throws PrompterException { } } + @Override public String prompt(String message, String defaultReply) throws PrompterException { try { writePrompt(formatMessage(message, null, defaultReply)); @@ -90,6 +87,7 @@ public String prompt(String message, String defaultReply) throws PrompterExcepti } } + @Override public String prompt(String message, List possibleValues, String defaultReply) throws PrompterException { String formattedMessage = formatMessage(message, possibleValues, defaultReply); @@ -127,10 +125,12 @@ public String prompt(String message, List possibleValues, String default return line; } + @Override public String prompt(String message, List possibleValues) throws PrompterException { return prompt(message, possibleValues, null); } + @Override public String promptForPassword(String message) throws PrompterException { try { writePrompt(message); @@ -177,6 +177,7 @@ private void writePrompt(String message) throws IOException { outputHandler.write(message + ": "); } + @Override public void showMessage(String message) throws PrompterException { try { writePrompt(message); diff --git a/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/InputHandler.java b/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/InputHandler.java index 0cde1f1..1ba375a 100644 --- a/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/InputHandler.java +++ b/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/InputHandler.java @@ -37,8 +37,6 @@ * @version $Id$ */ public interface InputHandler { - String ROLE = InputHandler.class.getName(); - /** * Read a single line of input, swalling the newline at the end. * If the input can be echoed, it will be. diff --git a/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/OutputHandler.java b/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/OutputHandler.java index 9b0c027..cc364fc 100644 --- a/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/OutputHandler.java +++ b/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/OutputHandler.java @@ -33,8 +33,6 @@ * @version $Id$ */ public interface OutputHandler { - String ROLE = OutputHandler.class.getName(); - /** * Write a single line of input, excluding the newline at the end. * @param line the line diff --git a/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/Prompter.java b/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/Prompter.java index b5f6ffb..a6e10db 100644 --- a/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/Prompter.java +++ b/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/Prompter.java @@ -33,8 +33,6 @@ * @version $Id$ */ public interface Prompter { - String ROLE = Prompter.class.getName(); - String prompt(String message) throws PrompterException; String prompt(String message, String defaultReply) throws PrompterException; diff --git a/plexus-interactivity-jline/src/main/java/org/codehaus/plexus/components/interactivity/jline/JLineInputHandler.java b/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/jline/JLineInputHandler.java similarity index 82% rename from plexus-interactivity-jline/src/main/java/org/codehaus/plexus/components/interactivity/jline/JLineInputHandler.java rename to plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/jline/JLineInputHandler.java index 40ab3b1..34caef6 100644 --- a/plexus-interactivity-jline/src/main/java/org/codehaus/plexus/components/interactivity/jline/JLineInputHandler.java +++ b/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/jline/JLineInputHandler.java @@ -24,12 +24,13 @@ * SOFTWARE. */ -import javax.annotation.PostConstruct; +import javax.inject.Named; import java.io.IOException; -import jline.ConsoleReader; import org.codehaus.plexus.components.interactivity.AbstractInputHandler; +import org.jline.reader.LineReader; +import org.jline.reader.LineReaderBuilder; /** * Default input handler, that uses the console. @@ -37,8 +38,9 @@ * @author Brett Porter * @version $Id$ */ +@Named("jline") public class JLineInputHandler extends AbstractInputHandler { - private ConsoleReader consoleReader; + private LineReader consoleReader = LineReaderBuilder.builder().build(); public String readLine() throws IOException { return consoleReader.readLine(); @@ -47,13 +49,4 @@ public String readLine() throws IOException { public String readPassword() throws IOException { return consoleReader.readLine(new Character('*')); } - - @PostConstruct - public void initialize() { - try { - consoleReader = new ConsoleReader(); - } catch (IOException e) { - throw new IllegalStateException("Cannot create console reader: ", e); - } - } } diff --git a/plexus-interactivity-api/src/main/resources/META-INF/plexus/components.xml b/plexus-interactivity-api/src/main/resources/META-INF/plexus/components.xml deleted file mode 100644 index 9e671cd..0000000 --- a/plexus-interactivity-api/src/main/resources/META-INF/plexus/components.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - org.codehaus.plexus.components.interactivity.InputHandler - default - org.codehaus.plexus.components.interactivity.DefaultInputHandler - per-lookup - - - org.codehaus.plexus.components.interactivity.OutputHandler - default - org.codehaus.plexus.components.interactivity.DefaultOutputHandler - per-lookup - - - org.codehaus.plexus.components.interactivity.Prompter - default - org.codehaus.plexus.components.interactivity.DefaultPrompter - per-lookup - - - org.codehaus.plexus.components.interactivity.InputHandler - default - - - org.codehaus.plexus.components.interactivity.OutputHandler - default - - - - - diff --git a/plexus-interactivity-api/src/test/java/org/codehaus/plexus/components/interactivity/DefaultPrompterComponentTest.java b/plexus-interactivity-api/src/test/java/org/codehaus/plexus/components/interactivity/DefaultPrompterComponentTest.java new file mode 100644 index 0000000..ca04bce --- /dev/null +++ b/plexus-interactivity-api/src/test/java/org/codehaus/plexus/components/interactivity/DefaultPrompterComponentTest.java @@ -0,0 +1,43 @@ +package org.codehaus.plexus.components.interactivity; + +/* + * The MIT License + * + * Copyright (c) 2005, The Codehaus + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import javax.inject.Inject; + +import org.eclipse.sisu.launch.InjectedTest; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class DefaultPrompterComponentTest extends InjectedTest { + + @Inject + private Prompter prompter; + + @Test + void smoke() throws PrompterException { + assertNotNull(prompter); + } +} diff --git a/plexus-interactivity-jline/pom.xml b/plexus-interactivity-jline/pom.xml deleted file mode 100644 index 9e5a30e..0000000 --- a/plexus-interactivity-jline/pom.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - 4.0.0 - - - org.codehaus.plexus - plexus-interactivity - 1.2-SNAPSHOT - - - plexus-interactivity-jline - - Plexus JLine Interactivity Handler - - - - jline - jline - 0.9.94 - - - org.codehaus.plexus - plexus-interactivity-api - ${project.version} - - - - javax.annotation - javax.annotation-api - 1.3.2 - - - diff --git a/plexus-interactivity-jline/src/main/resources/META-INF/plexus/components.xml b/plexus-interactivity-jline/src/main/resources/META-INF/plexus/components.xml deleted file mode 100644 index 001418c..0000000 --- a/plexus-interactivity-jline/src/main/resources/META-INF/plexus/components.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - org.codehaus.plexus.components.inputhandler.InputHandler - jline - org.codehaus.plexus.components.interactivity.jline.JLineInputHandler - per-lookup - - - diff --git a/plexus-interactivity-jline/src/site/site.xml b/plexus-interactivity-jline/src/site/site.xml deleted file mode 100644 index adc4a63..0000000 --- a/plexus-interactivity-jline/src/site/site.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - diff --git a/pom.xml b/pom.xml index 4d2e447..cbb1a3d 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,6 @@ plexus-interactivity-api - plexus-interactivity-jline @@ -42,6 +41,13 @@ + + org.apache.maven.plugins + maven-compiler-plugin + + none + + org.apache.maven.plugins maven-site-plugin