Skip to content

Commit

Permalink
Merge pull request #280 from gradle/wolfs/expose-tapi-connection
Browse files Browse the repository at this point in the history
Add ToolingApiGradleClient.runOperation
  • Loading branch information
wolfs authored Oct 6, 2020
2 parents f7e9925 + 4afe095 commit 0549d0e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/main/java/org/gradle/profiler/ToolingApiGradleClient.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.gradle.profiler;

import org.gradle.tooling.BuildAction;
import org.gradle.tooling.*;
import org.gradle.tooling.BuildActionExecuter;
import org.gradle.tooling.GradleConnectionException;
import org.gradle.tooling.LongRunningOperation;
import org.gradle.tooling.ProjectConnection;

import java.util.List;
import java.util.function.Consumer;
Expand Down Expand Up @@ -32,9 +35,16 @@ private static <T extends LongRunningOperation, R> R run(T operation, Function<T
}
}

public <T extends LongRunningOperation, R> R runOperation(
Function<ProjectConnection, T> createOperation,
Function<T, R> operationAction
) {
return run(createOperation.apply(projectConnection), operationAction);
}

@Override
public void runTasks(List<String> tasks, List<String> gradleArgs, List<String> jvmArgs) {
run(projectConnection.newBuild(), build -> {
runOperation(ProjectConnection::newBuild, build -> {
build.forTasks(tasks.toArray(new String[0]));
build.withArguments(gradleArgs);
build.setJvmArguments(jvmArgs);
Expand All @@ -45,7 +55,7 @@ public void runTasks(List<String> tasks, List<String> gradleArgs, List<String> j

@Override
public void loadToolingModel(List<String> tasks, List<String> gradleArgs, List<String> jvmArgs, Class<?> toolingModel) {
run(projectConnection.model(toolingModel), build -> {
runOperation(connection -> connection.model(toolingModel), build -> {
build.forTasks(tasks.toArray(new String[0]));
build.withArguments(gradleArgs);
build.setJvmArguments(jvmArgs);
Expand All @@ -56,7 +66,7 @@ public void loadToolingModel(List<String> tasks, List<String> gradleArgs, List<S

@Override
public <T> T runToolingAction(List<String> tasks, List<String> gradleArgs, List<String> jvmArgs, BuildAction<T> action, Consumer<BuildActionExecuter<?>> configureAction) {
return run(projectConnection.action(action), build -> {
return runOperation(connection -> connection.action(action), build -> {
build.forTasks(tasks.toArray(new String[0]));
build.withArguments(gradleArgs);
build.setJvmArguments(jvmArgs);
Expand Down

0 comments on commit 0549d0e

Please sign in to comment.