Search in sources :

Example 11 with MessageBus

use of com.intellij.util.messages.MessageBus in project intellij-community by JetBrains.

the class CompileDriver method compileInExternalProcess.

@Nullable
private TaskFuture compileInExternalProcess(@NotNull final CompileContextImpl compileContext, final boolean onlyCheckUpToDate) throws Exception {
    final CompileScope scope = compileContext.getCompileScope();
    final Collection<String> paths = CompileScopeUtil.fetchFiles(compileContext);
    List<TargetTypeBuildScope> scopes = getBuildScopes(compileContext, scope, paths);
    // need to pass scope's user data to server
    final Map<String, String> builderParams;
    if (onlyCheckUpToDate) {
        builderParams = Collections.emptyMap();
    } else {
        final Map<Key, Object> exported = scope.exportUserData();
        if (!exported.isEmpty()) {
            builderParams = new HashMap<>();
            for (Map.Entry<Key, Object> entry : exported.entrySet()) {
                final String _key = entry.getKey().toString();
                final String _value = entry.getValue().toString();
                builderParams.put(_key, _value);
            }
        } else {
            builderParams = Collections.emptyMap();
        }
    }
    final MessageBus messageBus = myProject.getMessageBus();
    final MultiMap<String, Artifact> outputToArtifact = ArtifactCompilerUtil.containsArtifacts(scopes) ? ArtifactCompilerUtil.createOutputToArtifactMap(myProject) : null;
    final BuildManager buildManager = BuildManager.getInstance();
    buildManager.cancelAutoMakeTasks(myProject);
    return buildManager.scheduleBuild(myProject, compileContext.isRebuild(), compileContext.isMake(), onlyCheckUpToDate, scopes, paths, builderParams, new DefaultMessageHandler(myProject) {

        @Override
        public void sessionTerminated(final UUID sessionId) {
            if (compileContext.shouldUpdateProblemsView()) {
                final ProblemsView view = ProblemsView.SERVICE.getInstance(myProject);
                view.clearProgress();
                view.clearOldMessages(compileContext.getCompileScope(), compileContext.getSessionId());
            }
        }

        @Override
        public void handleFailure(UUID sessionId, CmdlineRemoteProto.Message.Failure failure) {
            compileContext.addMessage(CompilerMessageCategory.ERROR, failure.hasDescription() ? failure.getDescription() : "", null, -1, -1);
            final String trace = failure.hasStacktrace() ? failure.getStacktrace() : null;
            if (trace != null) {
                LOG.info(trace);
            }
            compileContext.putUserData(COMPILE_SERVER_BUILD_STATUS, ExitStatus.ERRORS);
        }

        @Override
        protected void handleCompileMessage(UUID sessionId, CmdlineRemoteProto.Message.BuilderMessage.CompileMessage message) {
            final CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind kind = message.getKind();
            //System.out.println(compilerMessage.getText());
            final String messageText = message.getText();
            if (kind == CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind.PROGRESS) {
                final ProgressIndicator indicator = compileContext.getProgressIndicator();
                indicator.setText(messageText);
                if (message.hasDone()) {
                    indicator.setFraction(message.getDone());
                }
            } else {
                final CompilerMessageCategory category = kind == CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind.ERROR ? CompilerMessageCategory.ERROR : kind == CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind.WARNING ? CompilerMessageCategory.WARNING : CompilerMessageCategory.INFORMATION;
                String sourceFilePath = message.hasSourceFilePath() ? message.getSourceFilePath() : null;
                if (sourceFilePath != null) {
                    sourceFilePath = FileUtil.toSystemIndependentName(sourceFilePath);
                }
                final long line = message.hasLine() ? message.getLine() : -1;
                final long column = message.hasColumn() ? message.getColumn() : -1;
                final String srcUrl = sourceFilePath != null ? VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, sourceFilePath) : null;
                compileContext.addMessage(category, messageText, srcUrl, (int) line, (int) column);
                if (compileContext.shouldUpdateProblemsView() && kind == CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind.JPS_INFO) {
                    // treat JPS_INFO messages in a special way: add them as info messages to the problems view
                    final Project project = compileContext.getProject();
                    ProblemsView.SERVICE.getInstance(project).addMessage(new CompilerMessageImpl(project, category, messageText), compileContext.getSessionId());
                }
            }
        }

        @Override
        protected void handleBuildEvent(UUID sessionId, CmdlineRemoteProto.Message.BuilderMessage.BuildEvent event) {
            final CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.Type eventType = event.getEventType();
            switch(eventType) {
                case FILES_GENERATED:
                    final List<CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.GeneratedFile> generated = event.getGeneratedFilesList();
                    final CompilationStatusListener publisher = !myProject.isDisposed() ? messageBus.syncPublisher(CompilerTopics.COMPILATION_STATUS) : null;
                    Set<String> writtenArtifactOutputPaths = outputToArtifact != null ? new THashSet<>(FileUtil.PATH_HASHING_STRATEGY) : null;
                    for (CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.GeneratedFile generatedFile : generated) {
                        final String root = FileUtil.toSystemIndependentName(generatedFile.getOutputRoot());
                        final String relativePath = FileUtil.toSystemIndependentName(generatedFile.getRelativePath());
                        if (publisher != null) {
                            publisher.fileGenerated(root, relativePath);
                        }
                        if (outputToArtifact != null) {
                            Collection<Artifact> artifacts = outputToArtifact.get(root);
                            if (!artifacts.isEmpty()) {
                                for (Artifact artifact : artifacts) {
                                    ArtifactsCompiler.addChangedArtifact(compileContext, artifact);
                                }
                                writtenArtifactOutputPaths.add(FileUtil.toSystemDependentName(DeploymentUtil.appendToPath(root, relativePath)));
                            }
                        }
                    }
                    if (writtenArtifactOutputPaths != null && !writtenArtifactOutputPaths.isEmpty()) {
                        ArtifactsCompiler.addWrittenPaths(compileContext, writtenArtifactOutputPaths);
                    }
                    break;
                case BUILD_COMPLETED:
                    ExitStatus status = ExitStatus.SUCCESS;
                    if (event.hasCompletionStatus()) {
                        final CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.Status completionStatus = event.getCompletionStatus();
                        switch(completionStatus) {
                            case CANCELED:
                                status = ExitStatus.CANCELLED;
                                break;
                            case ERRORS:
                                status = ExitStatus.ERRORS;
                                break;
                            case SUCCESS:
                                status = ExitStatus.SUCCESS;
                                break;
                            case UP_TO_DATE:
                                status = ExitStatus.UP_TO_DATE;
                                break;
                        }
                    }
                    compileContext.putUserDataIfAbsent(COMPILE_SERVER_BUILD_STATUS, status);
                    break;
                case CUSTOM_BUILDER_MESSAGE:
                    if (event.hasCustomBuilderMessage()) {
                        final CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.CustomBuilderMessage message = event.getCustomBuilderMessage();
                        if (GlobalOptions.JPS_SYSTEM_BUILDER_ID.equals(message.getBuilderId()) && GlobalOptions.JPS_UNPROCESSED_FS_CHANGES_MESSAGE_ID.equals(message.getMessageType())) {
                            final String text = message.getMessageText();
                            if (!StringUtil.isEmpty(text)) {
                                compileContext.addMessage(CompilerMessageCategory.INFORMATION, text, null, -1, -1);
                            }
                        }
                    }
                    break;
            }
        }
    });
}
Also used : THashSet(gnu.trove.THashSet) MessageBus(com.intellij.util.messages.MessageBus) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) TargetTypeBuildScope(org.jetbrains.jps.api.CmdlineRemoteProto.Message.ControllerMessage.ParametersMessage.TargetTypeBuildScope) DefaultMessageHandler(com.intellij.compiler.server.DefaultMessageHandler) CmdlineRemoteProto(org.jetbrains.jps.api.CmdlineRemoteProto) Artifact(com.intellij.packaging.artifacts.Artifact) THashSet(gnu.trove.THashSet) Project(com.intellij.openapi.project.Project) MessageType(com.intellij.openapi.ui.MessageType) JavaSourceRootType(org.jetbrains.jps.model.java.JavaSourceRootType) BuildManager(com.intellij.compiler.server.BuildManager) HashMap(com.intellij.util.containers.HashMap) MultiMap(com.intellij.util.containers.MultiMap) Key(com.intellij.openapi.util.Key) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with MessageBus

