- Timestamp:
- 2017-05-20T19:06:29+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/tools
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/PlatformHook.java
r12217 r12219 2 2 package org.openstreetmap.josm.tools; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.awt.Dimension; 4 7 import java.awt.GraphicsEnvironment; 5 8 import java.io.BufferedReader; … … 13 16 import java.security.cert.CertificateException; 14 17 import java.security.cert.X509Certificate; 18 import java.text.DateFormat; 19 import java.util.Date; 15 20 import java.util.List; 16 21 22 import javax.swing.JOptionPane; 23 24 import org.openstreetmap.josm.Main; 25 import org.openstreetmap.josm.gui.ExtendedDialog; 17 26 import org.openstreetmap.josm.io.CertificateAmendment.CertAmend; 27 import org.openstreetmap.josm.tools.date.DateUtils; 18 28 19 29 /** … … 224 234 */ 225 235 List<File> getDefaultProj4NadshiftDirectories(); 236 237 /** 238 * Determines if the JVM is OpenJDK-based. 239 * @return {@code true} if {@code java.home} contains "openjdk", {@code false} otherwise 240 * @since 12219 241 */ 242 default boolean isOpenJDK() { 243 String javaHome = System.getProperty("java.home"); 244 return javaHome != null && javaHome.contains("openjdk"); 245 } 246 247 /** 248 * Asks user to update its version of Java. 249 * @param updVersion target update version 250 * @param url download URL 251 * @param major true for a migration towards a major version of Java (8->9), false otherwise 252 * @param eolDate the EOL/expiration date 253 * @since 12219 254 */ 255 default void askUpdateJava(String updVersion, String url, String eolDate, boolean major) { 256 ExtendedDialog ed = new ExtendedDialog( 257 Main.parent, 258 tr("Outdated Java version"), 259 new String[]{tr("OK"), tr("Update Java"), tr("Cancel")}); 260 // Check if the dialog has not already been permanently hidden by user 261 if (!ed.toggleEnable("askUpdateJava"+updVersion).toggleCheckState()) { 262 ed.setButtonIcons(new String[]{"ok", "java", "cancel"}).setCancelButton(3); 263 ed.setMinimumSize(new Dimension(480, 300)); 264 ed.setIcon(JOptionPane.WARNING_MESSAGE); 265 StringBuilder content = new StringBuilder(tr("You are running version {0} of Java.", 266 "<b>"+System.getProperty("java.version")+"</b>")).append("<br><br>"); 267 if ("Sun Microsystems Inc.".equals(System.getProperty("java.vendor")) && !isOpenJDK()) { 268 content.append("<b>").append(tr("This version is no longer supported by {0} since {1} and is not recommended for use.", 269 "Oracle", eolDate)).append("</b><br><br>"); 270 } 271 content.append("<b>") 272 .append(major ? 273 tr("JOSM will soon stop working with this version; we highly recommend you to update to Java {0}.", updVersion) : 274 tr("You may face critical Java bugs; we highly recommend you to update to Java {0}.", updVersion)) 275 .append("</b><br><br>") 276 .append(tr("Would you like to update now ?")); 277 ed.setContent(content.toString()); 278 279 if (ed.showDialog().getValue() == 2) { 280 try { 281 openUrl(url); 282 } catch (IOException e) { 283 Main.warn(e); 284 } 285 } 286 } 287 } 288 289 /** 290 * Checks if the running version of Java has expired, proposes to user to update it if needed. 291 * @since 12219 292 */ 293 default void checkExpiredJava() { 294 Date expiration = Utils.getJavaExpirationDate(); 295 if (expiration != null && expiration.before(new Date())) { 296 String version = Utils.getJavaLatestVersion(); 297 askUpdateJava(version != null ? version : "latest", 298 Main.pref.get("java.update.url", "https://www.java.com/download"), 299 DateUtils.getDateFormat(DateFormat.MEDIUM).format(expiration), false); 300 } 301 } 226 302 } -
trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java
r12217 r12219 79 79 Main.warn("Failed to register with OSX: " + ex); 80 80 } 81 checkExpiredJava(); 81 82 } 82 83 -
trunk/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java
r12217 r12219 5 5 6 6 import java.awt.Desktop; 7 import java.awt.Dimension;8 7 import java.awt.event.KeyEvent; 9 8 import java.io.BufferedReader; … … 20 19 import java.util.Locale; 21 20 22 import javax.swing.JOptionPane;23 24 21 import org.openstreetmap.josm.Main; 25 import org.openstreetmap.josm.gui.ExtendedDialog;26 import org.openstreetmap.josm.gui.util.GuiHelper;27 22 28 23 /** 29 * {@code PlatformHook} base implementation. 30 * 31 * Don't write (Main.platform instanceof PlatformHookUnixoid) because other platform 32 * hooks are subclasses of this class. 24 * {@code PlatformHook} implementation for Unix systems. 25 * @since 1023 33 26 */ 34 27 public class PlatformHookUnixoid implements PlatformHook { … … 97 90 return false; 98 91 } 99 }100 101 /**102 * Determines if the JVM is OpenJDK-based.103 * @return {@code true} if {@code java.home} contains "openjdk", {@code false} otherwise104 * @since 6951105 */106 public static boolean isOpenJDK() {107 String javaHome = System.getProperty("java.home");108 return javaHome != null && javaHome.contains("openjdk");109 92 } 110 93 … … 200 183 } 201 184 202 pr otectedString buildOSDescription() {185 private String buildOSDescription() { 203 186 String osName = System.getProperty("os.name"); 204 187 if ("Linux".equalsIgnoreCase(osName)) { … … 246 229 } 247 230 248 pr otectedstatic class LinuxReleaseInfo {231 private static class LinuxReleaseInfo { 249 232 private final String path; 250 233 private final String descriptionField; … … 254 237 private final String prefix; 255 238 256 publicLinuxReleaseInfo(String path, String descriptionField, String idField, String releaseField) {239 LinuxReleaseInfo(String path, String descriptionField, String idField, String releaseField) { 257 240 this(path, descriptionField, idField, releaseField, false, null); 258 241 } 259 242 260 publicLinuxReleaseInfo(String path) {243 LinuxReleaseInfo(String path) { 261 244 this(path, null, null, null, true, null); 262 245 } 263 246 264 publicLinuxReleaseInfo(String path, String prefix) {247 LinuxReleaseInfo(String path, String prefix) { 265 248 this(path, null, null, null, true, prefix); 266 249 } … … 275 258 } 276 259 277 @Override public String toString() { 260 @Override 261 public String toString() { 278 262 return "ReleaseInfo [path=" + path + ", descriptionField=" + descriptionField + 279 263 ", idField=" + idField + ", releaseField=" + releaseField + ']'; … … 331 315 } 332 316 333 // Method unused, but kept for translation already done. To reuse during Java 9 migration334 protected void askUpdateJava(final String version, final String url) {335 GuiHelper.runInEDTAndWait(() -> {336 ExtendedDialog ed = new ExtendedDialog(337 Main.parent,338 tr("Outdated Java version"),339 new String[]{tr("OK"), tr("Update Java"), tr("Cancel")});340 // Check if the dialog has not already been permanently hidden by user341 if (!ed.toggleEnable("askUpdateJava9").toggleCheckState()) {342 ed.setButtonIcons(new String[]{"ok", "java", "cancel"}).setCancelButton(3);343 ed.setMinimumSize(new Dimension(480, 300));344 ed.setIcon(JOptionPane.WARNING_MESSAGE);345 StringBuilder content = new StringBuilder(tr("You are running version {0} of Java.", "<b>"+version+"</b>"))346 .append("<br><br>");347 if ("Sun Microsystems Inc.".equals(System.getProperty("java.vendor")) && !isOpenJDK()) {348 content.append("<b>").append(tr("This version is no longer supported by {0} since {1} and is not recommended for use.",349 "Oracle", tr("April 2015"))).append("</b><br><br>"); // TODO: change date once Java 8 EOL is announced350 }351 content.append("<b>")352 .append(tr("JOSM will soon stop working with this version; we highly recommend you to update to Java {0}.", "8"))353 .append("</b><br><br>")354 .append(tr("Would you like to update now ?"));355 ed.setContent(content.toString());356 357 if (ed.showDialog().getValue() == 2) {358 try {359 openUrl(url);360 } catch (IOException e) {361 Main.warn(e);362 }363 }364 }365 });366 }367 368 317 /** 369 318 * Get the dot directory <code>~/.josm</code>. -
trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java
r12218 r12219 180 180 } 181 181 } 182 } 183 184 @Override 185 public void startupHook() { 186 checkExpiredJava(); 182 187 } 183 188 -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r12217 r12219 32 32 import java.security.PrivilegedAction; 33 33 import java.text.Bidi; 34 import java.text.DateFormat; 34 35 import java.text.MessageFormat; 36 import java.text.ParseException; 35 37 import java.util.AbstractCollection; 36 38 import java.util.AbstractList; … … 39 41 import java.util.Collection; 40 42 import java.util.Collections; 43 import java.util.Date; 41 44 import java.util.Iterator; 42 45 import java.util.List; … … 1646 1649 return Integer.parseInt(version.substring(bPos > -1 ? bPos + 1 : pPos + 1, version.length())); 1647 1650 } 1651 1652 /** 1653 * Returns the JRE expiration date. 1654 * @return the JRE expiration date, or null 1655 * @since 12219 1656 */ 1657 public static Date getJavaExpirationDate() { 1658 try { 1659 Object value = Class.forName("com.sun.deploy.config.BuiltInProperties").getDeclaredField("JRE_EXPIRATION_DATE").get(null); 1660 if (value instanceof String) { 1661 return DateFormat.getDateInstance(3, Locale.US).parse((String) value); 1662 } 1663 } catch (IllegalArgumentException | ReflectiveOperationException | SecurityException | ParseException e) { 1664 Main.debug(e); 1665 } 1666 return null; 1667 } 1668 1669 /** 1670 * Returns the latest version of Java, from Oracle website. 1671 * @return the latest version of Java, from Oracle website 1672 * @since 12219 1673 */ 1674 public static String getJavaLatestVersion() { 1675 try { 1676 return HttpClient.create( 1677 new URL(Main.pref.get("java.baseline.version.url", "http://javadl-esd-secure.oracle.com/update/baseline.version"))) 1678 .connect().fetchContent().split("\n")[0]; 1679 } catch (IOException e) { 1680 Main.error(e); 1681 } 1682 return null; 1683 } 1648 1684 }
Note:
See TracChangeset
for help on using the changeset viewer.