forked from I2P_Developers/i2p.i2p
Consolidate Java version checking code, fix bugs
where versions are in different forms Add warning about Java 7
This commit is contained in:
@ -264,8 +264,8 @@ class NewsFetcher extends UpdateRunner {
|
||||
}
|
||||
String minJava = args.get(MIN_JAVA_VERSION_KEY);
|
||||
if (minJava != null) {
|
||||
if (!SystemVersion.isJava(minJava)) {
|
||||
String ourJava = System.getProperty("java.version");
|
||||
if (VersionComparator.comp(ourJava, minJava) < 0) {
|
||||
String msg = _mgr._t("Requires Java version {0} but installed Java version is {1}", minJava, ourJava);
|
||||
_log.logAlways(Log.WARN, "Cannot update to version " + ver + ": " + msg);
|
||||
_mgr.notifyVersionConstraint(this, _currentURI, ROUTER_SIGNED, "", ver, msg);
|
||||
|
@ -409,8 +409,7 @@ class PluginUpdateRunner extends UpdateRunner {
|
||||
}
|
||||
|
||||
minVersion = PluginStarter.stripHTML(props, "min-java-version");
|
||||
if (minVersion != null &&
|
||||
VersionComparator.comp(System.getProperty("java.version"), minVersion) < 0) {
|
||||
if (minVersion != null && !SystemVersion.isJava(minVersion)) {
|
||||
to.delete();
|
||||
statusDone("<b>" + _t("This plugin requires Java version {0} or higher", minVersion) + "</b>");
|
||||
return;
|
||||
|
@ -358,8 +358,7 @@ public class PluginStarter implements Runnable {
|
||||
}
|
||||
|
||||
minVersion = stripHTML(props, "min-java-version");
|
||||
if (minVersion != null &&
|
||||
VersionComparator.comp(System.getProperty("java.version"), minVersion) < 0) {
|
||||
if (minVersion != null && !SystemVersion.isJava(minVersion)) {
|
||||
String foo = "Plugin " + appName + " requires Java version " + minVersion + " or higher";
|
||||
log.error(foo);
|
||||
disablePlugin(appName);
|
||||
|
@ -340,13 +340,13 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
|
||||
/** @since 0.9.17 */
|
||||
private void checkJavaVersion() {
|
||||
boolean noJava7 = !SystemVersion.isJava7();
|
||||
boolean noJava8 = !SystemVersion.isJava8();
|
||||
boolean noPack200 = (PluginStarter.pluginsEnabled(_context) || !NewsHelper.isUpdateDisabled(_context)) &&
|
||||
!FileUtil.isPack200Supported();
|
||||
boolean openARM = SystemVersion.isARM() && SystemVersion.isOpenJDK() && !SystemVersion.isJava9();
|
||||
boolean isZero = SystemVersion.isZeroVM();
|
||||
boolean isJava11 = false; // SystemVersion.isJava11();
|
||||
if (noJava7 || noPack200 || openARM || isZero || isJava11) {
|
||||
if (noJava8 || noPack200 || openARM || isZero || isJava11) {
|
||||
String s = "Java version: " + System.getProperty("java.version") +
|
||||
" OS: " + System.getProperty("os.name") + ' ' +
|
||||
System.getProperty("os.arch") + ' ' +
|
||||
@ -354,8 +354,8 @@ public class RouterConsoleRunner implements RouterApp {
|
||||
net.i2p.util.Log log = _context.logManager().getLog(RouterConsoleRunner.class);
|
||||
log.logAlways(net.i2p.util.Log.WARN, s);
|
||||
System.out.println("Warning: " + s);
|
||||
if (noJava7) {
|
||||
s = "Java 7 is now required, please upgrade";
|
||||
if (noJava8) {
|
||||
s = "Java 8 or higher will be required in a future release, please upgrade Java";
|
||||
log.logAlways(net.i2p.util.Log.WARN, s);
|
||||
System.out.println("Warning: " + s);
|
||||
}
|
||||
|
@ -243,6 +243,40 @@ public abstract class SystemVersion {
|
||||
return _oneDotEleven;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles Android also
|
||||
*
|
||||
* @param minVersion e.g. 11
|
||||
* @return true if greater than or equal to minVersion
|
||||
* @since 0.9.41
|
||||
*/
|
||||
public static boolean isJava(int minVersion) {
|
||||
return isJava("1." + minVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles Android, and minVersions in both forms (e.g. 11 or 1.11)
|
||||
*
|
||||
* @param minVersion either 1.x or x form works
|
||||
* @return true if greater than or equal to minVersion
|
||||
* @since 0.9.41
|
||||
*/
|
||||
public static boolean isJava(String minVersion) {
|
||||
String version = System.getProperty("java.version");
|
||||
if (!version.startsWith("1."))
|
||||
version = "1." + version;
|
||||
if (!minVersion.startsWith("1."))
|
||||
minVersion = "1." + minVersion;
|
||||
if (_isAndroid) {
|
||||
if (minVersion.startsWith("1.6"))
|
||||
return _oneDotSix;
|
||||
if (minVersion.startsWith("1.7"))
|
||||
return _oneDotSeven;
|
||||
return false;
|
||||
}
|
||||
return VersionComparator.comp(version, minVersion) >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* This isn't always correct.
|
||||
* http://stackoverflow.com/questions/807263/how-do-i-detect-which-kind-of-jre-is-installed-32bit-vs-64bit
|
||||
@ -342,6 +376,7 @@ public abstract class SystemVersion {
|
||||
System.out.println("Java 9 : " + isJava9());
|
||||
System.out.println("Java 10 : " + isJava10());
|
||||
System.out.println("Java 11 : " + isJava11());
|
||||
System.out.println("Java 12 : " + isJava(12));
|
||||
System.out.println("Android : " + isAndroid());
|
||||
if (isAndroid())
|
||||
System.out.println(" Version: " + getAndroidVersion());
|
||||
|
Reference in New Issue
Block a user