Search in sources :

Example 1 with RunnableAdapter

use of com.intellij.history.utils.RunnableAdapter in project intellij-community by JetBrains.

the class ActionsTest method testActionInsideCommandSurroundedWithSomeChanges.

public void testActionInsideCommandSurroundedWithSomeChanges() throws Exception {
    // see testActionInsideCommand comment
    final VirtualFile f = createFile("f.txt");
    CommandProcessor.getInstance().executeCommand(myProject, new RunnableAdapter() {

        @Override
        public void doRun() throws IOException {
            setContent(f, "file");
            setDocumentTextFor(f, "doc1");
            LocalHistoryAction a = LocalHistory.getInstance().startAction("action");
            setDocumentTextFor(f, "doc2");
            a.finish();
            saveDocument(f);
            setContent(f, "doc3");
        }
    }, "command", null);
    List<Revision> rr = getRevisionsFor(f);
    assertEquals(4, rr.size());
    assertContent("doc3", rr.get(0).findEntry());
    assertContent("doc1", rr.get(1).findEntry());
    assertContent("", rr.get(2).findEntry());
    assertEquals("command", rr.get(1).getChangeSetName());
    assertNull(rr.get(2).getChangeSetName());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RunnableAdapter(com.intellij.history.utils.RunnableAdapter) Revision(com.intellij.history.core.revisions.Revision) LocalHistoryAction(com.intellij.history.LocalHistoryAction) IOException(java.io.IOException)

Example 2 with RunnableAdapter

use of com.intellij.history.utils.RunnableAdapter in project sonarlint-intellij by SonarSource.

the class ServerUpdateTask method run.

public void run(@NotNull ProgressIndicator indicator) {
    indicator.setText("Fetching data...");
    try {
        TaskProgressMonitor monitor = new TaskProgressMonitor(indicator);
        ServerConfiguration serverConfiguration = SonarLintUtils.getServerConfiguration(server);
        if (!onlyModules) {
            UpdateResult updateResult = engine.update(serverConfiguration, monitor);
            Collection<SonarAnalyzer> tooOld = updateResult.analyzers().stream().filter(SonarAnalyzer::sonarlintCompatible).filter(ServerUpdateTask::tooOld).collect(Collectors.toList());
            if (!tooOld.isEmpty()) {
                ApplicationManager.getApplication().invokeAndWait(() -> Messages.showWarningDialog(buildMinimumVersionFailMessage(tooOld), "Analyzers Not Loaded"), ModalityState.any());
            }
            log.log("Server binding '" + server.getName() + "' updated", LogOutput.Level.INFO);
        }
        updateModules(serverConfiguration, monitor);
    } catch (CanceledException e) {
        LOGGER.info("Update of server '" + server.getName() + "' was cancelled");
        log.log("Update of server '" + server.getName() + "' was cancelled", LogOutput.Level.INFO);
    } catch (Exception e) {
        LOGGER.info("Error updating from server '" + server.getName() + "'", e);
        final String msg = (e.getMessage() != null) ? e.getMessage() : ("Failed to update binding for server configuration '" + server.getName() + "'");
        ApplicationManager.getApplication().invokeAndWait(new RunnableAdapter() {

            @Override
            public void doRun() {
                Messages.showErrorDialog((Project) null, msg, "Update Failed");
            }
        }, ModalityState.any());
    }
}
Also used : CanceledException(org.sonarsource.sonarlint.core.client.api.exceptions.CanceledException) RunnableAdapter(com.intellij.history.utils.RunnableAdapter) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) SonarAnalyzer(org.sonarsource.sonarlint.core.client.api.connected.SonarAnalyzer) TaskProgressMonitor(org.sonarlint.intellij.util.TaskProgressMonitor) UpdateResult(org.sonarsource.sonarlint.core.client.api.connected.UpdateResult) CanceledException(org.sonarsource.sonarlint.core.client.api.exceptions.CanceledException)

Example 3 with RunnableAdapter

