6363import org .netbeans .api .extexecution .base .input .InputProcessor ;
6464import org .netbeans .api .extexecution .base .input .InputProcessors ;
6565import org .netbeans .api .extexecution .base .input .LineProcessor ;
66+ import org .netbeans .api .progress .ProgressHandle ;
6667import org .netbeans .modules .php .api .executable .InvalidPhpExecutableException ;
6768import org .netbeans .modules .php .api .executable .PhpExecutable ;
6869import org .netbeans .modules .php .api .executable .PhpExecutableValidator ;
@@ -366,28 +367,35 @@ public List<FrameworkCommand> getCommands(boolean isForce) {
366367 return COMMANDS_CACHE ;
367368 }
368369
370+ @ NbBundle .Messages ("WordPressCli.update.command.progress=Updating wp-cli commands..." )
369371 public void updateCommands () {
370- long startTime = System .currentTimeMillis ();
371- COMMANDS_CACHE .clear ();
372- getCommands (Collections .<String >emptyList (), COMMANDS_CACHE );
373- if (COMMANDS_CACHE .isEmpty ()) {
374- NotifyDescriptor .Message message = new NotifyDescriptor .Message (Bundle .WordPressCli_commands_empty (), NotifyDescriptor .WARNING_MESSAGE );
375- DialogDisplayer .getDefault ().notify (message );
376- } else {
377- WordPressCliCommandListXmlBuilder builder = new WordPressCliCommandListXmlBuilder ();
378- builder .build (COMMANDS_CACHE );
379- String commadlist = builder .asText ();
380- if (!StringUtils .isEmpty (commadlist )) {
381- WordPressOptions .getInstance ().setWpCliCommandList (commadlist );
372+ ProgressHandle handle = ProgressHandle .createHandle (Bundle .WordPressCli_update_command_progress ());
373+ try {
374+ handle .start ();
375+ long startTime = System .currentTimeMillis ();
376+ COMMANDS_CACHE .clear ();
377+ getCommands (Collections .<String >emptyList (), COMMANDS_CACHE , handle );
378+ if (COMMANDS_CACHE .isEmpty ()) {
379+ NotifyDescriptor .Message message = new NotifyDescriptor .Message (Bundle .WordPressCli_commands_empty (), NotifyDescriptor .WARNING_MESSAGE );
380+ DialogDisplayer .getDefault ().notify (message );
381+ } else {
382+ WordPressCliCommandListXmlBuilder builder = new WordPressCliCommandListXmlBuilder ();
383+ builder .build (COMMANDS_CACHE );
384+ String commadlist = builder .asText ();
385+ if (!StringUtils .isEmpty (commadlist )) {
386+ WordPressOptions .getInstance ().setWpCliCommandList (commadlist );
387+ }
382388 }
389+ long endTime = System .currentTimeMillis ();
390+ LOGGER .log (INFO , "Update Commands: took {0}ms" , endTime - startTime ); // NOI18N
391+ LOGGER .log (INFO , "{0} wp-cli commands." , COMMANDS_CACHE .size ()); // NOI18N
392+ } finally {
393+ handle .finish ();
383394 }
384- long endTime = System .currentTimeMillis ();
385- LOGGER .log (INFO , "Update Commands: took {0}ms" , endTime - startTime ); // NOI18N
386- LOGGER .log (INFO , "{0} wp-cli commands." , COMMANDS_CACHE .size ()); // NOI18N
387395 }
388396
389397 // XXX get help later?
390- private void getCommands (List <String > subcommands , List <FrameworkCommand > commands ) {
398+ private void getCommands (List <String > subcommands , List <FrameworkCommand > commands , ProgressHandle handle ) {
391399 ArrayList <String > params = new ArrayList <>(subcommands .size () + 1 );
392400 params .add (HELP_COMMAND );
393401 params .addAll (subcommands );
@@ -409,6 +417,9 @@ private void getCommands(List<String> subcommands, List<FrameworkCommand> comman
409417 boolean isSubcommands = false ;
410418 boolean isFirstEmpty = false ;
411419 LOGGER .log (FINE , "{0} WP Command" , StringUtils .implode (subcommands , " " )); // NOI18N
420+ if (handle != null ) {
421+ handle .progress (StringUtils .implode (subcommands , " " )); // NOI18N
422+ }
412423 for (String line : lines ) {
413424 if (isSubcommands ) {
414425 if (StringUtils .isEmpty (line )) {
@@ -440,7 +451,7 @@ private void getCommands(List<String> subcommands, List<FrameworkCommand> comman
440451 commands .add (new WordPressCliCommand (nextSubcommands .toArray (new String []{}), description , help )); // NOI18N
441452
442453 // get commands recursively
443- getCommands (nextSubcommands , commands );
454+ getCommands (nextSubcommands , commands , handle );
444455 }
445456
446457 if (line .toLowerCase ().startsWith ("subcommands" )) { // NOI18N
0 commit comments