merge two OSUtils

This commit is contained in:
hengyunabc committed 2018-11-09 16:09:23 +08:00
1 parent 551432da0a
commit 0ae53869be
4 files changed
+26 -24

No files matched your search

+5
View File
@@ -52,6 +52,11 @@
</build> </build>
<dependencies> <dependencies>
<dependency>
<groupId>com.taobao.arthas</groupId>
<artifactId>arthas-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency> <dependency>
<groupId>com.alibaba.middleware</groupId> <groupId>com.alibaba.middleware</groupId>
<artifactId>cli</artifactId> <artifactId>cli</artifactId>
@@ -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;
}
}
@@ -17,6 +17,7 @@ import org.apache.commons.net.telnet.TelnetClient;
import org.apache.commons.net.telnet.TelnetOptionHandler; import org.apache.commons.net.telnet.TelnetOptionHandler;
import org.apache.commons.net.telnet.WindowSizeOptionHandler; import org.apache.commons.net.telnet.WindowSizeOptionHandler;
import com.taobao.arthas.common.OSUtils;
import com.taobao.middleware.cli.CLI; import com.taobao.middleware.cli.CLI;
import com.taobao.middleware.cli.CommandLine; import com.taobao.middleware.cli.CommandLine;
import com.taobao.middleware.cli.UsageMessageFormatter; import com.taobao.middleware.cli.UsageMessageFormatter;
@@ -152,11 +153,8 @@ public class TelnetConsole {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
// support mingw/cygw jline color // support mingw/cygw jline color
if (System.getProperty("os.name").startsWith("Windows")) { if (OSUtils.isCygwinOrMinGW()) {
if ((System.getenv("MSYSTEM") != null && System.getenv("MSYSTEM").startsWith("MINGW")) System.setProperty("jline.terminal", System.getProperty("jline.terminal", "jline.UnixTerminal"));
|| "/bin/shell".equals(System.getenv("SHELL"))) {
System.setProperty("jline.terminal", System.getProperty("jline.terminal", "jline.UnixTerminal"));
}
} }
TelnetConsole telnetConsole = new TelnetConsole(); TelnetConsole telnetConsole = new TelnetConsole();
@@ -220,7 +218,7 @@ public class TelnetConsole {
} else { } else {
width = terminal.getWidth(); width = terminal.getWidth();
// hack for windows dos // hack for windows dos
if (OSUtils.isWindowsOS()) { if (OSUtils.isWindows()) {
width--; width--;
} }
} }
@@ -1,22 +1,24 @@
package com.taobao.arthas.common; package com.taobao.arthas.common;
import java.util.Locale;
/** /**
* *
* @author hengyunabc 2018-11-08 * @author hengyunabc 2018-11-08
* *
*/ */
public class OSUtils { public class OSUtils {
private static final String OPERATING_SYSTEM_NAME = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
static PlatformEnum platform; static PlatformEnum platform;
static { static {
String osName = System.getProperty("os.name"); if (OPERATING_SYSTEM_NAME.startsWith("Linux")) {
if (osName.startsWith("Linux")) {
platform = PlatformEnum.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; 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; platform = PlatformEnum.MACOSX;
} else if (osName.startsWith("Windows")) { } else if (OPERATING_SYSTEM_NAME.startsWith("Windows")) {
platform = PlatformEnum.WINDOWS; platform = PlatformEnum.WINDOWS;
} else { } else {
platform = PlatformEnum.UNKNOWN; platform = PlatformEnum.UNKNOWN;
@@ -35,4 +37,14 @@ public class OSUtils {
return platform == PlatformEnum.MACOSX; 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;
}
} }