Changeset 14406 in josm
- Timestamp:
- 2018-11-03T01:07:53+01:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Version.java
r14273 r14406 6 6 import java.io.IOException; 7 7 import java.io.InputStream; 8 import java.net.URL; 9 import java.nio.file.InvalidPathException; 8 10 import java.util.Map.Entry; 9 11 import java.util.Optional; … … 105 107 */ 106 108 public void init() { 107 try (InputStream stream = Version.class.getResourceAsStream("/REVISION")) {109 try (InputStream stream = openRevisionStream("/REVISION")) { 108 110 if (stream == null) { 109 111 Logging.warn(tr("The revision file ''/REVISION'' is missing.")); … … 118 120 } 119 121 122 private static InputStream openRevisionStream(String path) throws IOException { 123 try { 124 return Version.class.getResourceAsStream(path); 125 } catch (InvalidPathException e) { 126 Logging.error("Cannot open {0}: {1}", path, e.getMessage()); 127 URL betterUrl = Utils.betterJarUrl(Version.class.getResource(path)); 128 if (betterUrl != null) { 129 return betterUrl.openStream(); 130 } 131 return null; 132 } 133 } 134 120 135 /** 121 136 * Replies the version string. Either the SVN revision "1234" (as string) or the -
trunk/src/org/openstreetmap/josm/io/CachedFile.java
r14404 r14406 227 227 if (name != null && name.startsWith("resource://")) { 228 228 String resourceName = name.substring("resource:/".length()); 229 InputStream is = getClass().getResourceAsStream(resourceName); 229 InputStream is = null; 230 try { 231 is = getClass().getResourceAsStream(resourceName); 232 } catch (InvalidPathException e) { 233 Logging.error("Cannot open {0}: {1}", resourceName, e.getMessage()); 234 Logging.trace(e); 235 } 230 236 if (is == null) { 231 237 URL resource = getClass().getResource(resourceName); -
trunk/src/org/openstreetmap/josm/tools/I18n.java
r14013 r14406 138 138 } 139 139 140 private static String format(String text, Object... objects) { 141 try { 142 return MessageFormat.format(text, objects); 143 } catch (InvalidPathException e) { 144 System.err.println("!!! Unable to format '" + text + "': " + e.getMessage()); 145 e.printStackTrace(); 146 return null; 147 } 148 } 149 140 150 /** 141 151 * Translates some text for the current locale. … … 162 172 public static String tr(String text, Object... objects) { 163 173 if (text == null) return null; 164 return MessageFormat.format(gettext(text, null), objects);174 return format(gettext(text, null), objects); 165 175 } 166 176 … … 182 192 if (text == null) 183 193 return null; 184 return MessageFormat.format(gettext(text, context), (Object) null);194 return format(gettext(text, context), (Object) null); 185 195 } 186 196 … … 190 200 if (text == null) 191 201 return null; 192 return MessageFormat.format(gettextLazy(text, context), (Object) null);202 return format(gettextLazy(text, context), (Object) null); 193 203 } 194 204 … … 235 245 */ 236 246 public static String trn(String singularText, String pluralText, long n, Object... objects) { 237 return MessageFormat.format(gettextn(singularText, pluralText, null, n), objects);247 return format(gettextn(singularText, pluralText, null, n), objects); 238 248 } 239 249 … … 262 272 */ 263 273 public static String trnc(String context, String singularText, String pluralText, long n, Object... objects) { 264 return MessageFormat.format(gettextn(singularText, pluralText, context, n), objects);274 return format(gettextn(singularText, pluralText, context, n), objects); 265 275 } 266 276 … … 348 358 } 349 359 350 static voidsetupJavaLocaleProviders() {360 static String setupJavaLocaleProviders() { 351 361 // Look up SPI providers first (for JosmDecimalFormatSymbolsProvider). 352 362 // Enable CLDR locale provider on Java 8 to get additional languages, such as Khmer. … … 355 365 // See https://docs.oracle.com/javase/9/docs/api/java/util/spi/LocaleServiceProvider.html 356 366 try { 357 // Don't call Utils.updateSystemProperty to avoid spurious log at startup 358 System.setProperty("java.locale.providers", "SPI,JRE,CLDR"); 367 try { 368 // First check we're able to open a stream to our own SPI file 369 // Java will fail on Windows if the jar file is in a folder with a space character! 370 I18n.class.getResourceAsStream("/META-INF/services/java.text.spi.DecimalFormatSymbolsProvider").close(); 371 // Don't call Utils.updateSystemProperty to avoid spurious log at startup 372 return System.setProperty("java.locale.providers", "SPI,JRE,CLDR"); 373 } catch (RuntimeException | IOException e) { 374 // Don't call Logging class, it may not be fully initialized yet 375 System.err.println("Unable to set SPI locale provider: " + e.getMessage()); 376 } 359 377 } catch (SecurityException e) { 360 378 // Don't call Logging class, it may not be fully initialized yet 361 379 System.err.println("Unable to set locale providers: " + e.getMessage()); 362 380 } 381 return System.setProperty("java.locale.providers", "JRE,CLDR"); 363 382 } 364 383 -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r14404 r14406 31 31 import java.net.URL; 32 32 import java.nio.charset.StandardCharsets; 33 import java.nio.file.InvalidPathException; 33 34 import java.util.Arrays; 34 35 import java.util.Base64; … … 1165 1166 synchronized (getSvgUniverse()) { 1166 1167 try { 1167 URI uri = getSvgUniverse().loadSVG(path); 1168 URI uri = null; 1169 try { 1170 uri = getSvgUniverse().loadSVG(path); 1171 } catch (InvalidPathException e) { 1172 Logging.error("Cannot open {0}: {1}", path, e.getMessage()); 1173 Logging.trace(e); 1174 } 1168 1175 if (uri == null && "jar".equals(path.getProtocol())) { 1169 1176 URL betterPath = Utils.betterJarUrl(path);
Note:
See TracChangeset
for help on using the changeset viewer.