Search in sources :

Example 6 with StandaloneSonarLintEngineImpl

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

the class StandaloneIssueMediumTest method prepare.

@BeforeClass
public static void prepare() throws Exception {
    Path sonarlintUserHome = temp.newFolder().toPath();
    Path fakeTypeScriptProjectPath = temp.newFolder().toPath();
    Path packagejson = fakeTypeScriptProjectPath.resolve("package.json");
    FileUtils.write(packagejson.toFile(), "{" + "\"devDependencies\": {\n" + "    \"typescript\": \"2.6.1\"\n" + "  }" + "}", StandardCharsets.UTF_8);
    ProcessBuilder pb = new ProcessBuilder("npm" + (SystemUtils.IS_OS_WINDOWS ? ".cmd" : ""), "install").directory(fakeTypeScriptProjectPath.toFile()).inheritIO();
    Process 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());
    StandaloneGlobalConfiguration config = StandaloneGlobalConfiguration.builder().addPlugin(PluginLocator.getJavaScriptPluginUrl()).addPlugin(PluginLocator.getJavaPluginUrl()).addPlugin(PluginLocator.getPhpPluginUrl()).addPlugin(PluginLocator.getPythonPluginUrl()).addPlugin(PluginLocator.getCppPluginUrl()).addPlugin(PluginLocator.getXooPluginUrl()).addPlugin(PluginLocator.getLicensePluginUrl()).addPlugin(PluginLocator.getTypeScriptPluginUrl()).setSonarLintUserHome(sonarlintUserHome).setLogOutput((msg, level) -> System.out.println(msg)).setExtraProperties(extraProperties).build();
    sonarlint = new StandaloneSonarLintEngineImpl(config);
}
Also used : Path(java.nio.file.Path) StandaloneGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneGlobalConfiguration) HashMap(java.util.HashMap) StandaloneSonarLintEngineImpl(org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl) BeforeClass(org.junit.BeforeClass)

Example 7 with StandaloneSonarLintEngineImpl

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

the class StandaloneNoPluginMediumTest method prepare.

@Before
public void prepare() throws IOException {
    LogOutput logOutput = (msg, level) -> logs.put(level, msg);
    sonarlint = new StandaloneSonarLintEngineImpl(StandaloneGlobalConfiguration.builder().setLogOutput(logOutput).build());
    baseDir = temp.newFolder();
}
Also used : LinkedListMultimap(com.google.common.collect.LinkedListMultimap) Arrays(java.util.Arrays) ImmutableMap(com.google.common.collect.ImmutableMap) TestUtils(org.sonarsource.sonarlint.core.TestUtils) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) Multimap(com.google.common.collect.Multimap) Level(org.sonarsource.sonarlint.core.client.api.common.LogOutput.Level) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) File(java.io.File) StandaloneSonarLintEngineImpl(org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl) StandaloneAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration) Rule(org.junit.Rule) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults) StandaloneGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneGlobalConfiguration) After(org.junit.After) TemporaryFolder(org.junit.rules.TemporaryFolder) LogOutput(org.sonarsource.sonarlint.core.client.api.common.LogOutput) StandaloneSonarLintEngine(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneSonarLintEngine) Before(org.junit.Before) LogOutput(org.sonarsource.sonarlint.core.client.api.common.LogOutput) StandaloneSonarLintEngineImpl(org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl) Before(org.junit.Before)

Example 8 with StandaloneSonarLintEngineImpl

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

the class StandaloneTest method prepare.

@BeforeClass
public static void prepare() throws Exception {
    Path sonarlintUserHome = temp.newFolder().toPath();
    logs = new ArrayList<>();
    Map<String, String> globalProps = new HashMap<>();
    globalProps.put("sonar.global.label", "It works");
    StandaloneGlobalConfiguration config = StandaloneGlobalConfiguration.builder().addPlugin(new File("../plugins/global-extension-plugin/target/global-extension-plugin.jar").toURI().toURL()).setSonarLintUserHome(sonarlintUserHome).setLogOutput((msg, level) -> logs.add(msg)).setExtraProperties(globalProps).build();
    sonarlint = new StandaloneSonarLintEngineImpl(config);
    assertThat(logs).containsOnlyOnce("Start Global Extension It works");
}
Also used : Path(java.nio.file.Path) StandaloneGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneGlobalConfiguration) HashMap(java.util.HashMap) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) File(java.io.File) StandaloneSonarLintEngineImpl(org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl) BeforeClass(org.junit.BeforeClass)

Example 9 with StandaloneSonarLintEngineImpl

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

the class SonarLintLanguageServer method initialize.

