1
package org.helioviewer.jhv.resourceloader;
3
import java.io.BufferedReader;
4
import java.io.IOException;
5
import java.io.InputStream;
6
import java.io.InputStreamReader;
8
import org.helioviewer.base.FileUtils;
9
import org.helioviewer.base.logging.Log;
10
import org.helioviewer.jhv.JHVGlobals;
13
* Helper class to set platform dependent system properties for example in order
14
* to determine compatible resource configurations in resource definitions
20
public class SystemProperties {
23
* Reads the builtin Java properties to determine the platform and set
24
* simplified properties used by JHelioviewer.
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");
32
System.setProperty("jhv.java.arch", javaArch);
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");
44
Log.error(">> Platform > Could not determine platform. OS: " + os + " - arch: " + arch);
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");
53
Log.error(">> Platform > Could not determine platform. OS: " + os + " - arch: " + arch);
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");
64
Log.error(">> Platform > Could not determine platform. OS: " + os + " - arch: " + arch);
67
Log.error(">> Platform > Could not determine platform. OS: " + os + " - arch: " + arch);
70
Log.error(">> Platform > Could not determine platform. OS: " + os + " - arch: " + arch);
75
* Determine the glibc version if possible and store the version in the
78
* @return The glibc version or null if it could not be determined
80
public static String setGLibcVersion() {
81
BufferedReader in = null;
82
InputStream err = null;
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);
94
} catch (IOException e) {
95
Log.error(">> SystemProperties.setGLibcVersion() > Could not determine glibc version", e);
100
} catch (IOException e) {
101
Log.error(">> SystemProperties.setGLibcVersion() > Could not close stdout of glibc-version tool", e);
107
} catch (IOException e) {
108
Log.error(">> SystemProperties.setGLibcVersion() > Could not close stderr of glibc-version tool", e);