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; }
OutputStream outputStream = new OutputStream() { private StringBuilder string = new StringBuilder(); @Override public void write(int b) throws IOException { this.string.append((char) b); } public String toString() { return this.string.toString(); } }; ProjectConnection connection = GradleConnector.newConnector() .forProjectDirectory(getProjectDirectoryFile()) .connect(); BuildLauncher buildLauncher = connection.newBuild(); buildLauncher.forTasks(":tasks"); buildLauncher.setStandardOutput(outputStream); buildLauncher.run(); for (String line : outputStream.toString().split("\\r?\\n")) { if(containsTaskName(line)) { String taskName = line.split(" ")[0]; System.out.println(taskName); } }
PipedInputStream inputStream = new PipedInputStream(outputStream); build.setStandardError(outputStream); build.setStandardOutput(outputStream); final VoidResultHandler handler = new VoidResultHandler(outputStream, inputStream, projectConnection);
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(); }
public void run(List<WatchTarget> targets) { if (targets == null || targets.isEmpty()) { return; } BuildLauncher launcher = connection .newBuild() .withArguments(arguments) .setStandardOutput(System.out); for (WatchTarget target : targets) { launcher.forTasks(target.getTasks().toArray(new String[0])); } final int[] taskNum = new int[1]; launcher.addProgressListener(new ProgressListener() { public void statusChanged(ProgressEvent event) { if ("Execute tasks".equals(event.getDescription())) { taskNum[0]++; } } }); long timestamp = System.currentTimeMillis(); try { launcher.run(); } catch (BuildException e) { // ignore... } for (WatchTarget target : targets) { target.setExecutedAt(timestamp); } }
launcher.setStandardOutput(System.out); launcher.setStandardError(System.err);
ByteArrayOutputStream err = new ByteArrayOutputStream(); launcher.setStandardError(err); launcher.setStandardOutput(out); launcher.forTasks("compileJava"); CompletableFuture<GradleConnectionException> future = new CompletableFuture<>();
.setStandardOutput(System.out) .setStandardInput(System.in) .setStandardError(System.err)
/* * 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.setStandardOutput(System.out); launcher.setStandardError(System.err);