Search in sources :

Example 6 with ClientInputFile

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);
}
Also used : SonarLintInputFile(org.sonarsource.sonarlint.core.container.analysis.filesystem.SonarLintInputFile) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)

Example 7 with 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);
    }
}
Also used : Path(java.nio.file.Path) DefaultClientInputFile(org.sonarlint.daemon.model.DefaultClientInputFile) ProxyIssueListener(org.sonarlint.daemon.model.ProxyIssueListener) StandaloneAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration) DefaultClientInputFile(org.sonarlint.daemon.model.DefaultClientInputFile) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) LinkedList(java.util.LinkedList) DefaultClientInputFile(org.sonarlint.daemon.model.DefaultClientInputFile) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) InputFile(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.InputFile)

Example 8 with ClientInputFile

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");
}
Also used : Issue(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Issue) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)

Example 9 with ClientInputFile

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"));
}
Also used : ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) Test(org.junit.Test)

Example 10 with ClientInputFile

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"));
}
Also used : ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) Test(org.junit.Test)

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