Skip to content

Commit

Permalink
SLI-549 Analyze C# code
Browse files Browse the repository at this point in the history
  • Loading branch information
henryju committed Jun 14, 2021
1 parent 4c0bd93 commit 069da07
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
7 changes: 3 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ dependencies {
implementation("org.apache.httpcomponents.client5:httpclient5:5.0.3") {
exclude(module = "slf4j-api")
}
implementation(project(":clion"))
implementation(project(":common"))
implementation(project(":clion"))
implementation(project(":rider"))
testImplementation("junit:junit:4.12")
testImplementation("org.assertj:assertj-core:3.16.1")
testImplementation("org.mockito:mockito-core:2.19.0")
Expand All @@ -181,6 +182,7 @@ dependencies {
"sqplugins"("org.sonarsource.slang:sonar-kotlin-plugin:1.8.3.2219@jar")
"sqplugins"("org.sonarsource.slang:sonar-ruby-plugin:1.8.3.2219@jar")
"sqplugins"("org.sonarsource.html:sonar-html-plugin:3.4.0.2754@jar")
"sqplugins"("org.sonarsource.sonarlint.omnisharp:sonarlint-omnisharp-plugin:1.0.0.33008@jar")
if (artifactoryUsername.isNotEmpty() && artifactoryPassword.isNotEmpty()) {
"sqplugins"("com.sonarsource.cpp:sonar-cfamily-plugin:6.21.0.32709@jar")
}
Expand Down Expand Up @@ -344,6 +346,3 @@ signing {
})
sign(configurations.archives.get())
}



2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version=4.17-SNAPSHOT
org.gradle.jvmargs=-XX:MaxPermSize=256M
sonarlintCoreVersion=6.1.0.32613
sonarlintCoreVersion=6.1.0.32869
intellijBuildVersion=IC-2020.1.3
clionBuildVersion=CL-2020.1.3
# Should be the same as the one embedded into SonarLint Core
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package org.sonarlint.intellij.core;

import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.util.PlatformUtils;
import java.io.IOException;
import java.net.URL;
import java.nio.file.DirectoryStream;
Expand All @@ -29,6 +31,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -71,7 +74,6 @@ ConnectedSonarLintEngine createEngine(String serverId) {

GlobalLogOutput globalLogOutput = SonarLintUtils.getService(GlobalLogOutput.class);
final NodeJsManager nodeJsManager = SonarLintUtils.getService(NodeJsManager.class);
URL cFamilyPluginUrl = findEmbeddedCFamilyPlugin(getPluginsDir());
ConnectedGlobalConfiguration.Builder config = ConnectedGlobalConfiguration.builder()
.setLogOutput(globalLogOutput)
.setSonarLintUserHome(getSonarLintHome())
Expand All @@ -80,9 +82,14 @@ ConnectedSonarLintEngine createEngine(String serverId) {
.setNodeJs(nodeJsManager.getNodeJsPath(), nodeJsManager.getNodeJsVersion())
.setWorkDir(getWorkDir())
.setConnectionId(serverId);
URL cFamilyPluginUrl = findEmbeddedCFamilyPlugin(getPluginsDir());
if (cFamilyPluginUrl != null) {
config.useEmbeddedPlugin(Language.CPP.getPluginKey(), cFamilyPluginUrl);
}
URL csPluginUrl = findEmbeddedCsharpPlugin(getPluginsDir());
if (csPluginUrl != null) {
config.useEmbeddedPlugin(Language.CS.getPluginKey(), csPluginUrl);
}

// it will also start it
return new ConnectedSonarLintEngineImpl(config.build());
Expand Down Expand Up @@ -151,6 +158,19 @@ private static URL findEmbeddedCFamilyPlugin(Path pluginsDir) {
}
}

@CheckForNull
private static URL findEmbeddedCsharpPlugin(Path pluginsDir) {
try {
List<URL> pluginsUrls = findFilesInDir(pluginsDir, "sonarlint-omnisharp-plugin-*.jar", "Found CSharp plugin: ");
if (pluginsUrls.size() > 1) {
throw new IllegalStateException("Multiple plugins found");
}
return pluginsUrls.size() == 1 ? pluginsUrls.get(0) : null;
} catch (Exception e) {
throw new IllegalStateException(e);
}
}

private static URL[] getPluginsUrls(Path pluginsDir) throws IOException {
return findFilesInDir(pluginsDir, "*.jar", "Found plugin: ").toArray(new URL[0]);
}
Expand Down Expand Up @@ -179,6 +199,26 @@ private static Path getWorkDir() {

private static Map<String, String> prepareExtraProps() {
SonarLintPlugin plugin = SonarLintUtils.getService(SonarLintPlugin.class);
return Collections.singletonMap("sonar.typescript.internal.typescriptLocation", plugin.getPath().toString());
Map<String, String> extraProps = new HashMap<>();
extraProps.put("sonar.typescript.internal.typescriptLocation", plugin.getPath().toString());
if (PlatformUtils.isRider()) {
addOmnisharpServerPath(plugin, extraProps);
}
return extraProps;
}

private static void addOmnisharpServerPath(SonarLintPlugin plugin, Map<String, String> extraProps) {
String osDir;
if (SystemInfo.isWindows) {
osDir = "win";
} else if (SystemInfo.isMac) {
osDir = "osx";
} else if (SystemInfo.isLinux) {
osDir = "linux";
} else {
GlobalLogOutput.get().log("Unsupported platform for Omnisharp", LogOutput.Level.WARN);
return;
}
extraProps.put("sonar.cs.internal.omnisharpLocation", plugin.getPath().resolve("omnisharp").resolve(osDir).toString());
}
}

0 comments on commit 069da07

Please sign in to comment.