Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3b6ca32b0f42bf3b874ed86c9f9fdf6df6066e80 (plain) (blame)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*******************************************************************************
 * Copyright (c) 2011, 2014 Wind River Systems, Inc. and others. 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:
 * Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.te.tcf.filesystem.core.internal.testers;

import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.tcf.protocol.Protocol;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode;

/**
 * The property tester to test if the target OS is a Windows OS.
 */
public class TargetPropertyTester extends PropertyTester {

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
	 */
	@Override
	public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
		if(receiver instanceof IPeerNode) {
			final IPeerNode peerNode = (IPeerNode) receiver;
			if(property.equals("isWindows")) { //$NON-NLS-1$
				return isWindows(peerNode);
			}
		}
		return false;
	}
	
	/**
	 * Test if the target represented by the peer model is a windows target.
	 * 
	 * @param peerNode The peer model of the target.
	 * @return true if it is a windows target.
	 */
	public static boolean isWindows(final IPeerNode peerNode) {
		final String osName = getOSName(peerNode);
		return osName == null ? false : (osName.startsWith("Windows")); //$NON-NLS-1$
	}
	
	/**
	 * Get the OS name from the peer model.
	 * 
	 * @param peerNode The peer model.
	 * @return OS name.
	 */
	public static String getOSName(final IPeerNode peerNode) {
	    final String[] osName = new String[1];
		if (Protocol.isDispatchThread()) {
			osName[0] = peerNode.getPeer().getOSName();
		}
		else {
			Protocol.invokeAndWait(new Runnable() {
				@Override
				public void run() {
					osName[0] = peerNode.getPeer().getOSName();
				}
			});
		}
	    return osName[0];
    }	
}

Back to the top