Skip to content

Commit 79eff99

Browse files
cstamasslachiewicz
authored andcommitted
Move off plexus
And collapse the build, make jline optional.
1 parent 2da2de8 commit 79eff99

File tree

15 files changed

+120
-149
lines changed

15 files changed

+120
-149
lines changed

plexus-interactivity-api/pom.xml

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,48 @@
1818
<artifactId>plexus-utils</artifactId>
1919
<version>4.0.0</version>
2020
</dependency>
21+
22+
<!-- JLine is optional -->
23+
<dependency>
24+
<groupId>org.jline</groupId>
25+
<artifactId>jline</artifactId>
26+
<version>3.23.0</version>
27+
<optional>true</optional>
28+
</dependency>
29+
30+
<dependency>
31+
<groupId>javax.inject</groupId>
32+
<artifactId>javax.inject</artifactId>
33+
<version>1</version>
34+
<scope>provided</scope>
35+
</dependency>
36+
37+
<!-- Test -->
2138
<dependency>
2239
<groupId>org.junit.jupiter</groupId>
23-
<artifactId>junit-jupiter</artifactId>
40+
<artifactId>junit-jupiter-api</artifactId>
41+
<scope>test</scope>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.eclipse.sisu</groupId>
45+
<artifactId>org.eclipse.sisu.inject</artifactId>
46+
<version>0.9.0.M2</version>
2447
<scope>test</scope>
2548
</dependency>
26-
<!--
27-
| @PostConstruct and @PreDestroy help with Plexus->JSR330 migration
28-
-->
2949
<dependency>
30-
<groupId>javax.annotation</groupId>
31-
<artifactId>javax.annotation-api</artifactId>
32-
<version>1.3.2</version>
50+
<groupId>com.google.inject</groupId>
51+
<artifactId>guice</artifactId>
52+
<version>6.0.0</version>
53+
<scope>test</scope>
3354
</dependency>
3455
</dependencies>
56+
57+
<build>
58+
<plugins>
59+
<plugin>
60+
<groupId>org.eclipse.sisu</groupId>
61+
<artifactId>sisu-maven-plugin</artifactId>
62+
</plugin>
63+
</plugins>
64+
</build>
3565
</project>

plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/AbstractInputHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@
3535
* @version $Id$
3636
*/
3737
public abstract class AbstractInputHandler implements InputHandler {
38+
@Override
3839
public List<String> readMultipleLines() throws IOException {
3940
List<String> lines = new ArrayList<>();
4041
String line = readLine();
41-
while (line != null && line.length() > 0) {
42+
while (line != null && !line.isEmpty()) {
4243
lines.add(line);
4344
line = readLine();
4445
}

plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/DefaultInputHandler.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* SOFTWARE.
2525
*/
2626

27-
import javax.annotation.PostConstruct;
27+
import javax.inject.Named;
2828

2929
import java.io.BufferedReader;
3030
import java.io.IOException;
@@ -36,19 +36,17 @@
3636
* @author Brett Porter
3737
* @version $Id$
3838
*/
39+
@Named
3940
public class DefaultInputHandler extends AbstractInputHandler {
40-
private BufferedReader consoleReader;
41+
private final BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in));
4142

43+
@Override
4244
public String readLine() throws IOException {
4345
return consoleReader.readLine();
4446
}
4547

48+
@Override
4649
public String readPassword() throws IOException {
4750
return consoleReader.readLine();
4851
}
49-
50-
@PostConstruct
51-
public void initialize() {
52-
consoleReader = new BufferedReader(new InputStreamReader(System.in));
53-
}
5452
}

plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/DefaultOutputHandler.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@
2424
* SOFTWARE.
2525
*/
2626

27-
import javax.annotation.PostConstruct;
27+
import javax.inject.Named;
2828

29-
import java.io.IOException;
3029
import java.io.PrintWriter;
3130

3231
/**
@@ -35,20 +34,18 @@
3534
* @author Brett Porter
3635
* @version $Id$
3736
*/
37+
@Named
3838
public class DefaultOutputHandler implements OutputHandler {
39-
private PrintWriter consoleWriter;
39+
private final PrintWriter consoleWriter = new PrintWriter(System.out);
4040

41-
@PostConstruct
42-
public void initialize() {
43-
consoleWriter = new PrintWriter(System.out);
44-
}
45-
46-
public void write(String line) throws IOException {
41+
@Override
42+
public void write(String line) {
4743
consoleWriter.print(line);
4844
consoleWriter.flush();
4945
}
5046

51-
public void writeLine(String line) throws IOException {
47+
@Override
48+
public void writeLine(String line) {
5249
consoleWriter.println();
5350
}
5451
}

plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/DefaultPrompter.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
* SOFTWARE.
2525
*/
2626

27+
import javax.inject.Inject;
28+
import javax.inject.Named;
29+
2730
import java.io.IOException;
2831
import java.util.Iterator;
2932
import java.util.List;
@@ -36,26 +39,19 @@
3639
* @author Brett Porter
3740
* @version $Id$
3841
*/
42+
@Named
3943
public class DefaultPrompter implements Prompter {
40-
/**
41-
* @requirement
42-
*/
43-
private OutputHandler outputHandler;
44-
45-
/**
46-
* @requirement
47-
*/
48-
private InputHandler inputHandler;
49-
50-
public DefaultPrompter() {
51-
super();
52-
}
44+
private final OutputHandler outputHandler;
45+
46+
private final InputHandler inputHandler;
5347

48+
@Inject
5449
public DefaultPrompter(OutputHandler outputHandler, InputHandler inputHandler) {
5550
this.outputHandler = outputHandler;
5651
this.inputHandler = inputHandler;
5752
}
5853

54+
@Override
5955
public String prompt(String message) throws PrompterException {
6056
try {
6157
writePrompt(message);
@@ -70,6 +66,7 @@ public String prompt(String message) throws PrompterException {
7066
}
7167
}
7268

69+
@Override
7370
public String prompt(String message, String defaultReply) throws PrompterException {
7471
try {
7572
writePrompt(formatMessage(message, null, defaultReply));
@@ -90,6 +87,7 @@ public String prompt(String message, String defaultReply) throws PrompterExcepti
9087
}
9188
}
9289

90+
@Override
9391
public String prompt(String message, List<String> possibleValues, String defaultReply) throws PrompterException {
9492
String formattedMessage = formatMessage(message, possibleValues, defaultReply);
9593

@@ -127,10 +125,12 @@ public String prompt(String message, List<String> possibleValues, String default
127125
return line;
128126
}
129127

128+
@Override
130129
public String prompt(String message, List<String> possibleValues) throws PrompterException {
131130
return prompt(message, possibleValues, null);
132131
}
133132

133+
@Override
134134
public String promptForPassword(String message) throws PrompterException {
135135
try {
136136
writePrompt(message);
@@ -177,6 +177,7 @@ private void writePrompt(String message) throws IOException {
177177
outputHandler.write(message + ": ");
178178
}
179179

180+
@Override
180181
public void showMessage(String message) throws PrompterException {
181182
try {
182183
writePrompt(message);

plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/InputHandler.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
* @version $Id$
3838
*/
3939
public interface InputHandler {
40-
String ROLE = InputHandler.class.getName();
41-
4240
/**
4341
* Read a single line of input, swalling the newline at the end.
4442
* If the input can be echoed, it will be.

plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/OutputHandler.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
* @version $Id$
3434
*/
3535
public interface OutputHandler {
36-
String ROLE = OutputHandler.class.getName();
37-
3836
/**
3937
* Write a single line of input, excluding the newline at the end.
4038
* @param line the line

plexus-interactivity-api/src/main/java/org/codehaus/plexus/components/interactivity/Prompter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
* @version $Id$
3434
*/
3535
public interface Prompter {
36-
String ROLE = Prompter.class.getName();
37-
3836
String prompt(String message) throws PrompterException;
3937

4038
String prompt(String message, String defaultReply) throws PrompterException;
Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,23 @@
2424
* SOFTWARE.
2525
*/
2626

27-
import javax.annotation.PostConstruct;
27+
import javax.inject.Named;
2828

2929
import java.io.IOException;
3030

31-
import jline.ConsoleReader;
3231
import org.codehaus.plexus.components.interactivity.AbstractInputHandler;
32+
import org.jline.reader.LineReader;
33+
import org.jline.reader.LineReaderBuilder;
3334

3435
/**
3536
* Default input handler, that uses the console.
3637
*
3738
* @author Brett Porter
3839
* @version $Id$
3940
*/
41+
@Named("jline")
4042
public class JLineInputHandler extends AbstractInputHandler {
41-
private ConsoleReader consoleReader;
43+
private LineReader consoleReader = LineReaderBuilder.builder().build();
4244

4345
public String readLine() throws IOException {
4446
return consoleReader.readLine();
@@ -47,13 +49,4 @@ public String readLine() throws IOException {
4749
public String readPassword() throws IOException {
4850
return consoleReader.readLine(new Character('*'));
4951
}
50-
51-
@PostConstruct
52-
public void initialize() {
53-
try {
54-
consoleReader = new ConsoleReader();
55-
} catch (IOException e) {
56-
throw new IllegalStateException("Cannot create console reader: ", e);
57-
}
58-
}
5952
}

plexus-interactivity-api/src/main/resources/META-INF/plexus/components.xml

Lines changed: 0 additions & 32 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.codehaus.plexus.components.interactivity;
2+
3+
/*
4+
* The MIT License
5+
*
6+
* Copyright (c) 2005, The Codehaus
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
9+
* this software and associated documentation files (the "Software"), to deal in
10+
* the Software without restriction, including without limitation the rights to
11+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12+
* of the Software, and to permit persons to whom the Software is furnished to do
13+
* so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in all
16+
* copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
* SOFTWARE.
25+
*/
26+
27+
import javax.inject.Inject;
28+
29+
import org.eclipse.sisu.launch.InjectedTest;
30+
import org.junit.jupiter.api.Test;
31+
32+
import static org.junit.jupiter.api.Assertions.assertNotNull;
33+
34+
public class DefaultPrompterComponentTest extends InjectedTest {
35+
36+
@Inject
37+
private Prompter prompter;
38+
39+
@Test
40+
void smoke() throws PrompterException {
41+
assertNotNull(prompter);
42+
}
43+
}

0 commit comments

Comments
 (0)