mirror of
https://github.com/alibaba/arthas.git
synced 2024-04-21 10:21:39 +00:00
merge two OSUtils
This commit is contained in:
@@ -52,6 +52,11 @@
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.taobao.arthas</groupId>
|
||||
<artifactId>arthas-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.middleware</groupId>
|
||||
<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.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--;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user