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); } }); } } }
@Override public BuildLauncher newBuild() { return this.delegate.newBuild(); }
private BuildLauncher getBuildLauncher() { if (buildLauncher == null) { projectConnection = connector.connect(); buildLauncher = projectConnection.newBuild(); } return buildLauncher; }
private BuildLauncher getBuildLauncher() { if (buildLauncher == null) { projectConnection = connector.connect(); buildLauncher = projectConnection.newBuild(); } return buildLauncher; }
@Override public BuildLauncher newBuild() { return configureOperation(this.delegate.newBuild()); }
@Override public Void execute(File directory, ProjectConnection connection) { connection.newBuild() .withArguments(arguments.toArray(new String[arguments.size()])) .run(); return null; } });
/** * Runs tasks in the project. * @param tasks the tasks * @return this */ public GradleAdapter launch(String... tasks) { if (LOG.isInfoEnabled()) { LOG.info("Gradle tasks: {}", Arrays.toString(tasks)); } configure(connection.newBuild().forTasks(tasks)).run(); return this; }
@Override public Void execute(File projectDirectory, ProjectConnection connection) { connection.newBuild() .forTasks("wrapper") .run(); return null; } });
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(); } }
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); } }
private void runPrepareCompileTask() throws IOException { if (!this.prepareCompileTask.isEmpty()) { final ProjectConnection connection = this.getProjectConnection(); try { final String[] tasks = prepareCompileTask.toArray(new String[0]); final BuildLauncher buildLauncher = connection.newBuild(); log.info("project {} run tasks:{}", this.name, tasks); GradleProject.setBuildJVMArgs(buildLauncher); buildLauncher.forTasks(tasks).run(); } finally { connection.close(); } } }
private void runPrepareTestCompileTask() throws IOException { if (!this.prepareTestCompileTask.isEmpty()) { final ProjectConnection connection = this.getProjectConnection(); try { final String[] tasks = prepareTestCompileTask.toArray(new String[0]); final BuildLauncher buildLauncher = connection.newBuild(); log.info("project {} run tasks:{}", this.name, tasks); GradleProject.setBuildJVMArgs(buildLauncher); buildLauncher.forTasks(tasks).run(); } finally { connection.close(); } } }
@Override public Void execute(File projectDirectory, ProjectConnection connection) { connection.newBuild() .forTasks("doNothing") .withArguments("--refresh-dependencies") .run(); return null; } });
public boolean build(String ...tasks) { ProjectConnection connection = connector.connect(); BuildLauncher build = connection.newBuild(); if (tasks.length > 0) { build.forTasks(tasks); } try { build.run(); }finally { connection.close(); } return true; }
public static BuildLauncher newBuildLauncher(GradleArguments gradleArguments, GradleProgressAttributes progressAttributes) { ProjectConnection connection = openConnection(gradleArguments); BuildEnvironment buildEnvironment = connection.getModel(BuildEnvironment.class); BuildLauncher launcher = connection.newBuild(); describeAndApplyConfiguration(launcher, gradleArguments, buildEnvironment, progressAttributes); return (BuildLauncher) newProxyInstance(connection, launcher); }
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(); }
void prepareCompileAndroidJava() { ProjectConnection connection = this.project.getProjectConnection(); try { BuildLauncher buildLauncher = connection.newBuild(); String genTask = this.project.getName() + this.genSourceTaskName; buildLauncher.forTasks(genTask).run(); int size = this.project.getDependencies().size(); String aar = Joiner.on(File.separator) .join(this.project.getProjectRoot(), BUILD_DIR, INTERMEDIATE_DIR, EXPLODED_DIR); List<File> jars = FileUtils.collectFiles(new File(aar), EXT_JAR); for (File jar : jars) { addAAR(jar); } int after = this.project.getDependencies().size(); if (size != after) { CachedASMReflector.getInstance().createClassIndexes(jars); this.project.resetCachedClasspath(); } } finally { connection.close(); } }
/* * 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(); } }
private void prepareCompileAndroidTestJavaV2() { ProjectConnection connection = this.project.getProjectConnection(); try { BuildLauncher buildLauncher = connection.newBuild(); String genTestTask = this.project.getName() + genUnitTestTaskName; String genAndroidTestTask = this.project.getName() + genAndroidTestTaskName; buildLauncher.forTasks(genTestTask, genAndroidTestTask).run(); int size = this.project.getDependencies().size(); String aar = Joiner.on(File.separator) .join(this.project.getProjectRoot(), BUILD_DIR, INTERMEDIATE_DIR, EXPLODED_DIR); List<File> jars = FileUtils.collectFiles(new File(aar), EXT_JAR); for (File jar : jars) { addAAR(jar); } int after = this.project.getDependencies().size(); if (size != after) { CachedASMReflector.getInstance().createClassIndexes(jars); this.project.resetCachedClasspath(); } } 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(); } }