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