From 1bb7afbc77d523670eaf45c92e7eeabbc769dc70 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Mon, 8 Jan 2024 12:27:16 +0100 Subject: [PATCH] Code cleanup to remove dependency to plexus-utils Closes #52 --- plexus-interactivity-api/pom.xml | 6 ------ .../components/interactivity/AbstractInputHandler.java | 1 - .../components/interactivity/DefaultInputHandler.java | 1 - .../components/interactivity/DefaultOutputHandler.java | 1 - .../plexus/components/interactivity/DefaultPrompter.java | 9 ++------- .../plexus/components/interactivity/InputHandler.java | 2 -- .../plexus/components/interactivity/OutputHandler.java | 1 - .../plexus/components/interactivity/Prompter.java | 1 - .../components/interactivity/PrompterException.java | 1 - .../interactivity/jline/JLineInputHandler.java | 5 ++--- .../interactivity/DefaultPrompterComponentTest.java | 2 +- 11 files changed, 5 insertions(+), 25 deletions(-) diff --git a/plexus-interactivity-api/pom.xml b/plexus-interactivity-api/pom.xml index 894a819..4ae80ff 100644 --- a/plexus-interactivity-api/pom.xml +++ b/plexus-interactivity-api/pom.xml @@ -13,12 +13,6 @@ Plexus Default Interactivity Handler - - org.codehaus.plexus - plexus-utils - 4.0.0 - - org.jline 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 ada52b0..eb0c946 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 @@ -32,7 +32,6 @@ * Base input handler, implements a default readMultipleLines. * * @author Brett Porter - * @version $Id$ */ public abstract class AbstractInputHandler implements InputHandler { @Override 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 6c3fa6b..d0b092c 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 @@ -34,7 +34,6 @@ * Default input handler, that uses the console. * * @author Brett Porter - * @version $Id$ */ @Named public class DefaultInputHandler extends AbstractInputHandler { 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 19a93be..69b96e8 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 @@ -32,7 +32,6 @@ * Default output handler, that uses the console. * * @author Brett Porter - * @version $Id$ */ @Named public class DefaultOutputHandler implements OutputHandler { 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 7505923..de32b5c 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 @@ -31,13 +31,10 @@ import java.util.Iterator; import java.util.List; -import org.codehaus.plexus.util.StringUtils; - /** * Default prompter. * * @author Brett Porter - * @version $Id$ */ @Named public class DefaultPrompter implements Prompter { @@ -76,11 +73,9 @@ public String prompt(String message, String defaultReply) throws PrompterExcepti try { String line = inputHandler.readLine(); - - if (StringUtils.isEmpty(line)) { + if (line == null || line.isEmpty()) { line = defaultReply; } - return line; } catch (IOException e) { throw new PrompterException("Failed to read user response", e); @@ -109,7 +104,7 @@ public String prompt(String message, List possibleValues, String default throw new PrompterException("Failed to read user response", e); } - if (StringUtils.isEmpty(line)) { + if (line == null || line.isEmpty()) { line = defaultReply; } 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 1ba375a..45bff69 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 @@ -29,12 +29,10 @@ /** * Manage user input from different sources. - * * TODO should this also echo any prompts before the input? * TODO should this validate the input, reprompt if required? * TODO readBoolean, readInt, readSingleChar - readLine's that parse the input * @author Brett Porter - * @version $Id$ */ public interface InputHandler { /** 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 cc364fc..619666b 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 @@ -30,7 +30,6 @@ * Manage user output to different sources. * * @author Brett Porter - * @version $Id$ */ public interface OutputHandler { /** 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 a6e10db..a54d1cf 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 @@ -30,7 +30,6 @@ * Prompt the user for input. * * @author Brett Porter - * @version $Id$ */ public interface Prompter { String prompt(String message) throws PrompterException; diff --git a/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/PrompterException.java b/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/PrompterException.java index 7385789..916c64d 100644 --- a/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/PrompterException.java +++ b/plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/PrompterException.java @@ -28,7 +28,6 @@ * Error while prompting. * * @author Brett Porter - * @version $Id$ */ public class PrompterException extends Exception { public PrompterException(String message) { diff --git a/plexus-interactivity-api/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 index 34caef6..93c8bd6 100644 --- a/plexus-interactivity-api/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 @@ -36,17 +36,16 @@ * Default input handler, that uses the console. * * @author Brett Porter - * @version $Id$ */ @Named("jline") public class JLineInputHandler extends AbstractInputHandler { - private LineReader consoleReader = LineReaderBuilder.builder().build(); + private final LineReader consoleReader = LineReaderBuilder.builder().build(); public String readLine() throws IOException { return consoleReader.readLine(); } public String readPassword() throws IOException { - return consoleReader.readLine(new Character('*')); + return consoleReader.readLine('*'); } } 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 index ca04bce..46dbe88 100644 --- 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 @@ -37,7 +37,7 @@ public class DefaultPrompterComponentTest extends InjectedTest { private Prompter prompter; @Test - void smoke() throws PrompterException { + void smoke() { assertNotNull(prompter); } }