Search in sources :

Example 41 with ClientInputFile

use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.

the class BrokenStorageMissingPluginMediumTest method prepareInputFile.

private ClientInputFile prepareInputFile(String relativePath, String content, final boolean isTest) throws IOException {
    final File file = new File(baseDir, relativePath);
    FileUtils.write(file, content);
    ClientInputFile inputFile = TestUtils.createInputFile(file.toPath(), relativePath, isTest);
    return inputFile;
}
Also used : ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) File(java.io.File)

Example 42 with ClientInputFile

use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.

the class BrokenStorageMissingPluginMediumTest method require_update.

@Test
public void require_update() throws Exception {
    assertThat(sonarlint.getState()).isEqualTo(ConnectedSonarLintEngine.State.NEED_UPDATE);
    ClientInputFile inputFile = prepareJavaInputFile();
    final List<Issue> issues = new ArrayList<>();
    try {
        sonarlint.analyze(new ConnectedAnalysisConfiguration(null, baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.<String, String>of()), new StoreIssueListener(issues), null, null);
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).isExactlyInstanceOf(GlobalUpdateRequiredException.class);
    }
}
Also used : GlobalUpdateRequiredException(org.sonarsource.sonarlint.core.client.api.exceptions.GlobalUpdateRequiredException) Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) ArrayList(java.util.ArrayList) ConnectedAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) GlobalUpdateRequiredException(org.sonarsource.sonarlint.core.client.api.exceptions.GlobalUpdateRequiredException) IOException(java.io.IOException) Test(org.junit.Test)

Example 43 with ClientInputFile

use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.

the class ConnectedEmptyStorageMediumTest method test_no_storage.

@Test
public void test_no_storage() throws Exception {
    assertThat(sonarlint.getState()).isEqualTo(State.NEVER_UPDATED);
    assertThat(sonarlint.getGlobalStorageStatus()).isNull();
    assertThat(sonarlint.getModuleStorageStatus("foo")).isNull();
    try {
        sonarlint.allModulesByKey();
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).isInstanceOf(GlobalUpdateRequiredException.class).hasMessage("Please update server 'localhost'");
    }
    try {
        sonarlint.getRuleDetails("rule");
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).isInstanceOf(GlobalUpdateRequiredException.class).hasMessage("Please update server 'localhost'");
    }
    try {
        sonarlint.analyze(new ConnectedAnalysisConfiguration(null, baseDir.toPath(), temp.newFolder().toPath(), Collections.<ClientInputFile>emptyList(), ImmutableMap.<String, String>of()), mock(IssueListener.class), null, null);
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).isInstanceOf(GlobalUpdateRequiredException.class).hasMessage("Please update server 'localhost'");
    }
}
Also used : IssueListener(org.sonarsource.sonarlint.core.client.api.common.analysis.IssueListener) ConnectedAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) GlobalUpdateRequiredException(org.sonarsource.sonarlint.core.client.api.exceptions.GlobalUpdateRequiredException) Test(org.junit.Test)

Example 44 with ClientInputFile

use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.

the class ConnectedFileExclusionsMediumTest method prepareInputFile.

private ClientInputFile prepareInputFile(String relativePath, String content, final boolean isTest) throws IOException {
    final File file = new File(baseDir, relativePath);
    FileUtils.write(file, content);
    ClientInputFile inputFile = TestUtils.createInputFile(file.toPath(), relativePath, isTest);
    return inputFile;
}
Also used : ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) File(java.io.File)

Example 45 with ClientInputFile

use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.

the class ConnectedFileExclusionsMediumTest method fileInclusionsExclusions.

@Test
public void fileInclusionsExclusions() throws Exception {
    ClientInputFile mainFile1 = prepareInputFile("foo.xoo", "function xoo() {}", false);
    ClientInputFile mainFile2 = prepareInputFile("src/foo2.xoo", "function xoo() {}", false);
    ClientInputFile testFile1 = prepareInputFile("fooTest.xoo", "function xoo() {}", true);
    ClientInputFile testFile2 = prepareInputFile("test/foo2Test.xoo", "function xoo() {}", true);
    StoragePaths storagePaths = sonarlint.getGlobalContainer().getComponentByType(StoragePaths.class);
    StorageReader storageReader = sonarlint.getGlobalContainer().getComponentByType(StorageReader.class);
    ModuleConfiguration originalModuleConfig = storageReader.readModuleConfig(MODULE_KEY);
    int result = count(mainFile1, mainFile2, testFile1, testFile2);
    assertThat(result).isEqualTo(4);
    updateModuleConfig(storagePaths, originalModuleConfig, ImmutableMap.of("sonar.inclusions", "src/**"));
    result = count(mainFile1, mainFile2, testFile1, testFile2);
    assertThat(result).isEqualTo(3);
    updateModuleConfig(storagePaths, originalModuleConfig, ImmutableMap.of("sonar.inclusions", "file:**/src/**"));
    result = count(mainFile1, mainFile2, testFile1, testFile2);
    assertThat(result).isEqualTo(3);
    updateModuleConfig(storagePaths, originalModuleConfig, ImmutableMap.of("sonar.exclusions", "src/**"));
    result = count(mainFile1, mainFile2, testFile1, testFile2);
    assertThat(result).isEqualTo(3);
    updateModuleConfig(storagePaths, originalModuleConfig, ImmutableMap.of("sonar.test.inclusions", "test/**"));
    result = count(mainFile1, mainFile2, testFile1, testFile2);
    assertThat(result).isEqualTo(3);
    updateModuleConfig(storagePaths, originalModuleConfig, ImmutableMap.of("sonar.test.exclusions", "test/**"));
    result = count(mainFile1, mainFile2, testFile1, testFile2);
    assertThat(result).isEqualTo(3);
    updateModuleConfig(storagePaths, originalModuleConfig, ImmutableMap.of("sonar.inclusions", "file:**/src/**", "sonar.test.exclusions", "**/*Test.*"));
    result = count(mainFile1, mainFile2, testFile1, testFile2);
    assertThat(result).isEqualTo(1);
}
Also used : StorageReader(org.sonarsource.sonarlint.core.container.storage.StorageReader) ModuleConfiguration(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) StoragePaths(org.sonarsource.sonarlint.core.container.storage.StoragePaths) 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