Changeset 12217 in josm
- Timestamp:
- 2017-05-20T17:11:37+02:00 (8 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java
r11746 r12217 84 84 String runtimeVersion = System.getProperty("java.runtime.version"); 85 85 text.append(Version.getInstance().getReleaseAttributes()) 86 .append("\nIdentification: ").append(Version.getInstance().getAgentString()) 87 .append("\nMemory Usage: ") 86 .append("\nIdentification: ").append(Version.getInstance().getAgentString()); 87 String buildNumber = Main.platform.getOSBuildNumber(); 88 if (!buildNumber.isEmpty()) { 89 text.append("\nOS Build number: ").append(buildNumber); 90 } 91 text.append("\nMemory Usage: ") 88 92 .append(Runtime.getRuntime().totalMemory()/1024/1024) 89 93 .append(" MB / ") -
trunk/src/org/openstreetmap/josm/tools/PlatformHook.java
r11944 r12217 3 3 4 4 import java.awt.GraphicsEnvironment; 5 import java.io.BufferedReader; 5 6 import java.io.File; 6 7 import java.io.IOException; 8 import java.io.InputStreamReader; 9 import java.nio.charset.StandardCharsets; 7 10 import java.security.KeyStore; 8 11 import java.security.KeyStoreException; … … 140 143 141 144 /** 145 * Returns OS build number. 146 * @return OS build number. 147 * @since 12217 148 */ 149 default String getOSBuildNumber() { 150 return ""; 151 } 152 153 /** 142 154 * Setup system keystore to add JOSM HTTPS certificate (for remote control). 143 155 * @param entryAlias The entry alias to use … … 172 184 173 185 /** 186 * Executes a native command and returns the first line of standard output. 187 * @param command array containing the command to call and its arguments. 188 * @return first stripped line of standard output 189 * @throws IOException if an I/O error occurs 190 * @since 12217 191 */ 192 default String exec(String... command) throws IOException { 193 Process p = Runtime.getRuntime().exec(command); 194 try (BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream(), StandardCharsets.UTF_8))) { 195 return Utils.strip(input.readLine()); 196 } 197 } 198 199 /** 174 200 * Returns the platform-dependent default cache directory. 175 201 * @return the platform-dependent default cache directory -
trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java
r12123 r12217 32 32 33 33 private static final PlatformHookOsx ivhandler = new PlatformHookOsx(); 34 35 private String oSBuildNumber; 34 36 35 37 @Override … … 386 388 } 387 389 390 private String buildOSBuildNumber() { 391 StringBuilder sb = new StringBuilder(); 392 try { 393 sb.append(exec("sw_vers", "-productName")) 394 .append(' ') 395 .append(exec("sw_vers", "-productVersion")) 396 .append(" (") 397 .append(exec("sw_vers", "-buildVersion")) 398 .append(')'); 399 } catch (IOException e) { 400 Main.error(e); 401 } 402 return sb.toString(); 403 } 404 405 @Override 406 public String getOSBuildNumber() { 407 if (oSBuildNumber == null) { 408 oSBuildNumber = buildOSBuildNumber(); 409 } 410 return oSBuildNumber; 411 } 412 388 413 @Override 389 414 public File getDefaultCacheDirectory() { -
trunk/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java
r11747 r12217 10 10 import java.io.File; 11 11 import java.io.IOException; 12 import java.io.InputStreamReader;13 12 import java.net.URI; 14 13 import java.net.URISyntaxException; … … 207 206 // Try lsb_release (only available on LSB-compliant Linux systems, 208 207 // see https://www.linuxbase.org/lsb-cert/productdir.php?by_prod ) 209 Process p = Runtime.getRuntime().exec("lsb_release -ds"); 210 try (BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream(), StandardCharsets.UTF_8))) { 211 String line = Utils.strip(input.readLine()); 212 if (line != null && !line.isEmpty()) { 213 line = line.replaceAll("\"+", ""); 214 line = line.replaceAll("NAME=", ""); // strange code for some Gentoo's 215 if (line.startsWith("Linux ")) // e.g. Linux Mint 216 return line; 217 else if (!line.isEmpty()) 218 return "Linux " + line; 219 } 208 String line = exec("lsb_release -ds"); 209 if (line != null && !line.isEmpty()) { 210 line = line.replaceAll("\"+", ""); 211 line = line.replaceAll("NAME=", ""); // strange code for some Gentoo's 212 if (line.startsWith("Linux ")) // e.g. Linux Mint 213 return line; 214 else if (!line.isEmpty()) 215 return "Linux " + line; 220 216 } 221 217 } catch (IOException e) { -
trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java
r12146 r12217 27 27 import static java.awt.event.KeyEvent.VK_Z; 28 28 import static org.openstreetmap.josm.tools.I18n.tr; 29 import static org.openstreetmap.josm.tools.WinRegistry.HKEY_LOCAL_MACHINE; 29 30 30 31 import java.awt.GraphicsEnvironment; … … 36 37 import java.io.OutputStreamWriter; 37 38 import java.io.Writer; 39 import java.lang.reflect.InvocationTargetException; 38 40 import java.nio.charset.StandardCharsets; 39 41 import java.nio.file.DirectoryStream; … … 64 66 65 67 import javax.swing.JOptionPane; 68 import javax.swing.UIManager; 66 69 67 70 import org.openstreetmap.josm.Main; 68 71 import org.openstreetmap.josm.data.Preferences; 72 import org.openstreetmap.josm.gui.preferences.display.LafPreference; 69 73 import org.openstreetmap.josm.io.CertificateAmendment.CertAmend; 70 74 … … 150 154 private static final String WINDOWS_ROOT = "Windows-ROOT"; 151 155 156 private static final String CURRENT_VERSION = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"; 157 158 private String oSBuildNumber; 159 152 160 @Override 153 161 public void afterPrefStartupHook() { 154 162 extendFontconfig("fontconfig.properties.src"); 163 // Workaround for JDK-8180379: crash on Windows 10 1703 with Windows L&F and java < 8u152 / 9+171 164 // To remove during Java 9 migration 165 if (System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows 10") && 166 getDefaultStyle().equals(LafPreference.LAF.get())) { 167 try { 168 final int currentBuild = Integer.parseInt(getCurrentBuild()); 169 final int javaVersion = Utils.getJavaVersion(); 170 final int javaUpdate = Utils.getJavaUpdate(); 171 final int javaBuild = Utils.getJavaBuild(); 172 // See https://technet.microsoft.com/en-us/windows/release-info.aspx 173 if (currentBuild >= 15_063 && ((javaVersion == 8 && javaUpdate < 152) 174 || (javaVersion == 9 && javaUpdate == 0 && javaBuild < 171))) { 175 // Workaround from https://bugs.openjdk.java.net/browse/JDK-8179014 176 UIManager.put("FileChooser.useSystemExtensionHiding", false); 177 } 178 } catch (NumberFormatException | ReflectiveOperationException e) { 179 Main.error(e); 180 } 181 } 155 182 } 156 183 … … 250 277 } 251 278 279 private static String getProductName() throws IllegalAccessException, InvocationTargetException { 280 return WinRegistry.readString(HKEY_LOCAL_MACHINE, CURRENT_VERSION, "ProductName"); 281 } 282 283 private static String getReleaseId() throws IllegalAccessException, InvocationTargetException { 284 return WinRegistry.readString(HKEY_LOCAL_MACHINE, CURRENT_VERSION, "ReleaseId"); 285 } 286 287 private static String getCurrentBuild() throws IllegalAccessException, InvocationTargetException { 288 return WinRegistry.readString(HKEY_LOCAL_MACHINE, CURRENT_VERSION, "CurrentBuild"); 289 } 290 291 private static String buildOSBuildNumber() { 292 StringBuilder sb = new StringBuilder(); 293 try { 294 sb.append(getProductName()).append(' ') 295 .append(getReleaseId()).append(" (") 296 .append(getCurrentBuild()).append(')'); 297 } catch (IllegalAccessException | InvocationTargetException e) { 298 Main.error(e); 299 } 300 return sb.toString(); 301 } 302 303 @Override 304 public String getOSBuildNumber() { 305 if (oSBuildNumber == null) { 306 oSBuildNumber = buildOSBuildNumber(); 307 } 308 return oSBuildNumber; 309 } 310 252 311 /** 253 312 * Loads Windows-ROOT keystore. -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r12130 r12217 1607 1607 dotPos > -1 ? dotPos : dashPos > -1 ? dashPos : 1)); 1608 1608 } 1609 1610 /** 1611 * Returns the Java update as an int value. 1612 * @return the Java update as an int value (121, 131, etc.) 1613 * @since 12217 1614 */ 1615 public static int getJavaUpdate() { 1616 String version = System.getProperty("java.version"); 1617 if (version.startsWith("1.")) { 1618 version = version.substring(2); 1619 } 1620 // Allow these formats: 1621 // 1.8.0_72-ea 1622 // 9-ea 1623 // 9 1624 // 9.0.1 1625 int undePos = version.indexOf('_'); 1626 int dashPos = version.indexOf('-'); 1627 if (undePos > -1) { 1628 return Integer.parseInt(version.substring(undePos + 1, 1629 dashPos > -1 ? dashPos : version.length())); 1630 } 1631 int firstDotPos = version.indexOf('.'); 1632 int lastDotPos = version.lastIndexOf('.'); 1633 return firstDotPos > - 1 ? Integer.parseInt(version.substring(firstDotPos + 1, 1634 lastDotPos > -1 ? lastDotPos : version.length())) : 0; 1635 } 1636 1637 /** 1638 * Returns the Java build number as an int value. 1639 * @return the Java build number as an int value (0, 1, etc.) 1640 * @since 12217 1641 */ 1642 public static int getJavaBuild() { 1643 String version = System.getProperty("java.runtime.version"); 1644 int bPos = version.indexOf('b'); 1645 int pPos = version.indexOf('+'); 1646 return Integer.parseInt(version.substring(bPos > -1 ? bPos + 1 : pPos + 1, version.length())); 1647 } 1609 1648 } -
trunk/test/unit/org/openstreetmap/josm/tools/UtilsTest.java
r12130 r12217 219 219 220 220 /** 221 * Test {@link Utils#getJavaUpdate} 222 */ 223 @Test 224 public void testGetJavaUpdate() { 225 String javaVersion = System.getProperty("java.version"); 226 try { 227 System.setProperty("java.version", "1.8.0_131"); 228 assertEquals(131, Utils.getJavaUpdate()); 229 230 System.setProperty("java.version", "1.8.0_152-ea"); 231 assertEquals(152, Utils.getJavaUpdate()); 232 233 System.setProperty("java.version", "9-ea"); 234 assertEquals(0, Utils.getJavaUpdate()); 235 236 System.setProperty("java.version", "9"); 237 assertEquals(0, Utils.getJavaUpdate()); 238 239 System.setProperty("java.version", "9.1.2"); 240 assertEquals(1, Utils.getJavaUpdate()); 241 } finally { 242 System.setProperty("java.version", javaVersion); 243 } 244 } 245 246 /** 247 * Test {@link Utils#getJavaBuild} 248 */ 249 @Test 250 public void testGetJavaBuild() { 251 String javaVersion = System.getProperty("java.runtime.version"); 252 try { 253 System.setProperty("java.runtime.version", "1.8.0_131-b11"); 254 assertEquals(11, Utils.getJavaBuild()); 255 256 System.setProperty("java.runtime.version", "1.8.0_152-ea-b04"); 257 assertEquals(4, Utils.getJavaBuild()); 258 259 System.setProperty("java.runtime.version", "9-ea+170"); 260 assertEquals(170, Utils.getJavaBuild()); 261 262 System.setProperty("java.runtime.version", "9+200"); 263 assertEquals(200, Utils.getJavaBuild()); 264 265 System.setProperty("java.runtime.version", "9.1.2+62"); 266 assertEquals(62, Utils.getJavaBuild()); 267 } finally { 268 System.setProperty("java.runtime.version", javaVersion); 269 } 270 } 271 272 /** 221 273 * Tests if readBytesFromStream handles null streams (might happen when there is no data on error stream) 222 274 * @throws IOException in case of I/O error
Note:
See TracChangeset
for help on using the changeset viewer.