use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class DefaultSensorStorage method store.
@Override
public void store(AnalysisError analysisError) {
ClientInputFile clientInputFile = ((SonarLintInputFile) analysisError.inputFile()).getClientInputFile();
analysisResult.addFailedAnalysisFile(clientInputFile);
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class StandaloneSonarLintImpl method analyze.
@Override
public void analyze(AnalysisReq requestConfig, StreamObserver<Issue> response) {
if (engine == null) {
response.onError(new IllegalStateException("Not registered"));
return;
}
try {
List<ClientInputFile> files = new LinkedList<>();
List<InputFile> requestFiles = requestConfig.getFileList();
Path baseDir = Paths.get(requestConfig.getBaseDir());
for (InputFile f : requestFiles) {
files.add(new DefaultClientInputFile(baseDir, Paths.get(f.getPath()), f.getIsTest(), Charset.forName(f.getCharset()), f.getUserObject(), trimToNull(f.getLanguage())));
}
StandaloneAnalysisConfiguration config = new StandaloneAnalysisConfiguration(baseDir, Paths.get(requestConfig.getWorkDir()), files, requestConfig.getPropertiesMap());
logOutput.log("Analysis configuration:\n" + config.toString(), Level.DEBUG);
engine.analyze(config, new ProxyIssueListener(response), logOutput, null);
response.onCompleted();
} catch (Exception e) {
LOGGER.error("Error analyzing", e);
response.onError(e);
}
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class ProxyIssueListenerTest method testWithType.
private void testWithType(Type type) {
StreamObserver<Issue> observer = mock(StreamObserver.class);
ClientInputFile inputFile = mock(ClientInputFile.class);
when(inputFile.getPath()).thenReturn("filename");
when(inputFile.getClientObject()).thenReturn("obj");
ProxyIssueListener listener = new ProxyIssueListener(observer);
org.sonarsource.sonarlint.core.client.api.common.analysis.Issue i = mock(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue.class);
when(i.getEndLine()).thenReturn(10);
when(i.getStartLine()).thenReturn(11);
when(i.getStartLineOffset()).thenReturn(12);
when(i.getEndLineOffset()).thenReturn(13);
when(i.getMessage()).thenReturn("msg");
when(i.getRuleKey()).thenReturn("key");
when(i.getRuleName()).thenReturn("name");
when(i.getSeverity()).thenReturn("MAJOR");
when(i.getType()).thenReturn(type.toString().toUpperCase());
when(i.getInputFile()).thenReturn(inputFile);
listener.handle(i);
ArgumentCaptor<Issue> argument = ArgumentCaptor.forClass(Issue.class);
verify(observer).onNext(argument.capture());
Issue captured = argument.getValue();
assertThat(captured.getEndLine()).isEqualTo(10);
assertThat(captured.getStartLine()).isEqualTo(11);
assertThat(captured.getStartLineOffset()).isEqualTo(12);
assertThat(captured.getEndLineOffset()).isEqualTo(13);
assertThat(captured.getMessage()).isEqualTo("msg");
assertThat(captured.getRuleKey()).isEqualTo("key");
assertThat(captured.getRuleName()).isEqualTo("name");
assertThat(captured.getType()).isEqualTo(type);
assertThat(captured.getFilePath()).isEqualTo("filename");
assertThat(captured.getUserObject()).isEqualTo("obj");
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class ConnectedIssueExclusionsMediumTest method issueExclusions.
@Test
public void issueExclusions() throws Exception {
ClientInputFile inputFile1 = prepareJavaInputFile1();
ClientInputFile inputFile2 = prepareJavaInputFile2();
assertThat(collectIssues(inputFile1, inputFile2)).extracting("ruleKey", "startLine", "inputFile.path", "severity").containsOnly(tuple("squid:S106", 4, inputFile1.getPath(), "MAJOR"), tuple("squid:S1220", null, inputFile1.getPath(), "MINOR"), tuple("squid:S1481", 3, inputFile1.getPath(), "MAJOR"), tuple("squid:S106", 4, inputFile2.getPath(), "MAJOR"), tuple("squid:S1220", null, inputFile2.getPath(), "MINOR"), tuple("squid:S1481", 3, inputFile2.getPath(), "MAJOR"));
updateModuleConfig(storagePaths, originalModuleConfig, ImmutableMap.of("sonar.issue.ignore.multicriteria", "1", "sonar.issue.ignore.multicriteria.1.resourceKey", "*", "sonar.issue.ignore.multicriteria.1.ruleKey", "*"));
assertThat(collectIssues(inputFile1, inputFile2)).isEmpty();
updateModuleConfig(storagePaths, originalModuleConfig, ImmutableMap.of("sonar.issue.ignore.multicriteria", "1", "sonar.issue.ignore.multicriteria.1.resourceKey", "*", "sonar.issue.ignore.multicriteria.1.ruleKey", "*S1481"));
assertThat(collectIssues(inputFile1, inputFile2)).extracting("ruleKey", "startLine", "inputFile.path", "severity").containsOnly(tuple("squid:S106", 4, inputFile1.getPath(), "MAJOR"), tuple("squid:S1220", null, inputFile1.getPath(), "MINOR"), tuple("squid:S106", 4, inputFile2.getPath(), "MAJOR"), tuple("squid:S1220", null, inputFile2.getPath(), "MINOR"));
updateModuleConfig(storagePaths, originalModuleConfig, ImmutableMap.of("sonar.issue.ignore.multicriteria", "1", "sonar.issue.ignore.multicriteria.1.resourceKey", "Foo2.java", "sonar.issue.ignore.multicriteria.1.ruleKey", "*"));
assertThat(collectIssues(inputFile1, inputFile2)).extracting("ruleKey", "startLine", "inputFile.path", "severity").containsOnly(tuple("squid:S106", 4, inputFile1.getPath(), "MAJOR"), tuple("squid:S1220", null, inputFile1.getPath(), "MINOR"), tuple("squid:S1481", 3, inputFile1.getPath(), "MAJOR"));
updateModuleConfig(storagePaths, originalModuleConfig, ImmutableMap.of("sonar.issue.ignore.multicriteria", "1,2", "sonar.issue.ignore.multicriteria.1.resourceKey", "Foo2.java", "sonar.issue.ignore.multicriteria.1.ruleKey", "squid:S1481", "sonar.issue.ignore.multicriteria.2.resourceKey", "Foo.java", "sonar.issue.ignore.multicriteria.2.ruleKey", "squid:S106"));
assertThat(collectIssues(inputFile1, inputFile2)).extracting("ruleKey", "startLine", "inputFile.path", "severity").containsOnly(tuple("squid:S1220", null, inputFile1.getPath(), "MINOR"), tuple("squid:S1481", 3, inputFile1.getPath(), "MAJOR"), tuple("squid:S106", 4, inputFile2.getPath(), "MAJOR"), tuple("squid:S1220", null, inputFile2.getPath(), "MINOR"));
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class ConnectedIssueExclusionsMediumTest method issueInclusions.
@Test
public void issueInclusions() throws Exception {
ClientInputFile inputFile1 = prepareJavaInputFile1();
ClientInputFile inputFile2 = prepareJavaInputFile2();
updateModuleConfig(storagePaths, originalModuleConfig, ImmutableMap.of("sonar.issue.enforce.multicriteria", "1", "sonar.issue.enforce.multicriteria.1.resourceKey", "Foo*.java", "sonar.issue.enforce.multicriteria.1.ruleKey", "*"));
assertThat(collectIssues(inputFile1, inputFile2)).extracting("ruleKey", "startLine", "inputFile.path", "severity").containsOnly(tuple("squid:S106", 4, inputFile1.getPath(), "MAJOR"), tuple("squid:S1220", null, inputFile1.getPath(), "MINOR"), tuple("squid:S1481", 3, inputFile1.getPath(), "MAJOR"), tuple("squid:S106", 4, inputFile2.getPath(), "MAJOR"), tuple("squid:S1220", null, inputFile2.getPath(), "MINOR"), tuple("squid:S1481", 3, inputFile2.getPath(), "MAJOR"));
updateModuleConfig(storagePaths, originalModuleConfig, ImmutableMap.of("sonar.issue.enforce.multicriteria", "1", "sonar.issue.enforce.multicriteria.1.resourceKey", "Foo2.java", "sonar.issue.enforce.multicriteria.1.ruleKey", "*S1481"));
assertThat(collectIssues(inputFile1, inputFile2)).extracting("ruleKey", "startLine", "inputFile.path", "severity").containsOnly(tuple("squid:S106", 4, inputFile1.getPath(), "MAJOR"), tuple("squid:S1220", null, inputFile1.getPath(), "MINOR"), tuple("squid:S106", 4, inputFile2.getPath(), "MAJOR"), tuple("squid:S1220", null, inputFile2.getPath(), "MINOR"), tuple("squid:S1481", 3, inputFile2.getPath(), "MAJOR"));
updateModuleConfig(storagePaths, originalModuleConfig, ImmutableMap.of("sonar.issue.enforce.multicriteria", "1", "sonar.issue.enforce.multicriteria.1.resourceKey", "Foo2.java", "sonar.issue.enforce.multicriteria.1.ruleKey", "*"));
assertThat(collectIssues(inputFile1, inputFile2)).extracting("ruleKey", "startLine", "inputFile.path", "severity").containsOnly(tuple("squid:S106", 4, inputFile2.getPath(), "MAJOR"), tuple("squid:S1220", null, inputFile2.getPath(), "MINOR"), tuple("squid:S1481", 3, inputFile2.getPath(), "MAJOR"));
updateModuleConfig(storagePaths, originalModuleConfig, ImmutableMap.of("sonar.issue.enforce.multicriteria", "1,2", "sonar.issue.enforce.multicriteria.1.resourceKey", "Foo2.java", "sonar.issue.enforce.multicriteria.1.ruleKey", "squid:S1481", "sonar.issue.enforce.multicriteria.2.resourceKey", "Foo.java", "sonar.issue.enforce.multicriteria.2.ruleKey", "squid:S106"));
assertThat(collectIssues(inputFile1, inputFile2)).extracting("ruleKey", "startLine", "inputFile.path", "severity").containsOnly(tuple("squid:S106", 4, inputFile1.getPath(), "MAJOR"), tuple("squid:S1220", null, inputFile1.getPath(), "MINOR"), tuple("squid:S1220", null, inputFile2.getPath(), "MINOR"), tuple("squid:S1481", 3, inputFile2.getPath(), "MAJOR"));
}
Aggregations