Java Code Examples for org.gradle.tooling.BuildLauncher#setStandardError()
The following examples show how to use
org.gradle.tooling.BuildLauncher#setStandardError() .
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: 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 2
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 3
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 4
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 5
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 6
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 7
Source File: ExecuteGoal.java From NBANDROID-V2 with Apache License 2.0 | 4 votes |
@Override public void run() { cancellation.set(false); cancellationReference.set(new DefaultBuildCancellationToken()); GradleConnector connector = GradleConnector.newConnector(); connector.useInstallation(gradleHome); connector.forProjectDirectory(FileUtil.toFile(project.getProjectDirectory())); try (ProjectConnection connection = connector.connect()) { BuildLauncher buildLauncher = connection.newBuild(); buildLauncher.forTasks(taskInfo.getName()); buildLauncher.withCancellationToken(this); ProjectConfigurationProvider pcp = project.getLookup().lookup(ProjectConfigurationProvider.class); if (pcp != null && pcp.getActiveConfiguration() != null) { buildLauncher.addArguments("-Pandroid.profile=" + pcp.getActiveConfiguration()); } if (argsConfiguration != null) { buildLauncher.addArguments(argsConfiguration.getJvmArguments()); } if (jvmConfiguration == null) { buildLauncher.addJvmArguments("-Xms800m", "-Xmx2000m"); } else { buildLauncher.addJvmArguments(jvmConfiguration.getJvmArguments()); } InputOutput io = project.getLookup().lookup(InputOutput.class); if (io != null) { io.show(ImmutableSet.of(ShowOperation.OPEN, ShowOperation.MAKE_VISIBLE)); io.getOut().print("\n\r"); io.getOut().print("\n\r"); io.getOut().print("\n\r"); io.getOut().print("\n\r"); io.getOut().println(BLUE + "Executing task: " + taskInfo.getName() + BLACK); io.getOut().print("\n\r"); io.getOut().print("\n\r"); CustomWriterOutputStream cwos = new CustomWriterOutputStream(io.getOut(), "UTF-8"); buildLauncher.setStandardOutput(cwos); buildLauncher.setStandardError(cwos); buildLauncher.setColorOutput(true); } final ProgressHandle progressHandle = ProgressHandleFactory.createSystemHandle(project.getProjectDirectory().getName() + " : " + taskInfo.getDescription(), this); progressHandle.start(); buildLauncher.addProgressListener(new ProgressListener() { @Override public void statusChanged(ProgressEvent event) { progressHandle.progress(event.getDisplayName()); } }); try { buildLauncher.run(); } catch (GradleConnectionException | IllegalStateException gradleConnectionException) { if (!(gradleConnectionException instanceof BuildCancelledException)) { Exceptions.printStackTrace(gradleConnectionException); } } progressHandle.finish(); ModelRefresh modelRefresh = project.getLookup().lookup(ModelRefresh.class); if (modelRefresh != null) { modelRefresh.refreshModels(); } } catch (Exception e) { Exceptions.printStackTrace(e); } }
Example 8
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); }