Ignore:
Timestamp:
2024-06-13T00:23:03+02:00 (5 months ago)
Author:
taylor.smock
Message:

Cleanup some new PMD warnings from PMD 7.x (followup of r19101)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java

    r18985 r19103  
    22package org.openstreetmap.josm.tools;
    33
     4import static org.openstreetmap.josm.tools.I18n.marktr;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    56import static org.openstreetmap.josm.tools.Utils.getSystemEnv;
     
    78
    89import java.awt.Desktop;
     10import java.awt.event.InputEvent;
    911import java.awt.event.KeyEvent;
    1012import java.io.BufferedReader;
     
    2931import java.util.Set;
    3032import java.util.concurrent.ExecutionException;
     33import java.util.regex.Matcher;
     34import java.util.regex.Pattern;
    3135
    3236import org.openstreetmap.josm.data.Preferences;
     
    5155        // See #12022, #16666 - Disable GNOME ATK Java wrapper as it causes a lot of serious trouble
    5256        if (isDebianOrUbuntu()) {
    53             if (Utils.getJavaVersion() >= 9) {
    54                 // TODO: find a way to disable ATK wrapper on Java >= 9
    55                 // We should probably be able to do that by embedding a no-op AccessibilityProvider in our jar
    56                 // so that it is loaded by ServiceLoader without error
    57                 // But this require to compile at least one class with Java 9
    58             } else {
    59                 // Java 8 does a simple Class.newInstance() from system classloader
    60                 Utils.updateSystemProperty("javax.accessibility.assistive_technologies", "java.lang.Object");
    61             }
    62         }
    63     }
    64 
    65     @Override
    66     public void startupHook(JavaExpirationCallback javaCallback, WebStartMigrationCallback webStartCallback,
    67             SanityCheckCallback sanityCheckCallback) {
    68         checkWebStartMigration(webStartCallback);
    69         PlatformHook.super.startupHook(javaCallback, webStartCallback, sanityCheckCallback);
     57            // TODO: find a way to disable ATK wrapper on Java >= 9
     58            // We should probably be able to do that by embedding a no-op AccessibilityProvider in our jar
     59            // so that it is loaded by ServiceLoader without error
     60            // But this require to compile at least one class with Java 9
     61        }
     62    }
     63
     64    @Override
     65    public void startupHook(JavaExpirationCallback javaCallback, SanityCheckCallback sanityCheckCallback) {
     66        PlatformHook.super.startupHook(javaCallback, sanityCheckCallback);
    7067    }
    7168
     
    9188
    9289    @Override
     90    @SuppressWarnings("squid:S103") // NOSONAR LineLength
    9391    public void initSystemShortcuts() {
     92        final String reserved = marktr("reserved");
    9493        // CHECKSTYLE.OFF: LineLength
    9594        // TODO: Insert system shortcuts here. See Windows and especially OSX to see how to.
    9695        for (int i = KeyEvent.VK_F1; i <= KeyEvent.VK_F12; ++i) {
    97             Shortcut.registerSystemShortcut("screen:toogle"+i, tr("reserved"), i, KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK)
     96            Shortcut.registerSystemShortcut("screen:toggle"+i, tr(reserved), i, InputEvent.CTRL_DOWN_MASK | InputEvent.ALT_DOWN_MASK)
    9897                .setAutomatic();
    9998        }
    100         Shortcut.registerSystemShortcut("system:reset", tr("reserved"), KeyEvent.VK_DELETE, KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK)
     99        Shortcut.registerSystemShortcut("system:reset", tr(reserved), KeyEvent.VK_DELETE, InputEvent.CTRL_DOWN_MASK | InputEvent.ALT_DOWN_MASK)
    101100            .setAutomatic();
    102         Shortcut.registerSystemShortcut("system:resetX", tr("reserved"), KeyEvent.VK_BACK_SPACE, KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK)
     101        Shortcut.registerSystemShortcut("system:resetX", tr(reserved), KeyEvent.VK_BACK_SPACE, InputEvent.CTRL_DOWN_MASK | InputEvent.ALT_DOWN_MASK)
    103102            .setAutomatic();
    104103        // CHECKSTYLE.ON: LineLength
     
    175174    /**
    176175     * Get the Java package name including detailed version.
    177      *
     176     * <p>
    178177     * Some Java bugs are specific to a certain security update, so in addition
    179178     * to the Java version, we also need the exact package version.
     
    183182    public String getJavaPackageDetails() {
    184183        String home = getSystemProperty("java.home");
    185         if (home.contains("java-8-openjdk") || home.contains("java-1.8.0-openjdk")) {
    186             return getPackageDetails("openjdk-8-jre", "java-1_8_0-openjdk", "java-1.8.0-openjdk");
    187         } else if (home.contains("java-9-openjdk") || home.contains("java-1.9.0-openjdk")) {
    188             return getPackageDetails("openjdk-9-jre", "java-1_9_0-openjdk", "java-1.9.0-openjdk", "java-9-openjdk");
    189         } else if (home.contains("java-10-openjdk")) {
    190             return getPackageDetails("openjdk-10-jre", "java-10-openjdk");
    191         } else if (home.contains("java-11-openjdk")) {
    192             return getPackageDetails("openjdk-11-jre", "java-11-openjdk");
    193         } else if (home.contains("java-17-openjdk")) {
    194             return getPackageDetails("openjdk-17-jre", "java-17-openjdk");
     184        if (home == null) {
     185            return null;
     186        }
     187        Matcher matcher = Pattern.compile("java-(\\d+)-openjdk").matcher(home);
     188        if (matcher.find()) {
     189            String version = matcher.group(1);
     190            return getPackageDetails("openjdk-" + version + "-jre", "java-" + version + "-openjdk");
    195191        } else if (home.contains("java-openjdk")) {
    196192            return getPackageDetails("java-openjdk");
     
    205201    /**
    206202     * Get the Web Start package name including detailed version.
    207      *
     203     * <p>
    208204     * OpenJDK packages are shipped with icedtea-web package,
    209205     * but its version generally does not match main java package version.
    210      *
     206     * <p>
    211207     * Simply return {@code null} if there's no separate package for Java WebStart.
    212208     *
     
    222218    /**
    223219     * Get the Gnome ATK wrapper package name including detailed version.
    224      *
     220     * <p>
    225221     * Debian and Ubuntu derivatives come with a pre-enabled accessibility software
    226222     * completely buggy that makes Swing crash in a lot of different ways.
    227      *
     223     * <p>
    228224     * Simply return {@code null} if it's not found.
    229225     *
Note: See TracChangeset for help on using the changeset viewer.