tisonkun / os-detector

Detect OS/Platform information for Java program.
Apache License 2.0
3 stars 1 forks source link

OS Detector

Maven Central

A detector for the OS name and architecture. It provides a uniform classifier to be used in the names of native artifacts.

This repository is an effort to provide functionalities the same as os-maven-plugin, but as a standalone artifact. It also redistributes the Maven plugin as well as the Gradle plugin (developed by Google) based on such a core lib to ensure the manner is the same.

I'm seeking for merging these three efforts into one. Check this issue for more information.

Currently, I'm actively maintaining this repository (lib, plugin-maven and plugin-gradle) for publicly testing, as well as bugfixes + improvements. You can use it as a production-ready solution since the original logics are battle-tested over the years.

Programmable

OS detector is provided as a normal module.

You can use it with Maven:

 <dependency>
    <groupId>com.tisonkun.os</groupId>
    <artifactId>os-detector-core</artifactId>
    <version>${os-detector.version}</version>
</dependency>

... or Gradle:

implementation("com.tisonkun.os:os-detector-core:$osDetectorVersion")

The common usage is:

public static void main(String[] args) {
    final Detector detector = new Detector(/* ... */);
    final Detected detected = detector.detect();
}

... where the Detected structure is defined as:

public class Detected {
    public final int bitness;
    public final String version;
    public final String classifier;
    public final OS os;
    public final Arch arch;
    @Nullable
    public final LinuxRelease linuxRelease;
}

Maven Extension

You can use OS detector as a Maven extension:

<build>
    <extensions>
        <extension>
            <groupId>com.tisonkun.os</groupId>
            <artifactId>os-detector-maven-plugin</artifactId>
            <version>${os-detector.version}</version>
        </extension>
    </extensions>
</build>

Gradle Plugin

You can use OS detector as a Gradle plugin:

plugins {
  id "com.tisonkun.osdetector" version "$osDetectorVersion"
}

The plugin creates osdetector extension in your project, through which you can access the following attributes: