Skip to content

Commit bb42c5d

Browse files
Merge pull request #11080 from srnagar/azd-mac
Update MacOS to use absolute path
2 parents 0feec8e + 5f4c8a2 commit bb42c5d

File tree

3 files changed

+34
-12
lines changed
  • PluginsAndFeatures/azure-toolkit-for-intellij
    • azure-intellij-plugin-lib/src/main/java/com/microsoft/azure/toolkit/intellij/common
    • azure-intellij-plugin-service-explorer/src/main/java/com/microsoft/azure/toolkit/intellij/explorer/azd

3 files changed

+34
-12
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-lib/src/main/java/com/microsoft/azure/toolkit/intellij/common/TerminalUtils.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,12 @@ public static TerminalWidget getOrCreateTerminalWidget(@Nonnull Project project,
7979
}
8080

8181
@Nonnull
82-
public static TerminalWidget getTerminalWidget(@Nonnull Project project, @Nullable Path workingDir, String terminalTabTitle) {
82+
public static synchronized TerminalWidget getTerminalWidget(@Nonnull Project project, @Nullable Path workingDir, String terminalTabTitle) {
8383
final TerminalToolWindowManager manager = TerminalToolWindowManager.getInstance(project);
8484
final String workingDirectory = Optional.ofNullable(workingDir).map(Path::toString).orElse(null);
85+
if (manager.getToolWindow() != null) {
86+
manager.getToolWindow().show();
87+
}
8588
return manager.getTerminalWidgets().stream()
8689
.filter(widget -> StringUtils.isBlank(terminalTabTitle) ||
8790
StringUtils.equals(widget.getTerminalTitle().buildTitle(), terminalTabTitle))

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-service-explorer/src/main/java/com/microsoft/azure/toolkit/intellij/explorer/azd/AzdNode.java

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
import com.microsoft.azure.toolkit.ide.common.component.Node;
1616
import com.microsoft.azure.toolkit.ide.common.icon.AzureIcons;
1717
import com.microsoft.azure.toolkit.lib.common.event.AzureEventBus;
18-
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
1918
import org.apache.commons.lang3.SystemUtils;
2019
import org.jetbrains.annotations.NotNull;
2120

2221
import java.io.BufferedReader;
22+
import java.io.File;
2323
import java.io.InputStreamReader;
2424
import java.util.function.Consumer;
2525
import java.util.stream.Collectors;
@@ -36,7 +36,8 @@ public final class AzdNode extends Node<String> {
3636

3737
private static final String WIN_AZD_INSTALL_COMMAND = "winget install microsoft.azd";
3838
private static final String LINUX_AZD_INSTALL_COMMAND = "set -o pipefail && curl -fsSL https://aka.ms/install-azd.sh | bash";
39-
private static final String MAC_AZD_INSTALL_COMMAND = "brew tap azure/azd && brew install azd";
39+
private static final String BREW_PATH = getBrewPath();
40+
private static final String MAC_AZD_INSTALL_COMMAND = "source ~/.zshrc && " + BREW_PATH + " tap azure/azd && " + BREW_PATH + " install azd";
4041

4142
private final Project project;
4243

@@ -198,19 +199,21 @@ private static String runAsBackgroundTask(String command, Consumer<String> onErr
198199
final String os = System.getProperty("os.name").toLowerCase();
199200
if (SystemUtils.IS_OS_WINDOWS) {
200201
processBuilder.command("cmd", "/c", command); // Windows
202+
} else if (SystemUtils.IS_OS_MAC) {
203+
processBuilder.command("zsh", "-c", command); // Mac
201204
} else {
202-
processBuilder.command("bash", "-c", command); // Linux/Unix
205+
processBuilder.command("bash", "-c", command); // Linux
203206
}
204207

205-
Process process = processBuilder.start();
208+
final Process process = processBuilder.start();
206209

207210
// Read the command output
208-
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
209-
String output = reader.lines().collect(Collectors.joining("<br>"));
210-
int exitCode = process.waitFor();
211+
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
212+
final String output = reader.lines().collect(Collectors.joining("<br>"));
213+
final int exitCode = process.waitFor();
211214
if (exitCode != 0) {
212-
try (BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()))) {
213-
String error = errorReader.lines().collect(Collectors.joining("<br>"));
215+
try (final BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()))) {
216+
final String error = errorReader.lines().collect(Collectors.joining("<br>"));
214217
if (onError != null) {
215218
onError.accept(error);
216219
}
@@ -219,8 +222,25 @@ private static String runAsBackgroundTask(String command, Consumer<String> onErr
219222
}
220223
return output;
221224
}
222-
} catch (Exception e) {
225+
} catch (final Exception e) {
223226
return null;
224227
}
225228
}
229+
230+
private static String getBrewPath() {
231+
// Try common brew locations
232+
final String[] possiblePaths = {
233+
"/opt/homebrew/bin/brew", // Apple Silicon
234+
"/usr/local/bin/brew" // Intel Mac
235+
};
236+
237+
for (final String path : possiblePaths) {
238+
if (new File(path).exists()) {
239+
return path;
240+
}
241+
}
242+
243+
// Fallback to PATH lookup
244+
return "brew";
245+
}
226246
}

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-service-explorer/src/main/java/com/microsoft/azure/toolkit/intellij/explorer/azd/AzdUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import javax.annotation.Nullable;
1515
import java.nio.file.Path;
1616
import java.util.Map;
17-
import java.util.concurrent.Callable;
1817

1918
import static com.microsoft.azure.toolkit.intellij.common.TerminalUtils.getTerminalWidget;
2019

0 commit comments

Comments
 (0)