]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/src/org/argeo/cms/util/OS.java
Prepare next development cycle
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / util / OS.java
1 package org.argeo.cms.util;
2
3 import java.io.File;
4 import java.nio.file.Path;
5 import java.nio.file.Paths;
6
7 /** When OS specific informations are needed. */
8 public class OS {
9 public final static OS LOCAL = new OS();
10
11 private final String arch, name, version;
12
13 /** The OS of the running JVM */
14 protected OS() {
15 arch = System.getProperty("os.arch");
16 name = System.getProperty("os.name");
17 version = System.getProperty("os.version");
18 }
19
20 public String getArch() {
21 return arch;
22 }
23
24 public String getName() {
25 return name;
26 }
27
28 public String getVersion() {
29 return version;
30 }
31
32 public boolean isMSWindows() {
33 // only MS Windows would use such an horrendous separator...
34 return File.separatorChar == '\\';
35 }
36
37 public String[] getDefaultShellCommand() {
38 if (!isMSWindows())
39 return new String[] { "/bin/bash", "-l", "-i" };
40 else
41 return new String[] { "cmd.exe", "/C" };
42 }
43
44 public static long getJvmPid() {
45 return ProcessHandle.current().pid();
46 // String pidAndHost = ManagementFactory.getRuntimeMXBean().getName();
47 // return Integer.parseInt(pidAndHost.substring(0, pidAndHost.indexOf('@')));
48 }
49
50 /**
51 * Get the runtime directory. It will be the environment variable
52 * XDG_RUNTIME_DIR if it is set, or ~/.cache/argeo if not.
53 */
54 public static Path getRunDir() {
55 Path runDir;
56 String xdgRunDir = System.getenv("XDG_RUNTIME_DIR");
57 if (xdgRunDir != null) {
58 // TODO support multiple names
59 runDir = Paths.get(xdgRunDir);
60 } else {
61 runDir = Paths.get(System.getProperty("user.home"), ".cache/argeo");
62 }
63 return runDir;
64 }
65 }