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 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); }
@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; }
/** * 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; }
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(); }
private static void initProjectIfNotExists(BuildConfiguration buildConfig, CancellationTokenSource tokenSource, IProgressMonitor monitor) { File projectDir = buildConfig.getRootProjectDirectory().getAbsoluteFile(); if (!projectDir.exists()) { if (projectDir.mkdir()) { List<String> tasks = ImmutableList.of("init", "--type", "java-library"); InternalGradleBuild gradleBuild = CorePlugin.internalGradleWorkspace().getGradleBuild(buildConfig); RunConfiguration runConfiguration = CorePlugin.configurationManager().createDefaultRunConfiguration(buildConfig); GradleProgressAttributes progressAttributes = GradleProgressAttributes.builder(tokenSource, monitor) .forNonInteractiveBackgroundProcess() .withFilteredProgress() .build(); gradleBuild.newBuildLauncher(runConfiguration, progressAttributes).forTasks(tasks.toArray(new String[tasks.size()])).run(); } } }
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 Assignable importBuildOutput() { final String oldValue = removeSAXParserFactoryProperty(); getBuildLauncher().forTasks(tasks).withArguments(arguments).run(); setSAXParserFactoryProperty(oldValue); return this; }
@Override public Assignable importBuildOutput() { final String oldValue = removeSAXParserFactoryProperty(); getBuildLauncher().forTasks(tasks).withArguments(arguments).run(); setSAXParserFactoryProperty(oldValue); return this; }
private void runTasks(final List<String> tasksToRun, IProgressMonitor monitor, CancellationTokenSource tokenSource) { RunConfiguration runConfiguration = CorePlugin.configurationManager().createDefaultRunConfiguration(this.buildConfig); GradleProgressAttributes progressAttributes = GradleProgressAttributes.builder(tokenSource, monitor) .forBackgroundProcess() .withFilteredProgress() .build(); BuildLauncher launcher = CorePlugin.internalGradleWorkspace().getGradleBuild(this.buildConfig).newBuildLauncher(runConfiguration, progressAttributes); launcher.forTasks(tasksToRun.toArray(new String[tasksToRun.size()])).run(); } }
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(); } }
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(); } }
/* * 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(); } }