diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index a1da7f79c..b9f19bc20 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -299,9 +299,9 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) return false; } - if (_settings->xml_version < 0 || _settings->xml_version > 2) { - // We only have xml versions 1 and 2 - PrintMessage("cppcheck: '--xml-version' can only be 1 or 2."); + if (_settings->xml_version != 2) { + // We only have xml version 2 + PrintMessage("cppcheck: '--xml-version' can only be 2."); return false; } @@ -772,14 +772,6 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) PrintMessage("cppcheck: unusedFunction check can't be used with '-j' option. Disabling unusedFunction check."); } - if (_settings->xml) { - // Warn about XML format 1, which will be removed in cppcheck 1.81 - if (_settings->xml_version == 1U) - PrintMessage("cppcheck: XML format version 1 is deprecated and will be removed in cppcheck 1.81. Use '--xml-version=2'."); - if (_settings->inconclusive && _settings->xml_version == 1U) - PrintMessage("cppcheck: inconclusive messages will not be shown, because the old xml format is not compatible."); - } - if (argc <= 1) { _showHelp = true; _exitAfterPrint = true; diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 3a6c3b1f7..b59311696 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -105,9 +105,9 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c if (parser.GetShowErrorMessages()) { errorlist = true; - std::cout << ErrorLogger::ErrorMessage::getXMLHeader(settings.xml_version); + std::cout << ErrorLogger::ErrorMessage::getXMLHeader(); cppcheck->getErrorMessages(); - std::cout << ErrorLogger::ErrorMessage::getXMLFooter(settings.xml_version) << std::endl; + std::cout << ErrorLogger::ErrorMessage::getXMLFooter() << std::endl; } if (parser.ExitAfterPrinting()) { @@ -830,7 +830,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha } if (settings.xml) { - reportErr(ErrorLogger::ErrorMessage::getXMLHeader(settings.xml_version)); + reportErr(ErrorLogger::ErrorMessage::getXMLHeader()); } if (!settings.buildDir.empty()) { @@ -927,7 +927,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha } if (settings.xml) { - reportErr(ErrorLogger::ErrorMessage::getXMLFooter(settings.xml_version)); + reportErr(ErrorLogger::ErrorMessage::getXMLFooter()); } _settings = 0; @@ -998,9 +998,9 @@ void CppCheckExecutor::reportStatus(std::size_t fileindex, std::size_t filecount void CppCheckExecutor::reportErr(const ErrorLogger::ErrorMessage &msg) { if (errorlist) { - reportOut(msg.toXML(false, _settings->xml_version)); + reportOut(msg.toXML()); } else if (_settings->xml) { - reportErr(msg.toXML(_settings->verbose, _settings->xml_version)); + reportErr(msg.toXML()); } else { reportErr(msg.toString(_settings->verbose, _settings->outputFormat)); } diff --git a/lib/analyzerinfo.cpp b/lib/analyzerinfo.cpp index 425297731..bb464cd10 100644 --- a/lib/analyzerinfo.cpp +++ b/lib/analyzerinfo.cpp @@ -148,10 +148,10 @@ bool AnalyzerInformation::analyzeFile(const std::string &buildDir, const std::st return true; } -void AnalyzerInformation::reportErr(const ErrorLogger::ErrorMessage &msg, bool verbose) +void AnalyzerInformation::reportErr(const ErrorLogger::ErrorMessage &msg, bool /*verbose*/) { if (fout.is_open()) - fout << msg.toXML(verbose,2) << '\n'; + fout << msg.toXML() << '\n'; } void AnalyzerInformation::setFileInfo(const std::string &check, const std::string &fileInfo) diff --git a/lib/check.cpp b/lib/check.cpp index 77cb21fde..2863bc991 100644 --- a/lib/check.cpp +++ b/lib/check.cpp @@ -38,7 +38,7 @@ Check::Check(const std::string &aname) void Check::reportError(const ErrorLogger::ErrorMessage &errmsg) { - std::cout << errmsg.toXML(true, 1) << std::endl; + std::cout << errmsg.toXML() << std::endl; } bool Check::wrongData(const Token *tok, bool condition, const char *str) diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index e864b99e4..b0fcb721f 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -287,7 +287,7 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data) return true; } -std::string ErrorLogger::ErrorMessage::getXMLHeader(int xml_version) +std::string ErrorLogger::ErrorMessage::getXMLHeader() { // xml_version 1 is the default xml format @@ -298,21 +298,19 @@ std::string ErrorLogger::ErrorMessage::getXMLHeader(int xml_version) // header printer.OpenElement("results", false); - // version 2 header - if (xml_version == 2) { - printer.PushAttribute("version", xml_version); - printer.OpenElement("cppcheck", false); - printer.PushAttribute("version", CppCheck::version()); - printer.CloseElement(false); - printer.OpenElement("errors", false); - } + + printer.PushAttribute("version", 2); + printer.OpenElement("cppcheck", false); + printer.PushAttribute("version", CppCheck::version()); + printer.CloseElement(false); + printer.OpenElement("errors", false); return std::string(printer.CStr()) + '>'; } -std::string ErrorLogger::ErrorMessage::getXMLFooter(int xml_version) +std::string ErrorLogger::ErrorMessage::getXMLFooter() { - return (xml_version<=1) ? "" : " \n"; + return " \n"; } // There is no utf-8 support around but the strings should at least be safe for to tinyxml2. @@ -337,55 +335,31 @@ std::string ErrorLogger::ErrorMessage::fixInvalidChars(const std::string& raw) return result; } -std::string ErrorLogger::ErrorMessage::toXML(bool verbose, int version) const +std::string ErrorLogger::ErrorMessage::toXML() const { - // The default xml format - if (version == 1) { - // No inconclusive messages in the xml version 1 - if (_inconclusive) - return ""; + tinyxml2::XMLPrinter printer(0, false, 2); + printer.OpenElement("error", false); + printer.PushAttribute("id", _id.c_str()); + printer.PushAttribute("severity", Severity::toString(_severity).c_str()); + printer.PushAttribute("msg", fixInvalidChars(_shortMessage).c_str()); + printer.PushAttribute("verbose", fixInvalidChars(_verboseMessage).c_str()); + if (_cwe.id) + printer.PushAttribute("cwe", _cwe.id); + if (_inconclusive) + printer.PushAttribute("inconclusive", "true"); - tinyxml2::XMLPrinter printer(0, false, 1); - printer.OpenElement("error", false); - if (!_callStack.empty()) { - printer.PushAttribute("file", _callStack.back().getfile().c_str()); - printer.PushAttribute("line", _callStack.back().line); - } - printer.PushAttribute("id", _id.c_str()); - printer.PushAttribute("severity", (_severity == Severity::error ? "error" : "style")); - printer.PushAttribute("msg", fixInvalidChars(verbose ? _verboseMessage : _shortMessage).c_str()); + for (std::list::const_reverse_iterator it = _callStack.rbegin(); it != _callStack.rend(); ++it) { + printer.OpenElement("location", false); + if (!file0.empty() && (*it).getfile() != file0) + printer.PushAttribute("file0", Path::toNativeSeparators(file0).c_str()); + printer.PushAttribute("file", (*it).getfile().c_str()); + printer.PushAttribute("line", (*it).line); + if (!it->getinfo().empty()) + printer.PushAttribute("info", it->getinfo().c_str()); printer.CloseElement(false); - return printer.CStr(); } - - // The xml format you get when you use --xml-version=2 - else if (version == 2) { - tinyxml2::XMLPrinter printer(0, false, 2); - printer.OpenElement("error", false); - printer.PushAttribute("id", _id.c_str()); - printer.PushAttribute("severity", Severity::toString(_severity).c_str()); - printer.PushAttribute("msg", fixInvalidChars(_shortMessage).c_str()); - printer.PushAttribute("verbose", fixInvalidChars(_verboseMessage).c_str()); - if (_cwe.id) - printer.PushAttribute("cwe", _cwe.id); - if (_inconclusive) - printer.PushAttribute("inconclusive", "true"); - - for (std::list::const_reverse_iterator it = _callStack.rbegin(); it != _callStack.rend(); ++it) { - printer.OpenElement("location", false); - if (!file0.empty() && (*it).getfile() != file0) - printer.PushAttribute("file0", Path::toNativeSeparators(file0).c_str()); - printer.PushAttribute("file", (*it).getfile().c_str()); - printer.PushAttribute("line", (*it).line); - if (!it->getinfo().empty()) - printer.PushAttribute("info", it->getinfo().c_str()); - printer.CloseElement(false); - } - printer.CloseElement(false); - return printer.CStr(); - } - - return ""; + printer.CloseElement(false); + return printer.CStr(); } void ErrorLogger::ErrorMessage::findAndReplace(std::string &source, const std::string &searchFor, const std::string &replaceWith) diff --git a/lib/errorlogger.h b/lib/errorlogger.h index 5a0f8a6f7..2569f6c77 100644 --- a/lib/errorlogger.h +++ b/lib/errorlogger.h @@ -247,13 +247,11 @@ public: /** * Format the error message in XML format - * @param verbose use verbose message - * @param version XML version */ - std::string toXML(bool verbose, int version) const; + std::string toXML() const; - static std::string getXMLHeader(int xml_version); - static std::string getXMLFooter(int xml_version); + static std::string getXMLHeader(); + static std::string getXMLFooter(); /** * Format the error message into a string. diff --git a/lib/settings.cpp b/lib/settings.cpp index 0f9f0ce2d..f978d29e6 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -37,7 +37,7 @@ Settings::Settings() verbose(false), force(false), relativePaths(false), - xml(false), xml_version(1), + xml(false), xml_version(2), jobs(1), loadAverage(0), exitCode(0), diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index 21d1079ae..4791a4e71 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -118,7 +118,6 @@ private: TEST_CASE(templatesVs); TEST_CASE(templatesEdit); TEST_CASE(xml); - TEST_CASE(xmlver1); TEST_CASE(xmlver2); TEST_CASE(xmlver2both); TEST_CASE(xmlver2both2); @@ -834,16 +833,6 @@ private: ASSERT_EQUALS(1, settings.xml_version); } - void xmlver1() { - REDIRECT; - const char *argv[] = {"cppcheck", "--xml-version=1", "file.cpp"}; - settings.xml_version = 1; - settings.xml = false; - ASSERT(defParser.ParseFromArgs(3, argv)); - ASSERT(settings.xml); - ASSERT_EQUALS(1, settings.xml_version); - } - void xmlver2() { REDIRECT; const char *argv[] = {"cppcheck", "--xml-version=2", "file.cpp"}; diff --git a/test/testerrorlogger.cpp b/test/testerrorlogger.cpp index e158cbe73..af5cf2e89 100644 --- a/test/testerrorlogger.cpp +++ b/test/testerrorlogger.cpp @@ -46,10 +46,6 @@ private: TEST_CASE(CustomFormat); TEST_CASE(CustomFormat2); TEST_CASE(CustomFormatLocations); - TEST_CASE(ToXml); - TEST_CASE(ToXmlLocations); - TEST_CASE(ToVerboseXml); - TEST_CASE(ToVerboseXmlLocations); TEST_CASE(ToXmlV2); TEST_CASE(ToXmlV2Locations); TEST_CASE(ToXmlV2Encoding); @@ -190,42 +186,6 @@ private: ASSERT_EQUALS("Verbose error - bar.cpp(8):(error,errorId)", msg.toString(true, "{message} - {file}({line}):({severity},{id})")); } - void ToXml() const { - std::list locs(1, fooCpp5); - ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false); - ASSERT_EQUALS("\n", ErrorLogger::ErrorMessage::getXMLHeader(1)); - ASSERT_EQUALS("", ErrorLogger::ErrorMessage::getXMLFooter(1)); - ASSERT_EQUALS(" ", msg.toXML(false,1)); - } - - void ToXmlLocations() const { - std::list locs; - locs.push_back(fooCpp5); - locs.push_back(barCpp8); - ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false); - ASSERT_EQUALS("\n", ErrorLogger::ErrorMessage::getXMLHeader(1)); - ASSERT_EQUALS("", ErrorLogger::ErrorMessage::getXMLFooter(1)); - ASSERT_EQUALS(" ", msg.toXML(false,1)); - } - - void ToVerboseXml() const { - std::list locs(1, fooCpp5); - ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false); - ASSERT_EQUALS("\n", ErrorLogger::ErrorMessage::getXMLHeader(1)); - ASSERT_EQUALS("", ErrorLogger::ErrorMessage::getXMLFooter(1)); - ASSERT_EQUALS(" ", msg.toXML(true,1)); - } - - void ToVerboseXmlLocations() const { - std::list locs; - locs.push_back(fooCpp5); - locs.push_back(barCpp8); - ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false); - ASSERT_EQUALS("\n", ErrorLogger::ErrorMessage::getXMLHeader(1)); - ASSERT_EQUALS("", ErrorLogger::ErrorMessage::getXMLFooter(1)); - ASSERT_EQUALS(" ", msg.toXML(true,1)); - } - void ToXmlV2() const { std::list locs(1, fooCpp5); ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false); @@ -233,12 +193,12 @@ private: header += " \n "; - ASSERT_EQUALS(header, ErrorLogger::ErrorMessage::getXMLHeader(2)); - ASSERT_EQUALS(" \n", ErrorLogger::ErrorMessage::getXMLFooter(2)); + ASSERT_EQUALS(header, ErrorLogger::ErrorMessage::getXMLHeader()); + ASSERT_EQUALS(" \n", ErrorLogger::ErrorMessage::getXMLFooter()); std::string message(" \n"; message += " \n "; - ASSERT_EQUALS(message, msg.toXML(false, 2)); + ASSERT_EQUALS(message, msg.toXML()); } void ToXmlV2Locations() const { @@ -250,30 +210,30 @@ private: header += " \n "; - ASSERT_EQUALS(header, ErrorLogger::ErrorMessage::getXMLHeader(2)); - ASSERT_EQUALS(" \n", ErrorLogger::ErrorMessage::getXMLFooter(2)); + ASSERT_EQUALS(header, ErrorLogger::ErrorMessage::getXMLHeader()); + ASSERT_EQUALS(" \n", ErrorLogger::ErrorMessage::getXMLFooter()); std::string message(" \n"; message += " \n"; message += " \n "; - ASSERT_EQUALS(message, msg.toXML(false, 2)); + ASSERT_EQUALS(message, msg.toXML()); } void ToXmlV2Encoding() const { { std::list locs; ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nComparing \"\203\" with \"\003\"", "errorId", false); - const std::string message(" "); - ASSERT_EQUALS(message, msg.toXML(false, 2)); + const std::string expected(" "); + ASSERT_EQUALS(expected, msg.toXML()); } { const char code1[]="äöü"; const char code2[]="\x12\x00\x00\x01"; std::list locs; ErrorMessage msg1(locs, emptyString, Severity::error, std::string("Programming error.\nReading \"")+code1+"\"", "errorId", false); - ASSERT_EQUALS(" ", msg1.toXML(false, 2)); + ASSERT_EQUALS(" ", msg1.toXML()); ErrorMessage msg2(locs, emptyString, Severity::error, std::string("Programming error.\nReading \"")+code2+"\"", "errorId", false); - ASSERT_EQUALS(" ", msg2.toXML(false, 2)); + ASSERT_EQUALS(" ", msg2.toXML()); } } @@ -284,14 +244,11 @@ private: // Inconclusive error message ErrorMessage msg(locs, emptyString, Severity::error, "Programming error", "errorId", true); - // Don't save inconclusive messages if the xml version is 1 - ASSERT_EQUALS("", msg.toXML(false, 1)); - // xml version 2 error message ASSERT_EQUALS(" \n" " \n" " ", - msg.toXML(false, 2)); + msg.toXML()); } void SerializeInconclusiveMessage() const {