@Override
public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
    String rootUri = params.getRootUri();
    // rootURI is null when no folder is open (like opening a single file in VSCode)
    if (rootUri != null) {
        try {
            workspaceRoot = new URI(rootUri);
        } catch (URISyntaxException e) {
            throw new IllegalStateException(e);
        }
    }
    Map<String, Object> options = (Map<String, Object>) params.getInitializationOptions();
    userSettings = new UserSettings(options);
    String productKey = (String) options.get("productKey");
    // deprecated, will be ignored when productKey present
    String telemetryStorage = (String) options.get("telemetryStorage");
    String productName = (String) options.get("productName");
    String productVersion = (String) options.get("productVersion");
    telemetry.init(getStoragePath(productKey, telemetryStorage), productName, productVersion);
    telemetry.optOut(userSettings.disableTelemetry);
    info("Starting SonarLint engine...");
    info("Using " + analyzers.size() + " analyzers");
    try {
        Map<String, String> extraProperties = new HashMap<>();
        extraProperties.put("sonar.typescript.internal.typescriptLocation", (String) options.get(TYPESCRIPT_LOCATION));
        Builder builder = StandaloneGlobalConfiguration.builder().setLogOutput(logOutput).setExtraProperties(extraProperties).addPlugins(analyzers.toArray(new URL[0]));
        this.engine = new StandaloneSonarLintEngineImpl(builder.build());
    } catch (Exception e) {
        error("Error starting SonarLint engine", e);
        throw new IllegalStateException(e);
    }
    info("SonarLint engine started");
    InitializeResult result = new InitializeResult();
    ServerCapabilities c = new ServerCapabilities();
    TextDocumentSyncOptions textDocumentSyncOptions = new TextDocumentSyncOptions();
    textDocumentSyncOptions.setOpenClose(true);
    textDocumentSyncOptions.setChange(TextDocumentSyncKind.Full);
    textDocumentSyncOptions.setSave(new SaveOptions(true));
    c.setTextDocumentSync(textDocumentSyncOptions);
    c.setCodeActionProvider(true);
    c.setExecuteCommandProvider(new ExecuteCommandOptions(asList(SONARLINT_OPEN_RULE_DESCRIPTION_COMMAND)));
    result.setCapabilities(c);
    return CompletableFuture.completedFuture(result);
}
Also used : TextDocumentSyncOptions(org.eclipse.lsp4j.TextDocumentSyncOptions) HashMap(java.util.HashMap) Builder(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneGlobalConfiguration.Builder) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) StandaloneSonarLintEngineImpl(org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl) InitializeResult(org.eclipse.lsp4j.InitializeResult) ServerCapabilities(org.eclipse.lsp4j.ServerCapabilities) SaveOptions(org.eclipse.lsp4j.SaveOptions) ExecuteCommandOptions(org.eclipse.lsp4j.ExecuteCommandOptions) Map(java.util.Map) HashMap(java.util.HashMap)

Example 10 with StandaloneSonarLintEngineImpl

use of org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl in project sonar-web by SonarSource.

the class SonarLintTest method prepare.

@BeforeClass
public static void prepare() throws Exception {
    StandaloneGlobalConfiguration sonarLintConfig = StandaloneGlobalConfiguration.builder().addPlugin(FileLocation.byWildcardMavenFilename(new File("../../sonar-web-plugin/target"), "sonar-web-plugin-*.jar").getFile().toURI().toURL()).setSonarLintUserHome(temp.newFolder().toPath()).setLogOutput((formattedMessage, level) -> {
    /* Don't pollute logs */
    }).build();
    sonarlintEngine = new StandaloneSonarLintEngineImpl(sonarLintConfig);
    baseDir = temp.newFolder();
}
Also used : AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FileLocation(com.sonar.orchestrator.locator.FileLocation) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) IOException(java.io.IOException) HashMap(java.util.HashMap) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) StandaloneSonarLintEngineImpl(org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) StandaloneAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration) ArrayList(java.util.ArrayList) List(java.util.List) Charset(java.nio.charset.Charset) StandaloneGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneGlobalConfiguration) Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) ClassRule(org.junit.ClassRule) Path(java.nio.file.Path) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) StandaloneSonarLintEngine(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneSonarLintEngine) StandaloneGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneGlobalConfiguration) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) File(java.io.File) StandaloneSonarLintEngineImpl(org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl) BeforeClass(org.junit.BeforeClass)

Aggregations

StandaloneSonarLintEngineImpl (org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl)11 StandaloneGlobalConfiguration (org.sonarsource.sonarlint.core.client.api.standalone.StandaloneGlobalConfiguration)8 IOException (java.io.IOException)6 Path (java.nio.file.Path)6 File (java.io.File)5 BeforeClass (org.junit.BeforeClass)5 ClientInputFile (org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)5 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Test (org.junit.Test)4 TemporaryFolder (org.junit.rules.TemporaryFolder)4 StandaloneAnalysisConfiguration (org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration)4 StandaloneSonarLintEngine (org.sonarsource.sonarlint.core.client.api.standalone.StandaloneSonarLintEngine)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 StandardCharsets (java.nio.charset.StandardCharsets)3 Collections (java.util.Collections)3 List (java.util.List)3 FileUtils (org.apache.commons.io.FileUtils)3