1515import com .microsoft .azure .toolkit .ide .common .component .Node ;
1616import com .microsoft .azure .toolkit .ide .common .icon .AzureIcons ;
1717import com .microsoft .azure .toolkit .lib .common .event .AzureEventBus ;
18- import com .microsoft .azure .toolkit .lib .common .task .AzureTaskManager ;
1918import org .apache .commons .lang3 .SystemUtils ;
2019import org .jetbrains .annotations .NotNull ;
2120
2221import java .io .BufferedReader ;
22+ import java .io .File ;
2323import java .io .InputStreamReader ;
2424import java .util .function .Consumer ;
2525import 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 = "source ~/.zshrc && 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
@@ -204,15 +205,15 @@ private static String runAsBackgroundTask(String command, Consumer<String> onErr
204205 processBuilder .command ("bash" , "-c" , command ); // Linux
205206 }
206207
207- Process process = processBuilder .start ();
208+ final Process process = processBuilder .start ();
208209
209210 // Read the command output
210- try (BufferedReader reader = new BufferedReader (new InputStreamReader (process .getInputStream ()))) {
211- String output = reader .lines ().collect (Collectors .joining ("<br>" ));
212- 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 ();
213214 if (exitCode != 0 ) {
214- try (BufferedReader errorReader = new BufferedReader (new InputStreamReader (process .getErrorStream ()))) {
215- 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>" ));
216217 if (onError != null ) {
217218 onError .accept (error );
218219 }
@@ -221,8 +222,25 @@ private static String runAsBackgroundTask(String command, Consumer<String> onErr
221222 }
222223 return output ;
223224 }
224- } catch (Exception e ) {
225+ } catch (final Exception e ) {
225226 return null ;
226227 }
227228 }
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+ }
228246}
0 commit comments