use of com.intellij.util.messages.MessageBus in project intellij-plugins by JetBrains.

the class DartAnalysisServerMessages method sendAnalysisStarted.

public static void sendAnalysisStarted(@NotNull Project project, boolean isStarting) {
    final MessageBus bus = project.getMessageBus();
    final DartAnalysisNotifier publisher = bus.syncPublisher(DART_ANALYSIS_TOPIC);
    if (isStarting) {
        publisher.analysisStarted();
    } else {
        publisher.analysisFinished();
    }
}
Also used : MessageBus(com.intellij.util.messages.MessageBus)

Example 13 with MessageBus

use of com.intellij.util.messages.MessageBus in project android by JetBrains.

the class GradleSyncStateTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    initMocks(this);
    MessageBus messageBus = mock(MessageBus.class);
    Project project = getProject();
    mySyncState = new GradleSyncState(project, GradleProjectInfo.getInstance(project), myGradleFiles, messageBus, myChangeNotification, mySummary);
    when(messageBus.syncPublisher(GRADLE_SYNC_TOPIC)).thenReturn(mySyncListener);
}
Also used : Project(com.intellij.openapi.project.Project) MessageBus(com.intellij.util.messages.MessageBus)

Example 14 with MessageBus

use of com.intellij.util.messages.MessageBus in project intellij-community by JetBrains.

