summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.remote.utils/src/org/yocto/remote/utils/CommonHelper.java
blob: 23afd3805c01f6133d99e774e5a9ed2960ca7ea9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*******************************************************************************
 * Copyright (c) 2013 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.remote.utils;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.swt.widgets.Display;

public class CommonHelper {

	static public boolean isExecAvail(String exec) {
		boolean ret = false;
		try {
			Process p = Runtime.getRuntime().exec(new String[] {"which", exec});
			p.waitFor();
			if(p.exitValue() == 0) {
				ret = true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ret;
	}

	public static void showErrorDialog(final String dialogTitle, final String errorMessage, final String reason) {
		//needs to be run in the ui thread otherwise swt throws invalid thread access
		Display.getDefault().syncExec(new Runnable() {
			@Override
			public void run() {
				ErrorDialog.openError(null, dialogTitle, errorMessage,
						new Status(IStatus.ERROR,Activator.PLUGIN_ID,reason));
			}
		});

	}

}