org.gradle.process.internal.ExecAction Java Examples

The following examples show how to use org.gradle.process.internal.ExecAction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RunTask.java    From azure-gradle-plugins with MIT License 6 votes vote down vote up
private void runCommand(final String[] command, final boolean showStdout, final List<Long> validReturnCodes,
                              final String errorMessage) throws Exception {
        getLogger().quiet("Executing command: " + StringUtils.join(command, " "));

        ExecAction action = new DefaultExecActionFactory(getServices().get(FileResolver.class)).newExecAction();
        action.setCommandLine(command);
        action.execute();
//        final ProcessBuilder.Redirect redirect = getStdoutRedirect(showStdout);
//        final Process process = new ProcessBuilder(command)
//                .redirectOutput(redirect)
//                .redirectErrorStream(true)
//                .start();
//
//        process.waitFor();
//
//        handleExitValue(process.exitValue(), validReturnCodes, errorMessage, process.getInputStream());
    }
 
Example #2
Source File: JavadocExecHandleBuilder.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ExecAction getExecHandle() {
    try {
        options.write(optionsFile);
    } catch (IOException e) {
        throw new GradleException("Failed to store javadoc options.", e);
    }

    ExecAction execAction = execActionFactory.newExecAction();
    execAction.workingDir(execDirectory);
    execAction.executable(GUtil.elvis(executable, Jvm.current().getJavadocExecutable()));
    execAction.args("@" + optionsFile.getAbsolutePath());

    options.contributeCommandLineOptions(execAction);

    return execAction;
}
 
Example #3
Source File: Javadoc.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void executeExternalJavadoc() {
    javadocExecHandleBuilder.setExecutable(executable);
    javadocExecHandleBuilder.execDirectory(getProject().getRootDir()).options(options).optionsFile(
            getOptionsFile());

    ExecAction execAction = javadocExecHandleBuilder.getExecHandle();
    if (!failOnError) {
        execAction.setIgnoreExitValue(true);
    }

    try {
        execAction.execute();
    } catch (ExecException e) {
        throw new GradleException("Javadoc generation failed.", e);
    }
}
 
Example #4
Source File: CommandLineTool.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public WorkResult execute(T spec) {
    ExecAction compiler = execActionFactory.newExecAction();
    compiler.executable(executable);
    if (workDir != null) {
        compiler.workingDir(workDir);
    }

    List<String> args = specToArgs.transform(specTransformer.transform(spec));
    compiler.args(args);

    if (!path.isEmpty()) {
        String pathVar = OperatingSystem.current().getPathVar();
        String compilerPath = Joiner.on(File.pathSeparator).join(path);
        compilerPath = compilerPath + File.pathSeparator + System.getenv(pathVar);
        compiler.environment(pathVar, compilerPath);
    }

    compiler.environment(environment);

    try {
        compiler.execute();
    } catch (ExecException e) {
        throw new GradleException(String.format("%s failed; see the error output for details.", action), e);
    }
    return new SimpleWorkResult(true);
}
 
Example #5
Source File: GccVersionDeterminer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public String transform(File gccBinary) {
    ExecAction exec = execActionFactory.newExecAction();
    exec.executable(gccBinary.getAbsolutePath());
    exec.setWorkingDir(gccBinary.getParentFile());
    exec.args("-dM", "-E", "-");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    exec.setStandardOutput(baos);
    exec.setIgnoreExitValue(true);
    ExecResult result = exec.execute();

    int exitValue = result.getExitValue();
    if (exitValue == 0) {
        return new String(baos.toByteArray());
    } else {
        return null;
    }
}
 
Example #6
Source File: JavadocExecHandleBuilder.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ExecAction getExecHandle() {
    try {
        options.write(optionsFile);
    } catch (IOException e) {
        throw new GradleException("Failed to store javadoc options.", e);
    }

    ExecAction execAction = execActionFactory.newExecAction();
    execAction.workingDir(execDirectory);
    execAction.executable(GUtil.elvis(executable, Jvm.current().getJavadocExecutable()));
    execAction.args("@" + optionsFile.getAbsolutePath());

    options.contributeCommandLineOptions(execAction);

    return execAction;
}
 
Example #7
Source File: JavadocGenerator.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public WorkResult execute(JavadocSpec spec) {
    JavadocExecHandleBuilder javadocExecHandleBuilder = new JavadocExecHandleBuilder(execActionFactory);
    javadocExecHandleBuilder.setExecutable(spec.getExecutable());
    javadocExecHandleBuilder.execDirectory(spec.getWorkingDir()).options(spec.getOptions()).optionsFile(spec.getOptionsFile());

    ExecAction execAction = javadocExecHandleBuilder.getExecHandle();
    if (spec.isIgnoreFailures()) {
        execAction.setIgnoreExitValue(true);
    }

    try {
        execAction.execute();
    } catch (ExecException e) {
        LOG.info("Problems generating Javadoc. The generated Javadoc options file used by Gradle has following contents:\n------\n{}------", GFileUtils.readFileQuietly(spec.getOptionsFile()));
        throw new GradleException(String.format("Javadoc generation failed. Generated Javadoc options file (useful for troubleshooting): '%s'", spec.getOptionsFile()), e);
    }

    return new SimpleWorkResult(true);
}
 
