Skip to content

Commit 33ea799

Browse files
Docs and Tests
1 parent d5e5d9e commit 33ea799

File tree

10 files changed

+559
-94
lines changed

10 files changed

+559
-94
lines changed

README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
![](https://github.com/wniemiec-io-java/terminal/blob/master/docs/img/logo/logo.jpg)
2+
3+
<h1 align='center'>Terminal</h1>
4+
<p align='center'>Utility for executing commands in a terminal.</p>
5+
<p align="center">
6+
<a href="https://github.com/wniemiec-io-java/terminal/actions/workflows/windows.yml"><img src="https://github.com/wniemiec-io-java/terminal/actions/workflows/windows.yml/badge.svg" alt=""></a>
7+
<a href="https://github.com/wniemiec-io-java/terminal/actions/workflows/macos.yml"><img src="https://github.com/wniemiec-io-java/terminal/actions/workflows/macos.yml/badge.svg" alt=""></a>
8+
<a href="https://github.com/wniemiec-io-java/terminal/actions/workflows/ubuntu.yml"><img src="https://github.com/wniemiec-io-java/terminal/actions/workflows/ubuntu.yml/badge.svg" alt=""></a>
9+
<a href="https://codecov.io/gh/wniemiec-io-java/terminal"><img src="https://codecov.io/gh/wniemiec-io-java/terminal/branch/master/graph/badge.svg?token=R2SFS4SP86" alt="Coverage status"></a>
10+
<a href="http://java.oracle.com"><img src="https://img.shields.io/badge/java-11+-D0008F.svg" alt="Java compatibility"></a>
11+
<a href="https://mvnrepository.com/artifact/io.github.wniemiec-io-java/terminal"><img src="https://img.shields.io/maven-central/v/io.github.wniemiec-io-java/terminal" alt="Maven Central release"></a>
12+
<a href="https://github.com/wniemiec-io-java/terminal/blob/master/LICENSE"><img src="https://img.shields.io/github/license/wniemiec-io-java/terminal" alt="License"></a>
13+
</p>
14+
<hr />
15+
16+
## ❇ Introduction
17+
Easy-to-use terminal manager, featuring history, error history and execution of multiple commands.
18+
19+
## ❓ How to use
20+
21+
1. Add one of the options below to the pom.xml file:
22+
23+
#### Using Maven Central (recomended):
24+
```
25+
<dependency>
26+
<groupId>io.github.wniemiec-io-java</groupId>
27+
<artifactId>terminal</artifactId>
28+
<version>LATEST</version>
29+
</dependency>
30+
```
31+
32+
2. Run
33+
```
34+
$ mvn install
35+
```
36+
37+
3. Use it
38+
```
39+
[...]
40+
41+
import wniemiec.io.java.Terminal;
42+
import wniemiec.io.java.StandardTerminalBuilder;
43+
44+
[...]
45+
46+
Terminal terminal = StandardTerminalBuilder
47+
.getInstance()
48+
.outputHandler(message -> { System.out.println("Terminal said " + message); })
49+
.outputErrorHandler(message -> { System.err.println("Terminal said " + message); })
50+
.build();
51+
52+
terminal.exec("echo", "hello");
53+
```
54+
55+
## 📖 Documentation
56+
| Property |Type|Description|Default|
57+
|----------------|-------------------------------|-----------------------------|--------|
58+
|implode |`(list: List<T>, delimiter: String): String`|Converts elements of a list into a string by separating each element with a delimiter| - |
59+
|capitalize |`(text: String): String`|Converts elements of a list into a string by separating each element with a delimiter| - |
60+
61+
62+
## 🚩 Changelog
63+
Details about each version are documented in the [releases section](https://github.com/williamniemiec/wniemiec-io-java/terminal/releases).
64+
65+
## 🤝 Contribute!
66+
See the documentation on how you can contribute to the project [here](https://github.com/wniemiec-io-java/terminal/blob/master/CONTRIBUTING.md).
67+
68+
## 📁 Files
69+
70+
### /
71+
| Name |Type|Description|
72+
|----------------|-------------------------------|-----------------------------|
73+
|dist |`Directory`|Released versions|
74+
|docs |`Directory`|Documentation files|
75+
|src |`Directory`| Source files|

pom.xml

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>io.github.wniemiec-io-java</groupId>
8+
<artifactId>terminal</artifactId>
9+
<version>1.0.0</version>
10+
<name>Terminal</name>
11+
<description>Utility for executing commands in a terminal.</description>
12+
<url>https://github.com/wniemiec-io-java/terminal</url>
13+
14+
<properties>
15+
<version.major>1</version.major>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
<java.source-target.version>11</java.source-target.version>
18+
</properties>
19+
20+
<licenses>
21+
<license>
22+
<name>MIT License</name>
23+
<url>http://www.opensource.org/licenses/mit-license.php</url>
24+
</license>
25+
</licenses>
26+
27+
<developers>
28+
<developer>
29+
<id>williamniemiec</id>
30+
<name>William Niemiec</name>
31+
<email>[email protected]</email>
32+
</developer>
33+
</developers>
34+
35+
<scm>
36+
<connection>scm:git:[email protected]:wniemiec-io-java/terminal.git</connection>
37+
<developerConnection>scm:git:ssh://github.com:wniemiec-io-java/terminal.git</developerConnection>
38+
<url>https://github.com/wniemiec-io-java/terminal/tree/main</url>
39+
</scm>
40+
41+
<distributionManagement>
42+
<snapshotRepository>
43+
<id>ossrh</id>
44+
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
45+
</snapshotRepository>
46+
<repository>
47+
<id>ossrh</id>
48+
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2</url>
49+
</repository>
50+
</distributionManagement>
51+
52+
<dependencies>
53+
<dependency>
54+
<groupId>org.junit.jupiter</groupId>
55+
<artifactId>junit-jupiter</artifactId>
56+
<version>5.7.0</version>
57+
<scope>test</scope>
58+
</dependency>
59+
</dependencies>
60+
61+
<build>
62+
<resources>
63+
<resource>
64+
<directory>src/main/java</directory>
65+
<includes>
66+
<include>**/*.java</include>
67+
<include>**/*.gwt.xml</include>
68+
</includes>
69+
</resource>
70+
</resources>
71+
72+
<plugins>
73+
<plugin>
74+
<artifactId>maven-clean-plugin</artifactId>
75+
<version>3.1.0</version>
76+
</plugin>
77+
78+
<plugin>
79+
<artifactId>maven-resources-plugin</artifactId>
80+
<version>3.0.2</version>
81+
</plugin>
82+
83+
<plugin>
84+
<groupId>org.apache.maven.plugins</groupId>
85+
<artifactId>maven-compiler-plugin</artifactId>
86+
<version>3.8.0</version>
87+
<configuration>
88+
<source>${java.source-target.version}</source>
89+
<target>${java.source-target.version}</target>
90+
<useIncrementalCompilation>false</useIncrementalCompilation>
91+
</configuration>
92+
</plugin>
93+
94+
<plugin>
95+
<groupId>org.apache.maven.plugins</groupId>
96+
<artifactId>maven-surefire-plugin</artifactId>
97+
<version>2.22.2</version>
98+
</plugin>
99+
100+
<plugin>
101+
<artifactId>maven-jar-plugin</artifactId>
102+
<version>3.0.2</version>
103+
<configuration>
104+
<outputDirectory>${project.build.directory}/../dist/${version.major}.x</outputDirectory>
105+
</configuration>
106+
</plugin>
107+
108+
<plugin>
109+
<artifactId>maven-install-plugin</artifactId>
110+
<version>2.5.2</version>
111+
</plugin>
112+
113+
<plugin>
114+
<artifactId>maven-deploy-plugin</artifactId>
115+
<version>2.8.2</version>
116+
</plugin>
117+
118+
<plugin>
119+
<artifactId>maven-site-plugin</artifactId>
120+
<version>3.7.1</version>
121+
</plugin>
122+
123+
<plugin>
124+
<artifactId>maven-project-info-reports-plugin</artifactId>
125+
<version>3.0.0</version>
126+
</plugin>
127+
128+
<plugin>
129+
<groupId>org.apache.maven.plugins</groupId>
130+
<artifactId>maven-source-plugin</artifactId>
131+
<version>3.2.1</version>
132+
<executions>
133+
<execution>
134+
<id>attach-sources</id>
135+
<goals>
136+
<goal>jar-no-fork</goal>
137+
</goals>
138+
</execution>
139+
</executions>
140+
</plugin>
141+
142+
<plugin>
143+
<groupId>org.apache.maven.plugins</groupId>
144+
<artifactId>maven-javadoc-plugin</artifactId>
145+
<version>3.2.0</version>
146+
<configuration>
147+
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
148+
</configuration>
149+
<executions>
150+
<execution>
151+
<id>attach-javadocs</id>
152+
<goals>
153+
<goal>jar</goal>
154+
</goals>
155+
</execution>
156+
</executions>
157+
</plugin>
158+
159+
<!-- Coverage -->
160+
<plugin>
161+
<groupId>org.jacoco</groupId>
162+
<artifactId>jacoco-maven-plugin</artifactId>
163+
<version>0.8.6</version>
164+
<executions>
165+
<execution>
166+
<id>jacoco-initialize</id>
167+
<goals>
168+
<goal>prepare-agent</goal>
169+
</goals>
170+
</execution>
171+
<execution>
172+
<id>jacoco-site</id>
173+
<phase>package</phase>
174+
<goals>
175+
<goal>report</goal>
176+
</goals>
177+
</execution>
178+
</executions>
179+
</plugin>
180+
</plugins>
181+
</build>
182+
183+
<profiles>
184+
<profile>
185+
<id>ci-cd</id>
186+
<build>
187+
<plugins>
188+
<plugin>
189+
<groupId>org.apache.maven.plugins</groupId>
190+
<artifactId>maven-gpg-plugin</artifactId>
191+
<version>1.6</version>
192+
<executions>
193+
<execution>
194+
<id>sign-artifacts</id>
195+
<phase>verify</phase>
196+
<goals>
197+
<goal>sign</goal>
198+
</goals>
199+
<configuration>
200+
<!-- Prevent gpg from using pinentry programs. Fixes: gpg: signing
201+
failed: Inappropriate ioctl for device -->
202+
<gpgArguments>
203+
<arg>--pinentry-mode</arg>
204+
<arg>loopback</arg>
205+
</gpgArguments>
206+
</configuration>
207+
</execution>
208+
</executions>
209+
</plugin>
210+
</plugins>
211+
</build>
212+
</profile>
213+
</profiles>
214+
</project>

src/main/java/wniemiec/io/java/StandardInputTerminal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class StandardInputTerminal implements InputTerminal {
4444
throw new IllegalArgumentException("Output terminal cannot be null");
4545
}
4646

47-
this.workingDirectory = workingDirectory.toFile();
47+
this.workingDirectory = (workingDirectory == null) ? null : workingDirectory.toFile();
4848
this.outputTerminal = outputTerminal;
4949
runtime = Runtime.getRuntime();
5050
}

src/main/java/wniemiec/io/java/StandardTerminalBuilder.java

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,32 @@ public class StandardTerminalBuilder {
1919
//-------------------------------------------------------------------------
2020
// Attributes
2121
//-------------------------------------------------------------------------
22+
private static StandardTerminalBuilder instance;
2223
private InputTerminal inputTerminal;
2324
private OutputTerminal outputTerminal;
2425
private Path workingDirectory;
2526
private Consumer<String> outputHandler;
2627
private Consumer<String> outputErrorHandler;
28+
29+
30+
31+
//-------------------------------------------------------------------------
32+
// Constructor
33+
//-------------------------------------------------------------------------
34+
private StandardTerminalBuilder() {
35+
}
36+
37+
38+
//-------------------------------------------------------------------------
39+
// Factory
40+
//-------------------------------------------------------------------------
41+
public static StandardTerminalBuilder getInstance() {
42+
if (instance == null) {
43+
instance = new StandardTerminalBuilder();
44+
}
45+
46+
return instance;
47+
}
2748

2849

2950
//-------------------------------------------------------------------------
@@ -47,18 +68,6 @@ public StandardTerminalBuilder outputErrorHandler(Consumer<String> outputErrorHa
4768
return this;
4869
}
4970

50-
public StandardTerminalBuilder inputTerminal(InputTerminal inputTerminal) {
51-
this.inputTerminal = inputTerminal;
52-
53-
return this;
54-
}
55-
56-
public StandardTerminalBuilder outputTerminal(OutputTerminal outputTerminal) {
57-
this.outputTerminal = outputTerminal;
58-
59-
return this;
60-
}
61-
6271
public Terminal build() {
6372
buildOutputTerminal();
6473
buildInputTerminal();
@@ -67,18 +76,10 @@ public Terminal build() {
6776
}
6877

6978
private void buildOutputTerminal() {
70-
if (outputTerminal != null) {
71-
return;
72-
}
73-
7479
outputTerminal = new StandardOutputTerminal(outputHandler, outputErrorHandler);
7580
}
7681

7782
private void buildInputTerminal() {
78-
if (inputTerminal != null) {
79-
return;
80-
}
81-
8283
inputTerminal = new StandardInputTerminal(workingDirectory, outputTerminal);
8384
}
8485

0 commit comments

Comments
 (0)