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 Jul 2, 2021
1 parent fb57724 commit 598d499
Show file tree
Hide file tree
Showing 2 changed files with 45 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.kotlin:sonar-kotlin-plugin:2.0.0.29@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 @@ -364,6 +366,3 @@ signing {
})
sign(configurations.archives.get())
}



Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import com.intellij.execution.process.OSProcessUtil;
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;
Expand All @@ -29,8 +31,8 @@
import java.nio.file.Path;
import java.nio.file.Paths;
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 @@ -75,16 +77,20 @@ ConnectedSonarLintEngine createEngine(String connectionId) {

ModulesRegistry modulesRegistry = SonarLintUtils.getService(ModulesRegistry.class);

URL cFamilyPluginUrl = findEmbeddedCFamilyPlugin(getPluginsDir());
ConnectedGlobalConfiguration.Builder configBuilder = ConnectedGlobalConfiguration.builder()
.addEnabledLanguages(enabledLanguages.toArray(new Language[0]))
.setConnectionId(connectionId)
.setModulesProvider(() -> modulesRegistry.getModulesForEngine(connectionId));
configureCommonEngine(configBuilder);

URL cFamilyPluginUrl = findEmbeddedCFamilyPlugin(getPluginsDir());
if (cFamilyPluginUrl != null) {
configBuilder.useEmbeddedPlugin(Language.CPP.getPluginKey(), cFamilyPluginUrl);
}
URL csPluginUrl = findEmbeddedCsharpPlugin(getPluginsDir());
if (csPluginUrl != null) {
configBuilder.useEmbeddedPlugin(Language.CS.getPluginKey(), csPluginUrl);
}

return new ConnectedSonarLintEngineImpl(configBuilder.build());
}
Expand Down Expand Up @@ -160,6 +166,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 @@ -188,6 +207,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 598d499

Please sign in to comment.