Search in sources :

Example 1 with NodeJsHelper

use of org.sonarsource.sonarlint.core.NodeJsHelper 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 2 with NodeJsHelper

use of org.sonarsource.sonarlint.core.NodeJsHelper in project sonarlint-core by SonarSource.

the class ConnectedModeTest method start.

@Before
public void start() {
    FileUtils.deleteQuietly(sonarUserHome.toFile());
    Map<String, String> globalProps = new HashMap<>();
    globalProps.put("sonar.global.label", "It works");
    logs = new ArrayList<>();
    var nodeJsHelper = new NodeJsHelper();
    nodeJsHelper.detect(null);
    globalConfig = ConnectedGlobalConfiguration.builder().setConnectionId("orchestrator").setSonarLintUserHome(sonarUserHome).addEnabledLanguage(Language.JAVA).addEnabledLanguage(Language.PHP).addEnabledLanguage(Language.JS).addEnabledLanguage(Language.PYTHON).addEnabledLanguage(Language.HTML).addEnabledLanguage(Language.RUBY).addEnabledLanguage(Language.KOTLIN).addEnabledLanguage(Language.SCALA).addEnabledLanguage(Language.XML).addEnabledLanguage(Language.COBOL).setLogOutput((msg, level) -> {
        logs.add(msg);
    }).setNodeJs(nodeJsHelper.getNodeJsPath(), nodeJsHelper.getNodeJsVersion()).setExtraProperties(globalProps).build();
    engine = new ConnectedSonarLintEngineImpl(globalConfig);
    assertThat(engine.getGlobalStorageStatus()).isNull();
    // This profile is altered in a test
    ORCHESTRATOR.getServer().restoreProfile(FileLocation.ofClasspath("/java-sonarlint.xml"));
}
Also used : HashMap(java.util.HashMap) NodeJsHelper(org.sonarsource.sonarlint.core.NodeJsHelper) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) Before(org.junit.Before)

Example 3 with NodeJsHelper

use of org.sonarsource.sonarlint.core.NodeJsHelper in project sonarlint-core by SonarSource.

the class SonarCloudTest method prepare.

