Changeset 16088 in josm
- Timestamp:
- 2020-03-08T20:15:37+01:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/ValidatorErrorWriter.java
r15735 r16088 3 3 4 4 import java.io.BufferedWriter; 5 import java.io.IOException; 5 6 import java.io.OutputStream; 6 7 import java.io.OutputStreamWriter; … … 60 61 * Write validator errors to designated output target 61 62 * @param validationErrors Test error collection to write 63 * @throws IOException in case of I/O error 62 64 */ 63 public void write(Collection<TestError> validationErrors) {65 public void write(Collection<TestError> validationErrors) throws IOException { 64 66 Set<Test> analysers = validationErrors.stream().map(TestError::getTester).collect(Collectors.toCollection(TreeSet::new)); 65 67 String timestamp = DateUtils.fromDate(new Date()); … … 68 70 out.println("<analysers generator='JOSM' timestamp='"+timestamp+"'>"); 69 71 70 OsmWriter osmWriter = OsmWriterFactory.createOsmWriter(out, true, OsmChangeBuilder.DEFAULT_API_VERSION);71 String lang = LanguageInfo.getJOSMLocaleCode();72 try (OsmWriter osmWriter = OsmWriterFactory.createOsmWriter(out, true, OsmChangeBuilder.DEFAULT_API_VERSION)) { 73 String lang = LanguageInfo.getJOSMLocaleCode(); 72 74 73 for (Test test : analysers) { 74 out.println(" <analyser timestamp='"+timestamp+"' name='"+XmlWriter.encode(test.getName())+"'>"); 75 // Build map of test error classes for the current test 76 Map<ErrorClass, List<TestError>> map = new HashMap<>(); 77 for (Entry<Severity, Map<String, Map<String, List<TestError>>>> e1 : 78 OsmValidator.getErrorsBySeverityMessageDescription(validationErrors, e -> e.getTester() == test).entrySet()) { 79 for (Entry<String, Map<String, List<TestError>>> e2 : e1.getValue().entrySet()) { 80 ErrorClass errorClass = new ErrorClass(e1.getKey(), e2.getKey()); 81 List<TestError> list = map.get(errorClass); 82 if (list == null) { 83 list = new ArrayList<>(); 84 map.put(errorClass, list); 75 for (Test test : analysers) { 76 out.println(" <analyser timestamp='" + timestamp + "' name='" + XmlWriter.encode(test.getName()) + "'>"); 77 // Build map of test error classes for the current test 78 Map<ErrorClass, List<TestError>> map = new HashMap<>(); 79 for (Entry<Severity, Map<String, Map<String, List<TestError>>>> e1 : 80 OsmValidator.getErrorsBySeverityMessageDescription(validationErrors, e -> e.getTester() == test).entrySet()) { 81 for (Entry<String, Map<String, List<TestError>>> e2 : e1.getValue().entrySet()) { 82 ErrorClass errorClass = new ErrorClass(e1.getKey(), e2.getKey()); 83 List<TestError> list = map.get(errorClass); 84 if (list == null) { 85 list = new ArrayList<>(); 86 map.put(errorClass, list); 87 } 88 e2.getValue().values().forEach(list::addAll); 85 89 } 86 e2.getValue().values().forEach(list::addAll);87 90 } 91 // Write classes 92 for (ErrorClass ec : map.keySet()) { 93 out.println(" <class id='" + ec.id + "' level='" + ec.severity.getLevel() + "'>"); 94 out.println(" <classtext lang='" + XmlWriter.encode(lang) + "' title='" + XmlWriter.encode(ec.message) + "'/>"); 95 out.println(" </class>"); 96 } 97 98 // Write errors 99 for (Entry<ErrorClass, List<TestError>> entry : map.entrySet()) { 100 for (TestError error : entry.getValue()) { 101 LatLon ll = error.getPrimitives().iterator().next().getBBox().getCenter(); 102 out.println(" <error class='" + entry.getKey().id + "'>"); 103 out.print(" <location"); 104 osmWriter.writeLatLon(ll); 105 out.println("/>"); 106 for (OsmPrimitive p : error.getPrimitives()) { 107 p.accept(osmWriter); 108 } 109 out.println(" <text lang='" + XmlWriter.encode(lang) + 110 "' value='" + XmlWriter.encode(error.getDescription()) + "'/>"); 111 if (error.isFixable()) { 112 out.println(" <fixes>"); 113 Command fix = error.getFix(); 114 if (fix instanceof AddPrimitivesCommand) { 115 Logging.info("TODO: {0}", fix); 116 } else if (fix instanceof DeleteCommand) { 117 Logging.info("TODO: {0}", fix); 118 } else if (fix instanceof ChangePropertyCommand) { 119 Logging.info("TODO: {0}", fix); 120 } else if (fix instanceof ChangePropertyKeyCommand) { 121 Logging.info("TODO: {0}", fix); 122 } else { 123 Logging.warn("Unsupported command type: {0}", fix); 124 } 125 out.println(" </fixes>"); 126 } 127 out.println(" </error>"); 128 } 129 } 130 131 out.println(" </analyser>"); 88 132 } 89 // Write classes90 for (ErrorClass ec : map.keySet()) {91 out.println(" <class id='"+ec.id+"' level='"+ec.severity.getLevel()+"'>");92 out.println(" <classtext lang='"+XmlWriter.encode(lang)+"' title='"+XmlWriter.encode(ec.message)+"'/>");93 out.println(" </class>");94 }95 96 // Write errors97 for (Entry<ErrorClass, List<TestError>> entry : map.entrySet()) {98 for (TestError error : entry.getValue()) {99 LatLon ll = error.getPrimitives().iterator().next().getBBox().getCenter();100 out.println(" <error class='"+entry.getKey().id+"'>");101 out.print(" <location");102 osmWriter.writeLatLon(ll);103 out.println("/>");104 for (OsmPrimitive p : error.getPrimitives()) {105 p.accept(osmWriter);106 }107 out.println(" <text lang='"+XmlWriter.encode(lang)+"' value='"+XmlWriter.encode(error.getDescription())+"'/>");108 if (error.isFixable()) {109 out.println(" <fixes>");110 Command fix = error.getFix();111 if (fix instanceof AddPrimitivesCommand) {112 Logging.info("TODO: {0}", fix);113 } else if (fix instanceof DeleteCommand) {114 Logging.info("TODO: {0}", fix);115 } else if (fix instanceof ChangePropertyCommand) {116 Logging.info("TODO: {0}", fix);117 } else if (fix instanceof ChangePropertyKeyCommand) {118 Logging.info("TODO: {0}", fix);119 } else {120 Logging.warn("Unsupported command type: {0}", fix);121 }122 out.println(" </fixes>");123 }124 out.println(" </error>");125 }126 }127 128 out.println(" </analyser>");129 133 } 130 134
Note:
See TracChangeset
for help on using the changeset viewer.