diff --git a/README.md b/README.md
index 0192b9a..c707871 100755
--- a/README.md
+++ b/README.md
@@ -21,10 +21,9 @@ public void startServer() throws Exception {
}
```
-### Failure Modes
+## Exit Status
-Use the `fail` function to specify whether data returned to the standard streams and/or an abnormal exit value
-constitute a failure.
+Use the `failOnExit` function to specify whether a command non-zero exit status constitutes a failure.
```java
@BuildCommand
@@ -38,28 +37,14 @@ public void startServer() throws Exception {
new ExecOperation()
.fromProject(this)
.command(cmds)
- .fail(ExecFail.STDERR)
+ .failOneExit(false)
.execute();
}
```
-The following predefined values are available:
+## Work Directory
-| Name | Failure When |
-|:------------------|:-----------------------------------------------------------------|
-| `ExecFail.EXIT` | Exit value > 0 |
-| `ExecFail.NORMAL` | Exit value > 0 or any data to the standard error stream (stderr) |
-| `ExecFail.OUTPUT` | Any data to the standard output stream (stdout) or stderr. |
-| `ExecFail.STDERR` | Any data to stderr. |
-| `ExecFail.STDOUT` | Any data to stdout. |
-| `ExecFail.ALL` | Any of the conditions above. |
-| `ExecFail.NONE` | Never fails. |
-
-`ExecFail.NORMAL` is the default value.
-
-## Working Directory
-
-You can also specify the working directory:
+You can also specify the work directory:
```java
@BuildCommand
diff --git a/src/bld/java/rife/bld/extension/ExecOperationBuild.java b/src/bld/java/rife/bld/extension/ExecOperationBuild.java
index 9d29282..37db549 100644
--- a/src/bld/java/rife/bld/extension/ExecOperationBuild.java
+++ b/src/bld/java/rife/bld/extension/ExecOperationBuild.java
@@ -35,7 +35,7 @@ public class ExecOperationBuild extends Project {
public ExecOperationBuild() {
pkg = "rife.bld.extension";
name = "ExecOperation";
- version = version(0, 9, 3);
+ version = version(1, 0, 0);
javaRelease = 17;
diff --git a/src/main/java/rife/bld/extension/ExecFail.java b/src/main/java/rife/bld/extension/ExecFail.java
deleted file mode 100644
index a6221b6..0000000
--- a/src/main/java/rife/bld/extension/ExecFail.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright 2023-2024 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package rife.bld.extension;
-
-/**
- * The failure modes enumeration.
- *
- * @author Erik C. Thauvin
- * @since 1.0
- */
-public enum ExecFail {
- ALL, EXIT, NONE, NORMAL, OUTPUT, STDERR, STDOUT
-}
diff --git a/src/main/java/rife/bld/extension/ExecOperation.java b/src/main/java/rife/bld/extension/ExecOperation.java
index 56e9658..f07d740 100644
--- a/src/main/java/rife/bld/extension/ExecOperation.java
+++ b/src/main/java/rife/bld/extension/ExecOperation.java
@@ -21,8 +21,9 @@ import rife.bld.operations.AbstractOperation;
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -36,7 +37,7 @@ import java.util.logging.Logger;
public class ExecOperation extends AbstractOperation {
private static final Logger LOGGER = Logger.getLogger(ExecOperation.class.getName());
private final List args_ = new ArrayList<>();
- private final Set fail_ = new HashSet<>();
+ private boolean failOnExit_ = true;
private BaseProject project_;
private int timeout = 30;
private String workDir_;
@@ -80,8 +81,6 @@ public class ExecOperation extends AbstractOperation {
LOGGER.severe("A project must be specified.");
}
- var errorMessage = new StringBuilder(27);
-
final File workDir;
if (workDir_ == null || workDir_.isBlank()) {
workDir = new File(project_.workDirectory().getAbsolutePath());
@@ -91,6 +90,7 @@ public class ExecOperation extends AbstractOperation {
if (workDir.isDirectory()) {
var pb = new ProcessBuilder();
+ pb.inheritIO();
pb.command(args_);
pb.directory(workDir);
@@ -100,63 +100,28 @@ public class ExecOperation extends AbstractOperation {
var proc = pb.start();
var err = proc.waitFor(timeout, TimeUnit.SECONDS);
- var stdout = readStream(proc.getInputStream());
- var stderr = readStream(proc.getErrorStream());
if (!err) {
- errorMessage.append("TIMEOUT");
- } else if (!fail_.contains(ExecFail.NONE)) {
- var all = fail_.contains(ExecFail.ALL);
- var output = fail_.contains(ExecFail.OUTPUT);
- if ((all || fail_.contains(ExecFail.EXIT) || fail_.contains(ExecFail.NORMAL)) && proc.exitValue() > 0) {
- errorMessage.append("EXIT ").append(proc.exitValue());
- if (!stderr.isEmpty()) {
- errorMessage.append(", STDERR -> ").append(stderr.get(0));
- } else if (!stdout.isEmpty()) {
- errorMessage.append(", STDOUT -> ").append(stdout.get(0));
- }
- } else if ((all || output || fail_.contains(ExecFail.STDERR) || fail_.contains(ExecFail.NORMAL))
- && !stderr.isEmpty()) {
- errorMessage.append("STDERR -> ").append(stderr.get(0));
- } else if ((all || output || fail_.contains(ExecFail.STDOUT)) && !stdout.isEmpty()) {
- errorMessage.append("STDOUT -> ").append(stdout.get(0));
- }
- }
-
- if (LOGGER.isLoggable(Level.INFO) && errorMessage.isEmpty() && !stdout.isEmpty()) {
- for (var l : stdout) {
- LOGGER.info(l);
- }
+ proc.destroy();
+ throw new IOException("The command timed out.");
+ } else if (proc.exitValue() != 0 && failOnExit_) {
+ throw new IOException("The command exit status is: " + proc.exitValue());
}
} else {
- errorMessage.append("Invalid working directory: ").append(workDir.getCanonicalPath());
- }
-
- if (!errorMessage.isEmpty()) {
- throw new IOException(errorMessage.toString());
+ throw new IOException("Invalid work directory: " + workDir);
}
}
/**
- * Configure the failure mode.
+ * Configures whether the operation should fail if the command exit status is not 0.
*
- * The failure modes are:
- *
- *
{@link ExecFail#EXIT}
Exit value > 0
- *
{@link ExecFail#NORMAL}
Exit value > 0 or any data to the standard error stream (stderr)
- *
{@link ExecFail#OUTPUT}
Any data to the standard output stream (stdout) or stderr