Search in sources :

Example 66 with ClientInputFile

use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-intellij by SonarSource.

the class SonarLintTask method run.

@Override
public void run(ProgressIndicator indicator) {
    AccumulatorIssueListener listener = new AccumulatorIssueListener();
    try {
        checkCanceled(indicator, myProject);
        List<AnalysisResults> results = analyze(myProject, indicator, listener);
        // last chance to cancel (to avoid the possibility of having interrupt flag set)
        checkCanceled(indicator, myProject);
        LOGGER.info("SonarLint analysis done");
        indicator.setIndeterminate(false);
        indicator.setFraction(.9);
        List<Issue> issues = listener.getIssues();
        indicator.setText("Creating SonarLint issues: " + issues.size());
        List<ClientInputFile> allFailedAnalysisFiles = results.stream().flatMap(r -> r.failedAnalysisFiles().stream()).collect(Collectors.toList());
        processor.process(job, indicator, issues, allFailedAnalysisFiles);
    } catch (CanceledException e1) {
        console.info("Analysis canceled");
        return;
    } catch (Throwable e) {
        handleError(e, indicator);
    } finally {
        myProject.getMessageBus().syncPublisher(TaskListener.SONARLINT_TASK_TOPIC).ended(job);
    }
}
Also used : AccumulatorIssueListener(org.sonarlint.intellij.editor.AccumulatorIssueListener) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModalityState(com.intellij.openapi.application.ModalityState) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) Task(com.intellij.openapi.progress.Task) Map(java.util.Map) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) LinkedList(java.util.LinkedList) IssueProcessor(org.sonarlint.intellij.issue.IssueProcessor) SonarLintUtils(org.sonarlint.intellij.util.SonarLintUtils) TaskListener(org.sonarlint.intellij.messages.TaskListener) Collection(java.util.Collection) ProgressMonitor(org.sonarsource.sonarlint.core.client.api.common.ProgressMonitor) Collectors(java.util.stream.Collectors) SonarLintConsole(org.sonarlint.intellij.ui.SonarLintConsole) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults) CanceledException(org.sonarsource.sonarlint.core.client.api.exceptions.CanceledException) Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) ApplicationManager(com.intellij.openapi.application.ApplicationManager) TaskProgressMonitor(org.sonarlint.intellij.util.TaskProgressMonitor) CanceledException(org.sonarsource.sonarlint.core.client.api.exceptions.CanceledException) Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults) AccumulatorIssueListener(org.sonarlint.intellij.editor.AccumulatorIssueListener) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)

Example 67 with ClientInputFile

use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-intellij by SonarSource.

the class StandaloneTest method simplePython.

@Test
public void simplePython() throws Exception {
    ClientInputFile inputFile = prepareInputFile("Foo.py", "print \"Hello world!\"");
    List<Issue> issues = analyze(inputFile);
    assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path", "severity").containsOnly(tuple("python:PrintStatementUsage", 1, inputFile.getPath(), "BLOCKER"));
}
Also used : Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) Test(org.junit.Test)

Example 68 with ClientInputFile

use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-intellij by SonarSource.

the class StandaloneTest method simpleJavascript.

@Test
public void simpleJavascript() throws Exception {
    ClientInputFile inputFile = prepareInputFile("Foo.js", "for (;;) {}");
    List<Issue> issues = analyze(inputFile);
    assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path", "severity").containsOnly(tuple("javascript:S2189", 1, inputFile.getPath(), "BLOCKER"), tuple("javascript:EmptyBlock", 1, inputFile.getPath(), "MAJOR"));
}
Also used : Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) Test(org.junit.Test)

Example 69 with ClientInputFile

use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-intellij by SonarSource.

the class StandaloneTest method simplePHP.

@Test
public void simplePHP() throws Exception {
    ClientInputFile inputFile = prepareInputFile("Foo.php", "<?php" + "class PhpUnderControl_Example_Math {}" + "?>");
    List<Issue> issues = analyze(inputFile);
    assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path", "severity").containsOnly(tuple("php:S101", 1, inputFile.getPath(), "MINOR"));
}
Also used : Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) Test(org.junit.Test)

Example 70 with ClientInputFile

use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-intellij by SonarSource.

the class IssueProcessor method transformIssues.

/**
 * Transforms issues and organizes them per file
 */
private Map<VirtualFile, Collection<LiveIssue>> transformIssues(Collection<Issue> issues, Collection<VirtualFile> analyzed, Collection<ClientInputFile> failedAnalysisFiles) {
    Map<VirtualFile, Collection<LiveIssue>> map = removeFailedFiles(analyzed, failedAnalysisFiles);
    for (Issue issue : issues) {
        ClientInputFile inputFile = issue.getInputFile();
        if (inputFile == null || inputFile.getPath() == null || failedAnalysisFiles.contains(inputFile)) {
            // ignore project level issues and files that had errors
            continue;
        }
        VirtualFile vFile = inputFile.getClientObject();
        if (!vFile.isValid() || !map.containsKey(vFile)) {
            // file is no longer valid (might have been deleted meanwhile) or there has been an error matching an issue in it
            continue;
        }
        try {
            LiveIssue toStore = transformIssue(issue, vFile);
            map.get(vFile).add(toStore);
        } catch (IssueMatcher.NoMatchException e) {
            console.error("Failed to find location of issue for file: '" + vFile.getName() + "'. The file won't be refreshed - " + e.getMessage());
            map.remove(vFile);
        } catch (Exception e) {
            LOGGER.error("Error finding location for issue", e);
        }
    }
    return map;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) Collection(java.util.Collection) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)

Aggregations

ClientInputFile (org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)72 Test (org.junit.Test)45 Issue (org.sonarsource.sonarlint.core.client.api.common.analysis.Issue)36 ArrayList (java.util.ArrayList)30 StandaloneAnalysisConfiguration (org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration)25 TestClientInputFile (org.sonarsource.sonarlint.core.TestClientInputFile)19 File (java.io.File)14 ConnectedAnalysisConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration)9 Path (java.nio.file.Path)8 HashMap (java.util.HashMap)7 AnalysisResults (org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults)7 LinkedList (java.util.LinkedList)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Collection (java.util.Collection)4 AccessToken (com.intellij.openapi.application.AccessToken)3 Logger (com.intellij.openapi.diagnostic.Logger)3 RangeMarker (com.intellij.openapi.editor.RangeMarker)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Project (com.intellij.openapi.project.Project)3 PsiFile (com.intellij.psi.PsiFile)3