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); } }); } } }
launcher.forTasks(getTasks()); launcher.setStandardOutput(System.out); launcher.setStandardError(System.err); launcher.setJvmArguments(jvmArgs); launcher.withArguments(finalArgs); launcher.setJavaHome(javaHome); launcher.addProgressListener(new MyProgressListener()); launcher.run(new MyResultHandler());
try { BuildLauncher build = connection.newBuild(); //select tasks to run: build.forTasks("clean", "test"); //include some build arguments: build.withArguments("--no-search-upward", "-i", "--project-dir", "someProjectDir"); //configure the standard input: build.setStandardInput(new ByteArrayInputStream("consume this!".getBytes())); //in case you want the build to use java different than default: build.setJavaHome(new File("/path/to/java")); //if your build needs crazy amounts of memory: build.setJvmArguments("-Xmx2048m", "-XX:MaxPermSize=512m"); //if you want to listen to the progress events: ProgressListener listener = null; // use your implementation build.addProgressListener(listener); //kick the build off: build.run(); } finally { connection.close(); }
@Override public Void execute(File projectDirectory, ProjectConnection connection) { connection.newBuild() .forTasks("doNothing") .withArguments("--refresh-dependencies") .run(); return null; } });
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); } }
.setStandardOutput(System.out) .setStandardInput(System.in) .setStandardError(System.err) .withArguments(args.toArray(new String[args.size()])) .setColorOutput(false) .run();
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); } }
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; }
@Override public Void execute(File directory, ProjectConnection connection) { connection.newBuild() .withArguments(arguments.toArray(new String[arguments.size()])) .run(); return null; } });
.withArguments("-q") .addProgressListener(new ProgressListener() { public void statusChanged(ProgressEvent event) { out.print(".."); .run(new ResultHandler<Void>() { public void onComplete(Void result) { System.setOut(out);
public void runTasks(final File projectFolder, final String... tasks) { GradleHelper.logger.info("Running gradle build with tasks=\'{}\'.", ((List<String>)Conversions.doWrapArray(tasks)).toArray()); final Consumer<BuildLauncher> _function = (BuildLauncher it) -> { it.forTasks(tasks); }; this.run(projectFolder, _function); }
task run << { ProjectConnection connection = GradleConnector.newConnector().forProjectDirectory(new File("someProjectFolder")).connect(); try { BuildLauncher build = connection.newBuild(); build.setJvmArguments("-javaagent:/home/audrius/org.springframework.instrument-3.0.5.RELEASE.jar") build.forTasks("jettyRun").run(); } finally { connection.close(); } }
public void run(final File projectFolder, final ResultHandler<? super Void> resultHandler, final Consumer<BuildLauncher> configClosure) { final ProjectConnection connector = GradleConnector.newConnector().useGradleVersion(GradleHelper.GRADLE_VERSION).forProjectDirectory(projectFolder).connect(); try { final BuildLauncher build = connector.newBuild(); final ProgressListener _function = (ProgressEvent event) -> { GradleHelper.logger.debug("Gradle build event=\'{}\'", event.getDisplayName()); }; build.addProgressListener(_function, OperationType.values()); configClosure.accept(build); if ((resultHandler != null)) { build.run(resultHandler); } else { build.run(); } } finally { connector.close(); } }
@Override protected void executeLaunch(BuildLauncher launcher) { launcher.run(); }
@Override public ConfigurationStage setJvmArguments(final String... jvmArguments) { getBuildLauncher().setJvmArguments(jvmArguments); return this; }
@Override public Assignable importBuildOutput() { final String oldValue = removeSAXParserFactoryProperty(); getBuildLauncher().forTasks(tasks).withArguments(arguments).run(); setSAXParserFactoryProperty(oldValue); return this; }
@Override protected BuildLauncher createLaunch(InternalGradleBuild gradleBuild, RunConfiguration runConfiguration, GradleProgressAttributes progressAttributes, ProcessDescription processDescription) { BuildLauncher launcher = gradleBuild.newBuildLauncher(runConfiguration, progressAttributes); launcher.forTasks(RunGradleBuildLaunchRequestJob.this.runConfig.getTasks().toArray(new String[0])); return launcher; }
private void build() { while (that.lastBuild < that.lastChange) { that.lastBuild = System.currentTimeMillis(); try { // Errors must be absorbed else the watcher will crap itself. builder.run(); } catch (Throwable e) { e.printStackTrace(); } } } };