Changeset 6103 in josm


Ignore:
Timestamp:
2013-08-02T23:42:34+02:00 (11 years ago)
Author:
bastiK
Message:

see #8921 - add Java package version to the status report

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java

    r6084 r6103  
    3030import org.openstreetmap.josm.tools.BugReportExceptionHandler;
    3131import org.openstreetmap.josm.tools.OpenBrowser;
     32import org.openstreetmap.josm.tools.PlatformHookUnixoid;
    3233import org.openstreetmap.josm.tools.PlatformHookWindows;
    3334import org.openstreetmap.josm.tools.Shortcut;
     
    8586        text.append("Java version: " + System.getProperty("java.version") + ", " + System.getProperty("java.vendor") + ", " + System.getProperty("java.vm.name"));
    8687        text.append("\n");
     88        if (Main.platform.getClass() == PlatformHookUnixoid.class) {
     89            String packageDetails = ((PlatformHookUnixoid) Main.platform).getJavaPackageDetails();
     90            if (packageDetails != null) {
     91                text.append("Java package: ");
     92                text.append(packageDetails);
     93                text.append("\n");
     94            }
     95        }
    8796        try {
    8897            final String env_java_home = System.getenv("JAVA_HOME");
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java

    r6070 r6103  
    1111import java.io.IOException;
    1212import java.io.InputStreamReader;
     13import java.util.Arrays;
     14import java.util.List;
    1315
    1416/**
     
    8890    {
    8991        return from.renameTo(to);
     92    }
     93
     94    /**
     95     * Get the Java package name including detailed version.
     96     *
     97     * Some Java bugs are specific to a certain security update, so in addition
     98     * to the Java version, we also need the exact package version.
     99     *
     100     * This was originally written for #8921, so only Debian based distributions
     101     * are covered at the moment. This can be extended to other distributions
     102     * if needed.
     103     *
     104     * @return The package name and package version if it can be identified, null
     105     * otherwise
     106     */
     107    public String getJavaPackageDetails() {
     108        try {
     109            String dist = Utils.execOutput(Arrays.asList("lsb_release", "-i", "-s"));
     110            if ("Debian".equalsIgnoreCase(dist) || "Ubuntu".equalsIgnoreCase(dist)) {
     111                String javaHome = System.getProperty("java.home");
     112                if ("/usr/lib/jvm/java-6-openjdk-amd64/jre".equals(javaHome) ||
     113                        "/usr/lib/jvm/java-6-openjdk-i386/jre".equals(javaHome) ||
     114                        "/usr/lib/jvm/java-6-openjdk/jre".equals(javaHome)) {
     115                    String version = Utils.execOutput(Arrays.asList("dpkg-query", "--show", "--showformat", "${Architecture}-${Version}", "openjdk-6-jre"));
     116                    return "openjdk-6-jre:" + version;
     117                }
     118                if ("/usr/lib/jvm/java-7-openjdk-amd64/jre".equals(javaHome) ||
     119                        "/usr/lib/jvm/java-7-openjdk-i386/jre".equals(javaHome)) {
     120                    String version = Utils.execOutput(Arrays.asList("dpkg-query", "--show", "--showformat", "${Architecture}-${Version}", "openjdk-7-jre"));
     121                    return "openjdk-7-jre:" + version;
     122                }
     123            }
     124        } catch (IOException e) {
     125        }
     126        return null;
    90127    }
    91128
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r6094 r6103  
    664664        return str.substring(start, end);
    665665    }
     666
     667    /**
     668     * Runs an external command and returns the standard output.
     669     *
     670     * The program is expected to execute fast.
     671     *
     672     * @param command the command with arguments
     673     * @return the output
     674     * @throws IOException when there was an error, e.g. command does not exist
     675     */
     676    public static String execOutput(List<String> command) throws IOException {
     677        Process p = new ProcessBuilder(command).start();
     678        BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
     679        StringBuilder all = null;
     680        String line;
     681        while ((line = input.readLine()) != null) {
     682            if (all == null) {
     683                all = new StringBuilder(line);
     684            } else {
     685                all.append(line);
     686                all.append("\n");
     687            }
     688        }
     689        Utils.close(input);
     690        return all.toString();
     691    }
     692
    666693}
Note: See TracChangeset for help on using the changeset viewer.