Changeset 04a985cd


Ignore:
Timestamp:
May 12, 2019 8:20:13 PM (18 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

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/src/net/i2p/router/update/NewsFetcher.java

    radb1c6f r04a985cd  
    265265                            String minJava = args.get(MIN_JAVA_VERSION_KEY);
    266266                            if (minJava != null) {
    267                                 String ourJava = System.getProperty("java.version");
    268                                 if (VersionComparator.comp(ourJava, minJava) < 0) {
     267                                if (!SystemVersion.isJava(minJava)) {
     268                                    String ourJava = System.getProperty("java.version");
    269269                                    String msg = _mgr._t("Requires Java version {0} but installed Java version is {1}", minJava, ourJava);
    270270                                    _log.logAlways(Log.WARN, "Cannot update to version " + ver + ": " + msg);
  • apps/routerconsole/java/src/net/i2p/router/update/PluginUpdateRunner.java

    radb1c6f r04a985cd  
    410410
    411411            minVersion = PluginStarter.stripHTML(props, "min-java-version");
    412             if (minVersion != null &&
    413                 VersionComparator.comp(System.getProperty("java.version"), minVersion) < 0) {
     412            if (minVersion != null && !SystemVersion.isJava(minVersion)) {
    414413                to.delete();
    415414                statusDone("<b>" + _t("This plugin requires Java version {0} or higher", minVersion) + "</b>");
  • apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java

    radb1c6f r04a985cd  
    359359
    360360        minVersion = stripHTML(props, "min-java-version");
    361         if (minVersion != null &&
    362             VersionComparator.comp(System.getProperty("java.version"), minVersion) < 0) {
     361        if (minVersion != null && !SystemVersion.isJava(minVersion)) {
    363362            String foo = "Plugin " + appName + " requires Java version " + minVersion + " or higher";
    364363            log.error(foo);
  • apps/routerconsole/java/src/net/i2p/router/web/RouterConsoleRunner.java

    radb1c6f r04a985cd  
    341341    /** @since 0.9.17 */
    342342    private void checkJavaVersion() {
    343         boolean noJava7 = !SystemVersion.isJava7();
     343        boolean noJava8 = !SystemVersion.isJava8();
    344344        boolean noPack200 = (PluginStarter.pluginsEnabled(_context) || !NewsHelper.isUpdateDisabled(_context)) &&
    345345                            !FileUtil.isPack200Supported();
     
    347347        boolean isZero = SystemVersion.isZeroVM();
    348348        boolean isJava11 = false; // SystemVersion.isJava11();
    349         if (noJava7 || noPack200 || openARM || isZero || isJava11) {
     349        if (noJava8 || noPack200 || openARM || isZero || isJava11) {
    350350            String s = "Java version: " + System.getProperty("java.version") +
    351351                       " OS: " + System.getProperty("os.name") + ' ' +
     
    355355            log.logAlways(net.i2p.util.Log.WARN, s);
    356356            System.out.println("Warning: " + s);
    357             if (noJava7) {
    358                 s = "Java 7 is now required, please upgrade";
     357            if (noJava8) {
     358                s = "Java 8 or higher will be required in a future release, please upgrade Java";
    359359                log.logAlways(net.i2p.util.Log.WARN, s);
    360360                System.out.println("Warning: " + s);
  • 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.