This package allows you to detect the host's Operating System and CPU Architecture, perfect if you need to implement native code conditionally.
Is the host system a Linux flavor?
if (Platform.osDistribution == OSDistribution.LINUX) {
// Yes.
}
Are we running on Unix (e.g macOS or Linux) or Windows?
switch (Platform.osFamily) {
case UNIX: {
break;
}
case WINDOWS: {
break;
}
default: {
break;
}
}
What CPU Arch does the host use?
System.out.println(Platform.arch); // amd64, aarch64, etc.
Get a filename for a library:
System.out.println(Platform.formatLibrary("Webview")); // libwebview.so, Webview.dll, etc.
Well, the history of operating systems is complicated.
For example, when looking at the history of the Unix family, we see a lot of familiar faces such as Linux, BSD, and even macOS; And since these distributions are decendants of the same parent project, they have a lot in common. This potentially allows you to reuse native code between Linux and macOS.
Replace VERSION_OR_HASH
with the latest version or commit in this repo and make sure to add the Repository to your build system.
Maven
<dependency>
<groupId>co.casterlabs.commons</groupId>
<artifactId>Platform</artifactId>
<version>VERSION_OR_HASH</version>
</dependency>
Gradle
dependencies {
implementation 'co.casterlabs.commons:Platform:VERSION_OR_HASH'
}
SBT
libraryDependencies += "co.casterlabs.commons" % "Platform" % "VERSION_OR_HASH"
Leiningen
:dependencies [[co.casterlabs.commons/Platform "VERSION_OR_HASH"]]