From 4ea77f65da718494bc32570b5110f74654dd0231 Mon Sep 17 00:00:00 2001 From: guwirth Date: Sat, 21 Feb 2015 21:53:50 +0100 Subject: [PATCH] mark inconclusive messages in cppcheck V2 - add [inconclusive] at the beginning of the message - close #247 --- .../plugins/cxx/cppcheck/CppcheckParserV2.java | 14 +++++++++++++- .../cxx/cppcheck/CxxCppCheckSensorTest.java | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/cppcheck/CppcheckParserV2.java b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/cppcheck/CppcheckParserV2.java index 00d53d4b1e..da8e8f0a55 100644 --- a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/cppcheck/CppcheckParserV2.java +++ b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/cppcheck/CppcheckParserV2.java @@ -72,7 +72,10 @@ public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException { SMInputCursor errorCursor = errorsCursor.childElementCursor("error"); while (errorCursor.getNext() != null) { String id = errorCursor.getAttrValue("id"); - String msg = errorCursor.getAttrValue("msg"); + String msg = createMsg( + errorCursor.getAttrValue("inconclusive"), + errorCursor.getAttrValue("msg") + ); String file = null; String line = null; @@ -99,6 +102,15 @@ public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException { } } + private String createMsg(String inconclusive, String msg) { + if (!StringUtils.isEmpty(msg)) { + if (!StringUtils.isEmpty(inconclusive) && "true".equals(inconclusive)) { + return "[inconclusive] " + msg; + } + } + return msg; + } + private boolean isInputValid(String file, String line, String id, String msg) { return !StringUtils.isEmpty(id) && !StringUtils.isEmpty(msg); } diff --git a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/cppcheck/CxxCppCheckSensorTest.java b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/cppcheck/CxxCppCheckSensorTest.java index 49af23e0ac..fe50c0c0c9 100644 --- a/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/cppcheck/CxxCppCheckSensorTest.java +++ b/sonar-cxx-plugin/src/test/java/org/sonar/plugins/cxx/cppcheck/CxxCppCheckSensorTest.java @@ -67,7 +67,7 @@ public void setUp() { @Test public void shouldReportCorrectViolations() { sensor.analyse(project, context); - verify(issuable, times(5)).addIssue(any(Issue.class)); + verify(issuable, times(7)).addIssue(any(Issue.class)); } @Test