本文整理汇总了Java中org.gradle.tooling.BuildLauncher.setStandardOutput方法的典型用法代码示例。如果您正苦于以下问题:Java BuildLauncher.setStandardOutput方法的具体用法?Java BuildLauncher.setStandardOutput怎么用?Java BuildLauncher.setStandardOutput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.gradle.tooling.BuildLauncher
的用法示例。
在下文中一共展示了BuildLauncher.setStandardOutput方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runTasks
import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
protected byte[] runTasks(String pathToRootOfProject, String... tasks) {
ProjectConnection connection = GradleConnector.newConnector().forProjectDirectory(new File(pathToRootOfProject)).connect();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
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();
}
示例2: executeBuild
import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
private void executeBuild(List<String> arguments, ProjectConnection connection,
String[] tasks) {
List<String> args = Lists.newArrayListWithCapacity(3 + arguments.size());
args.add("-i");
args.add("-u");
args.addAll(arguments);
BuildLauncher launcher = connection.newBuild()
.forTasks(tasks)
.withArguments(Iterables.toArray(args, String.class));
setJvmArguments(launcher);
if (stdout != null) {
launcher.setStandardOutput(stdout);
} else {
launcher.setStandardOutput(System.out);
}
if (stderr != null) {
launcher.setStandardError(stderr);
} else {
launcher.setStandardError(System.err);
}
launcher.run();
}
示例3: compile
import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
public void compile() throws Exception {
ProjectConnection connection = getConnector().connect();
try {
// Configure the build
BuildLauncher launcher = connection.newBuild();
if (flavor != null) {
launcher.forTasks(task + StringUtils.capitalize(flavor));
} else {
launcher.forTasks(task);
}
if (buildFile != null) {
launcher.withArguments("-b", buildFile.getAbsolutePath());
}
launcher.setStandardOutput(System.out);
launcher.setStandardError(System.err);
// Run the build
launcher.run();
} finally {
// Clean up
connection.close();
}
}
示例4: run
import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
public static void run(final BuildLauncher build, final IProgressMonitor monitor, String... runArgs) {
monitor.beginTask("Running gradle build", IProgressMonitor.UNKNOWN);
MessageConsole messageConsole = UiUtils.getMessageConsole("Gradle run");
final IOConsoleOutputStream consoleStream = messageConsole.newOutputStream();
build.setStandardOutput(consoleStream);
build.setStandardError(consoleStream);
GradlePluginUtils.setBuildLoggingOptions(build, runArgs);
UiUtils.showConsoleView();
// STUDIO-2676 - bring new console to front
ConsolePlugin.getDefault().getConsoleManager().showConsoleView(messageConsole);
build.addProgressListener(new ProgressListener() {
@Override
public void statusChanged(ProgressEvent progressEvent) {
monitor.beginTask(progressEvent.getDescription(), IProgressMonitor.UNKNOWN);
}
});
build.run();
monitor.done();
}
示例5: main
import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
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");
launcher.setStandardOutput(System.out);
launcher.setStandardError(System.err);
// Run the build
launcher.run();
} finally {
// Clean up
connection.close();
}
}
示例6: runTask
import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
@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 : temp.split(" ")) {
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();
this.setBuildJVMArgs(build);
build.forTasks(tasks.toArray(new String[tasks.size()]));
if (taskArgs.size() > 0) {
build.withArguments(taskArgs.toArray(new String[taskArgs.size()]));
}
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());
}
}
示例7: run
import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
/**
* Starts the progress handler and executes the gradle task.
*/
@Override
public void run() {
if (gradleTask != null && gradleTask.isValid()) {
progressHandler = ProgressHandle.createHandle(gradleTask.getDescription(), this);
progressHandler.start();
ProjectConnection connection = null;
try {
connection = getGradleConnection();
BuildLauncher buildLauncher = connection.newBuild();
buildLauncher.forTasks(gradleTask.getName());
String[] executionParameters = gradleTask.getExecutionParameters();
buildLauncher.withArguments(executionParameters);
LOG.info(EXECUTE_A_GRADLE_TASK);
LOG.log(Level.INFO, "{0} {1} on folder: {2}", new Object[]{gradleTask.getName(),
Arrays.toString(executionParameters),
gradleTask.getFolder()});
GradleResultHandler resultHandler = gradleTask.getResultHandler();
if (resultHandler != null) {
buildLauncher.setStandardError(resultHandler.getErrorOutputStream());
buildLauncher.setStandardOutput(resultHandler.getOutputStream());
buildLauncher.run(resultHandler);
} else {
buildLauncher.run();
}
} catch(GradleConnectionException | IllegalStateException ex) {
Exceptions.printStackTrace(ex);
} finally {
if (connection != null) {
connection.close();
}
}
}
}
示例8: attachTo
import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
void attachTo(@NotNull BuildLauncher launcher, @Nullable Listener listener) {
OutputStream stdout = new ConsoleAwareOutputStream(this, NORMAL_OUTPUT, listener);
OutputStream stderr = new ConsoleAwareOutputStream(this, ERROR_OUTPUT, listener);
launcher.setStandardOutput(stdout);
launcher.setStandardError(stderr);
}
示例9: main
import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
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();
}
}
示例10: BuildLauncherBackedGradleHandle
import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
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();
}
});
}
示例11: getDepsCoordinates
import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
public List<String> getDepsCoordinates(ProjectConnection connection, File buildFile) {
BuildLauncher launcher = connection.newBuild();
if (buildFile != null) {
launcher.withArguments("-b", buildFile.getAbsolutePath());
}
launcher.forTasks("dependencies");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
launcher.setStandardOutput(bos);
launcher.setStandardError(System.err);
launcher.run();
String content = bos.toString();
String[] lines = content.split("\\n");
List<String> coordinates = new LinkedList<String>();
for (int i = 0; i < lines.length; i++) {
if (lines[i].startsWith("compile") || lines[i].startsWith("provided")) {
if (i + 1 < lines.length && !lines[i + 1].startsWith("No dependencies")) {
int j = i + 1;
String prefix = null;
String nextGoal = "debugApk";
if (lines[i].startsWith("provided")) {
nextGoal = "releaseApk";
}
while (j < lines.length && !lines[j].startsWith(nextGoal)) {
int index = lines[j].lastIndexOf("--");
if (index != -1) {
prefix = lines[j].substring(0, index + 2);
if (lines[j].length() > prefix.length()) {
String artifact = lines[j].substring(prefix.length()).trim();
if (!artifact.endsWith("(*)")) {
int dynamicVersionIndex = artifact.indexOf("->");
if (dynamicVersionIndex != -1) {
String artifactName = artifact.substring(0, artifact.lastIndexOf(":")).trim();
String version = artifact.substring(dynamicVersionIndex + 2).trim();
artifact = artifactName + ":" + version;
}
coordinates.add(artifact);
}
}
}
j++;
}
}
}
}
return coordinates;
}