~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Platform.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
 *
 
8
 * Contributors:
 
9
 *     IBM Corporation - Initial API and implementation (Corey Ashford)
 
10
 *     Anton Leherbauer (Wind River Systems)
 
11
 *     Markus Schorn (Wind River Systems)
 
12
 *******************************************************************************/
 
13
 
 
14
package org.eclipse.cdt.utils;
 
15
 
 
16
import java.io.BufferedReader;
 
17
import java.io.IOException;
 
18
import java.io.InputStreamReader;
 
19
 
 
20
import org.eclipse.cdt.core.CCorePlugin;
 
21
import org.osgi.framework.Bundle;
 
22
 
 
23
/**
 
24
 * @noinstantiate This class is not intended to be instantiated by clients.
 
25
 */
 
26
public final class Platform {
 
27
 
 
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.
 
35
        //
 
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.
 
39
        
 
40
        public static final String OS_LINUX = org.eclipse.core.runtime.Platform.OS_LINUX;
 
41
        
 
42
        private static String cachedArch = null;
 
43
        
 
44
        public static Bundle getBundle(String symbolicName) {
 
45
                return org.eclipse.core.runtime.Platform.getBundle(symbolicName);
 
46
        }
 
47
        
 
48
        public static String getOS() {
 
49
                return org.eclipse.core.runtime.Platform.getOS();
 
50
        }
 
51
        
 
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
 
57
                                Process unameProcess;
 
58
                                String cmd[] = {"uname", "-p"};  //$NON-NLS-1$//$NON-NLS-2$
 
59
        
 
60
                                try {
 
61
                                        unameProcess = Runtime.getRuntime().exec(cmd);
 
62
        
 
63
                                        InputStreamReader inputStreamReader = new InputStreamReader(unameProcess.getInputStream());
 
64
                                        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
 
65
                                        String unameOutput= bufferedReader.readLine();
 
66
                                        if (unameOutput != null) {
 
67
                                                arch= unameOutput;
 
68
                                        }
 
69
                                        bufferedReader.close();
 
70
                                        unameProcess.waitFor(); // otherwise the process becomes a zombie
 
71
                                } catch (IOException e) {
 
72
                                        CCorePlugin.log(e);
 
73
                                } catch (InterruptedException exc) {
 
74
                                        // restore interrupted flag
 
75
                                        Thread.currentThread().interrupt();
 
76
                                }
 
77
                        } else if (arch.equals(org.eclipse.core.runtime.Platform.ARCH_X86)) {
 
78
                                // Determine if the platform is actually a x86_64 machine
 
79
                                Process unameProcess;
 
80
                                String cmd[];
 
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$
 
83
                                } else {
 
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$
 
86
                                }
 
87
        
 
88
                                try {
 
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;
 
97
                                        }
 
98
                                        bufferedReader.close();
 
99
                                        unameProcess.waitFor(); // otherwise the process becomes a zombie
 
100
                                } catch (IOException e) {
 
101
                                        CCorePlugin.log(e);
 
102
                                } catch (InterruptedException exc) {
 
103
                                        // restore interrupted flag
 
104
                                        Thread.currentThread().interrupt();
 
105
                                }
 
106
                        }
 
107
                        cachedArch= arch;
 
108
                }
 
109
                return cachedArch;
 
110
        }
 
111
}