use of org.gradle.api.tasks.Exec in project gradle-conjure by palantir.
the class ConjurePlugin method setupConjureTypescriptProject.
private static void setupConjureTypescriptProject(Project project, Supplier<GeneratorOptions> options, TaskProvider<?> compileConjure, TaskProvider<?> compileIrTask, TaskProvider<GenerateConjureServiceDependenciesTask> productDependencyTask) {
String typescriptProjectName = project.getName() + "-typescript";
if (derivedProjectExists(project, typescriptProjectName)) {
project.project(derivedProjectPath(project, typescriptProjectName), subproj -> {
applyDependencyForIdeTasks(subproj, compileConjure);
File srcDirectory = subproj.file("src");
TaskProvider<ExtractExecutableTask> extractConjureTypeScriptTask = ExtractConjurePlugin.applyConjureTypeScript(project);
TaskProvider<CompileConjureTypeScriptTask> compileConjureTypeScript = project.getTasks().register("compileConjureTypeScript", CompileConjureTypeScriptTask.class, task -> {
task.setDescription("Generates TypeScript files and a package.json from your " + "Conjure definitions.");
task.setGroup(TASK_GROUP);
task.setSource(compileIrTask);
task.getExecutablePath().set(extractConjureTypeScriptTask.flatMap(ExtractExecutableTask::getExecutable));
task.getProductDependencyFile().set(productDependencyTask.flatMap(GenerateConjureServiceDependenciesTask::getOutputFile));
task.getOutputDirectory().set(srcDirectory);
task.setOptions(options);
task.dependsOn(createWriteGitignoreTask(subproj, "gitignoreConjureTypeScript", subproj.getProjectDir(), "/src/\n"));
task.dependsOn(extractConjureTypeScriptTask);
task.dependsOn(productDependencyTask);
});
compileConjure.configure(t -> t.dependsOn(compileConjureTypeScript));
registerClean(project, compileConjureTypeScript);
String npmCommand = OsUtils.NPM_COMMAND_NAME;
TaskProvider<Exec> installTypeScriptDependencies = project.getTasks().register("installTypeScriptDependencies", Exec.class, task -> {
task.commandLine(npmCommand, "install", "--no-package-lock", "--no-production");
task.workingDir(srcDirectory);
task.dependsOn(compileConjureTypeScript);
task.getInputs().file(new File(srcDirectory, "package.json"));
task.getOutputs().dir(new File(srcDirectory, "node_modules"));
});
TaskProvider<Exec> compileTypeScript = project.getTasks().register("compileTypeScript", Exec.class, task -> {
task.setDescription("Runs `npm tsc` to compile generated TypeScript files into JavaScript files.");
task.setGroup(TASK_GROUP);
task.commandLine(npmCommand, "run-script", "build");
task.workingDir(srcDirectory);
task.dependsOn(installTypeScriptDependencies);
task.getOutputs().dir(srcDirectory);
});
TaskProvider<Exec> publishTypeScript = project.getTasks().register("publishTypeScript", Exec.class, task -> {
task.setDescription("Runs `npm publish` to publish a TypeScript package " + "generated from your Conjure definitions.");
task.setGroup(TASK_GROUP);
task.commandLine(npmCommand, "publish");
task.workingDir(srcDirectory);
task.dependsOn(compileConjureTypeScript);
task.dependsOn(compileTypeScript);
});
linkPublish(subproj, publishTypeScript);
});
}
}
use of org.gradle.api.tasks.Exec in project OpenSearch by opensearch-project.
the class LoggedExec method genericExec.
private static <T extends BaseExecSpec> ExecResult genericExec(Function<Action<T>, ExecResult> function, Action<T> action) {
if (LOGGER.isInfoEnabled()) {
return function.apply(action);
}
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
return function.apply(spec -> {
spec.setStandardOutput(output);
spec.setErrorOutput(output);
// optimize for short-lived process
if (spec instanceof JavaExecSpec) {
((JavaExecSpec) spec).setJvmArgs(shortLivedArgs());
}
action.execute(spec);
try {
output.write(("Output for " + spec.getExecutable() + ":").getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
} catch (Exception e) {
try {
if (output.size() != 0) {
LOGGER.error("Exec output and error:");
NEWLINE.splitAsStream(output.toString("UTF-8")).forEach(s -> LOGGER.error("| " + s));
}
} catch (UnsupportedEncodingException ue) {
throw new GradleException("Failed to read exec output", ue);
}
throw e;
}
}
Aggregations