Skip to content

Commit 516a51e

Browse files
authored
feat: running commands in separate job (#838)
1 parent 0267c08 commit 516a51e

File tree

8 files changed

+33
-8
lines changed

8 files changed

+33
-8
lines changed

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/handlers/Messages.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public class Messages extends NLS
1313
public static String NewProjectHandler_PathErrorTitle;
1414
public static String LanguageChange_ErrorTitle;
1515
public static String LanguageChange_ErrorMessage;
16+
public static String ProjectCleanCommandHandler_RunningProjectCleanJobName;
17+
public static String ProjectFullCleanCommandHandler_RunningFullcleanJobName;
18+
public static String PythonCleanCommandHandler_RunningPythonCleanJobName;
1619
public static String UpdateEspIdfCommand_JobMsg;
1720
public static String UpdateEspIdfCommand_InstallToolsJobMsg;
1821
public static String UpdateEspIdfCommand_SuggestToOpenInstallToolsWizard;

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/handlers/ProjectCleanCommandHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public Object execute(ExecutionEvent event) throws ExecutionException
4949

5050
commands.add("clean"); //$NON-NLS-1$
5151
Map<String, String> envMap = new IDFEnvironmentVariables().getSystemEnvMap();
52-
console.println(commands.toString());
53-
console.print((runCommand(commands, pathToProject, envMap)));
52+
runCommandInNewJob(Messages.ProjectCleanCommandHandler_RunningProjectCleanJobName, commands, pathToProject,
53+
envMap);
5454
return event;
5555
}
5656

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/handlers/ProjectFullCleanCommandHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException
5454
}
5555
commands.add("fullclean"); //$NON-NLS-1$
5656
Map<String, String> envMap = new IDFEnvironmentVariables().getSystemEnvMap();
57-
console.println(commands.toString());
58-
console.print((runCommand(commands, pathToProject, envMap)));
57+
runCommandInNewJob(Messages.ProjectFullCleanCommandHandler_RunningFullcleanJobName, commands, pathToProject, envMap);
5958
return event;
6059
}
6160

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/handlers/PythonCleanCommandHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException
4848
}
4949
commands.add("python-clean"); //$NON-NLS-1$
5050
Map<String, String> envMap = new IDFEnvironmentVariables().getSystemEnvMap();
51-
console.println(commands.toString());
52-
console.print((runCommand(commands, pathToProject, envMap)));
51+
runCommandInNewJob(Messages.PythonCleanCommandHandler_RunningPythonCleanJobName, commands, pathToProject, envMap);
5352
return event;
5453
}
5554

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/handlers/messages.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ NewProjectHandler_CouldntFindTools=Could't find installed tools path for GIT and
66
NewProjectHandler_MandatoryMsg=This is a mandatory step even if you've already installed the tools from the command line. Do you want to install the missing tools now?
77
NewProjectHandler_NavigateToHelpMenu=Please navigate to menu `Help > ESP-IDF Tools Manager > Install Tools` to install and configure the required paths for creating and building the ESP-IDF projects. \n \n
88
NewProjectHandler_PathErrorTitle=Path Error
9+
ProjectCleanCommandHandler_RunningProjectCleanJobName=Running Project Clean...
10+
ProjectFullCleanCommandHandler_RunningFullcleanJobName=Running fullclean...
11+
PythonCleanCommandHandler_RunningPythonCleanJobName=Running python-clean command...
912
UpdateEspIdfCommand_JobMsg=Updating ESP-IDF master...
1013
UpdateEspIdfCommand_InstallToolsJobMsg=Installing tools...
1114
UpdateEspIdfCommand_SuggestToOpenInstallToolsWizard = A new set of tools might be required to install. Do you want to open the Install Tools dialog?

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/AbstractToolsHandler.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
import org.eclipse.core.commands.ExecutionEvent;
1515
import org.eclipse.core.commands.ExecutionException;
1616
import org.eclipse.core.runtime.IPath;
17+
import org.eclipse.core.runtime.IProgressMonitor;
1718
import org.eclipse.core.runtime.IStatus;
1819
import org.eclipse.core.runtime.Path;
1920
import org.eclipse.core.runtime.Platform;
2021
import org.eclipse.core.runtime.Status;
22+
import org.eclipse.core.runtime.jobs.Job;
2123
import org.eclipse.jface.window.Window;
2224
import org.eclipse.swt.widgets.Display;
2325
import org.eclipse.ui.console.MessageConsoleStream;
@@ -161,7 +163,7 @@ protected IStatus runCommand(List<String> arguments, MessageConsoleStream consol
161163

162164
Map<String, String> environment = new HashMap<>(System.getenv());
163165
Logger.log(environment.toString());
164-
environment.put("PYTHONUNBUFFERED", "1");
166+
environment.put("PYTHONUNBUFFERED", "1"); //$NON-NLS-1$ //$NON-NLS-2$
165167

166168
if (gitExecutablePath != null)
167169
{
@@ -216,7 +218,7 @@ private IStatus processData(Process process)
216218
return Status.OK_STATUS;
217219
}
218220

219-
return new Status(IStatus.ERROR, IDFCorePlugin.PLUGIN_ID, "Error");
221+
return new Status(IStatus.ERROR, IDFCorePlugin.PLUGIN_ID, "Error"); //$NON-NLS-1$
220222

221223
}
222224
catch (InterruptedException e)
@@ -294,6 +296,23 @@ else if (!StringUtil.isEmpty(path2) && !path2.contains(gitDir)) // Git not found
294296
}
295297
}
296298

299+
protected void runCommandInNewJob(String jobName, List<String> commandArgs, Path pathToProject,
300+
Map<String, String> envMap)
301+
{
302+
Job job = new Job(jobName)
303+
{
304+
305+
protected IStatus run(IProgressMonitor monitor)
306+
{
307+
console.println(String.format(Messages.AbstractToolsHandler_RunningCommandFormatString,
308+
String.join(" ", commandArgs))); //$NON-NLS-1$
309+
console.println((runCommand(commandArgs, pathToProject, envMap)));
310+
return Status.OK_STATUS;
311+
}
312+
};
313+
job.schedule();
314+
}
315+
297316
protected String getCommandString(List<String> arguments)
298317
{
299318
StringBuilder builder = new StringBuilder();

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/Messages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class Messages extends NLS
1010
{
1111
private static final String BUNDLE_NAME = "com.espressif.idf.ui.update.messages"; //$NON-NLS-1$
1212
public static String AbstractToolsHandler_ExecutingMsg;
13+
public static String AbstractToolsHandler_RunningCommandFormatString;
1314
public static String DirectorySelectionDialog_Browse;
1415
public static String DirectorySelectionDialog_CantbeEmpty;
1516
public static String DirectorySelectionDialog_CheckTools;

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Use is subject to license terms.
44
###############################################################################
55
AbstractToolsHandler_ExecutingMsg=Executing
6+
AbstractToolsHandler_RunningCommandFormatString=Running command: %s
67
DirectorySelectionDialog_Browse=Browse...
78
DirectorySelectionDialog_CantbeEmpty=Fields can't be empty\!
89
DirectorySelectionDialog_CheckTools=Check Tools

0 commit comments

Comments
 (0)