org.gradle.tooling.BuildLauncher Java Examples
The following examples show how to use
org.gradle.tooling.BuildLauncher.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AndroidSupport.java From meghanada-server with GNU General Public License v3.0 | 6 votes |
private void prepareCompileAndroidTestJavaV2() { try (ProjectConnection connection = this.project.getProjectConnection()) { 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(); } } }
Example #2
Source File: ComparableGradleBuildExecuter.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public ProjectOutcomes executeWith(ProjectConnection connection) { List<String> tasksList = getSpec().getTasks(); String[] tasks = tasksList.toArray(new String[tasksList.size()]); List<String> argumentsList = getImpliedArguments(); String[] arguments = argumentsList.toArray(new String[argumentsList.size()]); if (isCanObtainProjectOutcomesModel()) { // Run the build and get the build outcomes model ModelBuilder<ProjectOutcomes> modelBuilder = connection.model(ProjectOutcomes.class); return modelBuilder. withArguments(arguments). forTasks(tasks). get(); } else { BuildLauncher buildLauncher = connection.newBuild(); buildLauncher. withArguments(arguments). forTasks(tasks). run(); return null; } }
Example #3
Source File: AndroidSupport.java From meghanada-server with GNU General Public License v3.0 | 6 votes |
void prepareCompileAndroidJava() { try (ProjectConnection connection = this.project.getProjectConnection()) { 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(); } } }
Example #4
Source File: ComparableGradleBuildExecuter.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
public ProjectOutcomes executeWith(ProjectConnection connection) { List<String> tasksList = getSpec().getTasks(); String[] tasks = tasksList.toArray(new String[tasksList.size()]); List<String> argumentsList = getImpliedArguments(); String[] arguments = argumentsList.toArray(new String[argumentsList.size()]); if (isCanObtainProjectOutcomesModel()) { // Run the build and get the build outcomes model ModelBuilder<ProjectOutcomes> modelBuilder = connection.model(ProjectOutcomes.class); return modelBuilder. withArguments(arguments). forTasks(tasks). get(); } else { BuildLauncher buildLauncher = connection.newBuild(); buildLauncher. withArguments(arguments). forTasks(tasks). run(); return null; } }
Example #5
Source File: DefaultBuildLauncher.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
public BuildLauncher forLaunchables(Iterable<? extends Launchable> launchables) { Set<String> taskPaths = new LinkedHashSet<String>(); List<InternalLaunchable> launchablesParams = Lists.newArrayList(); for (Launchable launchable : launchables) { if (launchable instanceof Task) { taskPaths.add(((Task) launchable).getPath()); } else if (launchable instanceof TaskListingLaunchable) { taskPaths.addAll(((TaskListingLaunchable) launchable).getTaskNames()); } else if (!(launchable instanceof TaskSelector)) { throw new GradleException("Only Task or TaskSelector instances are supported: " + (launchable != null ? launchable.getClass() : "null")); } maybeAddLaunchableParameter(launchablesParams, launchable); } operationParamsBuilder.setTasks(new ArrayList<String>(taskPaths)); operationParamsBuilder.setLaunchables(launchablesParams); return this; }
Example #6
Source File: ComparableGradleBuildExecuter.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
public ProjectOutcomes executeWith(ProjectConnection connection) { List<String> tasksList = getSpec().getTasks(); String[] tasks = tasksList.toArray(new String[tasksList.size()]); List<String> argumentsList = getImpliedArguments(); String[] arguments = argumentsList.toArray(new String[argumentsList.size()]); if (isCanObtainProjectOutcomesModel()) { // Run the build and get the build outcomes model ModelBuilder<ProjectOutcomes> modelBuilder = connection.model(ProjectOutcomes.class); return modelBuilder. withArguments(arguments). forTasks(tasks). get(); } else { BuildLauncher buildLauncher = connection.newBuild(); buildLauncher. withArguments(arguments). forTasks(tasks). run(); return null; } }
Example #7
Source File: DefaultBuildLauncher.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public BuildLauncher forLaunchables(Iterable<? extends Launchable> launchables) { Set<String> taskPaths = new LinkedHashSet<String>(); List<InternalLaunchable> launchablesParams = Lists.newArrayList(); for (Launchable launchable : launchables) { if (launchable instanceof Task) { taskPaths.add(((Task) launchable).getPath()); } else if (launchable instanceof TaskListingLaunchable) { taskPaths.addAll(((TaskListingLaunchable) launchable).getTaskNames()); } else if (!(launchable instanceof TaskSelector)) { throw new GradleException("Only Task or TaskSelector instances are supported: " + (launchable != null ? launchable.getClass() : "null")); } maybeAddLaunchableParameter(launchablesParams, launchable); } operationParamsBuilder.setTasks(new ArrayList<String>(taskPaths)); operationParamsBuilder.setLaunchables(launchablesParams); return this; }
Example #8
Source File: ComparableGradleBuildExecuter.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public ProjectOutcomes executeWith(ProjectConnection connection) { List<String> tasksList = getSpec().getTasks(); String[] tasks = tasksList.toArray(new String[tasksList.size()]); List<String> argumentsList = getImpliedArguments(); String[] arguments = argumentsList.toArray(new String[argumentsList.size()]); if (isCanObtainProjectOutcomesModel()) { // Run the build and get the build outcomes model ModelBuilder<ProjectOutcomes> modelBuilder = connection.model(ProjectOutcomes.class); return modelBuilder. withArguments(arguments). forTasks(tasks). get(); } else { BuildLauncher buildLauncher = connection.newBuild(); buildLauncher. withArguments(arguments). forTasks(tasks). run(); return null; } }
Example #9
Source File: GradleProject.java From meghanada-server with GNU General Public License v3.0 | 5 votes |
private void runPrepareTestCompileTask() throws IOException { if (!this.prepareTestCompileTask.isEmpty()) { try (ProjectConnection connection = this.getProjectConnection()) { final String[] tasks = prepareTestCompileTask.toArray(STRINGS); final BuildLauncher buildLauncher = connection.newBuild(); log.info("project {} run tasks:{}", this.name, tasks); GradleProject.setBuildJVMArgs(buildLauncher); buildLauncher.forTasks(tasks).run(); } } }
Example #10
Source File: GradleProject.java From meghanada-server with GNU General Public License v3.0 | 5 votes |
private void runPrepareCompileTask() throws IOException { if (!this.prepareCompileTask.isEmpty()) { try (ProjectConnection connection = this.getProjectConnection()) { final String[] tasks = prepareCompileTask.toArray(STRINGS); final BuildLauncher buildLauncher = connection.newBuild(); log.info("project {} run tasks:{}", this.name, tasks); GradleProject.setBuildJVMArgs(buildLauncher); buildLauncher.forTasks(tasks).run(); } } }
Example #11
Source File: Main.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public static void main(String[] args) { // Configure the connector and create the connection GradleConnector connector = GradleConnector.newConnector(); if (args.length > 0) { connector.useInstallation(new File(args[0])); if (args.length > 1) { connector.useGradleUserHomeDir(new File(args[1])); } } connector.forProjectDirectory(new File(".")); ProjectConnection connection = connector.connect(); try { // Configure the build BuildLauncher launcher = connection.newBuild(); launcher.forTasks("help"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); launcher.setStandardOutput(outputStream); launcher.setStandardError(outputStream); // Run the build launcher.run(); } finally { // Clean up connection.close(); } }
Example #12
Source File: GradleProject.java From meghanada-server with GNU General Public License v3.0 | 5 votes |
@Override public InputStream runTask(final List<String> args) throws IOException { try { final List<String> tasks = new ArrayList<>(4); final List<String> taskArgs = new ArrayList<>(4); for (final String temp : args) { for (final String arg : Splitter.on(" ").split(temp)) { if (arg.startsWith("-")) { taskArgs.add(arg.trim()); } else { tasks.add(arg.trim()); } } } log.debug("task:{}:{} args:{}:{}", tasks, tasks.size(), taskArgs, taskArgs.size()); final ProjectConnection projectConnection = getProjectConnection(); final BuildLauncher build = projectConnection.newBuild(); GradleProject.setBuildJVMArgs(build); build.forTasks(tasks.toArray(STRINGS)); if (taskArgs.size() > 0) { build.withArguments(taskArgs.toArray(STRINGS)); } final PipedOutputStream outputStream = new PipedOutputStream(); PipedInputStream inputStream = new PipedInputStream(outputStream); build.setStandardError(outputStream); build.setStandardOutput(outputStream); final VoidResultHandler handler = new VoidResultHandler(outputStream, inputStream, projectConnection); build.run(handler); return inputStream; } finally { Config.setProjectRoot(this.projectRoot.getCanonicalPath()); } }
Example #13
Source File: DefaultBuildLauncher.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public BuildLauncher forTasks(Iterable<? extends Task> tasks) { List<String> taskPaths = new ArrayList<String>(); for (Task task : tasks) { taskPaths.add(task.getPath()); } operationParamsBuilder.setTasks(taskPaths); return this; }
Example #14
Source File: Main.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public static void main(String[] args) { // Configure the connector and create the connection GradleConnector connector = GradleConnector.newConnector(); if (args.length > 0) { connector.useInstallation(new File(args[0])); if (args.length > 1) { connector.useGradleUserHomeDir(new File(args[1])); } } connector.forProjectDirectory(new File(".")); ProjectConnection connection = connector.connect(); try { // Configure the build BuildLauncher launcher = connection.newBuild(); launcher.forTasks("help"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); launcher.setStandardOutput(outputStream); launcher.setStandardError(outputStream); // Run the build launcher.run(); } finally { // Clean up connection.close(); } }
Example #15
Source File: DefaultBuildLauncher.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public BuildLauncher forTasks(Iterable<? extends Task> tasks) { List<String> taskPaths = new ArrayList<String>(); for (Task task : tasks) { taskPaths.add(task.getPath()); } operationParamsBuilder.setTasks(taskPaths); return this; }
Example #16
Source File: Main.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public static void main(String[] args) { // Configure the connector and create the connection GradleConnector connector = GradleConnector.newConnector(); if (args.length > 0) { connector.useInstallation(new File(args[0])); if (args.length > 1) { connector.useGradleUserHomeDir(new File(args[1])); } } connector.forProjectDirectory(new File(".")); ProjectConnection connection = connector.connect(); try { // Configure the build BuildLauncher launcher = connection.newBuild(); launcher.forTasks("help"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); launcher.setStandardOutput(outputStream); launcher.setStandardError(outputStream); // Run the build launcher.run(); } finally { // Clean up connection.close(); } }
Example #17
Source File: Main.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public static void main(String[] args) { // Configure the connector and create the connection GradleConnector connector = GradleConnector.newConnector(); if (args.length > 0) { connector.useInstallation(new File(args[0])); if (args.length > 1) { connector.useGradleUserHomeDir(new File(args[1])); } } connector.forProjectDirectory(new File(".")); ProjectConnection connection = connector.connect(); try { // Configure the build BuildLauncher launcher = connection.newBuild(); launcher.forTasks("help"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); launcher.setStandardOutput(outputStream); launcher.setStandardError(outputStream); // Run the build launcher.run(); } finally { // Clean up connection.close(); } }
Example #18
Source File: ToolingApiGradleHandleFactory.java From paraphrase with Apache License 2.0 | 5 votes |
public GradleHandle start(File directory, List<String> arguments) { GradleConnector connector = GradleConnector.newConnector(); connector.forProjectDirectory(directory); ProjectConnection connection = connector.connect(); BuildLauncher launcher = connection.newBuild(); String[] argumentArray = new String[arguments.size()]; arguments.toArray(argumentArray); launcher.withArguments(argumentArray); return new BuildLauncherBackedGradleHandle(launcher); }
Example #19
Source File: BuildLauncherBackedGradleHandle.java From paraphrase with Apache License 2.0 | 5 votes |
public BuildLauncherBackedGradleHandle(BuildLauncher launcher) { launcher.setStandardOutput(standardOutput); launcher.setStandardError(standardError); launcher.run(new ResultHandler<Void>() { public void onComplete(Void result) { finish(); } public void onFailure(GradleConnectionException failure) { exception = failure; finish(); } }); }
Example #20
Source File: GradleBuildAutomaticDeployment.java From arquillian-container-chameleon with Apache License 2.0 | 4 votes |
private Archive<?> runBuild(GradleBuild conf) { ProjectConnection projectConnector = GradleConnector .newConnector() .forProjectDirectory(new File(conf.path())) .connect(); BuildLauncher launcher = projectConnector .newBuild() .forTasks(conf.tasks()) .withArguments("-x", "test"); if (!conf.quiet()) { launcher.withArguments("--info", "--stacktrace"); launcher.setStandardOutput(System.out); launcher.setStandardError(System.err); } launcher.run(); GradleProject projectModel = projectConnector.getModel(GradleProject.class); final Path artifactDir = projectModel.getBuildDirectory().toPath().resolve("libs"); Path artifactPath = null; try (DirectoryStream<Path> filesInArtifactDir = Files.newDirectoryStream(artifactDir)) { for (Path file : filesInArtifactDir) { if (file.toString().endsWith(".war")) { artifactPath = file; break; } } } catch (Exception e) { throw new RuntimeException(e); } if (artifactPath == null) { throw new RuntimeException("No .war-file found in " + artifactDir.toString() + "."); } return ShrinkWrap .create(ZipImporter.class, artifactPath.getFileName().toString()) .importFrom(artifactPath.toFile()) .as(WebArchive.class); }
Example #21
Source File: DefaultBuildLauncher.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public BuildLauncher forLaunchables(Iterable<? extends Launchable> launchables) { operationParamsBuilder.setLaunchables(launchables); return this; }
Example #22
Source File: DefaultBuildLauncher.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public BuildLauncher forTasks(String... tasks) { operationParamsBuilder.setTasks(Arrays.asList(tasks)); return this; }
Example #23
Source File: DefaultBuildLauncher.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public BuildLauncher forTasks(Task... tasks) { forTasks(Arrays.asList(tasks)); return this; }
Example #24
Source File: DefaultBuildLauncher.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public BuildLauncher forLaunchables(Launchable... launchables) { return forLaunchables(Arrays.asList(launchables)); }
Example #25
Source File: DefaultBuildLauncher.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
public BuildLauncher forTasks(String... tasks) { operationParamsBuilder.setTasks(Arrays.asList(tasks)); return this; }
Example #26
Source File: DefaultBuildLauncher.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public BuildLauncher forLaunchables(Launchable... launchables) { return forLaunchables(Arrays.asList(launchables)); }
Example #27
Source File: DefaultBuildLauncher.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public BuildLauncher forTasks(Iterable<? extends Task> tasks) { operationParamsBuilder.setLaunchables(tasks); return this; }
Example #28
Source File: DefaultBuildLauncher.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public BuildLauncher forTasks(Task... tasks) { forTasks(Arrays.asList(tasks)); return this; }
Example #29
Source File: DefaultBuildLauncher.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public BuildLauncher forTasks(String... tasks) { operationParamsBuilder.setTasks(Arrays.asList(tasks)); return this; }
Example #30
Source File: GradleProject.java From meghanada-server with GNU General Public License v3.0 | 4 votes |
private static void setBuildJVMArgs(final BuildLauncher build) throws IOException { build.setJvmArguments("-Djava.io.tmpdir=" + getTmpDir()); }