use of org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Issue in project sonarlint-core by SonarSource.
the class StandaloneDaemonTest method test.
@Test
public void test() throws InterruptedException, IOException {
LogCollector logs = new LogCollector();
StandaloneSonarLintBlockingStub sonarlint = StandaloneSonarLintGrpc.newBlockingStub(channel);
AnalysisReq analysisConfig = createAnalysisConfig("sample-javascript");
long start = System.currentTimeMillis();
ClientCall<Void, LogEvent> call = getLogs(logs, channel);
try {
for (int i = 0; i < 10; i++) {
System.out.println("ITERATION: " + i);
Iterator<Issue> issues = sonarlint.analyze(analysisConfig);
assertThat(issues).hasSize(1);
// Give some time for logs to come
Thread.sleep(500);
List<String> logsLines = logs.getLogsAndClear();
// To be sure logs are not flooded by low level logs
assertThat(logsLines.size()).isLessThan(100);
assertThat(logsLines).contains("1 files indexed");
}
} finally {
call.cancel("no more logs needed", null);
}
System.out.println("TIME " + (System.currentTimeMillis() - start));
}
use of org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Issue 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.daemon.proto.SonarlintDaemon.Issue in project sonarlint-core by SonarSource.
the class ConnectedDaemonTest method testNormal.
@Test
public void testNormal() throws InterruptedException, IOException {
daemon.run();
daemon.waitReady();
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8050).usePlaintext(true).build();
LogCollector logs = new LogCollector();
ConnectedSonarLintBlockingStub sonarlint = ConnectedSonarLintGrpc.newBlockingStub(channel);
// REGISTER
sonarlint.start(createConnectedConfig());
// STATE
assertThat(sonarlint.getState(Void.newBuilder().build()).getState()).isEqualTo(StorageState.State.NEVER_UPDATED);
// UPDATE GLOBAL
ServerConfig serverConfig = ServerConfig.newBuilder().setHostUrl(ORCHESTRATOR.getServer().getUrl()).setCredentials(Credentials.newBuilder().setLogin(SONARLINT_USER).setPassword(SONARLINT_PWD).build()).build();
sonarlint.update(serverConfig);
// STATE
assertThat(sonarlint.getState(Void.newBuilder().build()).getState()).isEqualTo(StorageState.State.UPDATED);
// UPDATE MODULE
ModuleUpdateReq moduleUpdate = ModuleUpdateReq.newBuilder().setModuleKey(PROJECT_KEY_JAVA).setServerConfig(serverConfig).build();
sonarlint.updateModule(moduleUpdate);
// ANALYSIS
ClientCall<Void, LogEvent> call = getLogs(logs, channel);
Iterator<Issue> issues = sonarlint.analyze(createAnalysisConfig(PROJECT_KEY_JAVA));
assertThat(issues).hasSize(3);
// assertThat(logs.getLogsAndClear()).contains("2 files indexed");
call.cancel(null, null);
channel.shutdownNow();
channel.awaitTermination(2, TimeUnit.SECONDS);
}
use of org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Issue in project sonarlint-core by SonarSource.
the class ConnectedDaemonTest method testError.
@Test
public void testError() throws IOException {
daemon.run();
daemon.waitReady();
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8050).usePlaintext(true).build();
ConnectedSonarLintBlockingStub sonarlint = ConnectedSonarLintGrpc.newBlockingStub(channel);
sonarlint.start(createConnectedConfig());
// Analyze without update -> error
Iterator<Issue> analyze = sonarlint.analyze(createAnalysisConfig(PROJECT_KEY_JAVA));
exception.expectMessage("Please update server 'storage'");
exception.expect(StatusRuntimeException.class);
analyze.hasNext();
sonarlint.shutdown(null);
}
use of org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Issue 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());
}
Aggregations