An open API service indexing awesome lists of open source software.

https://github.com/maxandersen/fluent-process

fork of https://gitlab.com/ongresinc/fluent-process
https://github.com/maxandersen/fluent-process

Last synced: about 1 month ago
JSON representation

fork of https://gitlab.com/ongresinc/fluent-process

Awesome Lists containing this project

README

          

# fluent-process

## Table of content

* [What is it?](#what-is-it)
* [How to use it](#how-to-use-it)
* [How to build](#how-to-build)
* [Maven Profiles](#maven-profiles)

## What is it?

A Java 8 library to provide a Process interface that is fluent and Java Streams oriented.

## How to use it

Just use one of `FluentProcess.start(String command, String...args)` or `FluentProcess.builder(String command, String args...args)` for a more fine grained configuration:

* Will stream `Stream.of("hello", "world")`:

```java
FluentProcess.start(
"sh",
"-c",
"echo hello; echo world")
.stream()
```

* Same result as above but pipelining with `cat`:

```java
FluentProcess.start(
"sh",
"-c",
"echo hello; echo world")
.pipe("cat")
.stream()
```

* Same result as above but passing to `cat` a pure Java Stream:

```java
FluentProcess.start("cat")
.inputStream(
Stream.of("hello", "world"))
.stream()
```

* This will print "hello" followed by "world" but will fail when terminating the Java Stream:

```java
FluentProcess.start(
"sh",
"-c",
"echo hello; echo world; exit 79")
.stream()
.peek(System.out::println)
.count() // <- exception will be thrown here
```

* Same output as the above but will fail when leaving the `try` block:

```java
try (Stream stream = FluentProcess.start(
"sh",
"-c",
"echo hello; echo world; exit 79")
.withoutCloseAfterLast()
.stream()) {
stream
.peek(System.out::println)
.count();
} // <- exception will be thrown here when Stream.close() will be called
```

* Same result as above but will not fail at all:

```java
FluentProcess.start(
"sh",
"-c",
"echo hello; echo world; exit 79")
.withAllowedExitCode(79)
.stream()
.peek(System.out::println)
.count();
```

* You can also specify a timeout that will result in a `ProcessTimeoutException` exception:

```java
FluentProcess.start(
"sh",
"-c",
"sleep 3600")
.withTimeout(Duration.of(1, ChronoUnit.SECONDS))
.stream()
.count(); // <- will throw an ProcessTimeoutException exception
```

## How to build

Java 8 JDK and Maven are required to build this project.

Run following command:

```
mvn clean package
```

## Maven Profiles

- Safer: Slower but safer profile used to look for errors before pushing to SCM

```
mvn verify -P safer
```

### Integration tests

The integration test suite requires a Unix compatible system is installed on the system and and
some very common commands (sh, cat, env and sed).
To launch the integrations tests run the following command:

```
mvn verify -P integration
```

To run integration tests with Java debugging enabled on port 8000:

```
mvn verify -P integration -Dmaven.failsafe.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"
```