Last active
July 13, 2023 20:38
-
-
Save mikaelhg/40a71b1e0c2d7a34a81c4f049364fe76 to your computer and use it in GitHub Desktop.
Kotlin utility class for easily fetching standard system props
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.mikael | |
import java.time.LocalDate | |
object SystemProperties { | |
operator fun get(key: String): String? = System.getProperty(key) | |
fun get(key: String, default: String): String = get(key) ?: default | |
fun get(key: String, supplier: Supplier<String>): String = get(key) ?: supplier.get() | |
/** | |
* Character that separates components of a file path. | |
* This is "/" on UNIX and "\" on Windows. | |
*/ | |
val fileSeparator: String? | |
get() = get("file.separator") | |
/** | |
* Sequence used by operating system to separate lines in text files | |
*/ | |
val lineSeparator: String? | |
get() = get("line.separator") | |
/** | |
* Path separator character used in `java.class.path` | |
*/ | |
val pathSeparator: String? | |
get() = get("path.separator") | |
/** | |
* Path used to find directories and JAR archives containing class files. | |
* Elements of the class path are separated by a platform-specific character | |
* specified in the `path.separator` property. | |
*/ | |
val javaClassPath: String? | |
get() = get("java.class.path") | |
/** | |
* Java class format version number | |
*/ | |
val javaClassVersion: String? | |
get() = get("java.class.version") | |
val javaLibraryPath: String? | |
get() = get("java.library.path") | |
val javaTemporaryDirectory: String? | |
get() = get("java.io.tmpdir") | |
val javaCompiler: String? | |
get() = get("java.compiler") | |
/** | |
* Installation directory for Java Runtime Environment (JRE) | |
*/ | |
val javaHome: String? | |
get() = get("java.home") | |
val javaVendor: String? | |
get() = get("java.vendor") | |
val javaVendorUrl: String? | |
get() = get("java.vendor.url") | |
val javaVersion: String? | |
get() = get("java.version") | |
val javaVersionDate: LocalDate? | |
get() = get("java.version.date")?.let(LocalDate::parse) | |
val javaVmSpecificationVersion: String? | |
get() = get("java.vm.specification.version") | |
val javaVmSpecificationVendor: String? | |
get() = get("java.vm.specification.vendor") | |
val javaVmSpecificationName: String? | |
get() = get("java.vm.specification.name") | |
val javaVmVersion: String? | |
get() = get("java.vm.specification.version") | |
val javaVmVendor: String? | |
get() = get("java.vm.specification.vendor") | |
val javaVmName: String? | |
get() = get("java.vm.specification.name") | |
val javaSpecificationVersion: String? | |
get() = get("java.specification.version") | |
val javaSpecificationMaintenanceVersion: String? | |
get() = get("java.specification.maintenance.version") | |
val javaSpecificationVendor: String? | |
get() = get("java.specification.vendor") | |
val javaSpecificationName: String? | |
get() = get("java.specification.name") | |
val osArchitecture: String? | |
get() = get("os.arch") | |
val osName: String? | |
get() = get("os.name") | |
val osVersion: String? | |
get() = get("os.version") | |
val userDir: String? | |
get() = get("user.dir") | |
val userHome: String? | |
get() = get("user.home") | |
val userName: String? | |
get() = get("user.name") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment