33import com .fasterxml .jackson .annotation .JsonInclude ;
44import com .fasterxml .jackson .databind .DeserializationFeature ;
55import com .fasterxml .jackson .databind .ObjectMapper ;
6+ import com .intellij .ide .BrowserUtil ;
7+ import com .intellij .notification .Notification ;
8+ import com .intellij .notification .NotificationAction ;
69import com .intellij .notification .NotificationGroupManager ;
710import com .intellij .notification .NotificationType ;
11+ import com .intellij .openapi .actionSystem .AnActionEvent ;
812import com .intellij .openapi .progress .ProgressManager ;
913import com .intellij .openapi .progress .Task ;
1014import com .intellij .openapi .project .Project ;
1115import com .microsoft .azure .toolkit .ide .common .component .Node ;
1216import com .microsoft .azure .toolkit .ide .common .icon .AzureIcons ;
1317import com .microsoft .azure .toolkit .lib .common .event .AzureEventBus ;
18+ import com .microsoft .azure .toolkit .lib .common .task .AzureTaskManager ;
1419import org .apache .commons .lang3 .SystemUtils ;
20+ import org .jetbrains .annotations .NotNull ;
1521
1622import java .io .BufferedReader ;
1723import java .io .InputStreamReader ;
24+ import java .util .function .Consumer ;
1825import java .util .stream .Collectors ;
1926
2027import static com .microsoft .azure .toolkit .intellij .explorer .azd .AzdUtils .executeInTerminal ;
@@ -28,7 +35,7 @@ public final class AzdNode extends Node<String> {
2835 private static final String MAC_REFRESH_PATH_COMMAND = "source ~/.zshrc" ;
2936
3037 private static final String WIN_AZD_INSTALL_COMMAND = "winget install microsoft.azd" ;
31- private static final String LINUX_AZD_INSTALL_COMMAND = "curl -fsSL https://aka.ms/install-azd.sh | bash" ;
38+ private static final String LINUX_AZD_INSTALL_COMMAND = "set -o pipefail && curl -fsSL https://aka.ms/install-azd.sh | bash" ;
3239 private static final String MAC_AZD_INSTALL_COMMAND = "brew tap azure/azd && brew install azd" ;
3340
3441 private final Project project ;
@@ -79,8 +86,22 @@ private void installAzd(String command) {
7986 public void run (com .intellij .openapi .progress .ProgressIndicator indicator ) {
8087 indicator .setIndeterminate (true );
8188 indicator .setText (getTitle () + "..." );
82- final int exitCode = runAsBackgroundTask (command );
83- if (exitCode == 0 ) {
89+ final String output = runAsBackgroundTask (command , error -> {
90+ indicator .setText ("Installation of azd failed." );
91+ NotificationGroupManager .getInstance ()
92+ .getNotificationGroup ("Azure Developer" )
93+ .createNotification ("Installation of azd failed" , "Install azd manually and <b>restart IDE</b>.<br>" + error , NotificationType .ERROR )
94+ .addAction (new NotificationAction ("Install azd manually" ) {
95+ @ Override
96+ public void actionPerformed (@ NotNull AnActionEvent e , @ NotNull Notification notification ) {
97+ BrowserUtil .browse ("https://aka.ms/azd/install" );
98+ }
99+ })
100+ .notify (project );
101+ indicator .stop ();
102+ });
103+
104+ if (output != null ) {
84105 AzureEventBus .emit ("azd.installed" );
85106 NotificationGroupManager .getInstance ()
86107 .getNotificationGroup ("Azure Developer" )
@@ -95,20 +116,13 @@ public void run(com.intellij.openapi.progress.ProgressIndicator indicator) {
95116 executeInTerminal (project , MAC_REFRESH_PATH_COMMAND );
96117 }
97118 indicator .stop ();
98- } else {
99- indicator .setText ("Installation of azd failed." );
100- NotificationGroupManager .getInstance ()
101- .getNotificationGroup ("Azure Developer" )
102- .createNotification ("Installation of azd failed." , NotificationType .ERROR )
103- .notify (project );
104- indicator .stop ();
105119 }
106120 }
107121 });
108122 }
109123
110124 public void showAzdActions () {
111- AzdUtils .logTelemetryEvent ("azd-signed-in " );
125+ AzdUtils .logTelemetryEvent ("azd-show-actions " );
112126 addChild (getCreateFromTemplatesNode ());
113127 addChild (getInitializeFromSourceNode ());
114128 addChild (getProvisionResourcesNode ());
@@ -119,7 +133,7 @@ public void showAzdActions() {
119133 @ Override
120134 public synchronized void refreshView () {
121135 super .refreshView ();
122- refreshChildrenLater (true );
136+ refreshChildrenLater (false );
123137 }
124138
125139 private Node <String > getProvisionAndDeployToAzureNode () {
@@ -174,10 +188,10 @@ private Node<String> getCreateFromTemplatesNode() {
174188 }
175189
176190 public static boolean isAzdInstalled () {
177- return runAsBackgroundTask ("azd version -o json" ) == 0 ;
191+ return runAsBackgroundTask ("azd version -o json" , null ) != null ;
178192 }
179193
180- private static int runAsBackgroundTask (String command ) {
194+ private static String runAsBackgroundTask (String command , Consumer < String > onError ) {
181195 try {
182196 final ProcessBuilder processBuilder = new ProcessBuilder ();
183197 // Detect OS and set the appropriate command
@@ -192,12 +206,21 @@ private static int runAsBackgroundTask(String command) {
192206
193207 // Read the command output
194208 try (BufferedReader reader = new BufferedReader (new InputStreamReader (process .getInputStream ()))) {
195- String output = reader .lines ().collect (Collectors .joining ("\n " ));
209+ String output = reader .lines ().collect (Collectors .joining ("<br> " ));
196210 int exitCode = process .waitFor ();
197- return exitCode ;
211+ if (exitCode != 0 ) {
212+ try (BufferedReader errorReader = new BufferedReader (new InputStreamReader (process .getErrorStream ()))) {
213+ String error = errorReader .lines ().collect (Collectors .joining ("<br>" ));
214+ if (onError != null ) {
215+ onError .accept (error );
216+ }
217+ }
218+ return null ;
219+ }
220+ return output ;
198221 }
199222 } catch (Exception e ) {
200- return 1 ; // Handle error appropriately
223+ return null ;
201224 }
202225 }
203226}
0 commit comments