@BeforeClass
public static void prepare() throws Exception {
    randomPositiveInt = new Random().nextInt() & Integer.MAX_VALUE;
    adminWsClient = newAdminWsClient();
    sonarUserHome = temp.newFolder().toPath();
    restoreProfile("java-sonarlint.xml");
    restoreProfile("java-sonarlint-package.xml");
    restoreProfile("java-sonarlint-with-hotspot.xml");
    restoreProfile("java-empty-sonarlint.xml");
    restoreProfile("javascript-sonarlint.xml");
    restoreProfile("php-sonarlint.xml");
    restoreProfile("python-sonarlint.xml");
    restoreProfile("web-sonarlint.xml");
    restoreProfile("kotlin-sonarlint.xml");
    restoreProfile("ruby-sonarlint.xml");
    restoreProfile("scala-sonarlint.xml");
    restoreProfile("xml-sonarlint.xml");
    provisionProject(PROJECT_KEY_JAVA, "Sample Java");
    provisionProject(PROJECT_KEY_JAVA_PACKAGE, "Sample Java Package");
    provisionProject(PROJECT_KEY_JAVA_HOTSPOT, "Sample Java Hotspot");
    provisionProject(PROJECT_KEY_JAVA_EMPTY, "Sample Java Empty");
    provisionProject(PROJECT_KEY_PHP, "Sample PHP");
    provisionProject(PROJECT_KEY_JAVASCRIPT, "Sample Javascript");
    provisionProject(PROJECT_KEY_PYTHON, "Sample Python");
    provisionProject(PROJECT_KEY_WEB, "Sample Web");
    provisionProject(PROJECT_KEY_RUBY, "Sample Ruby");
    provisionProject(PROJECT_KEY_KOTLIN, "Sample Kotlin");
    provisionProject(PROJECT_KEY_SCALA, "Sample Scala");
    provisionProject(PROJECT_KEY_XML, "Sample XML");
    associateProjectToQualityProfile(PROJECT_KEY_JAVA, "java", "SonarLint IT Java");
    associateProjectToQualityProfile(PROJECT_KEY_JAVA_PACKAGE, "java", "SonarLint IT Java Package");
    associateProjectToQualityProfile(PROJECT_KEY_JAVA_HOTSPOT, "java", "SonarLint IT Java Hotspot");
    associateProjectToQualityProfile(PROJECT_KEY_JAVA_EMPTY, "java", "SonarLint IT Java Empty");
    associateProjectToQualityProfile(PROJECT_KEY_PHP, "php", "SonarLint IT PHP");
    associateProjectToQualityProfile(PROJECT_KEY_JAVASCRIPT, "js", "SonarLint IT Javascript");
    associateProjectToQualityProfile(PROJECT_KEY_PYTHON, "py", "SonarLint IT Python");
    associateProjectToQualityProfile(PROJECT_KEY_WEB, "web", "SonarLint IT Web");
    associateProjectToQualityProfile(PROJECT_KEY_RUBY, "ruby", "SonarLint IT Ruby");
    associateProjectToQualityProfile(PROJECT_KEY_KOTLIN, "kotlin", "SonarLint IT Kotlin");
    associateProjectToQualityProfile(PROJECT_KEY_SCALA, "scala", "SonarLint IT Scala");
    associateProjectToQualityProfile(PROJECT_KEY_XML, "xml", "SonarLint IT XML");
    // Build project to have bytecode
    var line = "mvn clean compile";
    var cmdLine = CommandLine.parse(line);
    var executor = new DefaultExecutor();
    executor.setWorkingDirectory(new File("projects/sample-java"));
    var exitValue = executor.execute(cmdLine);
    assertThat(exitValue).isZero();
    Map<String, String> globalProps = new HashMap<>();
    globalProps.put("sonar.global.label", "It works");
    var nodeJsHelper = new NodeJsHelper();
    nodeJsHelper.detect(null);
    engine = new ConnectedSonarLintEngineImpl(ConnectedGlobalConfiguration.builder().setConnectionId("sonarcloud").setSonarLintUserHome(sonarUserHome).addEnabledLanguage(Language.JAVA).addEnabledLanguage(Language.PHP).addEnabledLanguage(Language.JS).addEnabledLanguage(Language.PYTHON).addEnabledLanguage(Language.HTML).addEnabledLanguage(Language.RUBY).addEnabledLanguage(Language.KOTLIN).addEnabledLanguage(Language.SCALA).addEnabledLanguage(Language.XML).setNodeJs(nodeJsHelper.getNodeJsPath(), nodeJsHelper.getNodeJsVersion()).setExtraProperties(globalProps).build());
    assertThat(engine.getGlobalStorageStatus()).isNull();
    updateGlobal();
    assertThat(engine.getGlobalStorageStatus()).isNotNull();
    assertThat(engine.getGlobalStorageStatus().isStale()).isFalse();
    Set<String> ALL_PROJECTS = Set.of(projectKey(PROJECT_KEY_JAVA), projectKey(PROJECT_KEY_JAVA_PACKAGE), projectKey(PROJECT_KEY_JAVA_HOTSPOT), projectKey(PROJECT_KEY_JAVA_EMPTY), projectKey(PROJECT_KEY_PHP), projectKey(PROJECT_KEY_JAVASCRIPT), projectKey(PROJECT_KEY_PYTHON), projectKey(PROJECT_KEY_WEB), projectKey(PROJECT_KEY_KOTLIN), projectKey(PROJECT_KEY_RUBY), projectKey(PROJECT_KEY_SCALA), projectKey(PROJECT_KEY_XML));
    ALL_PROJECTS.forEach(p -> engine.updateProject(sonarcloudEndpointITOrg(), new SonarLintHttpClientOkHttpImpl(SC_CLIENT), p, false, null, null));
    engine.sync(sonarcloudEndpointITOrg(), new SonarLintHttpClientOkHttpImpl(SC_CLIENT), ALL_PROJECTS, null);
}
Also used : Random(java.util.Random) DefaultExecutor(org.apache.commons.exec.DefaultExecutor) HashMap(java.util.HashMap) NodeJsHelper(org.sonarsource.sonarlint.core.NodeJsHelper) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 4 with NodeJsHelper

