Add console fixes & run commands in a synchronous way
PATCH 1/1 Add console fixes & run commands in a synchronous way
- when creating a new Yocto Project, the window does not wait for the process to complete, and closes beforehand
- the long time running task will be created without forking and monitor will be updated when receiving events from the YoctoHostShellProcessAdapter
- use AbstractHostShellReader.isFinished to wait for command outputs
Signed-off-by Ioana Grigoropol <[email protected]>
--- .../src/org/yocto/bc/bitbake/ShellSession.java | 13 +- .../org/yocto/bc/remote/utils/ConsoleHelper.java | 18 +-- .../bc/remote/utils/ConsoleHelperRunnable.java | 31 +++++ .../org/yocto/bc/remote/utils/ConsoleRunnable.java | 37 ++++++ .../org/yocto/bc/remote/utils/RemoteHelper.java | 34 +++-- .../org/yocto/bc/remote/utils/RemoteMachine.java | 6 +- .../remote/utils/YoctoHostShellProcessAdapter.java | 140 +++++++++++++------- .../bc/ui/wizards/NewBitBakeFileRecipeWizard.java | 2 +- .../ui/wizards/NewBitBakeFileRecipeWizardPage.java | 10 +- .../yocto/bc/ui/wizards/install/InstallWizard.java | 86 +++--------- 10 files changed, 217 insertions(+), 160 deletions(-) create mode 100644 plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/ConsoleHelperRunnable.java create mode 100644 plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/ConsoleRunnable.java
plugins/org.yocto.bc.ui/src/org/yocto/bc/bitbake/ShellSession.java +6 -7
@@ -18,7 +18,6 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.io.Writer; -import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.rse.services.files.IHostFile;
@@ -119,12 +118,12 @@ public class ShellSession { synchronized public String execute(String command, int[] retCode) throws IOException { //FIXME : parse output - try { - RemoteHelper.runCommandRemote(RemoteHelper.getRemoteConnectionByName(projectInfo.getConnection().getName()), new YoctoCommand(command, root.getAbsolutePath(), ""), new NullProgressMonitor(), true); - } catch (Exception e) { - e.printStackTrace(); - } - +// try { +// RemoteHelper.runCommandRemote(RemoteHelper.getRemoteConnectionByName(projectInfo.getConnection().getName()), new YoctoCommand(command, root.getAbsolutePath(), ""), new NullProgressMonitor()); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// // String errorMessage = null; // interrupt = false; // out.write(command);
plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/ConsoleHelper.java +2 -16
@@ -1,14 +1,9 @@ package org.yocto.bc.remote.utils; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; +import org.eclipse.swt.widgets.Display; import org.eclipse.ui.console.ConsolePlugin; import org.eclipse.ui.console.IConsole; -import org.eclipse.ui.console.IConsoleConstants; import org.eclipse.ui.console.IConsoleManager; -import org.eclipse.ui.console.IConsoleView; import org.eclipse.ui.console.MessageConsole; public class ConsoleHelper {
@@ -28,15 +23,6 @@ public class ConsoleHelper { } public static void showConsole(MessageConsole console){ - IWorkbench wb = PlatformUI.getWorkbench(); - IWorkbenchWindow win = wb.getActiveWorkbenchWindow(); - IWorkbenchPage page = win.getActivePage(); - String id = IConsoleConstants.ID_CONSOLE_VIEW; - try { - IConsoleView view = (IConsoleView) page.showView(id); - view.display(console); - } catch (Exception e) { - e.printStackTrace(); - } + Display.getDefault().syncExec(new ConsoleRunnable(console)); } }
plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/ConsoleHelperRunnable.java new file +31 -0
@@ -0,0 +1,31 @@ +package org.yocto.bc.remote.utils; + +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.console.IConsoleConstants; +import org.eclipse.ui.console.IConsoleView; +import org.eclipse.ui.console.MessageConsole; + +public class ConsoleHelperRunnable implements Runnable { + MessageConsole console; + + ConsoleHelperRunnable(MessageConsole console){ + this.console = console; + } + @Override + public void run() { + IWorkbench wb = PlatformUI.getWorkbench(); + IWorkbenchWindow win = wb.getActiveWorkbenchWindow(); + IWorkbenchPage page = win.getActivePage(); + String id = IConsoleConstants.ID_CONSOLE_VIEW; + try { + IConsoleView view = (IConsoleView) page.showView(id); + view.display(console); + } catch (Exception e) { + e.printStackTrace(); + } + } + +}
plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/ConsoleRunnable.java new file +37 -0
@@ -0,0 +1,37 @@ +package org.yocto.bc.remote.utils; + +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.console.IConsoleConstants; +import org.eclipse.ui.console.IConsoleView; +import org.eclipse.ui.console.MessageConsole; + +public class ConsoleRunnable implements Runnable{ + MessageConsole console; + ConsoleRunnable (MessageConsole console){ + this.console = console; + } + @Override + public void run() { + IWorkbench wb = PlatformUI.getWorkbench(); + if (wb == null) + return; + IWorkbenchWindow win = wb.getActiveWorkbenchWindow(); + if (win == null) + return; + IWorkbenchPage page = win.getActivePage(); + if (page == null) + return; + String id = IConsoleConstants.ID_CONSOLE_VIEW; + try { + IConsoleView view = (IConsoleView) page.showView(id); + if (view == null) + return; + view.display(console); + } catch (Exception e) { + e.printStackTrace(); + } + } +}
plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/RemoteHelper.java +22 -12
@@ -34,7 +34,6 @@ import org.eclipse.rse.services.IService; import org.eclipse.rse.services.clientserver.messages.SystemMessageException; import org.eclipse.rse.services.files.IFileService; import org.eclipse.rse.services.files.IHostFile; -import org.eclipse.rse.services.shells.HostShellProcessAdapter; import org.eclipse.rse.services.shells.IHostShell; import org.eclipse.rse.subsystems.files.core.model.RemoteFileUtility; import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem;
@@ -46,6 +45,7 @@ import org.yocto.bc.ui.Activator; import org.yocto.bc.ui.wizards.install.Messages; public class RemoteHelper { + public static final int TOTALWORKLOAD = 100; private static Map<IHost, RemoteMachine> machines; public static RemoteMachine getRemoteMachine(IHost connection){
@@ -68,7 +68,7 @@ public class RemoteHelper { return getRemoteMachine(connection).getCmdHandler(); } - public static HostShellProcessAdapter getHostShellProcessAdapter(IHost connection) { + public static YoctoHostShellProcessAdapter getHostShellProcessAdapter(IHost connection) { return getRemoteMachine(connection).getHostShellProcessAdapter(); }
@@ -270,24 +270,34 @@ public class RemoteHelper { return null; } - public static void runCommandRemote(IHost connection, YoctoCommand cmd, IProgressMonitor monitor, boolean waitForOutput) throws Exception { + public static boolean runCommandRemote(IHost connection, YoctoCommand cmd, IProgressMonitor monitor) throws Exception { String remoteCommand = cmd.getCommand() + " " + cmd.getArguments(); - + boolean hasErrors = false; try { if (!cmd.getInitialDirectory().isEmpty()) { - writeToShell(connection, "cd " + cmd.getInitialDirectory(), waitForOutput); + hasErrors = writeToShell(connection, "cd " + cmd.getInitialDirectory(), monitor); } - writeToShell(connection, remoteCommand, waitForOutput); + if (!hasErrors) + return writeToShell(connection, remoteCommand, monitor); } catch (Exception e) { e.printStackTrace(); } + return hasErrors; } - public static void writeToShell(IHost connection, String remoteCommand, boolean waitForOutput){ - YoctoHostShellProcessAdapter hostShellProcessAdapter = ((YoctoHostShellProcessAdapter)getHostShellProcessAdapter(connection)); - hostShellProcessAdapter.setWaitForOutput(waitForOutput); - hostShellProcessAdapter.setLastCommand(remoteCommand); + public static boolean writeToShell(IHost connection, String remoteCommand, IProgressMonitor monitor){ + YoctoHostShellProcessAdapter hostShellProcessAdapter = getHostShellProcessAdapter(connection); + hostShellProcessAdapter.setMonitor(monitor); getHostShell(connection).writeToShell(remoteCommand); + + try { + while (!hostShellProcessAdapter.isFinished() && hostShellProcessAdapter.isAlive()) { + Thread.sleep(2); + } + } catch (Exception e) { + e.printStackTrace(); + } + return hostShellProcessAdapter.hasErrors(); } public static void runBatchRemote(IHost connection, List<YoctoCommand> cmds, IProgressMonitor monitor, boolean waitForOutput) throws CoreException {
@@ -298,9 +308,9 @@ public class RemoteHelper { for (YoctoCommand cmd : cmds) { remoteCommand = cmd.getCommand() + " " + cmd.getArguments(); if (!cmd.getInitialDirectory().isEmpty()) { - writeToShell(connection, "cd " + cmd.getInitialDirectory(), waitForOutput); + writeToShell(connection, "cd " + cmd.getInitialDirectory(), monitor); } - writeToShell(connection, remoteCommand, waitForOutput); + writeToShell(connection, remoteCommand, monitor); } } catch (Exception e1) { e1.printStackTrace();
plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/RemoteMachine.java +2 -4
@@ -12,7 +12,6 @@ import org.eclipse.rse.core.model.IHost; import org.eclipse.rse.core.subsystems.ISubSystem; import org.eclipse.rse.services.clientserver.messages.SystemMessageException; import org.eclipse.rse.services.files.IFileService; -import org.eclipse.rse.services.shells.HostShellProcessAdapter; import org.eclipse.rse.services.shells.IHostShell; import org.eclipse.rse.services.shells.IShellService; import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem;
@@ -27,7 +26,7 @@ public class RemoteMachine { private MessageConsole console; private CommandResponseHandler cmdHandler; private IHostShell hostShell; - private HostShellProcessAdapter hostShellProcessAdapter; + private YoctoHostShellProcessAdapter hostShellProcessAdapter; private IShellService shellService; private ProcessStreamBuffer processBuffer; private IHost connection;
@@ -61,7 +60,6 @@ public class RemoteMachine { try { if (hostShell == null) { hostShell = getShellService(new NullProgressMonitor()).launchShell("", new String[]{}, new NullProgressMonitor()); - getHostShellProcessAdapter(); } } catch (SystemMessageException e) { e.printStackTrace();
@@ -71,7 +69,7 @@ public class RemoteMachine { return hostShell; } - public HostShellProcessAdapter getHostShellProcessAdapter() { + public YoctoHostShellProcessAdapter getHostShellProcessAdapter() { try { if (hostShellProcessAdapter == null) hostShellProcessAdapter = new YoctoHostShellProcessAdapter(getHostShell(), getProcessBuffer(), getCmdHandler());
plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/YoctoHostShellProcessAdapter.java +89 -51
195 lines not on this page · raw message
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizard.java +1 -1
@@ -205,7 +205,7 @@ public class NewBitBakeFileRecipeWizard extends Wizard implements INewWizard { public void run(IProgressMonitor monitor) throws InvocationTargetException { try { doFinish(element, monitor); - RemoteHelper.runCommandRemote(connection, new YoctoCommand("rm -rf temp", element.getMetaDir() + "/temp", ""), monitor, true); + RemoteHelper.runCommandRemote(connection, new YoctoCommand("rm -rf temp", element.getMetaDir() + "/temp", ""), monitor); } catch (Exception e) { throw new InvocationTargetException(e); } finally {
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/NewBitBakeFileRecipeWizardPage.java +5 -5
@@ -352,11 +352,11 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage { String md5Cmd = "md5sum " + getSrcFileName(true); YoctoCommand md5YCmd = new YoctoCommand(md5Cmd, tempFolderPath, ""); - RemoteHelper.runCommandRemote(connection, md5YCmd, monitor, true); + RemoteHelper.runCommandRemote(connection, md5YCmd, monitor); String sha256Cmd = "sha256sum " + getSrcFileName(true); YoctoCommand sha256YCmd = new YoctoCommand(sha256Cmd, tempFolderPath, ""); - RemoteHelper.runCommandRemote(connection, sha256YCmd, monitor, true); + RemoteHelper.runCommandRemote(connection, sha256YCmd, monitor); URI extractDir = extractPackage(srcURI, monitor); YoctoCommand licenseChecksumCmd = populateLicenseFileChecksum(extractDir, monitor);
@@ -388,7 +388,7 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage { tarCmd += "-xvf "; } - RemoteHelper.runCommandRemote(connection, new YoctoCommand(tarCmd + path, tempFolderPath, ""), monitor, true); + RemoteHelper.runCommandRemote(connection, new YoctoCommand(tarCmd + path, tempFolderPath, ""), monitor); return RemoteHelper.createNewURI(metaDirLoc, TEMP_FOLDER_NAME + "/" + getSrcFileName(false));
@@ -427,7 +427,7 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage { try { YoctoCommand catCmd = new YoctoCommand("md5sum " + COPYING_FILE, extractDir.getPath(), ""); - RemoteHelper.runCommandRemote(connection, catCmd, monitor, true); + RemoteHelper.runCommandRemote(connection, catCmd, monitor); return catCmd; } catch (Exception e) { throw new RuntimeException("Unable to process file for MD5 calculation", e);
@@ -495,7 +495,7 @@ public class NewBitBakeFileRecipeWizardPage extends WizardPage { HashMap<String, String> mirrorMap = new HashMap<String, String>(); YoctoCommand cmd = new YoctoCommand("cat " + MIRRORS_FILE, getMetaFolderPath() + CLASSES_FOLDER, ""); - RemoteHelper.runCommandRemote(connection, cmd, monitor, true); + RemoteHelper.runCommandRemote(connection, cmd, monitor); if (!cmd.getProcessBuffer().hasErrors()){ String delims = "[\\t]+";
plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/install/InstallWizard.java +22 -64
144 lines not on this page · raw message
Signature · 1 line
1.7.9.5