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);
}
}
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"));
}
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"));
}
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"));
}
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;
}
Aggregations