Skip to content
Snippets Groups Projects
Commit 79bcfcd3 authored by Pierre Gruet's avatar Pierre Gruet
Browse files

New upstream version 1.3

parent 1fc3423d
Branches upstream
Tags upstream/1.3
No related merge requests found
Showing
with 378 additions and 421 deletions
version: 2
updates:
- package-ecosystem: "maven"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
_extends: .github
tag-template: plexus-interactivity-$NEXT_MINOR_VERSION
# 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
# 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
name: Release Drafter
on:
push:
branches:
- master
jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>plexus-interactivity</artifactId>
<groupId>org.codehaus.plexus</groupId>
<version>1.1</version>
<artifactId>plexus-interactivity</artifactId>
<version>1.3</version>
</parent>
<artifactId>plexus-interactivity-api</artifactId>
......@@ -12,13 +13,47 @@
<name>Plexus Default Interactivity Handler</name>
<dependencies>
<!-- JLine is optional -->
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline-reader</artifactId>
<version>3.25.1</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<scope>provided</scope>
</dependency>
<!-- Test -->
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.inject</artifactId>
<version>0.9.0.M2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>6.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.sisu</groupId>
<artifactId>sisu-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
......@@ -24,30 +24,22 @@ package org.codehaus.plexus.components.interactivity;
* 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 <code>readMultipleLines</code>.
*
* @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<String> readMultipleLines() throws IOException {
List<String> 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;
......
......@@ -24,8 +24,7 @@ package org.codehaus.plexus.components.interactivity;
* 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 @@ import java.io.InputStreamReader;
* 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 ) );
}
}
......@@ -24,40 +24,27 @@ package org.codehaus.plexus.components.interactivity;
* 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();
}
}
......@@ -24,7 +24,8 @@ package org.codehaus.plexus.components.interactivity;
* 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 @@ import java.util.List;
* 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<String> 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<String> 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<String> 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<String> 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 );
}
}
}
......@@ -24,43 +24,35 @@ package org.codehaus.plexus.components.interactivity;
* 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 <a href="mailto:brett@apache.org">Brett Porter</a>
* @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<String> readMultipleLines() throws IOException;
}
......@@ -30,23 +30,17 @@ import java.io.IOException;
* Manage user output to different sources.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @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;
}
......@@ -30,27 +30,17 @@ import java.util.List;
* Prompt the user for input.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @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<String> possibleValues) throws PrompterException;
String prompt( String message, List possibleValues )
throws PrompterException;
String prompt(String message, List<String> 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;
}
......@@ -28,18 +28,13 @@ package org.codehaus.plexus.components.interactivity;
* Error while prompting.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @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);
}
}
......@@ -24,47 +24,28 @@ package org.codehaus.plexus.components.interactivity.jline;
* 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('*');
}
}
<component-set>
<components>
<component>
<role>org.codehaus.plexus.components.interactivity.InputHandler</role>
<role-hint>default</role-hint>
<implementation>org.codehaus.plexus.components.interactivity.DefaultInputHandler</implementation>
<instantiation-strategy>per-lookup</instantiation-strategy>
</component>
<component>
<role>org.codehaus.plexus.components.interactivity.OutputHandler</role>
<role-hint>default</role-hint>
<implementation>org.codehaus.plexus.components.interactivity.DefaultOutputHandler</implementation>
<instantiation-strategy>per-lookup</instantiation-strategy>
</component>
<component>
<role>org.codehaus.plexus.components.interactivity.Prompter</role>
<role-hint>default</role-hint>
<implementation>org.codehaus.plexus.components.interactivity.DefaultPrompter</implementation>
<instantiation-strategy>per-lookup</instantiation-strategy>
<requirements>
<requirement>
<role>org.codehaus.plexus.components.interactivity.InputHandler</role>
<role-hint>default</role-hint>
</requirement>
<requirement>
<role>org.codehaus.plexus.components.interactivity.OutputHandler</role>
<role-hint>default</role-hint>
</requirement>
</requirements>
</component>
</components>
</component-set>
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);
}
}
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<String> 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);
}
}
}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>plexus-interactivity</artifactId>
<groupId>org.codehaus.plexus</groupId>
<version>1.1</version>
</parent>
<artifactId>plexus-interactivity-jline</artifactId>
<name>Plexus JLine Interactivity Handler</name>
<dependencies>
<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<version>0.9.94</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-interactivity-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
<component-set>
<components>
<component>
<role>org.codehaus.plexus.components.inputhandler.InputHandler</role>
<role-hint>jline</role-hint>
<implementation>org.codehaus.plexus.components.interactivity.jline.JLineInputHandler</implementation>
<instantiation-strategy>per-lookup</instantiation-strategy>
</component>
</components>
</component-set>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment