Search in sources :

Example 1 with InvalidExitValueException

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");
}
Also used : BuildContext(org.sonatype.plexus.build.incremental.BuildContext) InvalidExitValueException(org.zeroturnaround.exec.InvalidExitValueException) URL(java.net.URL) Component(org.apache.maven.plugins.annotations.Component) TimeoutException(java.util.concurrent.TimeoutException) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) Parameter(org.apache.maven.plugins.annotations.Parameter) HashSet(java.util.HashSet) URLClassLoader(java.net.URLClassLoader) Lists(com.google.common.collect.Lists) MavenProject(org.apache.maven.project.MavenProject) Map(java.util.Map) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Artifact(org.apache.maven.artifact.Artifact) Path(java.nio.file.Path) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) FileVisitor(java.nio.file.FileVisitor) Files(java.nio.file.Files) Set(java.util.Set) IOException(java.io.IOException) ProcessExecutor(org.zeroturnaround.exec.ProcessExecutor) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Log(org.apache.maven.plugin.logging.Log) Collectors(java.util.stream.Collectors) File(java.io.File) MojoFailureException(org.apache.maven.plugin.MojoFailureException) UncheckedIOException(java.io.UncheckedIOException) FileVisitResult(java.nio.file.FileVisitResult) List(java.util.List) Stream(java.util.stream.Stream) Resource(org.apache.maven.model.Resource) Paths(java.nio.file.Paths) RepositorySystem(org.apache.maven.repository.RepositorySystem) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) AbstractMojo(org.apache.maven.plugin.AbstractMojo) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Log(org.apache.maven.plugin.logging.Log) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ProcessExecutor(org.zeroturnaround.exec.ProcessExecutor) InvalidExitValueException(org.zeroturnaround.exec.InvalidExitValueException) File(java.io.File) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with InvalidExitValueException

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;
}
Also used : ArrayList(java.util.ArrayList) ProcessResult(org.zeroturnaround.exec.ProcessResult) IOException(java.io.IOException) ProcessExecutor(org.zeroturnaround.exec.ProcessExecutor) InvalidExitValueException(org.zeroturnaround.exec.InvalidExitValueException)

Example 3 with InvalidExitValueException

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();
}
Also used : WindowsProcess(org.zeroturnaround.process.WindowsProcess) PidProcess(org.zeroturnaround.process.PidProcess) InvalidExitValueException(org.zeroturnaround.exec.InvalidExitValueException)

Example 4 with InvalidExitValueException

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;
}
Also used : ProcessResult(org.zeroturnaround.exec.ProcessResult) InvalidExitValueException(org.zeroturnaround.exec.InvalidExitValueException) InvalidExitValueException(org.zeroturnaround.exec.InvalidExitValueException)

Example 5 with InvalidExitValueException

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);
    }
}
Also used : ArrayList(java.util.ArrayList) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ProcessExecutor(org.zeroturnaround.exec.ProcessExecutor) File(java.io.File) InvalidExitValueException(org.zeroturnaround.exec.InvalidExitValueException)

Aggregations

InvalidExitValueException (org.zeroturnaround.exec.InvalidExitValueException)11 ProcessExecutor (org.zeroturnaround.exec.ProcessExecutor)9 IOException (java.io.IOException)6 File (java.io.File)5 ProcessResult (org.zeroturnaround.exec.ProcessResult)5 ArrayList (java.util.ArrayList)3 TimeoutException (java.util.concurrent.TimeoutException)3 UncheckedIOException (java.io.UncheckedIOException)2 Objects (java.util.Objects)2 ContainerLaunchException (org.testcontainers.containers.ContainerLaunchException)2 LocalDirectorySSLConfig (com.github.dockerjava.core.LocalDirectorySSLConfig)1 SSLConfig (com.github.dockerjava.transport.SSLConfig)1 Lists (com.google.common.collect.Lists)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 FileVisitResult (java.nio.file.FileVisitResult)1 FileVisitor (java.nio.file.FileVisitor)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1