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();
}
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'");
}
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();
}
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);
}
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();
}
Aggregations