use of com.android.tools.idea.gradle.project.build.invoker.GradleBuildInvoker in project android by JetBrains.
the class AndroidGradleTaskManager method executeTasks.
@Override
public boolean executeTasks(@NotNull ExternalSystemTaskId id, @NotNull List<String> taskNames, @NotNull String projectPath, @Nullable GradleExecutionSettings settings, @NotNull List<String> vmOptions, @NotNull List<String> scriptParameters, @Nullable String debuggerSetup, @NotNull ExternalSystemTaskNotificationListener listener) throws ExternalSystemException {
GradleBuildInvoker gradleBuildInvoker = findGradleInvoker(id);
if (gradleBuildInvoker != null) {
GradleBuildInvoker.Request request = new GradleBuildInvoker.Request(gradleBuildInvoker.getProject(), taskNames, id);
// @formatter:off
request.setJvmArguments(vmOptions).setCommandLineArguments(scriptParameters).setTaskListener(listener).setWaitForCompletion(true);
// @formatter:on
gradleBuildInvoker.executeTasks(request);
return true;
}
// Returning false gives control back to the framework, and the task(s) will be invoked by IDEA.
return false;
}
use of com.android.tools.idea.gradle.project.build.invoker.GradleBuildInvoker in project android by JetBrains.
the class BuildApkAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
Project project = e.getProject();
if (project != null && isBuildWithGradle(project)) {
GoToApkLocationTask task = null;
Module[] modules = ModuleManager.getInstance(project).getModules();
for (Module module : modules) {
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet != null) {
String assembleTaskName = facet.getProperties().ASSEMBLE_TASK_NAME;
if (isNotEmpty(assembleTaskName)) {
task = new GoToApkLocationTask("Build APK", module, null);
break;
}
}
}
GradleBuildInvoker gradleBuildInvoker = GradleBuildInvoker.getInstance(project);
if (task != null) {
gradleBuildInvoker.add(task);
}
gradleBuildInvoker.assemble(modules, TestCompileType.NONE);
}
}
use of com.android.tools.idea.gradle.project.build.invoker.GradleBuildInvoker in project android by JetBrains.
the class GradleTaskRunner method newRunner.
static GradleTaskRunner newRunner(@NotNull Project project) {
return new GradleTaskRunner() {
@Override
public boolean run(@NotNull List<String> tasks, @Nullable BuildMode buildMode, @NotNull List<String> commandLineArguments) throws InvocationTargetException, InterruptedException {
assert !ApplicationManager.getApplication().isDispatchThread();
final GradleBuildInvoker gradleBuildInvoker = GradleBuildInvoker.getInstance(project);
final AtomicBoolean success = new AtomicBoolean();
final Semaphore done = new Semaphore();
done.down();
final GradleBuildInvoker.AfterGradleInvocationTask afterTask = new GradleBuildInvoker.AfterGradleInvocationTask() {
@Override
public void execute(@NotNull GradleInvocationResult result) {
success.set(result.isBuildSuccessful());
gradleBuildInvoker.remove(this);
done.up();
}
};
// To ensure that the "Run Configuration" waits for the Gradle tasks to be executed, we use SwingUtilities.invokeAndWait. I tried
// using Application.invokeAndWait but it never worked. IDEA also uses SwingUtilities in this scenario (see CompileStepBeforeRun.)
TransactionGuard.submitTransaction(project, () -> {
gradleBuildInvoker.add(afterTask);
gradleBuildInvoker.executeTasks(tasks, buildMode, commandLineArguments);
});
done.waitFor();
return success.get();
}
};
}
use of com.android.tools.idea.gradle.project.build.invoker.GradleBuildInvoker in project android by JetBrains.
the class AndroidGradleTestCase method invokeGradle.
@NotNull
private static GradleInvocationResult invokeGradle(@NotNull Project project, @NotNull Consumer<GradleBuildInvoker> gradleInvocationTask) throws InterruptedException {
Ref<GradleInvocationResult> resultRef = new Ref<>();
CountDownLatch latch = new CountDownLatch(1);
GradleBuildInvoker gradleBuildInvoker = GradleBuildInvoker.getInstance(project);
GradleBuildInvoker.AfterGradleInvocationTask task = result -> {
resultRef.set(result);
latch.countDown();
};
gradleBuildInvoker.add(task);
try {
gradleInvocationTask.consume(gradleBuildInvoker);
} finally {
gradleBuildInvoker.remove(task);
}
latch.await();
GradleInvocationResult result = resultRef.get();
assert result != null;
return result;
}
Aggregations