- Timestamp:
- 2018-01-08T02:45:59+01:00 (7 years ago)
- Location:
- trunk
- Files:
-
- 5 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r13294 r13300 1258 1258 File plugin = new File(filePath.substring(0, filePath.length() - 4)); 1259 1259 String pluginName = updatedPlugin.getName().substring(0, updatedPlugin.getName().length() - 8); 1260 if (plugin.exists() && !plugin.delete() && dowarn) {1261 Logging.warn(tr("Failed to delete outdated plugin ''{0}''.", plugin.toString()));1262 Logging.warn(tr("Failed to install already downloaded plugin ''{0}''. " +1263 "Skipping installation. JOSM is still going to load the old plugin version.",1264 pluginName));1265 continue;1266 }1267 1260 try { 1268 1261 // Check the plugin is a valid and accessible JAR file before installing it (fix #7754) … … 1273 1266 plugin.toString(), updatedPlugin.toString(), e.getLocalizedMessage()), e); 1274 1267 } 1268 continue; 1269 } 1270 if (plugin.exists() && !plugin.delete() && dowarn) { 1271 Logging.warn(tr("Failed to delete outdated plugin ''{0}''.", plugin.toString())); 1272 Logging.warn(tr("Failed to install already downloaded plugin ''{0}''. " + 1273 "Skipping installation. JOSM is still going to load the old plugin version.", 1274 pluginName)); 1275 1275 continue; 1276 1276 } -
trunk/test/unit/org/openstreetmap/josm/TestUtils.java
r13079 r13300 188 188 189 189 /** 190 * Sets a private static field value. 191 * @param cls object class 192 * @param fieldName private field name 193 * @param value replacement value 194 * @throws ReflectiveOperationException if a reflection operation error occurs 195 */ 196 public static void setPrivateStaticField(Class<?> cls, String fieldName, final Object value) throws ReflectiveOperationException { 197 Field f = cls.getDeclaredField(fieldName); 198 AccessController.doPrivileged((PrivilegedAction<Void>) () -> { 199 f.setAccessible(true); 200 return null; 201 }); 202 f.set(null, value); 203 } 204 205 /** 190 206 * Returns an instance of {@link AbstractProgressMonitor} which keeps track of the monitor state, 191 207 * but does not show the progress. -
trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/AbstractDownloadTaskTestParent.java
r12558 r13300 40 40 41 41 /** 42 * Returns the {@code Content-Type} with which to serve the file referenced 43 * by {@link #getRemoteFile()} 44 * @return the {@code Content-Type} string for file {@link #getRemoteFile()} 45 */ 46 protected String getRemoteContentType() { 47 return "text/xml"; 48 } 49 50 /** 42 51 * Returns the http URL to remote test file to download. 43 52 * @return the http URL to remote test file to download … … 54 63 .willReturn(aResponse() 55 64 .withStatus(200) 56 .withHeader("Content-Type", "text/xml")65 .withHeader("Content-Type", getRemoteContentType()) 57 66 .withBodyFile(getRemoteFile()))); 58 67 } -
trunk/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
r13078 r13300 3 3 4 4 import java.awt.Color; 5 import java.io.ByteArrayInputStream; 5 6 import java.io.File; 6 7 import java.io.IOException; … … 16 17 import org.openstreetmap.josm.JOSMFixture; 17 18 import org.openstreetmap.josm.Main; 19 import org.openstreetmap.josm.TestUtils; 18 20 import org.openstreetmap.josm.actions.DeleteAction; 19 21 import org.openstreetmap.josm.command.DeleteCommand; 20 22 import org.openstreetmap.josm.data.UserIdentityManager; 23 import org.openstreetmap.josm.data.Version; 21 24 import org.openstreetmap.josm.data.osm.User; 22 25 import org.openstreetmap.josm.data.osm.event.SelectionEventManager; … … 59 62 private String i18n = null; 60 63 private TileSourceRule tileSourceRule; 64 private String assumeRevisionString; 65 private Version originalVersion; 61 66 private boolean platform; 62 67 private boolean useProjection; … … 133 138 public JOSMTestRules platform() { 134 139 platform = true; 140 return this; 141 } 142 143 /** 144 * Mock this test's assumed JOSM version (as reported by {@link Version}). 145 * @param revisionProperties mock contents of JOSM's {@code REVISION} properties file 146 * @return this instance, for easy chaining 147 */ 148 public JOSMTestRules assumeRevision(final String revisionProperties) { 149 this.assumeRevisionString = revisionProperties; 135 150 return this; 136 151 } … … 277 292 /** 278 293 * Use the {@link Main#main}, {@code Main.contentPanePrivate}, {@code Main.mainPanel}, 279 * {@link Main#menu}, {@link Main#toolbar}global variables in this test.294 * global variables in this test. 280 295 * @return this instance, for easy chaining 281 296 * @since 12557 … … 285 300 main = true; 286 301 return this; 302 } 303 304 private static class MockVersion extends Version { 305 MockVersion(final String propertiesString) { 306 super.initFromRevisionInfo( 307 new ByteArrayInputStream(propertiesString.getBytes()) 308 ); 309 } 287 310 } 288 311 … … 318 341 * Set up before running a test 319 342 * @throws InitializationError If an error occured while creating the required environment. 320 */ 321 protected void before() throws InitializationError { 343 * @throws ReflectiveOperationException if a reflective access error occurs 344 */ 345 protected void before() throws InitializationError, ReflectiveOperationException { 322 346 // Tests are running headless by default. 323 347 System.setProperty("java.awt.headless", "true"); 324 348 325 349 cleanUpFromJosmFixture(); 350 351 if (this.assumeRevisionString != null) { 352 this.originalVersion = Version.getInstance(); 353 final Version replacementVersion = new MockVersion(this.assumeRevisionString); 354 TestUtils.setPrivateStaticField(Version.class, "instance", replacementVersion); 355 } 326 356 327 357 Config.setPreferencesInstance(Main.pref); … … 465 495 /** 466 496 * Clean up after running a test 497 * @throws ReflectiveOperationException if a reflective access error occurs 467 498 */ 468 499 @SuppressFBWarnings("DM_GC") 469 protected void after() {500 protected void after() throws ReflectiveOperationException { 470 501 // Sync AWT Thread 471 502 GuiHelper.runInEDTAndWait(new Runnable() { … … 481 512 Main.pref.resetToInitialState(); 482 513 Main.platform = null; 514 515 if (this.assumeRevisionString != null && this.originalVersion != null) { 516 TestUtils.setPrivateStaticField(Version.class, "instance", this.originalVersion); 517 } 518 483 519 // Parts of JOSM uses weak references - destroy them. 484 520 System.gc();
Note:
See TracChangeset
for help on using the changeset viewer.