X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Futil%2FOS.java;fp=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Futil%2FOS.java;h=c63d7a1906e3be03a7d5917c01659152906e81be;hb=54df376a9c2dd458a82eaa09bfbb718fe699dd0d;hp=0000000000000000000000000000000000000000;hpb=3c1cdc594d954520b14646102b366290bdad58c7;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/util/OS.java b/org.argeo.cms/src/org/argeo/cms/util/OS.java new file mode 100644 index 000000000..c63d7a190 --- /dev/null +++ b/org.argeo.cms/src/org/argeo/cms/util/OS.java @@ -0,0 +1,65 @@ +package org.argeo.cms.util; + +import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; + +/** When OS specific informations are needed. */ +public class OS { + public final static OS LOCAL = new OS(); + + private final String arch, name, version; + + /** The OS of the running JVM */ + protected OS() { + arch = System.getProperty("os.arch"); + name = System.getProperty("os.name"); + version = System.getProperty("os.version"); + } + + public String getArch() { + return arch; + } + + public String getName() { + return name; + } + + public String getVersion() { + return version; + } + + public boolean isMSWindows() { + // only MS Windows would use such an horrendous separator... + return File.separatorChar == '\\'; + } + + public String[] getDefaultShellCommand() { + if (!isMSWindows()) + return new String[] { "/bin/bash", "-l", "-i" }; + else + return new String[] { "cmd.exe", "/C" }; + } + + public static long getJvmPid() { + return ProcessHandle.current().pid(); +// String pidAndHost = ManagementFactory.getRuntimeMXBean().getName(); +// return Integer.parseInt(pidAndHost.substring(0, pidAndHost.indexOf('@'))); + } + + /** + * Get the runtime directory. It will be the environment variable + * XDG_RUNTIME_DIR if it is set, or ~/.cache/argeo if not. + */ + public static Path getRunDir() { + Path runDir; + String xdgRunDir = System.getenv("XDG_RUNTIME_DIR"); + if (xdgRunDir != null) { + // TODO support multiple names + runDir = Paths.get(xdgRunDir); + } else { + runDir = Paths.get(System.getProperty("user.home"), ".cache/argeo"); + } + return runDir; + } +}