Skip to content

Commit 7749d3c

Browse files
Release v1.0.0
1 parent cc4a0fb commit 7749d3c

File tree

5 files changed

+30
-22
lines changed

5 files changed

+30
-22
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Include the dependency into your `pom.xml`
2525
<dependency>
2626
<groupId>io.github.alekseysotnikov</groupId>
2727
<artifactId>CmdTool</artifactId>
28-
<version>0.4.3</version>
28+
<version>1.0.0</version>
2929
</dependency>
3030
````
3131
Or
@@ -41,7 +41,7 @@ Or
4141
<dependency>
4242
<groupId>org.cactoos</groupId>
4343
<artifactId>cactoos</artifactId>
44-
<version>0.29</version>
44+
<version>0.30</version>
4545
</dependency>
4646
````
4747
### Examples
@@ -74,7 +74,9 @@ System.out.println(output);
7474
> Save an output stream into a file, even if the process stopped unexpectedly
7575
```java
7676
new Cmd()
77-
.configuring(new RedirectToFile("./output.txt"))
77+
.configuring(
78+
RedirectToFile.fromOutputStream("./output.txt"),
79+
RedirectToFile.fromErrorStream("./errOutput.txt"))
7880
.command("echo", "Hello")
7981
.execute();
8082
````
@@ -88,7 +90,7 @@ new Cmd()
8890
.listening((Listening.AfterStop) process -> {
8991
System.out.println(new File("./foo").exists()); //true
9092
})
91-
.command("echo", "hello world")
93+
.command("echo", "Hello")
9294
.execute();
9395

9496
System.out.println(new File("./foo").exists()); // false

pom.xml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>io.github.alekseysotnikov</groupId>
55
<artifactId>CmdTool</artifactId>
66
<packaging>jar</packaging>
7-
<version>0.4.3</version>
7+
<version>1.0.0</version>
88
<name>CmdTool</name>
99
<description>Intended to execute console commands and scripts from Java easily</description>
1010
<developers>
@@ -53,7 +53,7 @@
5353
<groupId>org.codehaus.mojo</groupId>
5454
<artifactId>cobertura-maven-plugin</artifactId>
5555
<version>2.7</version>
56-
<configuration>
56+
<configuration><
5757
<formats>
5858
<format>html</format>
5959
<format>xml</format>
@@ -66,11 +66,6 @@
6666
<configuration>
6767
<appendAssemblyId>false</appendAssemblyId>
6868
<finalName>CmdTool-with-deps-${version}</finalName>
69-
<archive>
70-
<manifest>
71-
<mainClass>com.autodist.App</mainClass>
72-
</manifest>
73-
</archive>
7469
<descriptorRefs>
7570
<descriptorRef>jar-with-dependencies</descriptorRef>
7671
</descriptorRefs>
@@ -147,7 +142,7 @@
147142
<dependency>
148143
<groupId>org.cactoos</groupId>
149144
<artifactId>cactoos</artifactId>
150-
<version>0.29</version>
145+
<version>0.30</version>
151146
</dependency>
152147
</dependencies>
153148
</project>

src/main/java/io/github/alekseysotnikov/cmd/core/Cmd.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public Cmd(Iterable<ProcessListenerAdapter> listeners, Listening.BeforeStart[] c
3434
}
3535

3636
@Override
37-
public Cmd configuring(Listening.BeforeStart... configuring) {
37+
public ICmd configuring(Listening.BeforeStart... configuring) {
3838
return new Cmd(listeners, configuring, interpreter);
3939
}
4040

@@ -83,7 +83,7 @@ public ICmd listening(Listening.AfterStop... afterStop) {
8383
}
8484

8585
@Override
86-
public Cmd interpreter(String interpreter) {
86+
public ICmd interpreter(String interpreter) {
8787
return new Cmd(listeners, configuring, interpreter);
8888
}
8989

src/main/java/io/github/alekseysotnikov/cmd/listeners/RedirectToFile.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ public final class RedirectToFile implements Listening.BeforeStart, Listening.Af
2121
private final boolean fromErrorStream;
2222
private OutputStream outputStream;
2323

24+
public static RedirectToFile fromOutputStream(String path){
25+
return new RedirectToFile(path);
26+
}
27+
28+
public static RedirectToFile fromErrorStream(String path){
29+
return new RedirectToFile(path, true);
30+
}
31+
2432
public RedirectToFile(String path) {
2533
this(new File(path), false);
2634
}

src/test/java/io/github/alekseysotnikov/cmd/CmdTest.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import io.github.alekseysotnikov.cmd.core.Cmd;
44
import io.github.alekseysotnikov.cmd.core.Listening;
55
import io.github.alekseysotnikov.cmd.listeners.CleanUp;
6-
import io.github.alekseysotnikov.cmd.listeners.RedirectToFile;
76
import io.github.alekseysotnikov.cmd.listeners.RedirectTo;
7+
import io.github.alekseysotnikov.cmd.listeners.RedirectToFile;
88
import io.github.alekseysotnikov.cmd.listeners.WorkDir;
99
import org.junit.Test;
1010
import org.zeroturnaround.exec.stream.LogOutputStream;
1111

1212
import java.io.File;
1313
import java.io.IOException;
14+
import java.nio.file.Files;
1415
import java.nio.file.Path;
1516
import java.nio.file.Paths;
1617
import java.util.ArrayList;
@@ -117,19 +118,21 @@ public void cleanUp() throws Exception {
117118

118119
@Test
119120
public void outputFile() throws Exception {
120-
final String outputPath = "./test.output";
121-
final File workDir = generateRandomPath().toFile();
121+
final String outputFile = "./test.output";
122+
final Path workDirPath = generateRandomPath();
123+
final String FILE_CONTENT = "hello world";
122124
assertThat(true, allOf(
123-
is(not(workDir.exists())),
125+
is(Files.notExists(workDirPath)),
124126
is(0 == new Cmd()
125127
.configuring(
126-
new WorkDir(workDir),
127-
new RedirectToFile(outputPath)
128+
new WorkDir(workDirPath.toFile()),
129+
RedirectToFile.fromOutputStream(outputFile)
128130
)
129-
.command("echo", "hello world")
131+
.command("echo", FILE_CONTENT)
130132
.execute()
131133
.getExitValue()),
132-
is(new File(workDir, outputPath).exists())
134+
is(Files.exists(workDirPath.resolve(outputFile))),
135+
is((FILE_CONTENT + "\n").equals(new String(Files.readAllBytes(workDirPath.resolve(outputFile)))))
133136
));
134137
}
135138

0 commit comments

Comments
 (0)