Search in sources :

Example 1 with ClientModuleInfo

use of org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo in project sonarlint-core by SonarSource.

the class StandaloneIssueMediumTests method declare_module_should_create_a_module_container_with_loaded_extensions.

@Test
void declare_module_should_create_a_module_container_with_loaded_extensions() throws Exception {
    sonarlint.declareModule(new ClientModuleInfo("key", aClientFileSystemWith(new OnDiskTestClientInputFile(Paths.get("main.py"), "main.py", false, StandardCharsets.UTF_8, null)))).get();
    ComponentContainer moduleContainer = sonarlint.getAnalysisEngine().getModuleRegistry().getContainerFor("key");
    assertThat(moduleContainer).isNotNull();
    assertThat(moduleContainer.getComponentsByType(SonarLintModuleFileSystem.class)).isNotEmpty();
}
Also used : OnDiskTestClientInputFile(testutils.OnDiskTestClientInputFile) ComponentContainer(org.sonarsource.sonarlint.core.plugin.commons.pico.ComponentContainer) ClientModuleInfo(org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo) Test(org.junit.jupiter.api.Test)

Example 2 with ClientModuleInfo

use of org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo in project sonarlint-core by SonarSource.

the class StandaloneNodeJsTests method wrong_node_path.

@Test
void wrong_node_path() throws Exception {
    List<String> logs = new ArrayList<>();
    var configBuilder = StandaloneGlobalConfiguration.builder().addPlugin(PluginLocator.getJavaScriptPluginPath()).addEnabledLanguages(Language.JS, Language.TS).setSonarLintUserHome(sonarlintUserHome).setNodeJs(Paths.get("wrong"), Version.create("12.0")).setModulesProvider(() -> singletonList(new ClientModuleInfo("key", mock(ClientModuleFileSystem.class)))).setLogOutput((msg, level) -> logs.add(msg));
    sonarlint = new StandaloneSonarLintEngineImpl(configBuilder.build());
    var ruleDetails = sonarlint.getRuleDetails(JAVASCRIPT_S1481).get();
    assertThat(ruleDetails.getName()).isEqualTo("Unused local variables and functions should be removed");
    assertThat(ruleDetails.getLanguage()).isEqualTo(Language.JS);
    assertThat(ruleDetails.getSeverity()).isEqualTo("MINOR");
    assertThat(ruleDetails.getTags()).containsOnly("unused");
    assertThat(ruleDetails.getHtmlDescription()).contains("<p>", "If a local variable or a local function is declared but not used");
    final var issues = analyze();
    assertThat(issues).isEmpty();
    assertThat(logs).contains("Provided Node.js executable file does not exist. Property 'sonar.nodejs.executable' was to 'wrong'");
}
Also used : ArrayList(java.util.ArrayList) ClientModuleInfo(org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo) StandaloneSonarLintEngineImpl(org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl) Test(org.junit.jupiter.api.Test)

Example 3 with ClientModuleInfo

use of org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo in project sonarlint-core by SonarSource.

the class StandaloneNodeJsTests method unsatisfied_node_version.

@Test
void unsatisfied_node_version() throws Exception {
    List<String> logs = new ArrayList<>();
    var configBuilder = StandaloneGlobalConfiguration.builder().addPlugin(PluginLocator.getJavaScriptPluginPath()).addEnabledLanguages(Language.JS, Language.TS).setSonarLintUserHome(sonarlintUserHome).setNodeJs(Paths.get("node"), Version.create("1.0")).setModulesProvider(() -> singletonList(new ClientModuleInfo("key", mock(ClientModuleFileSystem.class)))).setLogOutput((msg, level) -> logs.add(msg));
    sonarlint = new StandaloneSonarLintEngineImpl(configBuilder.build());
    assertThat(logs).contains("Plugin 'JavaScript/TypeScript Code Quality and Security' requires Node.js 8.0.0 while current is 1.0. Skip loading it.");
    var skipReason = sonarlint.getPluginDetails().stream().filter(p -> p.key().equals("javascript")).findFirst().get().skipReason();
    assertThat(skipReason).isNotEmpty();
    assertThat(skipReason.get()).isInstanceOf(SkipReason.UnsatisfiedRuntimeRequirement.class);
    var unsatisfiedNode = (SkipReason.UnsatisfiedRuntimeRequirement) skipReason.get();
    assertThat(unsatisfiedNode.getRuntime()).isEqualTo(SkipReason.UnsatisfiedRuntimeRequirement.RuntimeRequirement.NODEJS);
    assertThat(unsatisfiedNode.getCurrentVersion()).isEqualTo("1.0");
    assertThat(unsatisfiedNode.getMinVersion()).isEqualTo("8.0.0");
    assertThat(sonarlint.getRuleDetails(JAVASCRIPT_S1481)).isEmpty();
    final var issues = analyze();
    assertThat(issues).isEmpty();
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) BeforeEach(org.junit.jupiter.api.BeforeEach) UnsatisfiedRuntimeRequirement(org.sonarsource.sonarlint.core.plugin.commons.SkipReason.UnsatisfiedRuntimeRequirement) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Language(org.sonarsource.sonarlint.core.commons.Language) StandaloneRuleDetails(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneRuleDetails) SkipReason(org.sonarsource.sonarlint.core.plugin.commons.SkipReason) Version(org.sonarsource.sonarlint.core.commons.Version) StandaloneSonarLintEngineImpl(org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Charset(java.nio.charset.Charset) StandaloneGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneGlobalConfiguration) OnDiskTestClientInputFile(testutils.OnDiskTestClientInputFile) Path(java.nio.file.Path) Nullable(javax.annotation.Nullable) ClientModuleFileSystem(org.sonarsource.sonarlint.core.analysis.api.ClientModuleFileSystem) ClientModuleInfo(org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo) SystemUtils(org.apache.commons.lang3.SystemUtils) ClientInputFile(org.sonarsource.sonarlint.core.analysis.api.ClientInputFile) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) StandaloneAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) Paths(java.nio.file.Paths) TempDir(org.junit.jupiter.api.io.TempDir) Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) Optional(java.util.Optional) PluginLocator(org.sonarsource.sonarlint.core.util.PluginLocator) Mockito.mock(org.mockito.Mockito.mock) UnsatisfiedRuntimeRequirement(org.sonarsource.sonarlint.core.plugin.commons.SkipReason.UnsatisfiedRuntimeRequirement) ArrayList(java.util.ArrayList) ClientModuleInfo(org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo) SkipReason(org.sonarsource.sonarlint.core.plugin.commons.SkipReason) StandaloneSonarLintEngineImpl(org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl) Test(org.junit.jupiter.api.Test)

