summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-01-23 09:18:07 +0100
committerSven Gothel <[email protected]>2023-01-23 09:18:07 +0100
commit0dc88144a9c6caa45fa5a604b6d59a158f7ac49e (patch)
tree5bdefa74f4a56786002475a1a852e3f834ad5037 /src
parenta8e998a0d8fbe5f4e17f074a1aa669413c6651d3 (diff)
Add OSType and Platform, providing certain OS and architecture properties of the runtime host platform
Diffstat (limited to 'src')
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/OSType.java5
-rw-r--r--src/main/java/net/sf/antcontrib/cpptasks/Platform.java70
2 files changed, 75 insertions, 0 deletions
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/OSType.java b/src/main/java/net/sf/antcontrib/cpptasks/OSType.java
new file mode 100644
index 0000000..b25644a
--- /dev/null
+++ b/src/main/java/net/sf/antcontrib/cpptasks/OSType.java
@@ -0,0 +1,5 @@
+package net.sf.antcontrib.cpptasks;
+
+public enum OSType {
+ LINUX, FREEBSD, ANDROID, MACOS, SUNOS, HPUX, WINDOWS, OPENKODE, IOS;
+}
diff --git a/src/main/java/net/sf/antcontrib/cpptasks/Platform.java b/src/main/java/net/sf/antcontrib/cpptasks/Platform.java
new file mode 100644
index 0000000..fd8ce22
--- /dev/null
+++ b/src/main/java/net/sf/antcontrib/cpptasks/Platform.java
@@ -0,0 +1,70 @@
+package net.sf.antcontrib.cpptasks;
+
+/**
+ * Platform provides certain OS and architecture properties of the runtime host platform.
+ */
+public class Platform {
+ /**
+ * The architecture name, , i.e. Java's `os.arch` property.
+ */
+ public static final String OS_ARCH;
+
+ /**
+ * The OS name, , i.e. Java's `os.name` property.
+ * <p>In case of {@link OSType#ANDROID}, see {@link #OS_TYPE}, the OS name is Linux</p>
+ */
+ public static final String OS_NAME;
+
+ /**
+ * The OS version string, i.e. Java's `os.version` property.
+ */
+ public static final String OS_VERSION;
+
+ /**
+ * The OS type, derived from {@link #OS_NAME}
+ * <p>In case of {@link OSType#ANDROID} the {@link #getOSName() OS name}, is Linux</p>
+ */
+ public static final OSType OS_TYPE;
+
+ static {
+ OS_ARCH = System.getProperty("os.arch");
+ OS_NAME = System.getProperty("os.name");
+ OS_VERSION = System.getProperty("os.version");
+ OS_TYPE = getOSTypeImpl(OS_NAME.toLowerCase(), false /* isAndroid */);
+ }
+
+ private static final OSType getOSTypeImpl(final String osLower, final boolean isAndroid) throws RuntimeException {
+ if ( isAndroid ) {
+ return OSType.ANDROID;
+ }
+ if ( osLower.startsWith("linux") ) {
+ return OSType.LINUX;
+ }
+ if ( osLower.startsWith("freebsd") ) {
+ return OSType.FREEBSD;
+ }
+ if ( osLower.startsWith("android") ) {
+ return OSType.ANDROID;
+ }
+ if ( osLower.startsWith("mac os x") ||
+ osLower.startsWith("darwin") ) {
+ return OSType.MACOS;
+ }
+ if ( osLower.startsWith("sunos") ) {
+ return OSType.SUNOS;
+ }
+ if ( osLower.startsWith("hp-ux") ) {
+ return OSType.HPUX;
+ }
+ if ( osLower.startsWith("windows") ) {
+ return OSType.WINDOWS;
+ }
+ if ( osLower.startsWith("kd") ) {
+ return OSType.OPENKODE;
+ }
+ if ( osLower.startsWith("ios") ) {
+ return OSType.IOS;
+ }
+ throw new RuntimeException("Please port OS detection to your platform (" + OS_NAME + ")");
+ }
+}