diff --git a/client/pom.xml b/client/pom.xml index 807ab5d71..1a3d0e15e 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -52,6 +52,11 @@ + + com.taobao.arthas + arthas-common + ${project.version} + com.alibaba.middleware cli diff --git a/client/src/main/java/com/taobao/arthas/client/OSUtils.java b/client/src/main/java/com/taobao/arthas/client/OSUtils.java deleted file mode 100644 index 93724e175..000000000 --- a/client/src/main/java/com/taobao/arthas/client/OSUtils.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.taobao.arthas.client; - -public class OSUtils { - - public static boolean isWindowsOS() { - boolean isWindowsOS = false; - String osName = System.getProperty("os.name"); - if (osName.toLowerCase().indexOf("windows") > -1) { - isWindowsOS = true; - } - return isWindowsOS; - } -} diff --git a/client/src/main/java/com/taobao/arthas/client/TelnetConsole.java b/client/src/main/java/com/taobao/arthas/client/TelnetConsole.java index 74461d99b..958c88b38 100644 --- a/client/src/main/java/com/taobao/arthas/client/TelnetConsole.java +++ b/client/src/main/java/com/taobao/arthas/client/TelnetConsole.java @@ -17,6 +17,7 @@ import org.apache.commons.net.telnet.TelnetClient; import org.apache.commons.net.telnet.TelnetOptionHandler; import org.apache.commons.net.telnet.WindowSizeOptionHandler; +import com.taobao.arthas.common.OSUtils; import com.taobao.middleware.cli.CLI; import com.taobao.middleware.cli.CommandLine; import com.taobao.middleware.cli.UsageMessageFormatter; @@ -152,11 +153,8 @@ public class TelnetConsole { public static void main(String[] args) throws IOException { // support mingw/cygw jline color - if (System.getProperty("os.name").startsWith("Windows")) { - if ((System.getenv("MSYSTEM") != null && System.getenv("MSYSTEM").startsWith("MINGW")) - || "/bin/shell".equals(System.getenv("SHELL"))) { - System.setProperty("jline.terminal", System.getProperty("jline.terminal", "jline.UnixTerminal")); - } + if (OSUtils.isCygwinOrMinGW()) { + System.setProperty("jline.terminal", System.getProperty("jline.terminal", "jline.UnixTerminal")); } TelnetConsole telnetConsole = new TelnetConsole(); @@ -220,7 +218,7 @@ public class TelnetConsole { } else { width = terminal.getWidth(); // hack for windows dos - if (OSUtils.isWindowsOS()) { + if (OSUtils.isWindows()) { width--; } } diff --git a/common/src/main/java/com/taobao/arthas/common/OSUtils.java b/common/src/main/java/com/taobao/arthas/common/OSUtils.java index c5fe3c85b..d2849b89e 100644 --- a/common/src/main/java/com/taobao/arthas/common/OSUtils.java +++ b/common/src/main/java/com/taobao/arthas/common/OSUtils.java @@ -1,22 +1,24 @@ package com.taobao.arthas.common; +import java.util.Locale; + /** * * @author hengyunabc 2018-11-08 * */ public class OSUtils { + private static final String OPERATING_SYSTEM_NAME = System.getProperty("os.name").toLowerCase(Locale.ENGLISH); static PlatformEnum platform; static { - String osName = System.getProperty("os.name"); - if (osName.startsWith("Linux")) { + if (OPERATING_SYSTEM_NAME.startsWith("Linux")) { platform = PlatformEnum.LINUX; - } else if (osName.startsWith("Mac") || osName.startsWith("Darwin")) { + } else if (OPERATING_SYSTEM_NAME.startsWith("Mac") || OPERATING_SYSTEM_NAME.startsWith("Darwin")) { platform = PlatformEnum.MACOSX; - } else if (osName.startsWith("Mac") || osName.startsWith("Darwin")) { + } else if (OPERATING_SYSTEM_NAME.startsWith("Mac") || OPERATING_SYSTEM_NAME.startsWith("Darwin")) { platform = PlatformEnum.MACOSX; - } else if (osName.startsWith("Windows")) { + } else if (OPERATING_SYSTEM_NAME.startsWith("Windows")) { platform = PlatformEnum.WINDOWS; } else { platform = PlatformEnum.UNKNOWN; @@ -35,4 +37,14 @@ public class OSUtils { return platform == PlatformEnum.MACOSX; } + public static boolean isCygwinOrMinGW() { + if (isWindows()) { + if ((System.getenv("MSYSTEM") != null && System.getenv("MSYSTEM").startsWith("MINGW")) + || "/bin/shell".equals(System.getenv("SHELL"))) { + return true; + } + } + return false; + } + }