Example #8
Source File: CommandLineTool.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void execute(CommandLineToolInvocation invocation) {
    ExecAction compiler = execActionFactory.newExecAction();
    compiler.executable(executable);
    if (invocation.getWorkDirectory() != null) {
        GFileUtils.mkdirs(invocation.getWorkDirectory());
        compiler.workingDir(invocation.getWorkDirectory());
    }

    compiler.args(invocation.getArgs());

    if (!invocation.getPath().isEmpty()) {
        String pathVar = OperatingSystem.current().getPathVar();
        String compilerPath = Joiner.on(File.pathSeparator).join(invocation.getPath());
        compilerPath = compilerPath + File.pathSeparator + System.getenv(pathVar);
        compiler.environment(pathVar, compilerPath);
    }

    compiler.environment(invocation.getEnvironment());

    try {
        compiler.execute();
    } catch (ExecException e) {
        throw new GradleException(String.format("%s failed; see the error output for details.", action), e);
    }
}
 
Example #9
Source File: GccVersionDeterminer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private String transform(File gccBinary, List<String> args) {
    ExecAction exec = execActionFactory.newExecAction();
    exec.executable(gccBinary.getAbsolutePath());
    exec.setWorkingDir(gccBinary.getParentFile());
    exec.args(args);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    exec.setStandardOutput(baos);
    exec.setErrorOutput(new ByteArrayOutputStream());
    exec.setIgnoreExitValue(true);
    ExecResult result = exec.execute();

    int exitValue = result.getExitValue();
    if (exitValue == 0) {
        return new String(baos.toByteArray());
    } else {
        return null;
    }
}
 
Example #10
Source File: JavadocExecHandleBuilder.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ExecAction getExecHandle() {
    try {
        options.write(optionsFile);
    } catch (IOException e) {
        throw new GradleException("Failed to store javadoc options.", e);
    }

    ExecAction execAction = execActionFactory.newExecAction();
    execAction.workingDir(execDirectory);
    execAction.executable(GUtil.elvis(executable, Jvm.current().getJavadocExecutable()));
    execAction.args("@" + optionsFile.getAbsolutePath());

    options.contributeCommandLineOptions(execAction);

    return execAction;
}
 
Example #11
Source File: Javadoc.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void executeExternalJavadoc() {
    javadocExecHandleBuilder.setExecutable(executable);
    javadocExecHandleBuilder.execDirectory(getProject().getRootDir()).options(options).optionsFile(
            getOptionsFile());

    ExecAction execAction = javadocExecHandleBuilder.getExecHandle();
    if (!failOnError) {
        execAction.setIgnoreExitValue(true);
    }

    try {
        execAction.execute();
    } catch (ExecException e) {
        throw new GradleException("Javadoc generation failed.", e);
    }
}
 
Example #12
Source File: CommandLineTool.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public WorkResult execute(T spec) {
    ExecAction compiler = execActionFactory.newExecAction();
    compiler.executable(executable);
    if (workDir != null) {
        compiler.workingDir(workDir);
    }

    List<String> args = specToArgs.transform(specTransformer.transform(spec));
    compiler.args(args);

    if (!path.isEmpty()) {
        String pathVar = OperatingSystem.current().getPathVar();
        String compilerPath = Joiner.on(File.pathSeparator).join(path);
        compilerPath = compilerPath + File.pathSeparator + System.getenv(pathVar);
        compiler.environment(pathVar, compilerPath);
    }

    compiler.environment(environment);

    try {
        compiler.execute();
    } catch (ExecException e) {
        throw new GradleException(String.format("%s failed; see the error output for details.", action), e);
    }
    return new SimpleWorkResult(true);
}
 
Example #13
Source File: GccVersionDeterminer.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public String transform(File gccBinary) {
    ExecAction exec = execActionFactory.newExecAction();
    exec.executable(gccBinary.getAbsolutePath());
    exec.setWorkingDir(gccBinary.getParentFile());
    exec.args("-dM", "-E", "-");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    exec.setStandardOutput(baos);
    exec.setIgnoreExitValue(true);
    ExecResult result = exec.execute();

    int exitValue = result.getExitValue();
    if (exitValue == 0) {
        return new String(baos.toByteArray());
    } else {
        return null;
    }
}
 
