diff --git a/pom.xml b/pom.xml index 5e341e1..48c41ce 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.psnrigner discord-rpc-java - 1.0.4 + 1.0.5 jar @@ -55,12 +55,6 @@ - - - commons-lang - commons-lang - 2.6 - diff --git a/src/main/java/com/github/psnrigner/discordrpcjava/impl/BaseConnection.java b/src/main/java/com/github/psnrigner/discordrpcjava/impl/BaseConnection.java index 3c4cfb4..f93f56f 100644 --- a/src/main/java/com/github/psnrigner/discordrpcjava/impl/BaseConnection.java +++ b/src/main/java/com/github/psnrigner/discordrpcjava/impl/BaseConnection.java @@ -1,6 +1,7 @@ package com.github.psnrigner.discordrpcjava.impl; -import org.apache.commons.lang.SystemUtils; + +import com.github.psnrigner.discordrpcjava.util.SystemUtils; /** * Base connection class @@ -15,16 +16,17 @@ public abstract class BaseConnection static BaseConnection create() { - if (SystemUtils.IS_OS_MAC_OSX) - return new BaseConnectionOsx(); - - if (SystemUtils.IS_OS_UNIX) - return new BaseConnectionUnix(); - - if (SystemUtils.IS_OS_WINDOWS) - return new BaseConnectionWindows(); - - throw new IllegalStateException("This OS is not supported"); + switch (SystemUtils.getOs()) { + case WINDOWS: + return new BaseConnectionWindows(); + case MAC_OSX: + return new BaseConnectionOsx(); + case UNIX: + return new BaseConnectionUnix(); + case UNKNOWN: + break; // throw error below + } + throw new IllegalStateException("OS is not supported: " + SystemUtils.getOsName()); } static void destroy(BaseConnection baseConnection) diff --git a/src/main/java/com/github/psnrigner/discordrpcjava/util/SystemUtils.java b/src/main/java/com/github/psnrigner/discordrpcjava/util/SystemUtils.java new file mode 100644 index 0000000..da51422 --- /dev/null +++ b/src/main/java/com/github/psnrigner/discordrpcjava/util/SystemUtils.java @@ -0,0 +1,50 @@ +package com.github.psnrigner.discordrpcjava.util; + +public class SystemUtils +{ + public static OS getOs() { + return OS.byOsName(getOsName()); + } + + public static String getOsName() { + return System.getProperty("os.name"); + } + + public enum OS { + WINDOWS(new String[]{"Windows"}), + MAC_OSX(new String[]{"Mac"}), + UNIX(new String[]{"Linux", "LINUX", "AIX", "HP-UX", "Trix", "OS/2", "Solaris", "SunOS"}), // feel free to add + UNKNOWN; + + private String[] osNames; + + OS() + { + } + + OS(String[] osNames) + { + this.osNames = osNames; + } + + + public String[] getOsNames() + { + return osNames; + } + + public static OS byOsName(String osName) + { + for(OS os: OS.values()) { + for(String name : os.getOsNames()) + { + if(osName.startsWith(name)) + { + return os; + } + } + } + return UNKNOWN; + } + } +}