diff --git a/Src/CSharpier.Rider/gradle.properties b/Src/CSharpier.Rider/gradle.properties index 80dcaa753..78ed9bb02 100644 --- a/Src/CSharpier.Rider/gradle.properties +++ b/Src/CSharpier.Rider/gradle.properties @@ -3,7 +3,7 @@ pluginGroup = com.intellij.csharpier pluginName = csharpier -pluginVersion = 1.6.1 +pluginVersion = 1.6.2-beta # See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html # for insight into build numbers and IntelliJ Platform versions. diff --git a/Src/CSharpier.Rider/src/main/java/com/intellij/csharpier/DotNetFinder.java b/Src/CSharpier.Rider/src/main/java/com/intellij/csharpier/DotNetFinder.java index 32c662fc8..ccc04d72f 100644 --- a/Src/CSharpier.Rider/src/main/java/com/intellij/csharpier/DotNetFinder.java +++ b/Src/CSharpier.Rider/src/main/java/com/intellij/csharpier/DotNetFinder.java @@ -1,6 +1,7 @@ package com.intellij.csharpier; import com.intellij.openapi.diagnostic.Logger; +import org.apache.commons.lang.SystemUtils; import java.nio.file.Files; import java.nio.file.Paths; @@ -13,7 +14,7 @@ public class DotNetFinder { public static String findOnPath(Logger logger) { - logger.debug("Trying to find dotnet on PATH"); + logger.debug("Trying to find dotnet on PATH using dotnet --info"); var env = Map.of( "DOTNET_CLI_UI_LANGUAGE", "en-US", @@ -21,6 +22,23 @@ public static String findOnPath(Logger logger) { "DOTNET_CLI_TELEMETRY_OPTOUT", "1", "DOTNET_SKIP_FIRST_TIME_EXPERIENCE", "1"); var dotnetInfo = ProcessHelper.executeCommand(List.of("dotnet", "--info"), env, null); + if (dotnetInfo == null && !SystemUtils.IS_OS_WINDOWS) + { + logger.debug("Trying to find dotnet on PATH using sh -c dotnet --info"); + dotnetInfo = ProcessHelper.executeCommand(List.of("sh", "-c", "dotnet --info"), env, null); + } + if (dotnetInfo == null && SystemUtils.IS_OS_MAC) { + logger.debug("Trying to find dotnet on PATH using /bin/zsh -c dotnet --info"); + + // For Mac, the .NET binary isn't available for ProcessBuilder, so we'll add the default + // installation location to the PATH. We'll prefer the ARM version and fallback to the x64. + var path = System.getenv("PATH"); + path += ":/usr/local/share/dotnet:/usr/local/share/dotnet/x64/dotnet"; + env = new HashMap<>(env); + env.put("PATH", path); + dotnetInfo = ProcessHelper.executeCommand(List.of("/bin/zsh", "-c", "dotnet --info"), env, null); + } + if (dotnetInfo == null) { return null; } diff --git a/Src/CSharpier.Rider/src/main/java/com/intellij/csharpier/DotNetProvider.java b/Src/CSharpier.Rider/src/main/java/com/intellij/csharpier/DotNetProvider.java index 51347dd9a..19523c97d 100644 --- a/Src/CSharpier.Rider/src/main/java/com/intellij/csharpier/DotNetProvider.java +++ b/Src/CSharpier.Rider/src/main/java/com/intellij/csharpier/DotNetProvider.java @@ -16,9 +16,20 @@ public class DotNetProvider { private final Project project; private String dotNetRoot; private String cliExePath; + private boolean isInitialized; public DotNetProvider(@NotNull Project project) { this.project = project; + } + + static DotNetProvider getInstance(@NotNull Project project) { + return project.getService(DotNetProvider.class); + } + + private synchronized void initializeIfNeeded() { + if (this.isInitialized) { + return; + } var foundDotNet = this.findDotNet(); if (!foundDotNet) { @@ -28,10 +39,8 @@ public DotNetProvider(@NotNull Project project) { var notification = NotificationGroupManager.getInstance().getNotificationGroup("CSharpier").createNotification(title, message, NotificationType.WARNING); notification.notify(this.project); } - } - static DotNetProvider getInstance(@NotNull Project project) { - return project.getService(DotNetProvider.class); + this.isInitialized = true; } private boolean findDotNet() { @@ -63,6 +72,7 @@ private boolean findDotNet() { } public String execDotNet(List command, File workingDirectory) { + this.initializeIfNeeded(); var commands = new ArrayList<>(command); commands.add(0, this.cliExePath); @@ -72,10 +82,12 @@ public String execDotNet(List command, File workingDirectory) { } public String getDotNetRoot() { + this.initializeIfNeeded(); return this.dotNetRoot; } public boolean foundDotNet() { + this.initializeIfNeeded(); return this.cliExePath != null; }