Search in sources :

Example 6 with ExternalSystemTaskId

use of com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId in project intellij-community by JetBrains.

the class GradleRunnerUtil method attachTaskExecutionView.

public static DuplexConsoleView attachTaskExecutionView(@NotNull final Project project, @NotNull final ConsoleView consoleView, final boolean isTaskConsoleEnabledByDefault, @Nullable final String stateStorageKey, @NotNull final ProcessHandler processHandler, @NotNull final ExternalSystemTaskId taskId) {
    final String tripleStateStorageKey = stateStorageKey != null ? stateStorageKey + "_str" : null;
    if (stateStorageKey != null && isTaskConsoleEnabledByDefault && !PropertiesComponent.getInstance().isValueSet(tripleStateStorageKey)) {
        PropertiesComponent.getInstance().setValue(tripleStateStorageKey, Boolean.TRUE.toString());
        PropertiesComponent.getInstance().setValue(stateStorageKey, Boolean.TRUE);
    }
    final TaskExecutionView gradleExecutionConsole = new TaskExecutionView(project);
    final Ref<DuplexConsoleView> duplexConsoleViewRef = Ref.create();
    final DuplexConsoleView duplexConsoleView = new DuplexConsoleView<ConsoleView, ConsoleView>(gradleExecutionConsole, consoleView, stateStorageKey) {

        @Override
        public void enableConsole(boolean primary) {
            super.enableConsole(primary);
            if (stateStorageKey != null) {
                PropertiesComponent.getInstance().setValue(tripleStateStorageKey, Boolean.toString(primary));
            }
        }

        @NotNull
        @Override
        public AnAction[] createConsoleActions() {
            final DefaultActionGroup textActionGroup = new DefaultActionGroup() {

                @Override
                public void update(AnActionEvent e) {
                    super.update(e);
                    if (duplexConsoleViewRef.get() != null) {
                        e.getPresentation().setVisible(!duplexConsoleViewRef.get().isPrimaryConsoleEnabled());
                    }
                }
            };
            final AnAction[] consoleActions = consoleView.createConsoleActions();
            for (AnAction anAction : consoleActions) {
                textActionGroup.add(anAction);
            }
            final List<AnAction> anActions = ContainerUtil.newArrayList(super.createConsoleActions());
            anActions.add(textActionGroup);
            return ArrayUtil.toObjectArray(anActions, AnAction.class);
        }
    };
    duplexConsoleViewRef.set(duplexConsoleView);
    duplexConsoleView.setDisableSwitchConsoleActionOnProcessEnd(false);
    duplexConsoleView.getSwitchConsoleActionPresentation().setIcon(AllIcons.Actions.ChangeView);
    duplexConsoleView.getSwitchConsoleActionPresentation().setText(GradleBundle.message("gradle.runner.toggle.tree.text.action.name"));
    final ExternalSystemProgressNotificationManager progressManager = ServiceManager.getService(ExternalSystemProgressNotificationManager.class);
    final ExternalSystemTaskNotificationListenerAdapter taskListener = new ExternalSystemTaskNotificationListenerAdapter() {

        @Override
        public void onStatusChange(@NotNull final ExternalSystemTaskNotificationEvent event) {
            if (event instanceof ExternalSystemTaskExecutionEvent) {
                UIUtil.invokeLaterIfNeeded(() -> {
                    if (((ExternalSystemTaskExecutionEvent) event).getProgressEvent() instanceof ExternalSystemProgressEventUnsupported) {
                        duplexConsoleView.enableConsole(false);
                    }
                    gradleExecutionConsole.onStatusChange((ExternalSystemTaskExecutionEvent) event);
                });
            }
        }

        @Override
        public void onQueued(@NotNull ExternalSystemTaskId id, final String workingDir) {
            UIUtil.invokeLaterIfNeeded(() -> gradleExecutionConsole.setWorkingDir(workingDir));
        }

        @Override
        public void onFailure(@NotNull ExternalSystemTaskId id, @NotNull final Exception e) {
            UIUtil.invokeLaterIfNeeded(() -> gradleExecutionConsole.onFailure(e));
        }

        @Override
        public void onEnd(@NotNull ExternalSystemTaskId id) {
            progressManager.removeNotificationListener(this);
        }
    };
    progressManager.addNotificationListener(taskId, taskListener);
    return duplexConsoleView;
}
Also used : ExternalSystemTaskId(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) ExternalSystemTaskNotificationListenerAdapter(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListenerAdapter) NotNull(org.jetbrains.annotations.NotNull) ExternalSystemProgressNotificationManager(com.intellij.openapi.externalSystem.service.notification.ExternalSystemProgressNotificationManager) ExternalSystemTaskNotificationEvent(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationEvent) DuplexConsoleView(com.intellij.execution.console.DuplexConsoleView)

Example 7 with ExternalSystemTaskId

use of com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId 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)

Example 8 with ExternalSystemTaskId

use of com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId in project android by JetBrains.

the class FastGradleSync method requestProjectSync.

@NotNull
public Callback requestProjectSync(@NotNull Project project) {
    Callback callback = new Callback();
    GradleExecutionSettings settings = getGradleExecutionSettings(project);
    ExternalSystemTaskId id = ExternalSystemTaskId.create(GRADLE_SYSTEM_ID, RESOLVE_PROJECT, project);
    String projectPath = project.getBasePath();
    assert projectPath != null;
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        try {
            DataNode<ProjectData> projectDataNode = myProjectResolver.resolveProjectInfo(id, projectPath, false, settings, NULL_OBJECT);
            assert projectDataNode != null;
            invokeAndWaitIfNeeded((ThrowableRunnable) () -> populate(project, projectDataNode, null, false));
            callback.setDone();
        } catch (Throwable e) {
            callback.setRejected(e);
        }
    });
    return callback;
}
Also used : GradleExecutionSettings(org.jetbrains.plugins.gradle.settings.GradleExecutionSettings) GradleUtil.getGradleExecutionSettings(com.android.tools.idea.gradle.util.GradleUtil.getGradleExecutionSettings) ExternalSystemTaskId(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId) ActionCallback(com.intellij.openapi.util.ActionCallback) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with ExternalSystemTaskId

use of com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId in project android by JetBrains.

the class AndroidGradleProjectResolverIdeaTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    initMocks(this);
    myProjectModel = new IdeaProjectStub("multiProject");
    myAndroidProject = TestProjects.createBasicProject(myProjectModel.getRootDir());
    myNativeAndroidProject = TestProjects.createNativeProject(myProjectModel.getRootDir());
    myAndroidModuleModel = myProjectModel.addModule(myAndroidProject.getName(), "androidTask");
    myNativeAndroidModuleModel = myProjectModel.addModule(myNativeAndroidProject.getName(), "nativeAndroidTask");
    myJavaModuleModel = myProjectModel.addModule("util", "compileJava", "jar", "classes");
    myProjectModel.addModule("notReallyAGradleProject");
    ProjectImportAction.AllModels allModels = new ProjectImportAction.AllModels(myProjectModel);
    allModels.addExtraProject(myAndroidProject, AndroidProject.class, myAndroidModuleModel);
    allModels.addExtraProject(myNativeAndroidProject, NativeAndroidProject.class, myNativeAndroidModuleModel);
    ExternalSystemTaskId id = ExternalSystemTaskId.create(SYSTEM_ID, RESOLVE_PROJECT, myProjectModel.getName());
    String projectPath = toSystemDependentName(myProjectModel.getBuildFile().getParent());
    ExternalSystemTaskNotificationListener notificationListener = new ExternalSystemTaskNotificationListenerAdapter() {
    };
    myResolverCtx = new DefaultProjectResolverContext(id, projectPath, null, mock(ProjectConnection.class), notificationListener, true);
    myResolverCtx.setModels(allModels);
    myProjectResolver = new AndroidGradleProjectResolver(myCommandLineArgs, myErrorHandler, myProjectFinder, myVariantSelector);
    myProjectResolver.setProjectResolverContext(myResolverCtx);
    GradleProjectResolverExtension next = new BaseGradleProjectResolverExtension();
    next.setProjectResolverContext(myResolverCtx);
    myProjectResolver.setNext(next);
}
Also used : GradleProjectResolverExtension(org.jetbrains.plugins.gradle.service.project.GradleProjectResolverExtension) BaseGradleProjectResolverExtension(org.jetbrains.plugins.gradle.service.project.BaseGradleProjectResolverExtension) ExternalSystemTaskId(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId) BaseGradleProjectResolverExtension(org.jetbrains.plugins.gradle.service.project.BaseGradleProjectResolverExtension) ExternalSystemTaskNotificationListener(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener) IdeaProjectStub(com.android.tools.idea.gradle.stubs.gradle.IdeaProjectStub) DefaultProjectResolverContext(org.jetbrains.plugins.gradle.service.project.DefaultProjectResolverContext) ExternalSystemTaskNotificationListenerAdapter(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListenerAdapter) ProjectImportAction(org.jetbrains.plugins.gradle.model.ProjectImportAction)

Aggregations

ExternalSystemTaskId (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId)9 ExternalSystemTaskNotificationListenerAdapter (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListenerAdapter)5 NotNull (org.jetbrains.annotations.NotNull)5 ExternalSystemTaskNotificationListener (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener)3 ExternalSystemProgressNotificationManager (com.intellij.openapi.externalSystem.service.notification.ExternalSystemProgressNotificationManager)3 Project (com.intellij.openapi.project.Project)3 GradleExecutionSettings (org.jetbrains.plugins.gradle.settings.GradleExecutionSettings)3 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)2 ActionCallback (com.intellij.openapi.util.ActionCallback)2 Function (com.intellij.util.Function)2 List (java.util.List)2 CancellationTokenSource (org.gradle.tooling.CancellationTokenSource)2 ProjectConnection (org.gradle.tooling.ProjectConnection)2 Nullable (org.jetbrains.annotations.Nullable)2 GradleExecutionHelper (org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper)2 GradleProjectResolverExtension (org.jetbrains.plugins.gradle.service.project.GradleProjectResolverExtension)2 AndroidProject (com.android.builder.model.AndroidProject)1 NativeAndroidProject (com.android.builder.model.NativeAndroidProject)1 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)1 ArtifactDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel)1