Example 4 with ClientModuleInfo

use of org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo in project sonarlint-core by SonarSource.

the class ConnectedExtraPluginMediumTests method prepare.

@BeforeAll
static void prepare(@TempDir Path slHome) throws Exception {
    var storage = newStorage(SERVER_ID).withJSPlugin().withProject("test-project").withProject(JAVA_MODULE_KEY).withProject("stale_module", ProjectStorageFixture.ProjectStorageBuilder::stale).create(slHome);
    var nodeJsHelper = new NodeJsHelper();
    nodeJsHelper.detect(null);
    var config = ConnectedGlobalConfiguration.builder().setConnectionId(SERVER_ID).setSonarLintUserHome(slHome).setStorageRoot(storage.getPath()).setLogOutput(createNoOpLogOutput()).addEnabledLanguages(Language.JAVA, Language.JS, Language.PHP).addExtraPlugin(Language.JAVA.getPluginKey(), PluginLocator.getJavaPluginPath()).addExtraPlugin(Language.PHP.getPluginKey(), PluginLocator.getPhpPluginPath()).setNodeJs(nodeJsHelper.getNodeJsPath(), nodeJsHelper.getNodeJsVersion()).setModulesProvider(() -> List.of(new ClientModuleInfo("key", mock(ClientModuleFileSystem.class)))).build();
    sonarlint = new ConnectedSonarLintEngineImpl(config);
}
Also used : NodeJsHelper(org.sonarsource.sonarlint.core.NodeJsHelper) ClientModuleInfo(org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) ProjectStorageFixture(org.sonarsource.sonarlint.core.mediumtest.fixtures.ProjectStorageFixture) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 5 with ClientModuleInfo

use of org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo in project sonarlint-core by SonarSource.

the class ConnectedIssueMediumTests method stop_module_should_stop_the_module_container.

@Test
void stop_module_should_stop_the_module_container() throws Exception {
    sonarlint.declareModule(new ClientModuleInfo("key", aClientFileSystemWith(new OnDiskTestClientInputFile(Paths.get("main.py"), "main.py", false, StandardCharsets.UTF_8, null)))).get();
    ComponentContainer moduleContainer = sonarlint.getAnalysisEngine().getModuleRegistry().getContainerFor("key");
    sonarlint.stopModule("key").get();
    assertThat(moduleContainer.getPicoContainer().getLifecycleState().isStarted()).isFalse();
}
Also used : OnDiskTestClientInputFile(testutils.OnDiskTestClientInputFile) ComponentContainer(org.sonarsource.sonarlint.core.plugin.commons.pico.ComponentContainer) ClientModuleInfo(org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo) Test(org.junit.jupiter.api.Test)

Aggregations

ClientModuleInfo (org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo)12 Test (org.junit.jupiter.api.Test)10 OnDiskTestClientInputFile (testutils.OnDiskTestClientInputFile)7 ComponentContainer (org.sonarsource.sonarlint.core.plugin.commons.pico.ComponentContainer)5 ArrayList (java.util.ArrayList)4 StandaloneSonarLintEngineImpl (org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl)4 ClientInputFile (org.sonarsource.sonarlint.core.analysis.api.ClientInputFile)4 File (java.io.File)3 IOException (java.io.IOException)3 StandardCharsets (java.nio.charset.StandardCharsets)3 List (java.util.List)3 FileUtils (org.apache.commons.io.FileUtils)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 TempDir (org.junit.jupiter.api.io.TempDir)3 Mockito.mock (org.mockito.Mockito.mock)3 ClientModuleFileSystem (org.sonarsource.sonarlint.core.analysis.api.ClientModuleFileSystem)3 Language (org.sonarsource.sonarlint.core.commons.Language)3 Path (java.nio.file.Path)2 Paths (java.nio.file.Paths)2