diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..b76b895 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + - package-ecosystem: "maven" + directory: "/" + schedule: + interval: "daily" + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..8ae0341 --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,2 @@ +_extends: .github +tag-template: plexus-interactivity-$NEXT_MINOR_VERSION diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index 216b262..0000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,67 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL" - -on: - push: - branches: [ master ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ master ] - schedule: - - cron: '33 3 * * 1' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - language: [ 'java' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] - # Learn more: - # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v1 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v1 - - # â„šī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # âœī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..09feae4 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,31 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +name: GitHub CI + +on: [push, pull_request] + +jobs: + build: + name: Build it + uses: codehaus-plexus/.github/.github/workflows/maven.yml@master + + deploy: + name: Deploy + needs: build + uses: codehaus-plexus/.github/.github/workflows/maven-deploy.yml@master + secrets: inherit diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml new file mode 100644 index 0000000..4c09c8a --- /dev/null +++ b/.github/workflows/release-drafter.yml @@ -0,0 +1,12 @@ +name: Release Drafter +on: + push: + branches: + - master +jobs: + update_release_draft: + runs-on: ubuntu-latest + steps: + - uses: release-drafter/release-drafter@v6 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index 4386f9b..50b93cb 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ Plexus-Interactivity -=============== +==================== [![Apache License, Version 2.0, January 2004](https://img.shields.io/github/license/codehaus-plexus/plexus-interactivity.svg?label=License)](http://www.apache.org/licenses/) [![Maven Central](https://img.shields.io/maven-central/v/org.codehaus.plexus/plexus-interactivity.svg?label=Maven%20Central)](https://search.maven.org/artifact/org.codehaus.plexus/plexus-interactivity) [![Build Status](https://travis-ci.org/codehaus-plexus/plexus-interactivity.svg?branch=master)](https://travis-ci.org/codehaus-plexus/plexus-interactivity) +[![Reproducible Builds](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/jvm-repo-rebuild/reproducible-central/master/content/org/codehaus/plexus/plexus-interactivity/badge.json)](https://github.com/jvm-repo-rebuild/reproducible-central/blob/master/content/org/codehaus/plexus/plexus-interactivity/README.md) The canonical git repository is located at https://github.com/codehaus-plexus/plexus-interactivity diff --git a/plexus-interactivity-api/pom.xml b/plexus-interactivity-api/pom.xml index 367cdbd..969cc99 100644 --- a/plexus-interactivity-api/pom.xml +++ b/plexus-interactivity-api/pom.xml @@ -1,10 +1,11 @@ + 4.0.0 - plexus-interactivity org.codehaus.plexus - 1.1 + plexus-interactivity + 1.5-SNAPSHOT plexus-interactivity-api @@ -12,13 +13,47 @@ Plexus Default Interactivity Handler + + + org.jline + jline-reader + 3.30.5 + true + + - org.codehaus.plexus - plexus-utils + javax.inject + javax.inject + 1 + provided + + - org.codehaus.plexus - plexus-container-default + org.junit.jupiter + junit-jupiter-api + test + + + org.eclipse.sisu + org.eclipse.sisu.inject + 0.9.0.M4 + test + + + 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 35b642a..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 @@ -24,30 +24,22 @@ * SOFTWARE. */ -import org.codehaus.plexus.logging.AbstractLogEnabled; - -import java.util.List; -import java.util.ArrayList; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; /** * Base input handler, implements a default readMultipleLines. * * @author Brett Porter - * @version $Id$ */ -public abstract class AbstractInputHandler - extends AbstractLogEnabled - implements InputHandler -{ - public List readMultipleLines() - throws IOException - { - List lines = new ArrayList(); +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 ) - { - lines.add( line ); + while (line != null && !line.isEmpty()) { + lines.add(line); line = readLine(); } return lines; 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 79f65f6..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 @@ -24,8 +24,7 @@ * SOFTWARE. */ -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; +import javax.inject.Named; import java.io.BufferedReader; import java.io.IOException; @@ -35,29 +34,18 @@ * Default input handler, that uses the console. * * @author Brett Porter - * @version $Id$ */ -public class DefaultInputHandler - extends AbstractInputHandler - implements Initializable -{ - private BufferedReader consoleReader; +@Named +public class DefaultInputHandler extends AbstractInputHandler { + private final BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in)); - public String readLine() - throws IOException - { + @Override + public String readLine() throws IOException { return consoleReader.readLine(); } - public String readPassword() - throws IOException - { + @Override + public String readPassword() throws IOException { return consoleReader.readLine(); } - - public void initialize() - throws InitializationException - { - 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 cc95e3d..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 @@ -24,40 +24,27 @@ * SOFTWARE. */ -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; +import javax.inject.Named; -import java.io.IOException; import java.io.PrintWriter; /** * Default output handler, that uses the console. * * @author Brett Porter - * @version $Id$ */ -public class DefaultOutputHandler - implements Initializable, OutputHandler -{ - private PrintWriter consoleWriter; +@Named +public class DefaultOutputHandler implements OutputHandler { + private final PrintWriter consoleWriter = new PrintWriter(System.out); - public void initialize() - throws InitializationException - { - consoleWriter = new PrintWriter( System.out ); - } - - public void write( String line ) - throws IOException - { - consoleWriter.print( line ); + @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 b7de00e..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 @@ -24,7 +24,8 @@ * SOFTWARE. */ -import org.codehaus.plexus.util.StringUtils; +import javax.inject.Inject; +import javax.inject.Named; import java.io.IOException; import java.util.Iterator; @@ -34,202 +35,149 @@ * Default prompter. * * @author Brett Porter - * @version $Id$ */ -public class DefaultPrompter - implements Prompter -{ - /** - * @requirement - */ - private OutputHandler outputHandler; - - /** - * @requirement - */ - private InputHandler inputHandler; - - public String prompt( String message ) - throws PrompterException - { - try - { - writePrompt( message ); - } - catch ( IOException e ) - { - throw new PrompterException( "Failed to present prompt", e ); +@Named +public class DefaultPrompter implements Prompter { + 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); + } catch (IOException e) { + throw new PrompterException("Failed to present prompt", e); } - try - { + try { return inputHandler.readLine(); - } - catch ( IOException e ) - { - throw new PrompterException( "Failed to read user response", e ); + } catch (IOException e) { + throw new PrompterException("Failed to read user response", e); } } - public String prompt( String message, String defaultReply ) - throws PrompterException - { - try - { - writePrompt( formatMessage( message, null, defaultReply ) ); - } - catch ( IOException e ) - { - throw new PrompterException( "Failed to present prompt", e ); + @Override + public String prompt(String message, String defaultReply) throws PrompterException { + try { + writePrompt(formatMessage(message, null, defaultReply)); + } catch (IOException e) { + throw new PrompterException("Failed to present prompt", e); } - try - { + 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 ); + } catch (IOException e) { + throw new PrompterException("Failed to read user response", e); } } - public String prompt( String message, List possibleValues, String defaultReply ) - throws PrompterException - { - String formattedMessage = formatMessage( message, possibleValues, defaultReply ); + @Override + public String prompt(String message, List possibleValues, String defaultReply) throws PrompterException { + String formattedMessage = formatMessage(message, possibleValues, defaultReply); String line; - do - { - try - { - writePrompt( formattedMessage ); - } - catch ( IOException e ) - { - throw new PrompterException( "Failed to present prompt", e ); + do { + try { + writePrompt(formattedMessage); + } catch (IOException e) { + throw new PrompterException("Failed to present prompt", e); } - try - { + try { line = inputHandler.readLine(); if (line == null && defaultReply == null) { throw new IOException("EOF"); } - } - catch ( IOException e ) - { - throw new PrompterException( "Failed to read user response", e ); + } catch (IOException e) { + throw new PrompterException("Failed to read user response", e); } - if ( StringUtils.isEmpty( line ) ) - { + if (line == null || line.isEmpty()) { line = defaultReply; } - if ( line != null && !possibleValues.contains( line ) ) - { - try - { - outputHandler.writeLine( "Invalid selection." ); - } - catch ( IOException e ) - { - throw new PrompterException( "Failed to present feedback", e ); + if (line != null && !possibleValues.contains(line)) { + try { + outputHandler.writeLine("Invalid selection."); + } catch (IOException e) { + throw new PrompterException("Failed to present feedback", e); } } - } - while ( line == null || !possibleValues.contains( line ) ); + } while (line == null || !possibleValues.contains(line)); return line; } - public String prompt( String message, List possibleValues ) - throws PrompterException - { - return prompt( message, possibleValues, null ); + @Override + public String prompt(String message, List possibleValues) throws PrompterException { + return prompt(message, possibleValues, null); } - public String promptForPassword( String message ) - throws PrompterException - { - try - { - writePrompt( message ); - } - catch ( IOException e ) - { - throw new PrompterException( "Failed to present prompt", e ); + @Override + public String promptForPassword(String message) throws PrompterException { + try { + writePrompt(message); + } catch (IOException e) { + throw new PrompterException("Failed to present prompt", e); } - try - { + try { return inputHandler.readPassword(); - } - catch ( IOException e ) - { - throw new PrompterException( "Failed to read user response", e ); + } catch (IOException e) { + throw new PrompterException("Failed to read user response", e); } } - private String formatMessage( String message, List possibleValues, String defaultReply ) - { - StringBuffer formatted = new StringBuffer( message.length() * 2 ); + private String formatMessage(String message, List possibleValues, String defaultReply) { + StringBuilder formatted = new StringBuilder(message.length() * 2); - formatted.append( message ); + formatted.append(message); - if ( possibleValues != null && !possibleValues.isEmpty() ) - { - formatted.append( " (" ); + if (possibleValues != null && !possibleValues.isEmpty()) { + formatted.append(" ("); - for ( Iterator it = possibleValues.iterator(); it.hasNext(); ) - { - String possibleValue = (String) it.next(); + for (Iterator it = possibleValues.iterator(); it.hasNext(); ) { + String possibleValue = it.next(); - formatted.append( possibleValue ); + formatted.append(possibleValue); - if ( it.hasNext() ) - { - formatted.append( '/' ); + if (it.hasNext()) { + formatted.append('/'); } } - formatted.append( ')' ); + formatted.append(')'); } - if ( defaultReply != null ) - { - formatted.append( ' ' ).append( defaultReply ).append( ": " ); + if (defaultReply != null) { + formatted.append(' ').append(defaultReply); } return formatted.toString(); } - private void writePrompt( String message ) - throws IOException - { - outputHandler.write( message + ": " ); + private void writePrompt(String message) throws IOException { + outputHandler.write(message + ": "); } - public void showMessage( String message ) - throws PrompterException - { - try - { - writePrompt( message ); + @Override + public void showMessage(String message) throws PrompterException { + try { + writePrompt(message); + } catch (IOException e) { + throw new PrompterException("Failed to present prompt", e); } - catch ( IOException e ) - { - throw new PrompterException( "Failed to present prompt", e ); - } - } } 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 ca0ea24..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 @@ -24,43 +24,35 @@ * SOFTWARE. */ -import java.util.List; import java.io.IOException; +import java.util.List; /** * 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 + * 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 -{ - String ROLE = InputHandler.class.getName(); - +public interface InputHandler { /** * Read a single line of input, swalling the newline at the end. * If the input can be echoed, it will be. * @return the line read */ - String readLine() - throws IOException; + String readLine() throws IOException; /** * Read a single line of input, swalling the newline at the end. * This method guarantees input is not echoed. * @return the line read */ - String readPassword() - throws IOException; + String readPassword() throws IOException; /** * Read a set of lines. Equivalent to multiple calls to {@link #readLine()}. * Ends when an empty line is encountered. * @return a list of lines read */ - List readMultipleLines() - throws IOException; + List readMultipleLines() throws IOException; } 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 240a984..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,23 +30,17 @@ * Manage user output to different sources. * * @author Brett Porter - * @version $Id$ */ -public interface OutputHandler -{ - String ROLE = OutputHandler.class.getName(); - +public interface OutputHandler { /** * Write a single line of input, excluding the newline at the end. * @param line the line */ - void write( String line ) - throws IOException; + void write(String line) throws IOException; /** * Write a single line of input, including the newline at the end. * @param line the line */ - void writeLine( String line ) - throws IOException; + void writeLine(String line) throws IOException; } 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 016597c..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,27 +30,17 @@ * Prompt the user for input. * * @author Brett Porter - * @version $Id$ */ -public interface Prompter -{ - String ROLE = Prompter.class.getName(); +public interface Prompter { + String prompt(String message) throws PrompterException; - String prompt( String message ) - throws PrompterException; + String prompt(String message, String defaultReply) throws PrompterException; - String prompt( String message, String defaultReply ) - throws PrompterException; + String prompt(String message, List possibleValues) throws PrompterException; - String prompt( String message, List possibleValues ) - throws PrompterException; + String prompt(String message, List possibleValues, String defaultReply) throws PrompterException; - String prompt( String message, List possibleValues, String defaultReply ) - throws PrompterException; + String promptForPassword(String message) throws PrompterException; - String promptForPassword( String message ) - throws PrompterException; - - void showMessage( String message ) - throws PrompterException; + void showMessage(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 d6a0b00..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,18 +28,13 @@ * Error while prompting. * * @author Brett Porter - * @version $Id$ */ -public class PrompterException - extends Exception -{ - public PrompterException( String message ) - { - super( message ); +public class PrompterException extends Exception { + public PrompterException(String message) { + super(message); } - public PrompterException( String message, Throwable cause ) - { - super( message, cause ); + public PrompterException(String message, Throwable cause) { + super(message, cause); } } 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 63% 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 fd624d9..93c8bd6 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,47 +24,28 @@ * SOFTWARE. */ -import jline.ConsoleReader; -import org.codehaus.plexus.components.interactivity.AbstractInputHandler; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; +import javax.inject.Named; import java.io.IOException; +import org.codehaus.plexus.components.interactivity.AbstractInputHandler; +import org.jline.reader.LineReader; +import org.jline.reader.LineReaderBuilder; + /** * Default input handler, that uses the console. * * @author Brett Porter - * @version $Id$ */ -public class JLineInputHandler - extends AbstractInputHandler - implements Initializable -{ - private ConsoleReader consoleReader; +@Named("jline") +public class JLineInputHandler extends AbstractInputHandler { + private final LineReader consoleReader = LineReaderBuilder.builder().build(); - public String readLine() - throws IOException - { + public String readLine() throws IOException { return consoleReader.readLine(); } - public String readPassword() - throws IOException - { - return consoleReader.readLine( new Character( '*' ) ); - } - - public void initialize() - throws InitializationException - { - try - { - consoleReader = new ConsoleReader(); - } - catch ( IOException e ) - { - throw new InitializationException( "Cannot create console reader: ", e ); - } + public String readPassword() throws IOException { + return consoleReader.readLine('*'); } } 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/site/site.xml b/plexus-interactivity-api/src/site/site.xml index adc4a63..3814c4b 100644 --- a/plexus-interactivity-api/src/site/site.xml +++ b/plexus-interactivity-api/src/site/site.xml @@ -1,7 +1,11 @@ - - + + + + Plexus + + + @@ -12,4 +16,4 @@ - + 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..46dbe88 --- /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() { + assertNotNull(prompter); + } +} diff --git a/plexus-interactivity-api/src/test/java/org/codehaus/plexus/components/interactivity/DefaultPrompterTest.java b/plexus-interactivity-api/src/test/java/org/codehaus/plexus/components/interactivity/DefaultPrompterTest.java new file mode 100644 index 0000000..e261cd3 --- /dev/null +++ b/plexus-interactivity-api/src/test/java/org/codehaus/plexus/components/interactivity/DefaultPrompterTest.java @@ -0,0 +1,96 @@ +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 java.util.List; + +import org.junit.jupiter.api.Test; + +import static java.util.Arrays.asList; +import static java.util.Objects.requireNonNull; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class DefaultPrompterTest { + @Test + void promptSimple() throws PrompterException { + final InMemoryOutput out = new InMemoryOutput(); + final Prompter prompter = new DefaultPrompter(out, new InMemoryInput("ok")); + prompter.prompt("test"); + assertEquals("test: ", out.builder.toString()); + } + + @Test + void promptOption() throws PrompterException { + final InMemoryOutput out = new InMemoryOutput(); + final Prompter prompter = new DefaultPrompter(out, new InMemoryInput("ok")); + prompter.prompt("test", "value"); + assertEquals("test value: ", out.builder.toString()); + } + + @Test + void promptOptions() throws PrompterException { + final InMemoryOutput out = new InMemoryOutput(); + final Prompter prompter = new DefaultPrompter(out, new InMemoryInput("yes")); + prompter.prompt("test", asList("yes", "no"), "value"); + assertEquals("test (yes/no) value: ", out.builder.toString()); + } + + private static class InMemoryInput implements InputHandler { + private final String line; + + private InMemoryInput(String line) { + this.line = requireNonNull(line); + } + + @Override + public String readLine() { + return line; + } + + @Override + public String readPassword() { + throw new UnsupportedOperationException(); + } + + @Override + public List readMultipleLines() { + throw new UnsupportedOperationException(); + } + } + + private static class InMemoryOutput implements OutputHandler { + private final StringBuilder builder = new StringBuilder(); + + @Override + public void write(String line) { + builder.append(line); + } + + @Override + public void writeLine(String line) { + builder.append(line); + } + } +} diff --git a/plexus-interactivity-jline/pom.xml b/plexus-interactivity-jline/pom.xml deleted file mode 100644 index c5a938f..0000000 --- a/plexus-interactivity-jline/pom.xml +++ /dev/null @@ -1,30 +0,0 @@ - - 4.0.0 - - - plexus-interactivity - org.codehaus.plexus - 1.1 - - - plexus-interactivity-jline - - Plexus JLine Interactivity Handler - - - - jline - jline - 0.9.94 - - - org.codehaus.plexus - plexus-interactivity-api - ${project.version} - - - org.codehaus.plexus - plexus-container-default - - - \ No newline at end of file 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 6fa0e5e..f34ff4e 100644 --- a/pom.xml +++ b/pom.xml @@ -1,23 +1,28 @@ + 4.0.0 - plexus-components org.codehaus.plexus - 6.5 + plexus + 23 plexus-interactivity - 1.1 + 1.5-SNAPSHOT pom Plexus Interactivity Handler Component + + plexus-interactivity-api + + ${scm.url} ${scm.url} + plexus-interactivity-1.2 https://github.com/codehaus-plexus/plexus-interactivity - plexus-interactivity-1.1 github @@ -32,14 +37,9 @@ scm:git:https://github.com/codehaus-plexus/plexus-interactivity.git - 2021-09-11T07:18:40Z + 2025-04-05T16:18:20Z - - plexus-interactivity-api - plexus-interactivity-jline - - @@ -51,5 +51,4 @@ - diff --git a/src/site/site.xml b/src/site/site.xml index f0905e7..5594a85 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -1,8 +1,12 @@ - + + + + Plexus + + - +