Search in sources :

Example 6 with BuildMode

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);
}
Also used : BuildMode(com.android.tools.idea.gradle.util.BuildMode)

Example 7 with BuildMode

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()));
}
Also used : BuildMode(com.android.tools.idea.gradle.util.BuildMode) ModuleManager(com.intellij.openapi.module.ModuleManager)

Example 8 with BuildMode

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);
}
Also used : BuildMode(com.android.tools.idea.gradle.util.BuildMode)

Example 9 with BuildMode

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);
}
Also used : InstantRunContext(com.android.tools.idea.fd.InstantRunContext) InstantRunBuilder(com.android.tools.idea.fd.InstantRunBuilder) BuildMode(com.android.tools.idea.gradle.util.BuildMode) GradleBuildInvoker(com.android.tools.idea.gradle.project.build.invoker.GradleBuildInvoker)

Example 10 with BuildMode

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();
        }
    };
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GradleInvocationResult(com.android.tools.idea.gradle.project.build.invoker.GradleInvocationResult) List(java.util.List) Semaphore(com.intellij.util.concurrency.Semaphore) BuildMode(com.android.tools.idea.gradle.util.BuildMode) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable) GradleBuildInvoker(com.android.tools.idea.gradle.project.build.invoker.GradleBuildInvoker)

Aggregations

BuildMode (com.android.tools.idea.gradle.util.BuildMode)10 BuildSettings (com.android.tools.idea.gradle.project.BuildSettings)2 GradleBuildInvoker (com.android.tools.idea.gradle.project.build.invoker.GradleBuildInvoker)2 ModuleManager (com.intellij.openapi.module.ModuleManager)2 NotNull (org.jetbrains.annotations.NotNull)2 InstantRunBuilder (com.android.tools.idea.fd.InstantRunBuilder)1 InstantRunContext (com.android.tools.idea.fd.InstantRunContext)1 GradleInvocationResult (com.android.tools.idea.gradle.project.build.invoker.GradleInvocationResult)1 GradleSyncInvoker (com.android.tools.idea.gradle.project.sync.GradleSyncInvoker)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 CompositeScope (com.intellij.compiler.impl.CompositeScope)1 ModuleCompileScope (com.intellij.compiler.impl.ModuleCompileScope)1 ProjectCompileScope (com.intellij.compiler.impl.ProjectCompileScope)1 Module (com.intellij.openapi.module.Module)1 Semaphore (com.intellij.util.concurrency.Semaphore)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1