Search in sources :

Example 1 with GradleBuildInvoker

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

Example 2 with GradleBuildInvoker

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);
    }
}
Also used : Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) GradleBuildInvoker(com.android.tools.idea.gradle.project.build.invoker.GradleBuildInvoker)

Example 3 with GradleBuildInvoker

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();
        }
    };
}
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)

Example 4 with GradleBuildInvoker

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Projects.isLegacyIdeaAndroidProject(com.android.tools.idea.gradle.util.Projects.isLegacyIdeaAndroidProject) TestFixtureBuilder(com.intellij.testFramework.fixtures.TestFixtureBuilder) PsiManager(com.intellij.psi.PsiManager) Matcher(java.util.regex.Matcher) ProjectManager(com.intellij.openapi.project.ProjectManager) JavaTestFixtureFactory(com.intellij.testFramework.fixtures.JavaTestFixtureFactory) GradleProjectImporter(com.android.tools.idea.gradle.project.importing.GradleProjectImporter) Messages(com.intellij.openapi.ui.Messages) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) GradleSyncInvoker(com.android.tools.idea.gradle.project.sync.GradleSyncInvoker) Truth.assertAbout(com.google.common.truth.Truth.assertAbout) IdeInfo(com.android.tools.idea.IdeInfo) PlatformTestCase(com.intellij.testFramework.PlatformTestCase) EmptyModuleType(com.intellij.openapi.module.EmptyModuleType) AndroidGradleProjectComponent(com.android.tools.idea.gradle.project.AndroidGradleProjectComponent) LocalProperties(com.android.tools.idea.gradle.util.LocalProperties) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) AndroidProjectInfo(com.android.tools.idea.project.AndroidProjectInfo) Nullable(org.jetbrains.annotations.Nullable) CountDownLatch(java.util.concurrent.CountDownLatch) FileSubject.file(com.android.tools.idea.testing.FileSubject.file) IdeaTestApplication(com.intellij.idea.IdeaTestApplication) Pattern(java.util.regex.Pattern) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) GradleSyncState(com.android.tools.idea.gradle.project.sync.GradleSyncState) Consumer(com.intellij.util.Consumer) GradleSyncListener(com.android.tools.idea.gradle.project.sync.GradleSyncListener) JDK_1_8(com.intellij.pom.java.LanguageLevel.JDK_1_8) WriteCommandAction.runWriteCommandAction(com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction) WriteAction(com.intellij.openapi.application.WriteAction) SdkConstants(com.android.SdkConstants) ModuleManager(com.intellij.openapi.module.ModuleManager) MINUTES(java.util.concurrent.TimeUnit.MINUTES) Lists(com.google.common.collect.Lists) IdeaProjectTestFixture(com.intellij.testFramework.fixtures.IdeaProjectTestFixture) Files(com.google.common.io.Files) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) ModuleType(com.intellij.openapi.module.ModuleType) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidTestBase(org.jetbrains.android.AndroidTestBase) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) Charsets(com.google.common.base.Charsets) SIMPLE_APPLICATION(com.android.tools.idea.testing.TestProjectPaths.SIMPLE_APPLICATION) Files.write(com.google.common.io.Files.write) GradleBuildInvoker(com.android.tools.idea.gradle.project.build.invoker.GradleBuildInvoker) ProjectManagerEx(com.intellij.openapi.project.ex.ProjectManagerEx) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) IOException(java.io.IOException) StringUtil.isEmpty(com.intellij.openapi.util.text.StringUtil.isEmpty) GradleWrapper(com.android.tools.idea.gradle.util.GradleWrapper) TestDialog(com.intellij.openapi.ui.TestDialog) Truth.assertThat(com.google.common.truth.Truth.assertThat) Sdk(com.intellij.openapi.projectRoots.Sdk) RegEx(javax.annotation.RegEx) File(java.io.File) IdeSdks(com.android.tools.idea.sdk.IdeSdks) TestUtils.getWorkspaceFile(com.android.testutils.TestUtils.getWorkspaceFile) TestUtils.getSdk(com.android.testutils.TestUtils.getSdk) Result(com.intellij.openapi.application.Result) GradleInvocationResult(com.android.tools.idea.gradle.project.build.invoker.GradleInvocationResult) Jdks(com.android.tools.idea.sdk.Jdks) IdeaTestFixtureFactory(com.intellij.testFramework.fixtures.IdeaTestFixtureFactory) ModuleFileType(com.intellij.ide.highlighter.ModuleFileType) GradleInvocationResult(com.android.tools.idea.gradle.project.build.invoker.GradleInvocationResult) Ref(com.intellij.openapi.util.Ref) CountDownLatch(java.util.concurrent.CountDownLatch) GradleBuildInvoker(com.android.tools.idea.gradle.project.build.invoker.GradleBuildInvoker) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GradleBuildInvoker (com.android.tools.idea.gradle.project.build.invoker.GradleBuildInvoker)4 GradleInvocationResult (com.android.tools.idea.gradle.project.build.invoker.GradleInvocationResult)2 Module (com.intellij.openapi.module.Module)2 Project (com.intellij.openapi.project.Project)2 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 SdkConstants (com.android.SdkConstants)1 TestUtils.getSdk (com.android.testutils.TestUtils.getSdk)1 TestUtils.getWorkspaceFile (com.android.testutils.TestUtils.getWorkspaceFile)1 IdeInfo (com.android.tools.idea.IdeInfo)1 AndroidGradleProjectComponent (com.android.tools.idea.gradle.project.AndroidGradleProjectComponent)1 GradleProjectImporter (com.android.tools.idea.gradle.project.importing.GradleProjectImporter)1 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 GradleSyncInvoker (com.android.tools.idea.gradle.project.sync.GradleSyncInvoker)1 GradleSyncListener (com.android.tools.idea.gradle.project.sync.GradleSyncListener)1 GradleSyncState (com.android.tools.idea.gradle.project.sync.GradleSyncState)1 BuildMode (com.android.tools.idea.gradle.util.BuildMode)1 GradleWrapper (com.android.tools.idea.gradle.util.GradleWrapper)1 LocalProperties (com.android.tools.idea.gradle.util.LocalProperties)1