1
/*******************************************************************************
2
* Copyright (c) 2006, 2009 IBM Corporation and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* IBM Corporation - Initial API and implementation (Corey Ashford)
10
* Anton Leherbauer (Wind River Systems)
11
* Markus Schorn (Wind River Systems)
12
*******************************************************************************/
14
package org.eclipse.cdt.utils;
16
import java.io.BufferedReader;
17
import java.io.IOException;
18
import java.io.InputStreamReader;
20
import org.eclipse.cdt.core.CCorePlugin;
21
import org.osgi.framework.Bundle;
24
* @noinstantiate This class is not intended to be instantiated by clients.
26
public final class Platform {
28
// This class duplicates all of the methods in org.eclipse.core.runtime.Platform
29
// that are used by the CDT. getOSArch() needs a few tweaks because the value returned
30
// by org.eclipse.core.runtime.Platform.getOSArch represents what the JVM thinks the
31
// architecture is. In some cases, we may actually be running on a 64-bit machine,
32
// but the JVM thinks it's running on a 32-bit machine. Without this change, the CDT
33
// will not handle 64-bit executables on some ppc64. This method could easily be
34
// extended to handle other platforms with similar issues.
36
// Unfortunately, the org.eclipse.core.runtime.Platform is final, so we cannot just
37
// extend it and and then override the getOSArch method, so getBundle and getOS just
38
// encapsulate calls to the same methods in org.eclipse.core.runtime.Platform.
40
public static final String OS_LINUX = org.eclipse.core.runtime.Platform.OS_LINUX;
42
private static String cachedArch = null;
44
public static Bundle getBundle(String symbolicName) {
45
return org.eclipse.core.runtime.Platform.getBundle(symbolicName);
48
public static String getOS() {
49
return org.eclipse.core.runtime.Platform.getOS();
52
public static String getOSArch() {
53
if (cachedArch == null) {
54
String arch = org.eclipse.core.runtime.Platform.getOSArch();
55
if (arch.equals(org.eclipse.core.runtime.Platform.ARCH_PPC)) {
56
// Determine if the platform is actually a ppc64 machine
58
String cmd[] = {"uname", "-p"}; //$NON-NLS-1$//$NON-NLS-2$
61
unameProcess = Runtime.getRuntime().exec(cmd);
63
InputStreamReader inputStreamReader = new InputStreamReader(unameProcess.getInputStream());
64
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
65
String unameOutput= bufferedReader.readLine();
66
if (unameOutput != null) {
69
bufferedReader.close();
70
unameProcess.waitFor(); // otherwise the process becomes a zombie
71
} catch (IOException e) {
73
} catch (InterruptedException exc) {
74
// restore interrupted flag
75
Thread.currentThread().interrupt();
77
} else if (arch.equals(org.eclipse.core.runtime.Platform.ARCH_X86)) {
78
// Determine if the platform is actually a x86_64 machine
81
if (org.eclipse.core.runtime.Platform.OS_WIN32.equals(getOS())) {
82
cmd = new String[] {"cmd", "/d", "/c", "set", "PROCESSOR_ARCHITECTURE"}; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
84
// We don't use "uname -p" since it returns "unknown" on some Linux systems.
85
cmd = new String[] {"uname", "-m"}; //$NON-NLS-1$//$NON-NLS-2$
89
unameProcess = Runtime.getRuntime().exec(cmd);
90
unameProcess.getOutputStream().close();
91
unameProcess.getErrorStream().close();
92
InputStreamReader inputStreamReader = new InputStreamReader(unameProcess.getInputStream());
93
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
94
String unameOutput = bufferedReader.readLine();
95
if (unameOutput != null && unameOutput.endsWith("64")) { //$NON-NLS-1$
96
arch= org.eclipse.core.runtime.Platform.ARCH_X86_64;
98
bufferedReader.close();
99
unameProcess.waitFor(); // otherwise the process becomes a zombie
100
} catch (IOException e) {
102
} catch (InterruptedException exc) {
103
// restore interrupted flag
104
Thread.currentThread().interrupt();