diff --git a/CHANGES.md b/CHANGES.md index 221e1651..1aa42778 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ - Added CHANGES.md - Added a reset function for checks ([#279](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/279)) - Added unittest for [#78](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/78) + - Fixed XMLReporter output after introducing multithreading in 2.2.0 - Updated formula for number of pre-parsed files [#386](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/386) - Removed conditional section for unittest [#181](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/181) diff --git a/src/checkstyle/reporter/XMLReporter.hx b/src/checkstyle/reporter/XMLReporter.hx index fffd9452..8f2d82c7 100644 --- a/src/checkstyle/reporter/XMLReporter.hx +++ b/src/checkstyle/reporter/XMLReporter.hx @@ -4,6 +4,8 @@ class XMLReporter extends BaseReporter { var style:String; + var messageCache:Map>; + /* * Solution from mustache.js * https://github.com/janl/mustache.js/blob/master/mustache.js#L49 @@ -21,6 +23,7 @@ class XMLReporter extends BaseReporter { public function new(numFiles:Int, checkCount:Int, usedCheckCount:Int, path:String, s:String, ns:Bool) { super(numFiles, checkCount, usedCheckCount, path, ns); + messageCache = new Map>(); style = s; } @@ -49,15 +52,17 @@ class XMLReporter extends BaseReporter { } override public function fileStart(f:CheckFile) { - var sb = new StringBuf(); - sb.add("\t\n"); - if (file != null) report.add(sb.toString()); + messageCache.set(f.name, []); } override public function fileFinish(f:CheckFile) { var sb = new StringBuf(); + sb.add("\t\n"); + var messages:Array = messageCache.get(f.name); + for (m in messages) sb.add(formatMessage(m)); + messageCache.remove(f.name); sb.add("\t\n"); if (file != null) report.add(sb.toString()); } @@ -73,6 +78,11 @@ class XMLReporter extends BaseReporter { } override public function addMessage(m:CheckMessage) { + if (!messageCache.exists(m.fileName)) messageCache.set(m.fileName, [m]); + else messageCache.get(m.fileName).push(m); + } + + function formatMessage(m:CheckMessage):String { var sb:StringBuf = new StringBuf(); sb.add("\t\t