use of org.sonarsource.sonarlint.core.NodeJsHelper in project sonarlint-core by SonarSource.

the class StandaloneIssueMediumTests method prepare.

@BeforeAll
static void prepare(@TempDir Path temp) throws Exception {
    sonarlintUserHome = temp.resolve("home");
    fakeTypeScriptProjectPath = temp.resolve("ts");
    var packagejson = fakeTypeScriptProjectPath.resolve("package.json");
    FileUtils.write(packagejson.toFile(), "{" + "\"devDependencies\": {\n" + "    \"typescript\": \"2.6.1\"\n" + "  }" + "}", StandardCharsets.UTF_8);
    var pb = new ProcessBuilder("npm" + (SystemUtils.IS_OS_WINDOWS ? ".cmd" : ""), "install").directory(fakeTypeScriptProjectPath.toFile()).inheritIO();
    var process = pb.start();
    if (process.waitFor() != 0) {
        fail("Unable to run npm install");
    }
    Map<String, String> extraProperties = new HashMap<>();
    extraProperties.put("sonar.typescript.internal.typescriptLocation", fakeTypeScriptProjectPath.resolve("node_modules").toString());
    // See test sonarjs_should_honor_global_and_analysis_level_properties
    extraProperties.put("sonar.javascript.globals", "GLOBAL1");
    var nodeJsHelper = new NodeJsHelper();
    nodeJsHelper.detect(null);
    var configBuilder = StandaloneGlobalConfiguration.builder().addPlugin(PluginLocator.getJavaScriptPluginPath()).addPlugin(PluginLocator.getJavaPluginPath()).addPlugin(PluginLocator.getPhpPluginPath()).addPlugin(PluginLocator.getPythonPluginPath()).addEnabledLanguages(Language.JS, Language.JAVA, Language.PHP, Language.PYTHON, Language.TS, Language.C).setSonarLintUserHome(sonarlintUserHome).setNodeJs(nodeJsHelper.getNodeJsPath(), nodeJsHelper.getNodeJsVersion()).setExtraProperties(extraProperties);
    if (COMMERCIAL_ENABLED) {
        configBuilder.addPlugin(PluginLocator.getCppPluginPath());
    }
    sonarlint = new StandaloneSonarLintEngineImpl(configBuilder.build());
}
Also used : HashMap(java.util.HashMap) NodeJsHelper(org.sonarsource.sonarlint.core.NodeJsHelper) StandaloneSonarLintEngineImpl(org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 5 with NodeJsHelper

use of org.sonarsource.sonarlint.core.NodeJsHelper in project sonarlint-core by SonarSource.

the class ConnectedEmbeddedPluginMediumTests method prepare.

@BeforeAll
static void prepare(@TempDir Path slHome) throws Exception {
    var storage = newStorage(SERVER_ID).withJSPlugin().withJavaPlugin().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((m, l) -> System.out.println(m)).addEnabledLanguages(Language.JAVA, Language.JS).setNodeJs(nodeJsHelper.getNodeJsPath(), nodeJsHelper.getNodeJsVersion()).useEmbeddedPlugin("java", PluginLocator.getJavaPluginPath()).build();
    sonarlint = new ConnectedSonarLintEngineImpl(config);
}
Also used : NodeJsHelper(org.sonarsource.sonarlint.core.NodeJsHelper) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) ProjectStorageFixture(org.sonarsource.sonarlint.core.mediumtest.fixtures.ProjectStorageFixture) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

NodeJsHelper (org.sonarsource.sonarlint.core.NodeJsHelper)6 ConnectedSonarLintEngineImpl (org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl)5 BeforeAll (org.junit.jupiter.api.BeforeAll)4 HashMap (java.util.HashMap)3 ProjectStorageFixture (org.sonarsource.sonarlint.core.mediumtest.fixtures.ProjectStorageFixture)3 File (java.io.File)2 ClientModuleInfo (org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo)2 IOException (java.io.IOException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Random (java.util.Random)1 DefaultExecutor (org.apache.commons.exec.DefaultExecutor)1 FileUtils (org.apache.commons.io.FileUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.fail (org.assertj.core.api.Assertions.fail)1 Assertions.tuple (org.assertj.core.api.Assertions.tuple)1