Skip to content

Commit

Permalink
More fixes:
Browse files Browse the repository at this point in the history
* make sure out prompter override legacy
* honor proper exceptions
  • Loading branch information
cstamas committed Feb 5, 2025
1 parent 1f99aa9 commit 729bd6b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 29 deletions.
11 changes: 11 additions & 0 deletions impl/maven-jline/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ under the License.
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-interactivity-api</artifactId>
</dependency>

<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.inject</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ String doPrompt(String message, boolean password) throws IOException {
}
}

/**
* Used by {@link LegacyPlexusInteractivity}
*/
void doDisplay(String message) throws IOException {
try {
MessageUtils.terminal.writer().print(message);
MessageUtils.terminal.flush();
} catch (Exception e) {
throw new IOException("Unable to display message", e);
}
}

private String doPrompt(String message, List<?> possibleValues, String defaultReply, boolean password)
throws IOException {
String formattedMessage = formatMessage(message, possibleValues, defaultReply);
Expand Down Expand Up @@ -123,13 +135,4 @@ private String formatMessage(String message, List<?> possibleValues, String defa
}
return formatted.toString();
}

private void doDisplay(String message) throws IOException {
try {
MessageUtils.terminal.writer().print(message);
MessageUtils.terminal.flush();
} catch (Exception e) {
throw new IOException("Unable to display message", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@
*/
package org.apache.maven.jline;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.di.Inject;
import org.apache.maven.api.di.Named;
import org.apache.maven.api.di.Priority;
import org.apache.maven.api.di.Singleton;
import org.codehaus.plexus.components.interactivity.InputHandler;
import org.codehaus.plexus.components.interactivity.OutputHandler;
import org.codehaus.plexus.components.interactivity.Prompter;
import org.codehaus.plexus.components.interactivity.PrompterException;
import org.eclipse.sisu.Priority;

/**
* This class is injected into any legacy component that would want to use legacy "Plexus Interactivity API".
Expand Down Expand Up @@ -67,42 +69,66 @@ public List<String> readMultipleLines() throws IOException {
}

@Override
public void write(String line) {
defaultPrompter.showMessage(line);
public void write(String line) throws IOException {
defaultPrompter.doDisplay(line);
}

@Override
public void writeLine(String line) {
defaultPrompter.showMessage(line + System.lineSeparator());
public void writeLine(String line) throws IOException {
defaultPrompter.doDisplay(line + System.lineSeparator());
}

@Override
public String prompt(String message) {
return defaultPrompter.prompt(message, null, null);
public String prompt(String message) throws PrompterException {
try {
return defaultPrompter.prompt(message, null, null);
} catch (org.apache.maven.api.services.PrompterException e) {
throw new PrompterException("Unable to prompt", e);
}
}

@Override
public String prompt(String message, String defaultReply) {
return defaultPrompter.prompt(message, null, defaultReply);
public String prompt(String message, String defaultReply) throws PrompterException {
try {
return defaultPrompter.prompt(message, null, defaultReply);
} catch (org.apache.maven.api.services.PrompterException e) {
throw new PrompterException("Unable to prompt", e);
}
}

@Override
public String prompt(String message, List possibleValues) {
return defaultPrompter.prompt(message, possibleValues, null);
public String prompt(String message, List possibleValues) throws PrompterException {
try {
return defaultPrompter.prompt(message, possibleValues, null);
} catch (org.apache.maven.api.services.PrompterException e) {
throw new PrompterException("Unable to prompt", e);
}
}

@Override
public String prompt(String message, List possibleValues, String defaultReply) {
return defaultPrompter.prompt(message, possibleValues, defaultReply);
public String prompt(String message, List possibleValues, String defaultReply) throws PrompterException {
try {
return defaultPrompter.prompt(message, possibleValues, defaultReply);
} catch (org.apache.maven.api.services.PrompterException e) {
throw new PrompterException("Unable to prompt", e);
}
}

@Override
public String promptForPassword(String message) {
return defaultPrompter.promptForPassword(message);
public String promptForPassword(String message) throws PrompterException {
try {
return defaultPrompter.promptForPassword(message);
} catch (org.apache.maven.api.services.PrompterException e) {
throw new PrompterException("Unable to promptForPassword", e);
}
}

@Override
public void showMessage(String message) {
defaultPrompter.showMessage(message);
public void showMessage(String message) throws PrompterException {
try {
defaultPrompter.showMessage(message);
} catch (org.apache.maven.api.services.PrompterException e) {
throw new PrompterException("Unable to showMessage", e);
}
}
}

0 comments on commit 729bd6b

Please sign in to comment.