本文整理汇总了Java中org.gradle.tooling.BuildLauncher.forTasks方法的典型用法代码示例。如果您正苦于以下问题:Java BuildLauncher.forTasks方法的具体用法?Java BuildLauncher.forTasks怎么用?Java BuildLauncher.forTasks使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.gradle.tooling.BuildLauncher
的用法示例。
在下文中一共展示了BuildLauncher.forTasks方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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();
}
}
示例3: 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();
}
}
示例4: 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());
}
}
示例5: 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();
}
}
}
}
示例6: 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();
}
}
示例7: buildProject
import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
private void buildProject(SubMonitor monitor, ProjectConnection connection) throws CoreException {
monitor.beginTask(Messages.GradleBuildTask_monitorBuild, 100);
try {
GradleUtil.checkCancel(monitor);
BuildEnvironment environment = GradleUtil.getEnvironment(connection);
BuildLauncher builder = connection.newBuild();
builder.forTasks(tasks.toArray(new String[tasks.size()]));
OperationHandler<Void> handler = GradleUtil.configureOperation(environment, builder, configuration);
try {
builder.run(handler);
while (handler.await() == false) {
GradleUtil.checkCancel(monitor, handler);
ProgressEvent event = handler.takeProgressEvent();
if (event != null) {
monitor.setTaskName(String.format("[Gradle] %s", event.getDescriptor())); //$NON-NLS-1$
}
monitor.worked(1);
monitor.setWorkRemaining(100);
}
if (handler.hasException()) {
GradleUtil.reportException(configuration, handler.getException());
throw new GradleException(new Status(
IStatus.WARNING,
Activator.PLUGIN_ID,
MessageFormat.format(
Messages.GradleBuildTask_errorFailedToBuildProject,
configuration.projectDirectory.getName()),
handler.getException()), handler.getException());
}
} finally {
handler.close();
}
} catch (InterruptedException e) {
throw new CoreException(Status.CANCEL_STATUS);
}
}
示例8: executeTasks
import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
@Override
public void executeTasks(@NotNull final ExternalSystemTaskId id,
@NotNull final List<String> taskNames,
@NotNull String projectPath,
@Nullable final GradleExecutionSettings settings,
@NotNull final List<String> vmOptions,
@NotNull final List<String> scriptParameters,
@Nullable final String debuggerSetup,
@NotNull final ExternalSystemTaskNotificationListener listener) throws ExternalSystemException {
// TODO add support for external process mode
if (ExternalSystemApiUtil.isInProcessMode(GradleConstants.SYSTEM_ID)) {
for (GradleTaskManagerExtension gradleTaskManagerExtension : GradleTaskManagerExtension.EP_NAME.getExtensions()) {
if (gradleTaskManagerExtension.executeTasks(
id, taskNames, projectPath, settings, vmOptions, scriptParameters, debuggerSetup, listener)) {
return;
}
}
}
if(!scriptParameters.contains("--tests") && taskNames.contains("test")) {
ContainerUtil.addAll(scriptParameters, "--tests", "*");
}
Function<ProjectConnection, Void> f = new Function<ProjectConnection, Void>() {
@Override
public Void fun(ProjectConnection connection) {
final List<String> initScripts = ContainerUtil.newArrayList();
final GradleProjectResolverExtension projectResolverChain = GradleProjectResolver.createProjectResolverChain(settings);
for (GradleProjectResolverExtension resolverExtension = projectResolverChain;
resolverExtension != null;
resolverExtension = resolverExtension.getNext()) {
final String resolverClassName = resolverExtension.getClass().getName();
resolverExtension.enhanceTaskProcessing(taskNames, debuggerSetup, new Consumer<String>() {
@Override
public void consume(String script) {
if (StringUtil.isNotEmpty(script)) {
ContainerUtil.addAllNotNull(
initScripts,
"//-- Generated by " + resolverClassName,
script,
"//");
}
}
});
}
if (!initScripts.isEmpty()) {
try {
final File tempFile = FileUtil.createTempFile("init", ".gradle");
tempFile.deleteOnExit();
FileUtil.writeToFile(tempFile, StringUtil.join(initScripts, SystemProperties.getLineSeparator()));
ContainerUtil.addAll(scriptParameters, GradleConstants.INIT_SCRIPT_CMD_OPTION, tempFile.getAbsolutePath());
}
catch (IOException e) {
throw new ExternalSystemException(e);
}
}
GradleVersion gradleVersion = GradleExecutionHelper.getGradleVersion(connection);
BuildLauncher launcher = myHelper.getBuildLauncher(id, connection, settings, listener, vmOptions, scriptParameters);
launcher.forTasks(ArrayUtil.toStringArray(taskNames));
if (gradleVersion != null && gradleVersion.compareTo(GradleVersion.version("2.1")) < 0) {
myCancellationMap.put(id, new UnsupportedCancellationToken());
} else {
final CancellationTokenSource cancellationTokenSource = GradleConnector.newCancellationTokenSource();
launcher.withCancellationToken(cancellationTokenSource.token());
myCancellationMap.put(id, cancellationTokenSource);
}
try {
launcher.run();
}
finally {
myCancellationMap.remove(id);
}
return null;
}
};
myHelper.execute(projectPath, settings, f);
}
示例9: 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;
}