use of org.zeroturnaround.exec.InvalidExitValueException in project jax-maven-plugin by davidmoten.
the class BaseMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
Log log = getLog();
log.info("Starting " + cmd + " mojo");
List<File> outputDirectories = //
cmd.getDirectoryParameters().stream().map(param -> Util.createOutputDirectoryIfSpecifiedOrDefault(log, param, arguments)).collect(Collectors.toList());
try {
List<String> command = createCommand();
//
new ProcessExecutor().command(//
command).directory((project.getBasedir())).exitValueNormal().redirectOutput(//
System.out).redirectError(//
System.out).execute();
outputDirectories.forEach(buildContext::refresh);
addSources(log);
addResources(log);
} catch (InvalidExitValueException | IOException | InterruptedException | TimeoutException | DependencyResolutionRequiredException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
log.info(cmd + " mojo finished");
}
use of org.zeroturnaround.exec.InvalidExitValueException in project mvn-golang by raydac.
the class GolangGetMojo method processCustomScriptCallForPackage.
private boolean processCustomScriptCallForPackage(@Nonnull final String packageName, @Nonnull final File rootCvsFolder, @Nonnull final CustomScript script) {
final List<String> command = new ArrayList<>();
command.add(script.path);
if (script.options != null) {
command.addAll(Arrays.asList(script.options));
}
if (getLog().isDebugEnabled()) {
getLog().debug("CLI : " + command);
getLog().debug("Package name : " + packageName);
getLog().debug("Root CVS folder : " + rootCvsFolder);
}
getLog().warn(String.format("Starting script in VCS folder [%s] : %s", packageName, StringUtils.join(command.toArray(), ' ')));
final ProcessExecutor processExecutor = new ProcessExecutor(command.toArray(new String[0]));
processExecutor.exitValueAny().directory(rootCvsFolder).environment("MVNGO_CVS_BRANCH", GetUtils.ensureNonNull(this.branch, "")).environment("MVNGO_CVS_TAG", GetUtils.ensureNonNull(this.tag, "")).environment("MVNGO_CVS_REVISION", GetUtils.ensureNonNull(this.revision, "")).environment("MVNGO_CVS_PACKAGE", packageName).redirectError(System.err).redirectOutput(System.out);
boolean result = false;
try {
final ProcessResult process = processExecutor.executeNoTimeout();
final int exitValue = process.getExitValue();
result = script.ignoreFail || exitValue == 0;
} catch (IOException | InterruptedException | InvalidExitValueException ex) {
getLog().error("Error in custom script processing", ex);
}
return result;
}
use of org.zeroturnaround.exec.InvalidExitValueException in project aws-greengrass-nucleus by aws-greengrass.
the class WindowsPlatform method killProcessAndChildren.
@Override
public Set<Integer> killProcessAndChildren(Process process, boolean force, Set<Integer> additionalPids, UserDecorator decorator) throws IOException, InterruptedException {
PidProcess pp = Processes.newPidProcess(process);
((WindowsProcess) pp).setIncludeChildren(true);
((WindowsProcess) pp).setGracefulDestroyEnabled(true);
try {
pp.destroy(force);
} catch (InvalidExitValueException e) {
// In other words, we rethrow the exception if the process is still alive.
if (process.isAlive()) {
throw e;
}
}
return Collections.emptySet();
}
use of org.zeroturnaround.exec.InvalidExitValueException in project docker-compose-wrapper by sahabpardaz.
the class DockerComposeRunner method execute.
/**
* Executes the given commands using the given executor and ensures that the process exited with 0.
*
* @throws InvalidExitValueException when the commands exit with non-zero value
* @throws IllegalStateException if the commands is not executed properly or being interrupted in the mean time.
*/
private static ProcessResult execute(ProcessExecutor executor, List<String> commands) {
String command = String.join(" ", commands);
ProcessResult result;
try {
result = executor.command(commands).readOutput(true).exitValue(0).execute();
} catch (InvalidExitValueException e) {
throw e;
} catch (Exception e) {
// Also we treat the InterruptedException the same since we don't file in a multi-threaded environment.
throw new IllegalStateException("Fundamental error during running command " + command, e);
}
// Log and validate the result of running
if (logger.isDebugEnabled()) {
logger.debug("Command {} resulted to {}.", command, result.outputString());
}
return result;
}
use of org.zeroturnaround.exec.InvalidExitValueException in project flow by vaadin.
the class BuildFrontendUtil method runFrontendBuildTool.
private static void runFrontendBuildTool(PluginAdapterBase adapter, FrontendTools frontendTools, String toolName, String executable, Map<String, String> environment, String... params) throws TimeoutException, URISyntaxException {
File buildExecutable = new File(adapter.npmFolder(), NODE_MODULES + executable);
if (!buildExecutable.isFile()) {
throw new IllegalStateException(String.format("Unable to locate %s executable by path '%s'. Double" + " check that the plugin is executed correctly", toolName, buildExecutable.getAbsolutePath()));
}
String nodePath;
if (adapter.requireHomeNodeExec()) {
nodePath = frontendTools.forceAlternativeNodeExecutable();
} else {
nodePath = frontendTools.getNodeExecutable();
}
List<String> command = new ArrayList<>();
command.add(nodePath);
command.add(buildExecutable.getAbsolutePath());
command.addAll(Arrays.asList(params));
ProcessBuilder builder = FrontendUtils.createProcessBuilder(command);
ProcessExecutor processExecutor = new ProcessExecutor().command(builder.command()).environment(builder.environment()).environment(environment).directory(adapter.projectBaseDirectory().toFile());
adapter.logInfo("Running " + toolName + " ...");
if (adapter.isDebugEnabled()) {
adapter.logDebug(FrontendUtils.commandToString(adapter.npmFolder().getAbsolutePath(), command));
}
try {
processExecutor.exitValueNormal().readOutput(true).destroyOnExit().execute();
} catch (InvalidExitValueException e) {
throw new IllegalStateException(String.format("%s process exited with non-zero exit code.%nStderr: '%s'", toolName, e.getResult().outputUTF8()), e);
} catch (IOException | InterruptedException e) {
throw new IllegalStateException(String.format("Failed to run %s due to an error", toolName), e);
}
}
Aggregations