Search in sources :

Example 1 with ExternalSystemTaskNotificationEvent

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

the class GradleExecutionHelper method prepare.

@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
public static void prepare(@NotNull LongRunningOperation operation, @NotNull final ExternalSystemTaskId id, @NotNull GradleExecutionSettings settings, @NotNull final ExternalSystemTaskNotificationListener listener, @NotNull ProjectConnection connection, @NotNull final OutputStream standardOutput, @NotNull final OutputStream standardError) {
    Set<String> jvmArgs = settings.getVmOptions();
    if (!jvmArgs.isEmpty()) {
        // merge gradle args e.g. defined in gradle.properties
        BuildEnvironment buildEnvironment = getBuildEnvironment(connection);
        Collection<String> merged = buildEnvironment != null ? mergeJvmArgs(settings.getServiceDirectory(), buildEnvironment.getJava().getJvmArguments(), jvmArgs) : jvmArgs;
        // filter nulls and empty strings
        List<String> filteredArgs = ContainerUtil.mapNotNull(merged, s -> StringUtil.isEmpty(s) ? null : s);
        operation.setJvmArguments(ArrayUtil.toStringArray(filteredArgs));
    }
    if (settings.isOfflineWork()) {
        settings.withArgument(GradleConstants.OFFLINE_MODE_CMD_OPTION);
    }
    final Application application = ApplicationManager.getApplication();
    if (application != null && application.isUnitTestMode()) {
        if (!settings.getArguments().contains("--quiet")) {
            settings.withArgument("--info");
        }
        settings.withArgument("--recompile-scripts");
    }
    if (!settings.getArguments().isEmpty()) {
        LOG.info("Passing command-line args to Gradle Tooling API: " + StringUtil.join(settings.getArguments(), " "));
        // filter nulls and empty strings
        List<String> filteredArgs = ContainerUtil.mapNotNull(settings.getArguments(), s -> StringUtil.isEmpty(s) ? null : s);
        // TODO remove this replacement when --tests option will become available for tooling API
        replaceTestCommandOptionWithInitScript(filteredArgs);
        operation.withArguments(ArrayUtil.toStringArray(filteredArgs));
    }
    final String javaHome = settings.getJavaHome();
    if (javaHome != null && new File(javaHome).isDirectory()) {
        operation.setJavaHome(new File(javaHome));
    }
    operation.addProgressListener(new ProgressListener() {

        @Override
        public void statusChanged(ProgressEvent event) {
            listener.onStatusChange(new ExternalSystemTaskNotificationEvent(id, event.getDescription()));
        }
    });
    operation.addProgressListener(new org.gradle.tooling.events.ProgressListener() {

        @Override
        public void statusChanged(org.gradle.tooling.events.ProgressEvent event) {
            listener.onStatusChange(GradleProgressEventConverter.convert(id, event));
        }
    });
    operation.setStandardOutput(standardOutput);
    operation.setStandardError(standardError);
}
Also used : ExternalSystemTaskNotificationEvent(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationEvent) BuildEnvironment(org.gradle.tooling.model.build.BuildEnvironment) Application(com.intellij.openapi.application.Application) File(java.io.File)

Example 2 with ExternalSystemTaskNotificationEvent

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

the class GradleProgressEventConverter method convert.

@NotNull
public static ExternalSystemTaskNotificationEvent convert(ExternalSystemTaskId id, ProgressEvent event) {
    final InternalOperationDescriptor internalDesc = event.getDescriptor() instanceof DefaultOperationDescriptor ? ((DefaultOperationDescriptor) event.getDescriptor()).getInternalOperationDescriptor() : null;
    final String eventId = internalDesc == null ? event.getDescriptor().getDisplayName() : internalDesc.getId().toString();
    final String parentEventId;
    if (event.getDescriptor().getParent() == null) {
        parentEventId = null;
    } else {
        parentEventId = internalDesc == null ? event.getDescriptor().getParent().getDisplayName() : internalDesc.getParentId().toString();
    }
    final String description = event.getDescriptor().getName();
    if (event instanceof StartEvent) {
        final OperationDescriptor descriptor = convert(event.getDescriptor(), event.getEventTime());
        return new ExternalSystemTaskExecutionEvent(id, new ExternalSystemStartEventImpl<>(eventId, parentEventId, descriptor));
    } else if (event instanceof FinishEvent) {
        final OperationDescriptor descriptor = convert(event.getDescriptor(), event.getEventTime());
        return new ExternalSystemTaskExecutionEvent(id, new ExternalSystemFinishEventImpl<>(eventId, parentEventId, descriptor, convert(((FinishEvent) event).getResult())));
    } else if (event instanceof TaskProgressEvent) {
        final OperationDescriptor descriptor = convert(event.getDescriptor(), event.getEventTime());
        return new ExternalSystemTaskExecutionEvent(id, new BaseExternalSystemProgressEvent<>(eventId, parentEventId, descriptor));
    } else {
        return new ExternalSystemTaskNotificationEvent(id, description);
    }
}
Also used : InternalOperationDescriptor(org.gradle.tooling.internal.protocol.events.InternalOperationDescriptor) OperationDescriptor(com.intellij.openapi.externalSystem.model.task.event.OperationDescriptor) DefaultOperationDescriptor(org.gradle.tooling.events.internal.DefaultOperationDescriptor) TaskOperationDescriptor(org.gradle.tooling.events.task.TaskOperationDescriptor) JvmTestOperationDescriptor(org.gradle.tooling.events.test.JvmTestOperationDescriptor) InternalOperationDescriptor(org.gradle.tooling.internal.protocol.events.InternalOperationDescriptor) DefaultOperationDescriptor(org.gradle.tooling.events.internal.DefaultOperationDescriptor) ExternalSystemTaskNotificationEvent(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationEvent) TaskProgressEvent(org.gradle.tooling.events.task.TaskProgressEvent) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ExternalSystemTaskNotificationEvent

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

Aggregations

ExternalSystemTaskNotificationEvent (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationEvent)3 NotNull (org.jetbrains.annotations.NotNull)2 DuplexConsoleView (com.intellij.execution.console.DuplexConsoleView)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 Application (com.intellij.openapi.application.Application)1 ExternalSystemTaskId (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId)1 ExternalSystemTaskNotificationListenerAdapter (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListenerAdapter)1 OperationDescriptor (com.intellij.openapi.externalSystem.model.task.event.OperationDescriptor)1 ExternalSystemProgressNotificationManager (com.intellij.openapi.externalSystem.service.notification.ExternalSystemProgressNotificationManager)1 File (java.io.File)1 DefaultOperationDescriptor (org.gradle.tooling.events.internal.DefaultOperationDescriptor)1 TaskOperationDescriptor (org.gradle.tooling.events.task.TaskOperationDescriptor)1 TaskProgressEvent (org.gradle.tooling.events.task.TaskProgressEvent)1 JvmTestOperationDescriptor (org.gradle.tooling.events.test.JvmTestOperationDescriptor)1 InternalOperationDescriptor (org.gradle.tooling.internal.protocol.events.InternalOperationDescriptor)1 BuildEnvironment (org.gradle.tooling.model.build.BuildEnvironment)1