io.github.laskowski.os.DefaultOperatingSystemDiscoveryStrategy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of shell-commander Show documentation
Show all versions of shell-commander Show documentation
Library to launch .bat and .sh scripts of your choice with different configurations. Allows you to read tasks and services output from terminal
The newest version!
package io.github.laskowski.os;
public class DefaultOperatingSystemDiscoveryStrategy implements OperatingSystemDiscoveryStrategy {
private static DefaultOperatingSystemDiscoveryStrategy instance;
private static final String OPERATING_SYSTEM_NAME = System.getProperty("os.name").toLowerCase();
public static DefaultOperatingSystemDiscoveryStrategy getInstance() {
if (instance == null) {
instance = new DefaultOperatingSystemDiscoveryStrategy();
}
return instance;
}
private DefaultOperatingSystemDiscoveryStrategy() {}
@Override
public OperatingSystem getOS() {
if (OPERATING_SYSTEM_NAME.contains("win")) {
return OperatingSystem.WINDOWS;
} else if (OPERATING_SYSTEM_NAME.contains("mac")) {
return OperatingSystem.MAC;
} else if (OPERATING_SYSTEM_NAME.contains("nix") || OPERATING_SYSTEM_NAME.contains("nux") || OPERATING_SYSTEM_NAME.contains("aix")) {
return OperatingSystem.UNIX;
} else {
throw new IllegalArgumentException(String.format("Unrecognized Operating System: %s", OPERATING_SYSTEM_NAME));
}
}
}