Skip to content

Commit

Permalink
Delay calling getDotNetCoreRuntime even longer. Take into account sh …
Browse files Browse the repository at this point in the history
…and zsh for trying to find dotnet on PAH
  • Loading branch information
belav committed Mar 8, 2024
1 parent 695284d commit 72a4804
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Src/CSharpier.Rider/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,14 +14,31 @@
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",
"DOTNET_NOLOGO", "1",
"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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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() {
Expand Down Expand Up @@ -63,6 +72,7 @@ private boolean findDotNet() {
}

public String execDotNet(List<String> command, File workingDirectory) {
this.initializeIfNeeded();
var commands = new ArrayList<>(command);
commands.add(0, this.cliExePath);

Expand All @@ -72,10 +82,12 @@ public String execDotNet(List<String> command, File workingDirectory) {
}

public String getDotNetRoot() {
this.initializeIfNeeded();
return this.dotNetRoot;
}

public boolean foundDotNet() {
this.initializeIfNeeded();
return this.cliExePath != null;
}

Expand Down

0 comments on commit 72a4804

Please sign in to comment.