Skip to content

Commit

Permalink
Release v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alekseysotnikov committed Apr 24, 2018
1 parent cc4a0fb commit 7749d3c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 22 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Include the dependency into your `pom.xml`
<dependency>
<groupId>io.github.alekseysotnikov</groupId>
<artifactId>CmdTool</artifactId>
<version>0.4.3</version>
<version>1.0.0</version>
</dependency>
````
Or
Expand All @@ -41,7 +41,7 @@ Or
<dependency>
<groupId>org.cactoos</groupId>
<artifactId>cactoos</artifactId>
<version>0.29</version>
<version>0.30</version>
</dependency>
````
### Examples
Expand Down Expand Up @@ -74,7 +74,9 @@ System.out.println(output);
> Save an output stream into a file, even if the process stopped unexpectedly
```java
new Cmd()
.configuring(new RedirectToFile("./output.txt"))
.configuring(
RedirectToFile.fromOutputStream("./output.txt"),
RedirectToFile.fromErrorStream("./errOutput.txt"))
.command("echo", "Hello")
.execute();
````
Expand All @@ -88,7 +90,7 @@ new Cmd()
.listening((Listening.AfterStop) process -> {
System.out.println(new File("./foo").exists()); //true
})
.command("echo", "hello world")
.command("echo", "Hello")
.execute();

System.out.println(new File("./foo").exists()); // false
Expand Down
11 changes: 3 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>io.github.alekseysotnikov</groupId>
<artifactId>CmdTool</artifactId>
<packaging>jar</packaging>
<version>0.4.3</version>
<version>1.0.0</version>
<name>CmdTool</name>
<description>Intended to execute console commands and scripts from Java easily</description>
<developers>
Expand Down Expand Up @@ -53,7 +53,7 @@
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<configuration><
<formats>
<format>html</format>
<format>xml</format>
Expand All @@ -66,11 +66,6 @@
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<finalName>CmdTool-with-deps-${version}</finalName>
<archive>
<manifest>
<mainClass>com.autodist.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
Expand Down Expand Up @@ -147,7 +142,7 @@
<dependency>
<groupId>org.cactoos</groupId>
<artifactId>cactoos</artifactId>
<version>0.29</version>
<version>0.30</version>
</dependency>
</dependencies>
</project>
4 changes: 2 additions & 2 deletions src/main/java/io/github/alekseysotnikov/cmd/core/Cmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Cmd(Iterable<ProcessListenerAdapter> listeners, Listening.BeforeStart[] c
}

@Override
public Cmd configuring(Listening.BeforeStart... configuring) {
public ICmd configuring(Listening.BeforeStart... configuring) {
return new Cmd(listeners, configuring, interpreter);
}

Expand Down Expand Up @@ -83,7 +83,7 @@ public ICmd listening(Listening.AfterStop... afterStop) {
}

@Override
public Cmd interpreter(String interpreter) {
public ICmd interpreter(String interpreter) {
return new Cmd(listeners, configuring, interpreter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ public final class RedirectToFile implements Listening.BeforeStart, Listening.Af
private final boolean fromErrorStream;
private OutputStream outputStream;

public static RedirectToFile fromOutputStream(String path){
return new RedirectToFile(path);
}

public static RedirectToFile fromErrorStream(String path){
return new RedirectToFile(path, true);
}

public RedirectToFile(String path) {
this(new File(path), false);
}
Expand Down
19 changes: 11 additions & 8 deletions src/test/java/io/github/alekseysotnikov/cmd/CmdTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import io.github.alekseysotnikov.cmd.core.Cmd;
import io.github.alekseysotnikov.cmd.core.Listening;
import io.github.alekseysotnikov.cmd.listeners.CleanUp;
import io.github.alekseysotnikov.cmd.listeners.RedirectToFile;
import io.github.alekseysotnikov.cmd.listeners.RedirectTo;
import io.github.alekseysotnikov.cmd.listeners.RedirectToFile;
import io.github.alekseysotnikov.cmd.listeners.WorkDir;
import org.junit.Test;
import org.zeroturnaround.exec.stream.LogOutputStream;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand Down Expand Up @@ -117,19 +118,21 @@ public void cleanUp() throws Exception {

@Test
public void outputFile() throws Exception {
final String outputPath = "./test.output";
final File workDir = generateRandomPath().toFile();
final String outputFile = "./test.output";
final Path workDirPath = generateRandomPath();
final String FILE_CONTENT = "hello world";
assertThat(true, allOf(
is(not(workDir.exists())),
is(Files.notExists(workDirPath)),
is(0 == new Cmd()
.configuring(
new WorkDir(workDir),
new RedirectToFile(outputPath)
new WorkDir(workDirPath.toFile()),
RedirectToFile.fromOutputStream(outputFile)
)
.command("echo", "hello world")
.command("echo", FILE_CONTENT)
.execute()
.getExitValue()),
is(new File(workDir, outputPath).exists())
is(Files.exists(workDirPath.resolve(outputFile))),
is((FILE_CONTENT + "\n").equals(new String(Files.readAllBytes(workDirPath.resolve(outputFile)))))
));
}

Expand Down

0 comments on commit 7749d3c

Please sign in to comment.