the class ConfigProjectComponent method runActivity.

@Override
public void runActivity(@NotNull Project project) {
    // Register project-level config managers
    final EditorFactory editorFactory = EditorFactory.getInstance();
    MessageBus bus = project.getMessageBus();
    EditorSettingsManager editorSettingsManager = new EditorSettingsManager(project);
    EncodingManager encodingManager = new EncodingManager(project);
    LineEndingsManager lineEndingsManager = new LineEndingsManager(project);
    bus.connect().subscribe(AppTopics.FILE_DOCUMENT_SYNC, encodingManager);
    bus.connect().subscribe(AppTopics.FILE_DOCUMENT_SYNC, editorSettingsManager);
    bus.connect().subscribe(AppTopics.FILE_DOCUMENT_SYNC, lineEndingsManager);
    VirtualFileManager.getInstance().addVirtualFileListener(new VirtualFileAdapter() {

        @Override
        public void fileCreated(@NotNull VirtualFileEvent event) {
            updateOpenEditors(event);
        }

        @Override
        public void fileDeleted(@NotNull VirtualFileEvent event) {
            updateOpenEditors(event);
        }

        @Override
        public void contentsChanged(@NotNull VirtualFileEvent event) {
            updateOpenEditors(event);
        }

        private void updateOpenEditors(VirtualFileEvent event) {
            final VirtualFile file = event.getFile();
            if (".editorconfig".equals(file.getName())) {
                if (ProjectRootManager.getInstance(project).getFileIndex().isInContent(file) || !Registry.is("editor.config.stop.at.project.root")) {
                    for (Editor editor : editorFactory.getAllEditors()) {
                        if (editor.isDisposed())
                            continue;
                        ;
                        ((EditorEx) editor).reinitSettings();
                    }
                }
            }
        }
    }, project);
}
Also used : EncodingManager(org.editorconfig.configmanagement.EncodingManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) EditorFactory(com.intellij.openapi.editor.EditorFactory) MessageBus(com.intellij.util.messages.MessageBus) EditorSettingsManager(org.editorconfig.configmanagement.EditorSettingsManager) VirtualFileEvent(com.intellij.openapi.vfs.VirtualFileEvent) LineEndingsManager(org.editorconfig.configmanagement.LineEndingsManager) Editor(com.intellij.openapi.editor.Editor) VirtualFileAdapter(com.intellij.openapi.vfs.VirtualFileAdapter)

Example 15 with MessageBus

use of com.intellij.util.messages.MessageBus in project intellij-community by JetBrains.

the class Alarm method addRequest.

public void addRequest(@NotNull final Runnable request, final int delay, boolean runWithActiveFrameOnly) {
    if (runWithActiveFrameOnly && !ApplicationManager.getApplication().isActive()) {
        final MessageBus bus = ApplicationManager.getApplication().getMessageBus();
        final MessageBusConnection connection = bus.connect(this);
        connection.subscribe(ApplicationActivationListener.TOPIC, new ApplicationActivationListener.Adapter() {

            @Override
            public void applicationActivated(IdeFrame ideFrame) {
                connection.disconnect();
                addRequest(request, delay);
            }
        });
    } else {
        addRequest(request, delay);
    }
}
Also used : MessageBus(com.intellij.util.messages.MessageBus) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) IdeFrame(com.intellij.openapi.wm.IdeFrame) ApplicationActivationListener(com.intellij.openapi.application.ApplicationActivationListener)

Aggregations

MessageBus (com.intellij.util.messages.MessageBus)19 Project (com.intellij.openapi.project.Project)4 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)3 Application (com.intellij.openapi.application.Application)2 InstanceInfo (com.almightyalpaca.jetbrains.plugins.discord.data.InstanceInfo)1 ReplicatedData (com.almightyalpaca.jetbrains.plugins.discord.data.ReplicatedData)1 BuildManager (com.intellij.compiler.server.BuildManager)1 DefaultMessageHandler (com.intellij.compiler.server.DefaultMessageHandler)1 MockLocalFileSystem (com.intellij.mock.MockLocalFileSystem)1 Notification (com.intellij.notification.Notification)1 NotificationAction (com.intellij.notification.NotificationAction)1 Disposable (com.intellij.openapi.Disposable)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 ApplicationActivationListener (com.intellij.openapi.application.ApplicationActivationListener)1 Editor (com.intellij.openapi.editor.Editor)1 EditorFactory (com.intellij.openapi.editor.EditorFactory)1 EditorEventMulticaster (com.intellij.openapi.editor.event.EditorEventMulticaster)1 ExtensionsArea (com.intellij.openapi.extensions.ExtensionsArea)1 ModuleManager (com.intellij.openapi.module.ModuleManager)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1