]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/src/org/argeo/cms/util/OS.java
1 package org
.argeo
.cms
.util
;
4 import java
.nio
.file
.Files
;
5 import java
.nio
.file
.Path
;
6 import java
.nio
.file
.Paths
;
9 * Wrapper around system properties and portable Java APIS, for when OS specific
10 * informations are needed.
13 public final static OS LOCAL
= new OS();
15 private final String arch
, name
, version
;
17 /** The OS of the running JVM */
19 arch
= System
.getProperty("os.arch");
20 name
= System
.getProperty("os.name");
21 version
= System
.getProperty("os.version");
24 public String
getArch() {
28 public String
getName() {
32 public String
getVersion() {
36 public boolean isMSWindows() {
37 // only MS Windows would use such an horrendous separator...
38 return File
.separatorChar
== '\\';
41 public String
[] getDefaultShellCommand() {
43 return new String
[] { "/bin/bash", "-l", "-i" };
45 return new String
[] { "cmd.exe", "/C" };
48 // public static long getJvmPid() {
49 // return ProcessHandle.current().pid();
50 //// String pidAndHost = ManagementFactory.getRuntimeMXBean().getName();
51 //// return Integer.parseInt(pidAndHost.substring(0, pidAndHost.indexOf('@')));
55 * Get the runtime directory. It will be the environment variable
56 * XDG_RUNTIME_DIR if it is set, or /run if the user is 'root', or
57 * ~/.cache/argeo if not.
59 public static Path
getRunDir() {
61 String xdgRunDir
= System
.getenv("XDG_RUNTIME_DIR");
62 if (xdgRunDir
!= null) {
63 // TODO support multiple names
64 runDir
= Paths
.get(xdgRunDir
);
66 String username
= System
.getProperty("user.name");
67 if (username
.equals("root")) {
68 runDir
= Paths
.get("/run");
70 Path homeDir
= Paths
.get(System
.getProperty("user.home"));
71 if (!Files
.isWritable(homeDir
)) {
72 // typically, dameon's home (/usr/sbin) is not writable
73 runDir
= Paths
.get("/tmp/" + username
+ "/run");
75 runDir
= homeDir
.resolve(".cache/argeo");