use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-intellij by SonarSource.
the class IssueTreeModelBuilderTest method mockFile.
private static ClientInputFile mockFile(String path) {
ClientInputFile file = mock(ClientInputFile.class);
when(file.getPath()).thenReturn(path);
when(file.getCharset()).thenReturn(Charset.defaultCharset());
when(file.isTest()).thenReturn(false);
return file;
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class ProxyIssueListener method handle.
@Override
public void handle(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue issue) {
Severity severity;
ClientInputFile inputFile = issue.getInputFile();
switch(issue.getSeverity()) {
case "MINOR":
severity = Severity.MINOR;
break;
case "BLOCKER":
severity = Severity.BLOCKER;
break;
case "INFO":
severity = Severity.INFO;
break;
case "CRITICAL":
severity = Severity.CRITICAL;
break;
case "MAJOR":
default:
severity = Severity.MAJOR;
break;
}
Type type = Type.CODE_SMELL;
if (issue.getType() != null) {
switch(StringUtils.lowerCase(issue.getType())) {
case "bug":
type = Type.BUG;
break;
case "vulnerability":
type = Type.VULNERABILITY;
break;
case "code_smell":
default:
type = Type.CODE_SMELL;
break;
}
}
Issue.Builder builder = Issue.newBuilder();
builder.setRuleKey(issue.getRuleKey()).setRuleName(issue.getRuleName()).setMessage(issue.getMessage()).setSeverity(severity).setType(type).setStartLine(issue.getStartLine() != null ? issue.getStartLine() : 0).setStartLineOffset(issue.getStartLineOffset() != null ? issue.getStartLineOffset() : 0).setEndLine(issue.getEndLine() != null ? issue.getEndLine() : 0).setEndLineOffset(issue.getEndLineOffset() != null ? issue.getEndLineOffset() : 0);
if (inputFile != null) {
builder.setFilePath(inputFile.getPath());
if (inputFile.getClientObject() != null) {
builder.setUserObject((String) inputFile.getClientObject());
}
}
observer.onNext(builder.build());
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class ConnectedSonarLintImpl method analyze.
@Override
public void analyze(ConnectedAnalysisReq requestConfig, StreamObserver<org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Issue> response) {
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())));
}
ConnectedAnalysisConfiguration config = new ConnectedAnalysisConfiguration(requestConfig.getModuleKey(), baseDir, Paths.get(requestConfig.getWorkDir()), files, requestConfig.getPropertiesMap());
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 testWithSeverity.
private void testWithSeverity(Severity severity) {
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(severity.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.getSeverity()).isEqualTo(severity);
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 ProxyIssueListenerTest method dont_fail_if_no_user_obj.
@Test
public void dont_fail_if_no_user_obj() {
StreamObserver<Issue> observer = mock(StreamObserver.class);
ClientInputFile inputFile = mock(ClientInputFile.class);
when(inputFile.getPath()).thenReturn("filename");
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("MINOR");
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.getSeverity()).isEqualTo(Severity.MINOR);
assertThat(captured.getFilePath()).isEqualTo("filename");
assertThat(captured.getUserObject()).isEqualTo("");
}
Aggregations