Changeset 04a985cd for core


Ignore:
Timestamp:
May 12, 2019 8:20:13 PM (13 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
e174a46
Parents:
adb1c6f
Message:

Consolidate Java version checking code, fix bugs
where versions are in different forms
Add warning about Java 7

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/util/SystemVersion.java

    radb1c6f r04a985cd  
    245245
    246246    /**
     247     *  Handles Android also
     248     *
     249     *  @param minVersion e.g. 11
     250     *  @return true if greater than or equal to minVersion
     251     *  @since 0.9.41
     252     */
     253    public static boolean isJava(int minVersion) {
     254        return isJava("1." + minVersion);
     255    }
     256
     257    /**
     258     *  Handles Android, and minVersions in both forms (e.g. 11 or 1.11)
     259     *
     260     *  @param minVersion either 1.x or x form works
     261     *  @return true if greater than or equal to minVersion
     262     *  @since 0.9.41
     263     */
     264    public static boolean isJava(String minVersion) {
     265        String version = System.getProperty("java.version");
     266        if (!version.startsWith("1."))
     267            version = "1." + version;
     268        if (!minVersion.startsWith("1."))
     269            minVersion = "1." + minVersion;
     270        if (_isAndroid) {
     271            if (minVersion.startsWith("1.6"))
     272                return _oneDotSix;
     273            if (minVersion.startsWith("1.7"))
     274                return _oneDotSeven;
     275            return false;
     276        }
     277        return VersionComparator.comp(version, minVersion) >= 0;
     278    }
     279
     280    /**
    247281     * This isn't always correct.
    248282     * http://stackoverflow.com/questions/807263/how-do-i-detect-which-kind-of-jre-is-installed-32bit-vs-64bit
     
    343377        System.out.println("Java 10  : " + isJava10());
    344378        System.out.println("Java 11  : " + isJava11());
     379        System.out.println("Java 12  : " + isJava(12));
    345380        System.out.println("Android  : " + isAndroid());
    346381        if (isAndroid())
Note: See TracChangeset for help on using the changeset viewer.