mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-07-31 20:11:23 +00:00
Utils: Add isOpenJDKRuntime() and isJavaSERuntime() helpers.
This commit is contained in:
@@ -36,6 +36,8 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.bouncycastle.crypto.digests.RIPEMD160Digest;
|
import org.bouncycastle.crypto.digests.RIPEMD160Digest;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.google.common.base.Joiner;
|
import com.google.common.base.Joiner;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
@@ -69,6 +71,8 @@ public class Utils {
|
|||||||
|
|
||||||
private static BlockingQueue<Boolean> mockSleepQueue;
|
private static BlockingQueue<Boolean> mockSleepQueue;
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(Utils.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* The regular {@link BigInteger#toByteArray()} includes the sign bit of the number and
|
* The regular {@link BigInteger#toByteArray()} includes the sign bit of the number and
|
||||||
@@ -546,13 +550,35 @@ public class Utils {
|
|||||||
return maxItem;
|
return maxItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int isAndroid = -1;
|
private enum Runtime {
|
||||||
|
ANDROID, OPENJDK, ORACLE_JAVA
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Runtime runtime = null;
|
||||||
|
static {
|
||||||
|
String runtimeProp = System.getProperty("java.runtime.name").toLowerCase(Locale.US);
|
||||||
|
if (runtimeProp == null)
|
||||||
|
runtime = null;
|
||||||
|
else if (runtimeProp.contains("android"))
|
||||||
|
runtime = Runtime.ANDROID;
|
||||||
|
else if (runtimeProp.contains("openjdk"))
|
||||||
|
runtime = Runtime.OPENJDK;
|
||||||
|
else if (runtimeProp.contains("java(tm) se"))
|
||||||
|
runtime = Runtime.ORACLE_JAVA;
|
||||||
|
else
|
||||||
|
log.info("Unknown java.runtime.name '{}'", runtimeProp);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isAndroidRuntime() {
|
public static boolean isAndroidRuntime() {
|
||||||
if (isAndroid == -1) {
|
return runtime == Runtime.ANDROID;
|
||||||
final String runtime = System.getProperty("java.runtime.name");
|
}
|
||||||
isAndroid = (runtime != null && runtime.equals("Android Runtime")) ? 1 : 0;
|
|
||||||
}
|
public static boolean isOpenJDKRuntime() {
|
||||||
return isAndroid == 1;
|
return runtime == Runtime.OPENJDK;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isOracleJavaRuntime() {
|
||||||
|
return runtime == Runtime.ORACLE_JAVA;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isLinux() {
|
public static boolean isLinux() {
|
||||||
|
@@ -112,4 +112,11 @@ public class UtilsTest {
|
|||||||
byte[] actual = Utils.bigIntegerToBytes(b, 1);
|
byte[] actual = Utils.bigIntegerToBytes(b, 1);
|
||||||
assertTrue(Arrays.equals(expected, actual));
|
assertTrue(Arrays.equals(expected, actual));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void runtime() {
|
||||||
|
// This test assumes it is run within a Java runtime for desktop computers.
|
||||||
|
assertTrue(Utils.isOpenJDKRuntime() || Utils.isOracleJavaRuntime());
|
||||||
|
assertFalse(Utils.isAndroidRuntime());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user