private void runTask(final ProjectConnection connection, final Path path, final String task) { synchronized (LOCK) { Map<String, String> xml = new HashMap<>(); try { // clean jaxp XML_PROPS.forEach(p -> xml.put(p, (String) System.getProperties().remove(p))); try { connection.newBuild() .setStandardError(System.err) .setStandardOutput(System.out) .forTasks(task) .run(); } catch (Exception ex) { getLogger().debug("Execution of " + task + " resulted in exception", ex); } } finally { // restore jaxp xml.forEach((k, v) -> { if (v != null) { System.setProperty(k, v); } }); } } }
public List<IPath> getGradleSourceSetPaths(final IPath projectRoot) { if ((this.gradleClasspath == null)) { final ByteArrayOutputStream outTask = new ByteArrayOutputStream(); final Consumer<BuildLauncher> _function = (BuildLauncher it) -> { it.withArguments("-q", "sourceSetPaths"); it.setStandardOutput(outTask); it.setStandardError(outTask); }; this.gradle.run(projectRoot.toFile(), null, _function); this.gradleClasspath = this.parseGradleSourcePaths(outTask.toString()); } return this.gradleClasspath; }
build.setStandardError(outputStream); build.setStandardOutput(outputStream); final VoidResultHandler handler =
protected byte[] runTasks(String... tasks) { ProjectConnection connection = GradleConnector.newConnector().forProjectDirectory(new File(InputConfiguration.get().getAbsolutePathToProjectRoot())).connect(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); LOGGER.info("Run gradle tasks: {}", String.join(" ", tasks)); try { BuildLauncher build = connection.newBuild(); build.forTasks(tasks); build.setStandardOutput(outputStream); build.setStandardError(outputStream); build.run(); } catch (Exception e) { throw new RuntimeException(e); } finally { connection.close(); } return outputStream.toByteArray(); }
launcher.withArguments("--info", "--stacktrace"); launcher.setStandardOutput(System.out); launcher.setStandardError(System.err);
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream err = new ByteArrayOutputStream(); launcher.setStandardError(err); launcher.setStandardOutput(out); launcher.forTasks("compileJava");
.setStandardOutput(System.out) .setStandardInput(System.in) .setStandardError(System.err) .withArguments(args.toArray(new String[args.size()])) .setColorOutput(false)
/* * perform Gradle tasks such as compile, build, test */ public static void performGradleTasks(String path, String ... tasks) { GradleConnector connector = GradleConnector.newConnector(); connector.forProjectDirectory(new File(path)); ProjectConnection connection = connector.connect(); try { // Configure the build BuildLauncher launcher = connection.newBuild(); launcher.forTasks(tasks); launcher.setStandardOutput(System.out); launcher.setStandardError(System.err); // Run the build launcher.run(); } finally { // Clean up connection.close(); } }
launcher.setStandardError(System.err);