Changeset 12830 in josm for trunk


Ignore:
Timestamp:
2017-09-12T17:23:17+02:00 (7 years ago)
Author:
Don-vip
Message:

fix #15297, fix #15298 - proper detection of java packages on rpm-based Linux systems

Location:
trunk/src/org/openstreetmap/josm/tools
Files:
2 edited

Legend:

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

    r12776 r12830  
    2323import java.util.Arrays;
    2424import java.util.Locale;
     25import java.util.concurrent.ExecutionException;
    2526
    2627import org.openstreetmap.josm.Main;
     
    3435
    3536    private String osDescription;
    36 
    37     // rpm returns translated string "package %s is not installed\n", can't find a way to force english output
    38     // translations from https://github.com/rpm-software-management/rpm
    39     private static final String[] NOT_INSTALLED = {
    40             "not installed",          // en
    41             "no s'ha instal·lat",     // ca
    42             "尚未安裝",                // cmn
    43             "není nainstalován",      // cs
    44             "ikke installeret",       // da
    45             "nicht installiert",      // de
    46             "ne estas instalita",     // eo
    47             "no está instalado",      // es
    48             "ole asennettu",          // fi
    49             "pas installé",           // fr
    50             "non è stato installato", // it
    51             "はインストールされていません。",   // ja
    52             "패키지가 설치되어 있지 않습니다", // ko
    53             "ikke installert",        // nb
    54             "nie jest zainstalowany", // pl
    55             "não está instalado",     // pt
    56             "не установлен",          // ru
    57             "ni nameščen",            // sl
    58             "nie je nainštalovaný",   // sk
    59             "није инсталиран",        // sr
    60             "inte installerat",       // sv
    61             "kurulu değil",           // tr
    62             "не встановлено",         // uk
    63             "chưa cài đặt gói",       // vi
    64             "未安装软件包",             // zh_CN
    65             "尚未安裝"                // zh_TW
    66     };
    6737
    6838    @Override
     
    12797            String dist = Utils.execOutput(Arrays.asList("lsb_release", "-i", "-s"));
    12898            return "Debian".equalsIgnoreCase(dist) || "Ubuntu".equalsIgnoreCase(dist) || "Mint".equalsIgnoreCase(dist);
    129         } catch (IOException e) {
     99        } catch (IOException | ExecutionException | InterruptedException e) {
    130100            // lsb_release is not available on all Linux systems, so don't log at warning level
    131101            Logging.debug(e);
     
    157127                        args = new String[] {"rpm", "-q", "--qf", "%{arch}-%{version}", packageName};
    158128                    }
    159                     String version = Utils.execOutput(Arrays.asList(args));
    160                     if (version != null) {
    161                         for (String notInstalled : NOT_INSTALLED) {
    162                             if (version.contains(notInstalled))
    163                                 break;
     129                    try {
     130                        String version = Utils.execOutput(Arrays.asList(args));
     131                        if (version != null && !version.isEmpty()) {
     132                            return packageName + ':' + version;
    164133                        }
    165                         return packageName + ':' + version;
     134                    } catch (ExecutionException e) {
     135                        // Package does not exist, continue
     136                        Logging.trace(e);
    166137                    }
    167138                }
    168139            }
    169         } catch (IOException e) {
     140        } catch (IOException | InterruptedException e) {
    170141            Logging.warn(e);
    171142        }
     
    186157            return getPackageDetails("openjdk-8-jre", "java-1_8_0-openjdk", "java-1.8.0-openjdk");
    187158        } 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");
     159            return getPackageDetails("openjdk-9-jre", "java-1_9_0-openjdk", "java-1.9.0-openjdk", "java-9-openjdk");
    189160        } else if (home.contains("icedtea")) {
    190161            return getPackageDetails("icedtea-bin");
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r12798 r12830  
    4545import java.util.List;
    4646import java.util.Locale;
     47import java.util.concurrent.ExecutionException;
    4748import java.util.concurrent.Executor;
    4849import java.util.concurrent.ForkJoinPool;
     
    867868     * @return the output
    868869     * @throws IOException when there was an error, e.g. command does not exist
    869      */
    870     public static String execOutput(List<String> command) throws IOException {
     870     * @throws ExecutionException when the return code is != 0. The output is can be retrieved in the exception message
     871     * @throws InterruptedException if the current thread is {@linkplain Thread#interrupt() interrupted} by another thread while waiting
     872     */
     873    public static String execOutput(List<String> command) throws IOException, ExecutionException, InterruptedException {
    871874        if (Logging.isDebugEnabled()) {
    872875            Logging.debug(join(" ", command));
     
    884887                }
    885888            }
    886             return all != null ? all.toString() : null;
     889            String msg = all != null ? all.toString() : null;
     890            if (p.waitFor() != 0) {
     891                throw new ExecutionException(msg, null);
     892            }
     893            return msg;
    887894        }
    888895    }
Note: See TracChangeset for help on using the changeset viewer.