Cppcheck: Write product name if provided in xml output

This commit is contained in:
Daniel Marjamäki 2022-07-07 17:35:13 +02:00
parent 68bb724dcc
commit d1812c8022
4 changed files with 8 additions and 6 deletions

View File

@ -122,7 +122,7 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
if (parser.getShowErrorMessages()) {
mShowAllErrors = true;
std::cout << ErrorMessage::getXMLHeader();
std::cout << ErrorMessage::getXMLHeader(settings.cppcheckCfgProductName);
cppcheck->getErrorMessages();
std::cout << ErrorMessage::getXMLFooter() << std::endl;
}
@ -908,7 +908,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck)
}
if (settings.xml) {
reportErr(ErrorMessage::getXMLHeader());
reportErr(ErrorMessage::getXMLHeader(settings.cppcheckCfgProductName));
}
if (!settings.buildDir.empty()) {

View File

@ -368,7 +368,7 @@ bool ErrorMessage::deserialize(const std::string &data)
return true;
}
std::string ErrorMessage::getXMLHeader()
std::string ErrorMessage::getXMLHeader(const std::string& productName)
{
tinyxml2::XMLPrinter printer;
@ -380,6 +380,8 @@ std::string ErrorMessage::getXMLHeader()
printer.PushAttribute("version", 2);
printer.OpenElement("cppcheck", false);
if (!productName.empty())
printer.PushAttribute("product-name", productName.c_str());
printer.PushAttribute("version", CppCheck::version());
printer.CloseElement(false);
printer.OpenElement("errors", false);

View File

@ -160,7 +160,7 @@ public:
*/
std::string toXML() const;
static std::string getXMLHeader();
static std::string getXMLHeader(const std::string& productName);
static std::string getXMLFooter();
/**

View File

@ -192,7 +192,7 @@ private:
header += " <cppcheck version=\"";
header += CppCheck::version();
header += "\"/>\n <errors>";
ASSERT_EQUALS(header, ErrorMessage::getXMLHeader());
ASSERT_EQUALS(header, ErrorMessage::getXMLHeader(""));
ASSERT_EQUALS(" </errors>\n</results>", ErrorMessage::getXMLFooter());
std::string message(" <error id=\"errorId\" severity=\"error\"");
message += " msg=\"Programming error.\" verbose=\"Verbose error\">\n";
@ -208,7 +208,7 @@ private:
header += " <cppcheck version=\"";
header += CppCheck::version();
header += "\"/>\n <errors>";
ASSERT_EQUALS(header, ErrorMessage::getXMLHeader());
ASSERT_EQUALS(header, ErrorMessage::getXMLHeader(""));
ASSERT_EQUALS(" </errors>\n</results>", ErrorMessage::getXMLFooter());
std::string message(" <error id=\"errorId\" severity=\"error\"");
message += " msg=\"Programming error.\" verbose=\"Verbose error\">\n";