Ticket #19053: 19053.7.patch
| File 19053.7.patch, 8.9 KB (added by , 6 years ago) |
|---|
-
src/org/openstreetmap/josm/data/preferences/sources/ValidatorPrefHelper.java
47 47 /** The preferences key for the ignorelist */ 48 48 public static final String PREF_IGNORELIST = PREFIX + ".ignorelist"; 49 49 50 /** The preferences key for the ignorelist format */ 51 public static final String PREF_IGNORELIST_FORMAT = PREF_IGNORELIST + ".version"; 52 50 53 /** 51 54 * The preferences key for enabling the permanent filtering 52 55 * of the displayed errors in the tree regarding the current selection -
src/org/openstreetmap/josm/data/validation/OsmValidator.java
18 18 import java.util.EnumMap; 19 19 import java.util.Enumeration; 20 20 import java.util.HashMap; 21 import java.util.HashSet; 21 22 import java.util.Iterator; 22 23 import java.util.List; 23 24 import java.util.Map; 24 25 import java.util.Map.Entry; 26 import java.util.Set; 25 27 import java.util.SortedMap; 26 28 import java.util.TreeMap; 27 29 import java.util.TreeSet; … … 221 223 TreeSet<String> treeSet = new TreeSet<>(); 222 224 treeSet.addAll(Files.readAllLines(path, StandardCharsets.UTF_8)); 223 225 treeSet.forEach(ignore -> ignoredErrors.putIfAbsent(ignore, "")); 226 removeLegacyEntries(true); 224 227 225 228 saveIgnoredErrors(); 226 229 Files.deleteIfExists(path); … … 234 237 } catch (SecurityException e) { 235 238 Logging.log(Logging.LEVEL_ERROR, "Unable to load ignored errors", e); 236 239 } 237 // see #19053: remove invalid entry 238 ignoredErrors.remove("3000"); 240 removeLegacyEntries(Config.getPref().get(ValidatorPrefHelper.PREF_IGNORELIST_FORMAT).isEmpty()); 239 241 } 240 242 } 241 243 244 private static void removeLegacyEntries(boolean force) { 245 // see #19053: 246 boolean wasChanged = false; 247 if (force) { 248 Iterator<Entry<String, String>> iter = ignoredErrors.entrySet().iterator(); 249 while (iter.hasNext()) { 250 Entry<String, String> entry = iter.next(); 251 if (entry.getKey().startsWith("3000_")) { 252 Logging.warn(tr("Cannot handle ignore list entry {0}", entry)); 253 iter.remove(); 254 wasChanged = true; 255 } 256 } 257 } 258 String legacyEntry = ignoredErrors.remove("3000"); 259 if (legacyEntry != null) { 260 if (!legacyEntry.isEmpty()) { 261 addIgnoredError("3000_" + legacyEntry, legacyEntry); 262 } 263 wasChanged = true; 264 } 265 if (wasChanged) { 266 saveIgnoredErrors(); 267 } 268 } 269 242 270 /** 243 271 * Adds an ignored error 244 272 * @param s The ignore group / sub group name … … 265 293 * Make sure that we don't keep single entries for a "group ignore". 266 294 */ 267 295 static void cleanupIgnoredErrors() { 296 cleanup3000(); 268 297 if (ignoredErrors.size() > 1) { 269 298 List<String> toRemove = new ArrayList<>(); 270 299 … … 288 317 } 289 318 } 290 319 320 private static void cleanup3000() { 321 // see #19053 322 if (ignoredErrors.size() > 1) { 323 Set<String> toRemove = new HashSet<>(); 324 for (Entry<String, String> entry : ignoredErrors.entrySet()) { 325 if (entry.getKey().equals("3000_" + entry.getValue())) 326 toRemove.add(entry.getValue()); 327 } 328 ignoredErrors.entrySet() 329 .removeIf(e -> toRemove.contains(e.getValue()) && !e.getKey().equals("3000_" + e.getValue())); 330 331 } 332 } 333 291 334 private static boolean sameCode(String key1, String key2) { 292 335 return extractCodeFromIgnoreKey(key1).equals(extractCodeFromIgnoreKey(key2)); 293 336 } … … 482 525 } 483 526 if (list.isEmpty()) list = null; 484 527 Config.getPref().putListOfMaps(ValidatorPrefHelper.PREF_IGNORELIST, list); 528 Config.getPref().put(ValidatorPrefHelper.PREF_IGNORELIST_FORMAT, "2"); 485 529 } 486 530 487 531 /** -
src/org/openstreetmap/josm/data/validation/TestError.java
338 338 * @return The ignore sub group 339 339 */ 340 340 public String getIgnoreSubGroup() { 341 if (code == 3000) { 342 // see #19053 343 return "3000_" + (description == null ? message : description); 344 } 341 345 String ignorestring = getIgnoreGroup(); 342 346 if (descriptionEn != null) { 343 347 ignorestring += '_' + descriptionEn; … … 351 355 * @see TestError#getIgnoreSubGroup() 352 356 */ 353 357 public String getIgnoreGroup() { 358 if (code == 3000) { 359 // see #19053 360 return "3000_" + getMessage(); 361 } 354 362 return Integer.toString(code); 355 363 } 356 364 … … 524 532 public String toString() { 525 533 return "TestError [tester=" + tester + ", code=" + code + ", message=" + message + ']'; 526 534 } 535 527 536 } -
src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java
410 410 411 411 lastSelectedNode = node; 412 412 if (node != null) { 413 final Set<String> codes = new HashSet<>();414 413 ValidatorTreePanel.visitTestErrors(node, error -> { 415 codes.add(error.getIgnoreSubGroup()); // see #19053416 414 error.setSelected(true); 417 415 418 416 hasFixes.set(hasFixes.get() || error.isFixable()); … … 424 422 }); 425 423 selectAction.setEnabled(true); 426 424 if (ignoreAction != null) { 427 ignoreAction.setEnabled(!(node.getUserObject() instanceof Severity) && codes.size() <= 1);425 ignoreAction.setEnabled(!(node.getUserObject() instanceof Severity)); 428 426 } 429 427 } 430 428 -
test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java
144 144 final Collection<TestError> errors = test.getErrorsForPrimitive(p, false); 145 145 assertEquals(1, errors.size()); 146 146 assertEquals("has alt_name but not name", errors.iterator().next().getMessage()); 147 assertEquals("3000_ *[.+_name][!name]", errors.iterator().next().getIgnoreSubGroup());147 assertEquals("3000_has alt_name but not name", errors.iterator().next().getIgnoreSubGroup()); 148 148 } 149 149 150 150 /** … … 159 159 final Collection<TestError> errors = test.getErrorsForPrimitive(p, false); 160 160 assertEquals(1, errors.size()); 161 161 assertEquals("footway used with foot=no", errors.iterator().next().getMessage()); 162 assertEquals("3000_ way[highway=footway][foot]", errors.iterator().next().getIgnoreSubGroup());162 assertEquals("3000_footway used with foot=no", errors.iterator().next().getIgnoreSubGroup()); 163 163 } 164 164 165 165 /** … … 413 413 } 414 414 } 415 415 416 /** 417 * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/19053">Bug #19053</a>. 418 * Mapcss rule with group. 419 * @throws ParseException if a parsing error occurs 420 */ 421 @Test 422 public void testTicket19053() throws ParseException { 423 final MapCSSTagChecker test = buildTagChecker( 424 "*[ele][ele =~ /^-?[0-9]+\\.[0-9][0-9][0-9]+$/] {" 425 + "throwWarning: tr(\"{0}\",\"{0.tag}\");" 426 + "group: tr(\"Unnecessary amount of decimal places\");" + "}"); 427 final OsmPrimitive p = OsmUtils.createPrimitive("node ele=12.123456"); 428 final Collection<TestError> errors = test.getErrorsForPrimitive(p, false); 429 assertEquals(1, errors.size()); 430 assertEquals("Unnecessary amount of decimal places", errors.iterator().next().getMessage()); 431 assertEquals("3000_ele=12.123456", errors.iterator().next().getIgnoreSubGroup()); 432 assertEquals("3000_Unnecessary amount of decimal places", errors.iterator().next().getIgnoreGroup()); 433 } 434 416 435 }