use of com.intellij.history.utils.RunnableAdapter in project sonarlint-intellij by SonarSource.

the class ServerUpdateTask method updateModules.

/**
 * Updates all known modules belonging to a server configuration.
 * It assumes that the server binding is updated.
 */
private void updateModules(ServerConfiguration serverConfiguration, TaskProgressMonitor monitor) {
    Set<String> failedModules = new LinkedHashSet<>();
    for (Map.Entry<String, List<Project>> entry : projectsPerModule.entrySet()) {
        try {
            updateModule(serverConfiguration, entry.getKey(), entry.getValue(), monitor);
        } catch (Exception e) {
            // in case of error, save module key and keep updating other modules
            LOGGER.info(e.getMessage(), e);
            failedModules.add(entry.getKey());
        }
    }
    if (!projectsPerModule.isEmpty() && !failedModules.isEmpty()) {
        String errorMsg = "Failed to update the following modules. " + "Please check if the server bindings are updated and the module key is correct: " + failedModules.toString();
        log.log(errorMsg, LogOutput.Level.WARN);
        ApplicationManager.getApplication().invokeLater(new RunnableAdapter() {

            @Override
            public void doRun() {
                Messages.showWarningDialog((Project) null, errorMsg, "Modules Not Updated");
            }
        }, ModalityState.any());
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Project(com.intellij.openapi.project.Project) RunnableAdapter(com.intellij.history.utils.RunnableAdapter) List(java.util.List) Map(java.util.Map) CanceledException(org.sonarsource.sonarlint.core.client.api.exceptions.CanceledException)

Example 4 with RunnableAdapter

use of com.intellij.history.utils.RunnableAdapter in project intellij-community by JetBrains.

the class IntegrationTestCase method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    LocalHistoryImpl.getInstanceImpl().cleanupForNextTest();
    Clock.reset();
    Paths.useSystemCaseSensitivity();
    myGateway = new IdeaGateway();
    ApplicationManager.getApplication().runWriteAction(new RunnableAdapter() {

        @Override
        public void doRun() throws Exception {
            setUpInWriteAction();
        }
    });
}
Also used : RunnableAdapter(com.intellij.history.utils.RunnableAdapter) IOException(java.io.IOException)

Example 5 with RunnableAdapter

use of com.intellij.history.utils.RunnableAdapter in project intellij-community by JetBrains.

the class FileListeningTest method testRenamingFileOnlyAfterRenamedEvent.

public void testRenamingFileOnlyAfterRenamedEvent() throws Exception {
    final VirtualFile f = createFile("old.txt");
    final int[] log = new int[2];
    VirtualFileListener l = new VirtualFileAdapter() {

        @Override
        public void beforePropertyChange(@NotNull VirtualFilePropertyEvent e) {
            log[0] = getRevisionsFor(f).size();
        }
    };
    assertEquals(2, getRevisionsFor(f).size());
    addFileListenerDuring(l, new RunnableAdapter() {

        @Override
        public void doRun() throws IOException {
            rename(f, "new.txt");
        }
    });
    assertEquals(2, log[0]);
    assertEquals(3, getRevisionsFor(f).size());
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) RunnableAdapter(com.intellij.history.utils.RunnableAdapter) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

RunnableAdapter (com.intellij.history.utils.RunnableAdapter)5 IOException (java.io.IOException)3 CanceledException (org.sonarsource.sonarlint.core.client.api.exceptions.CanceledException)2 LocalHistoryAction (com.intellij.history.LocalHistoryAction)1 Revision (com.intellij.history.core.revisions.Revision)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 NotNull (org.jetbrains.annotations.NotNull)1 TaskProgressMonitor (org.sonarlint.intellij.util.TaskProgressMonitor)1 ServerConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration)1 SonarAnalyzer (org.sonarsource.sonarlint.core.client.api.connected.SonarAnalyzer)1 UpdateResult (org.sonarsource.sonarlint.core.client.api.connected.UpdateResult)1