Example #14
Source File: JavadocExecHandleBuilder.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ExecAction getExecHandle() {
    try {
        options.write(optionsFile);
    } catch (IOException e) {
        throw new GradleException("Failed to store javadoc options.", e);
    }

    ExecAction execAction = execActionFactory.newExecAction();
    execAction.workingDir(execDirectory);
    execAction.executable(GUtil.elvis(executable, Jvm.current().getJavadocExecutable()));
    execAction.args("@" + optionsFile.getAbsolutePath());

    options.contributeCommandLineOptions(execAction);

    return execAction;
}
 
Example #15
Source File: JavadocGenerator.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public WorkResult execute(JavadocSpec spec) {
    JavadocExecHandleBuilder javadocExecHandleBuilder = new JavadocExecHandleBuilder(execActionFactory);
    javadocExecHandleBuilder.setExecutable(spec.getExecutable());
    javadocExecHandleBuilder.execDirectory(spec.getWorkingDir()).options(spec.getOptions()).optionsFile(spec.getOptionsFile());

    ExecAction execAction = javadocExecHandleBuilder.getExecHandle();
    if (spec.isIgnoreFailures()) {
        execAction.setIgnoreExitValue(true);
    }

    try {
        execAction.execute();
    } catch (ExecException e) {
        LOG.info("Problems generating Javadoc. The generated Javadoc options file used by Gradle has following contents:\n------\n{}------", GFileUtils.readFileQuietly(spec.getOptionsFile()));
        throw new GradleException(String.format("Javadoc generation failed. Generated Javadoc options file (useful for troubleshooting): '%s'", spec.getOptionsFile()), e);
    }

    return new SimpleWorkResult(true);
}
 
Example #16
Source File: CommandLineTool.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void execute(CommandLineToolInvocation invocation) {
    ExecAction compiler = execActionFactory.newExecAction();
    compiler.executable(executable);
    if (invocation.getWorkDirectory() != null) {
        GFileUtils.mkdirs(invocation.getWorkDirectory());
        compiler.workingDir(invocation.getWorkDirectory());
    }

    compiler.args(invocation.getArgs());

    if (!invocation.getPath().isEmpty()) {
        String pathVar = OperatingSystem.current().getPathVar();
        String compilerPath = Joiner.on(File.pathSeparator).join(invocation.getPath());
        compilerPath = compilerPath + File.pathSeparator + System.getenv(pathVar);
        compiler.environment(pathVar, compilerPath);
    }

    compiler.environment(invocation.getEnvironment());

    try {
        compiler.execute();
    } catch (ExecException e) {
        throw new GradleException(String.format("%s failed; see the error output for details.", action), e);
    }
}
 
Example #17
Source File: GccVersionDeterminer.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private String transform(File gccBinary, List<String> args) {
    ExecAction exec = execActionFactory.newExecAction();
    exec.executable(gccBinary.getAbsolutePath());
    exec.setWorkingDir(gccBinary.getParentFile());
    exec.args(args);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    exec.setStandardOutput(baos);
    exec.setErrorOutput(new ByteArrayOutputStream());
    exec.setIgnoreExitValue(true);
    ExecResult result = exec.execute();

    int exitValue = result.getExitValue();
    if (exitValue == 0) {
        return new String(baos.toByteArray());
    } else {
        return null;
    }
}
 
Example #18
Source File: CompilerMetaDataProviderFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public CompilerMetaDataProviderFactory(final FileLookup fileLookup) {
    ExecActionFactory factory = new ExecActionFactory() {
        public ExecAction newExecAction() {
            return new DefaultExecAction(fileLookup.getFileResolver());
        }
    };
    gcc = new CachingCompilerMetaDataProvider(GccVersionDeterminer.forGcc(factory));
    clang = new CachingCompilerMetaDataProvider(GccVersionDeterminer.forClang(factory));
}
 
Example #19
Source File: CompilerMetaDataProviderFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public CompilerMetaDataProviderFactory(final FileLookup fileLookup) {
    ExecActionFactory factory = new ExecActionFactory() {
        public ExecAction newExecAction() {
            return new DefaultExecAction(fileLookup.getFileResolver());
        }
    };
    gcc = new CachingCompilerMetaDataProvider(GccVersionDeterminer.forGcc(factory));
    clang = new CachingCompilerMetaDataProvider(GccVersionDeterminer.forClang(factory));
}
 
Example #20
Source File: Exec.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
void setExecAction(ExecAction execAction) {
    this.execAction = execAction;
}
 
Example #21
Source File: AbstractExecTask.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
void setExecAction(ExecAction execAction) {
    this.execAction = execAction;
}
 
Example #22
Source File: AbstractExecTask.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
void setExecAction(ExecAction execAction) {
    this.execAction = execAction;
}
 
Example #23
Source File: Exec.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
void setExecAction(ExecAction execAction) {
    this.execAction = execAction;
}