From 41ac47d732eed8392d60d0f6773e5a279d49b999 Mon Sep 17 00:00:00 2001 From: Adrian Dudau Date: Thu, 12 Dec 2013 13:36:50 +0100 Subject: initial commit of Enea Linux 3.1 Migrated from the internal git server on the dora-enea branch Signed-off-by: Adrian Dudau --- .../src/org/yocto/sdk/remotetools/LocalJob.java | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/LocalJob.java (limited to 'plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/LocalJob.java') diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/LocalJob.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/LocalJob.java new file mode 100644 index 0000000..5b082a0 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/LocalJob.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2010 Intel Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel - initial API and implementation + *******************************************************************************/ + +package org.yocto.sdk.remotetools; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.SWTException; + +public class LocalJob extends Job { + + public static final String LOCAL_JOB_FAMILY = "localJobFamily"; + private String[] cmdarray; + private String[] envp; + private File dir; + private int exitValue; + private Exception exception; + private IWorkbenchWindow window; + + public LocalJob(String name, String[] cmdarray, String[] envp, File dir, IWorkbenchWindow window) { + super(name); + this.cmdarray=cmdarray; + this.envp=envp; + this.dir=dir; + this.window=window; + this.exitValue=0; + this.exception=null; + } + + @Override + protected IStatus run(IProgressMonitor monitor) { + Process p=null; + boolean cancel=false; + + try { + //start process + p=Runtime.getRuntime().exec(cmdarray,envp,dir); + + //wait for completion + while (!cancel) { + + if(monitor.isCanceled()) + cancel=true; + + try { + exitValue=p.exitValue(); + break; + }catch (IllegalThreadStateException e) { + } + + Thread.sleep(500); + } + + }catch (IOException e) { + exception=e; + }catch (InterruptedException e){ + cancel=true; + }finally { + if(p!=null) + p.destroy(); + } + try { + if(exitValue!=0 || exception!=null) { + window.getWorkbench().getDisplay().syncExec(new Runnable() { + public void run() { + MessageDialog.openError(window.getShell(), + Messages.LocalJob_Title, + Messages.ErrorLocalJob + ": " + getName() + + (exitValue!=0 ? "\n\tExit value: " + new Integer(exitValue).toString() : new String("")) + + (exception!=null ? "\n\t" + exception.getMessage() : new String ("")) + ); + } + }); + } + }catch (SWTException e) { + e.printStackTrace(); + }catch (Exception e) { + e.printStackTrace(); + } + return (cancel!=true) ? Status.OK_STATUS : Status.CANCEL_STATUS; + } + + public boolean belongsTo(Object family) { + return family == LOCAL_JOB_FAMILY; + } +} -- cgit v1.2.3-54-g00ecf