~josejuan-sanchez/+junk/original-jhv-experimental-version

« back to all changes in this revision

Viewing changes to src/jhv/src/org/helioviewer/jhv/resourceloader/SystemProperties.java

  • Committer: José Juan Sánchez Hernández
  • Date: 2013-02-05 13:32:08 UTC
  • Revision ID: josejuan.sanchez@gmail.com-20130205133208-dfz1sh1uge5pjkny
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.helioviewer.jhv.resourceloader;
 
2
 
 
3
import java.io.BufferedReader;
 
4
import java.io.IOException;
 
5
import java.io.InputStream;
 
6
import java.io.InputStreamReader;
 
7
 
 
8
import org.helioviewer.base.FileUtils;
 
9
import org.helioviewer.base.logging.Log;
 
10
import org.helioviewer.jhv.JHVGlobals;
 
11
 
 
12
/**
 
13
 * Helper class to set platform dependent system properties for example in order
 
14
 * to determine compatible resource configurations in resource definitions
 
15
 * files.
 
16
 * 
 
17
 * @author Andre Dau
 
18
 * 
 
19
 */
 
20
public class SystemProperties {
 
21
 
 
22
    /**
 
23
     * Reads the builtin Java properties to determine the platform and set
 
24
     * simplified properties used by JHelioviewer.
 
25
     */
 
26
 
 
27
    public static void setPlatform() {
 
28
        String os = System.getProperty("os.name");
 
29
        String arch = System.getProperty("os.arch");
 
30
        String javaArch = System.getProperty("sun.arch.data.model");
 
31
 
 
32
        System.setProperty("jhv.java.arch", javaArch);
 
33
 
 
34
        if (os != null && arch != null) {
 
35
            os = os.toLowerCase();
 
36
            arch = arch.toLowerCase();
 
37
            if (os.indexOf("windows") != -1) {
 
38
                System.setProperty("jhv.os", "windows");
 
39
                if (arch.indexOf("64") != -1)
 
40
                    System.setProperty("jhv.arch", "x86-64");
 
41
                else if (arch.indexOf("86") != -1)
 
42
                    System.setProperty("jhv.arch", "x86-32");
 
43
                else {
 
44
                    Log.error(">> Platform > Could not determine platform. OS: " + os + " - arch: " + arch);
 
45
                }
 
46
            } else if (os.indexOf("linux") != -1) {
 
47
                System.setProperty("jhv.os", "linux");
 
48
                if (arch.indexOf("64") != -1)
 
49
                    System.setProperty("jhv.arch", "x86-64");
 
50
                else if (arch.indexOf("86") != -1)
 
51
                    System.setProperty("jhv.arch", "x86-32");
 
52
                else {
 
53
                    Log.error(">> Platform > Could not determine platform. OS: " + os + " - arch: " + arch);
 
54
                }
 
55
            } else if (os.indexOf("mac os x") != -1) {
 
56
                System.setProperty("jhv.os", "mac");
 
57
                if (arch.indexOf("ppc") != -1)
 
58
                    System.setProperty("jhv.arch", "ppc");
 
59
                else if (arch.indexOf("64") != -1)
 
60
                    System.setProperty("jhv.arch", "x86-64");
 
61
                else if (arch.indexOf("86") != -1)
 
62
                    System.setProperty("jhv.arch", "x86-32");
 
63
                else {
 
64
                    Log.error(">> Platform > Could not determine platform. OS: " + os + " - arch: " + arch);
 
65
                }
 
66
            } else {
 
67
                Log.error(">> Platform > Could not determine platform. OS: " + os + " - arch: " + arch);
 
68
            }
 
69
        } else {
 
70
            Log.error(">> Platform > Could not determine platform. OS: " + os + " - arch: " + arch);
 
71
        }
 
72
    }
 
73
 
 
74
    /**
 
75
     * Determine the glibc version if possible and store the version in the
 
76
     * system properties.
 
77
     * 
 
78
     * @return The glibc version or null if it could not be determined
 
79
     */
 
80
    public static String setGLibcVersion() {
 
81
        BufferedReader in = null;
 
82
        InputStream err = null;
 
83
        try {
 
84
            if (System.getProperty("jhv.os").equals("linux")) {
 
85
                Process p = FileUtils.invokeExecutable(JHVGlobals.GLibVersionTool, null);
 
86
                in = new BufferedReader(new InputStreamReader(p.getInputStream()));
 
87
                err = p.getErrorStream();
 
88
                String version = in.readLine();
 
89
                System.setProperty("glibc.version", version);
 
90
                in.close();
 
91
                err.close();
 
92
                return version;
 
93
            }
 
94
        } catch (IOException e) {
 
95
            Log.error(">> SystemProperties.setGLibcVersion() > Could not determine glibc version", e);
 
96
        } finally {
 
97
            if (in != null) {
 
98
                try {
 
99
                    in.close();
 
100
                } catch (IOException e) {
 
101
                    Log.error(">> SystemProperties.setGLibcVersion() > Could not close stdout of glibc-version tool", e);
 
102
                }
 
103
            }
 
104
            if (err != null) {
 
105
                try {
 
106
                    err.close();
 
107
                } catch (IOException e) {
 
108
                    Log.error(">> SystemProperties.setGLibcVersion() > Could not close stderr of glibc-version tool", e);
 
109
                }
 
110
            }
 
111
        }
 
112
        return null;
 
113
    }
 
114
}