use of com.android.tools.idea.gradle.util.BuildMode in project android by JetBrains.
the class GradleBuildInvoker method assemble.
public void assemble(@NotNull Module[] modules, @NotNull TestCompileType testCompileType, @NotNull List<String> arguments) {
BuildMode buildMode = ASSEMBLE;
setProjectBuildMode(buildMode);
List<String> tasks = findTasksToExecute(modules, buildMode, testCompileType);
executeTasks(tasks, arguments);
}
use of com.android.tools.idea.gradle.util.BuildMode in project android by JetBrains.
the class GradleBuildInvoker method generateSources.
public void generateSources(boolean cleanProject) {
BuildMode buildMode = SOURCE_GEN;
setProjectBuildMode(buildMode);
ModuleManager moduleManager = ModuleManager.getInstance(myProject);
List<String> tasks = findTasksToExecute(moduleManager.getModules(), buildMode, TestCompileType.NONE);
if (cleanProject) {
tasks.add(0, CLEAN_TASK_NAME);
}
executeTasks(tasks, Collections.singletonList(createGenerateSourcesOnlyProperty()));
}
use of com.android.tools.idea.gradle.util.BuildMode in project android by JetBrains.
the class GradleBuildInvoker method compileJava.
/**
* Execute Gradle tasks that compile the relevant Java sources.
*
* @param modules Modules that need to be compiled
* @param testCompileType Kind of tests that the caller is interested in. Use {@link TestCompileType#NONE} if compiling just the
* main sources, {@link TestCompileType#UNIT_TESTS} if class files for running unit tests are needed.
*/
public void compileJava(@NotNull Module[] modules, @NotNull TestCompileType testCompileType) {
BuildMode buildMode = COMPILE_JAVA;
setProjectBuildMode(buildMode);
List<String> tasks = findTasksToExecute(modules, buildMode, testCompileType);
executeTasks(tasks);
}
use of com.android.tools.idea.gradle.util.BuildMode in project android by JetBrains.
the class MakeBeforeRunTaskProvider method createBuilder.
private static BeforeRunBuilder createBuilder(@NotNull ExecutionEnvironment env, @NotNull Module[] modules, @NotNull RunConfiguration configuration, @Nullable AndroidRunConfigContext runConfigContext, @Nullable String userGoal) {
if (modules.length == 0) {
throw new IllegalStateException("Unable to determine list of modules to build");
}
if (!isEmpty(userGoal)) {
return new DefaultGradleBuilder(Collections.singletonList(userGoal), null);
}
GradleModuleTasksProvider gradleTasksProvider = new GradleModuleTasksProvider(modules);
GradleBuildInvoker.TestCompileType testCompileType = GradleBuildInvoker.getTestCompileType(configuration.getType().getId());
if (testCompileType == GradleBuildInvoker.TestCompileType.UNIT_TESTS) {
BuildMode buildMode = BuildMode.COMPILE_JAVA;
return new DefaultGradleBuilder(gradleTasksProvider.getUnitTestTasks(buildMode), buildMode);
}
InstantRunContext irContext = env.getCopyableUserData(InstantRunContext.KEY);
DeviceFutures deviceFutures = runConfigContext == null ? null : runConfigContext.getTargetDevices();
if (deviceFutures == null || irContext == null) {
return new DefaultGradleBuilder(gradleTasksProvider.getTasksFor(BuildMode.ASSEMBLE, testCompileType), BuildMode.ASSEMBLE);
}
List<AndroidDevice> targetDevices = deviceFutures.getDevices();
assert targetDevices.size() == 1 : "instant run context available, but deploying to > 1 device";
return new InstantRunBuilder(getLaunchedDevice(targetDevices.get(0)), irContext, runConfigContext, gradleTasksProvider);
}
use of com.android.tools.idea.gradle.util.BuildMode 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();
}
};
}
Aggregations