Search in sources :

Example 1 with BuildActionExecuter

use of org.gradle.tooling.BuildActionExecuter in project android by JetBrains.

the class NewGradleSync method sync.

@VisibleForTesting
@NotNull
Callback sync(@NotNull Project project) {
    Callback callback = new Callback();
    if (project.isDisposed()) {
        callback.reject(String.format("Project '%1$s' is already disposed", project.getName()));
    }
    // TODO: Handle sync cancellation.
    // TODO: Show Gradle output.
    GradleExecutionSettings executionSettings = getOrCreateGradleExecutionSettings(project, useEmbeddedGradle());
    Function<ProjectConnection, Void> syncFunction = connection -> {
        List<Class<?>> modelTypes = Lists.newArrayList(AndroidProject.class, NativeAndroidProject.class, GradleBuild.class, ModuleExtendedModel.class);
        BuildActionExecuter<SyncAction.ProjectModels> executor = connection.action(new SyncAction(modelTypes));
        ExternalSystemTaskNotificationListener listener = new ExternalSystemTaskNotificationListenerAdapter() {
        };
        List<String> commandLineArgs = myCommandLineArgs.get(project);
        ExternalSystemTaskId id = createId(project);
        prepare(executor, id, executionSettings, listener, Collections.emptyList(), commandLineArgs, connection);
        CancellationTokenSource cancellationTokenSource = newCancellationTokenSource();
        executor.withCancellationToken(cancellationTokenSource.token());
        try {
            SyncAction.ProjectModels models = executor.run();
            callback.setDone(models);
        } catch (RuntimeException e) {
            callback.setRejected(e);
        }
        return null;
    };
    myHelper.execute(getBaseDirPath(project).getPath(), executionSettings, syncFunction);
    return callback;
}
Also used : GradleExecutionSettings(org.jetbrains.plugins.gradle.settings.GradleExecutionSettings) GradleUtil.getOrCreateGradleExecutionSettings(com.android.tools.idea.gradle.util.GradleUtil.getOrCreateGradleExecutionSettings) ExternalSystemTaskNotificationListener(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener) GradleExecutionSettings(org.jetbrains.plugins.gradle.settings.GradleExecutionSettings) CommandLineArgs(com.android.tools.idea.gradle.project.sync.common.CommandLineArgs) ExceptionUtil.getRootCause(com.intellij.util.ExceptionUtil.getRootCause) GradleUtil.getOrCreateGradleExecutionSettings(com.android.tools.idea.gradle.util.GradleUtil.getOrCreateGradleExecutionSettings) ExternalSystemTaskNotificationListenerAdapter(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListenerAdapter) GradleExecutionHelper(org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper) Lists(com.google.common.collect.Lists) Task(com.intellij.openapi.progress.Task) NativeAndroidProject(com.android.builder.model.NativeAndroidProject) GRADLE_SYSTEM_ID(com.android.tools.idea.gradle.util.GradleUtil.GRADLE_SYSTEM_ID) RESOLVE_PROJECT(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskType.RESOLVE_PROJECT) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) GradleConnector.newCancellationTokenSource(org.gradle.tooling.GradleConnector.newCancellationTokenSource) GradleBuild(org.gradle.tooling.model.gradle.GradleBuild) ActionCallback(com.intellij.openapi.util.ActionCallback) AndroidProject(com.android.builder.model.AndroidProject) ProgressExecutionMode(com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode) StringUtil.isEmpty(com.intellij.openapi.util.text.StringUtil.isEmpty) UIUtil.invokeAndWaitIfNeeded(com.intellij.util.ui.UIUtil.invokeAndWaitIfNeeded) ModuleExtendedModel(org.jetbrains.plugins.gradle.model.ModuleExtendedModel) GradleExecutionHelper.prepare(org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper.prepare) Nullable(org.jetbrains.annotations.Nullable) ExternalSystemTaskId(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) CancellationTokenSource(org.gradle.tooling.CancellationTokenSource) List(java.util.List) Projects.getBaseDirPath(com.android.tools.idea.gradle.util.Projects.getBaseDirPath) Function(com.intellij.util.Function) BuildActionExecuter(org.gradle.tooling.BuildActionExecuter) ProjectConnection(org.gradle.tooling.ProjectConnection) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) ExternalSystemTaskId(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId) ProjectConnection(org.gradle.tooling.ProjectConnection) NativeAndroidProject(com.android.builder.model.NativeAndroidProject) AndroidProject(com.android.builder.model.AndroidProject) BuildActionExecuter(org.gradle.tooling.BuildActionExecuter) ExternalSystemTaskNotificationListenerAdapter(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListenerAdapter) NativeAndroidProject(com.android.builder.model.NativeAndroidProject) ExternalSystemTaskNotificationListener(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener) ActionCallback(com.intellij.openapi.util.ActionCallback) ModuleExtendedModel(org.jetbrains.plugins.gradle.model.ModuleExtendedModel) GradleConnector.newCancellationTokenSource(org.gradle.tooling.GradleConnector.newCancellationTokenSource) CancellationTokenSource(org.gradle.tooling.CancellationTokenSource) List(java.util.List) GradleBuild(org.gradle.tooling.model.gradle.GradleBuild) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AndroidProject (com.android.builder.model.AndroidProject)1 NativeAndroidProject (com.android.builder.model.NativeAndroidProject)1 CommandLineArgs (com.android.tools.idea.gradle.project.sync.common.CommandLineArgs)1 GRADLE_SYSTEM_ID (com.android.tools.idea.gradle.util.GradleUtil.GRADLE_SYSTEM_ID)1 GradleUtil.getOrCreateGradleExecutionSettings (com.android.tools.idea.gradle.util.GradleUtil.getOrCreateGradleExecutionSettings)1 Projects.getBaseDirPath (com.android.tools.idea.gradle.util.Projects.getBaseDirPath)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Lists (com.google.common.collect.Lists)1 Logger (com.intellij.openapi.diagnostic.Logger)1 ExternalSystemTaskId (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId)1 ExternalSystemTaskNotificationListener (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener)1 ExternalSystemTaskNotificationListenerAdapter (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListenerAdapter)1 RESOLVE_PROJECT (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskType.RESOLVE_PROJECT)1 ProgressExecutionMode (com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 Project (com.intellij.openapi.project.Project)1 ActionCallback (com.intellij.openapi.util.ActionCallback)1 StringUtil.isEmpty (com.intellij.openapi.util.text.StringUtil.isEmpty)1 ExceptionUtil.getRootCause (com.intellij.util.ExceptionUtil.getRootCause)1