Ensured exit status is set on failure
This commit is contained in:
parent
df9aee7ca3
commit
8f4bb51dd2
1 changed files with 38 additions and 26 deletions
|
@ -18,9 +18,9 @@ package rife.bld.extension;
|
||||||
|
|
||||||
import rife.bld.BaseProject;
|
import rife.bld.BaseProject;
|
||||||
import rife.bld.operations.AbstractOperation;
|
import rife.bld.operations.AbstractOperation;
|
||||||
|
import rife.bld.operations.exceptions.ExitStatusException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -89,9 +89,11 @@ public class ExecOperation extends AbstractOperation<ExecOperation> {
|
||||||
@Override
|
@Override
|
||||||
public void execute() throws Exception {
|
public void execute() throws Exception {
|
||||||
if (project_ == null) {
|
if (project_ == null) {
|
||||||
|
if (LOGGER.isLoggable(Level.SEVERE) && !silent()) {
|
||||||
LOGGER.severe("A project must be specified.");
|
LOGGER.severe("A project must be specified.");
|
||||||
}
|
}
|
||||||
|
throw new ExitStatusException(ExitStatusException.EXIT_FAILURE);
|
||||||
|
} else {
|
||||||
final File workDir = Objects.requireNonNullElseGet(workDir_,
|
final File workDir = Objects.requireNonNullElseGet(workDir_,
|
||||||
() -> new File(project_.workDirectory().getAbsolutePath()));
|
() -> new File(project_.workDirectory().getAbsolutePath()));
|
||||||
|
|
||||||
|
@ -105,7 +107,7 @@ public class ExecOperation extends AbstractOperation<ExecOperation> {
|
||||||
pb.command(args_.stream().toList());
|
pb.command(args_.stream().toList());
|
||||||
pb.directory(workDir);
|
pb.directory(workDir);
|
||||||
|
|
||||||
if (LOGGER.isLoggable(Level.INFO)) {
|
if (LOGGER.isLoggable(Level.INFO) && !silent()) {
|
||||||
LOGGER.info(String.join(" ", args_));
|
LOGGER.info(String.join(" ", args_));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,12 +116,22 @@ public class ExecOperation extends AbstractOperation<ExecOperation> {
|
||||||
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
proc.destroy();
|
proc.destroy();
|
||||||
throw new IOException("The command timed out.");
|
if (LOGGER.isLoggable(Level.SEVERE) && !silent()) {
|
||||||
|
LOGGER.severe("The command timed out.");
|
||||||
|
}
|
||||||
|
throw new ExitStatusException(ExitStatusException.EXIT_FAILURE);
|
||||||
} else if (proc.exitValue() != 0 && failOnExit_) {
|
} else if (proc.exitValue() != 0 && failOnExit_) {
|
||||||
throw new IOException("The command exit value/status is: " + proc.exitValue());
|
if (LOGGER.isLoggable(Level.SEVERE) && !silent()) {
|
||||||
|
LOGGER.severe("The command exit value/status is: " + proc.exitValue());
|
||||||
|
}
|
||||||
|
ExitStatusException.throwOnFailure(proc.exitValue());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new IOException("Invalid working directory: " + workDir);
|
if (LOGGER.isLoggable(Level.SEVERE) && !silent()) {
|
||||||
|
LOGGER.severe("Invalid working directory: " + workDir);
|
||||||
|
}
|
||||||
|
throw new ExitStatusException(ExitStatusException.EXIT_FAILURE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue