From: Mathieu Baudier Date: Sun, 8 Sep 2019 04:40:37 +0000 (+0200) Subject: Move OS to a dedicated package. X-Git-Tag: argeo-commons-2.1.79~17 X-Git-Url: https://git.argeo.org/?p=lgpl%2Fargeo-commons.git;a=commitdiff_plain;h=0d46a59c2e2a704b617c1a665fa5155bd4e40682 Move OS to a dedicated package. --- diff --git a/org.argeo.core/src/org/argeo/ssh/SimpleSshServer.java b/org.argeo.core/src/org/argeo/ssh/SimpleSshServer.java index 801384513..c1f90efe9 100644 --- a/org.argeo.core/src/org/argeo/ssh/SimpleSshServer.java +++ b/org.argeo.core/src/org/argeo/ssh/SimpleSshServer.java @@ -8,7 +8,7 @@ import org.apache.sshd.server.SshServer; import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; import org.apache.sshd.server.scp.ScpCommandFactory; import org.apache.sshd.server.shell.ProcessShellFactory; -import org.argeo.util.OS; +import org.argeo.util.os.OS; /** A simple SSH server with some defaults. Supports SCP. */ public class SimpleSshServer { diff --git a/org.argeo.util/src/org/argeo/util/OS.java b/org.argeo.util/src/org/argeo/util/OS.java deleted file mode 100644 index d8127b600..000000000 --- a/org.argeo.util/src/org/argeo/util/OS.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.argeo.util; - -import java.io.File; -import java.lang.management.ManagementFactory; - -/** 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/sh", "-l", "-i" }; - else - return new String[] { "cmd.exe", "/C" }; - } - - public static Integer getJvmPid() { - /* - * This method works on most platforms (including Linux). Although when Java 9 - * comes along, there is a better way: long pid = - * ProcessHandle.current().getPid(); - * - * See: - * http://stackoverflow.com/questions/35842/how-can-a-java-program-get-its-own- - * process-id - */ - String pidAndHost = ManagementFactory.getRuntimeMXBean().getName(); - return Integer.parseInt(pidAndHost.substring(0, pidAndHost.indexOf('@'))); - } -} diff --git a/org.argeo.util/src/org/argeo/util/os/OS.java b/org.argeo.util/src/org/argeo/util/os/OS.java new file mode 100644 index 000000000..246f7449b --- /dev/null +++ b/org.argeo.util/src/org/argeo/util/os/OS.java @@ -0,0 +1,56 @@ +package org.argeo.util.os; + +import java.io.File; +import java.lang.management.ManagementFactory; + +/** 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/sh", "-l", "-i" }; + else + return new String[] { "cmd.exe", "/C" }; + } + + public static Integer getJvmPid() { + /* + * This method works on most platforms (including Linux). Although when Java 9 + * comes along, there is a better way: long pid = + * ProcessHandle.current().getPid(); + * + * See: + * http://stackoverflow.com/questions/35842/how-can-a-java-program-get-its-own- + * process-id + */ + String pidAndHost = ManagementFactory.getRuntimeMXBean().getName(); + return Integer.parseInt(pidAndHost.substring(0, pidAndHost.indexOf('@'))); + } +}