xml2: replace --xml2 with --xmlver=2. Ticket: #2106

This commit is contained in:
Daniel Marjamäki 2010-12-02 17:32:51 +01:00
parent 12c8eeff2c
commit af80384ae7
10 changed files with 31 additions and 28 deletions

View File

@ -144,8 +144,11 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
#ifndef NDEBUG
// Experimental: Write results in xml2 format
else if (strcmp(argv[i], "--xml2") == 0)
_settings->_xml2 = true;
else if (strcmp(argv[i], "--xmlver=2") == 0)
{
_settings->_xml = true;
_settings->_xml_version = 2;
}
#endif
// Only print something when there are errors

View File

@ -95,11 +95,7 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
_settings = cppCheck.settings();
if (_settings._xml)
{
reportErr(ErrorLogger::ErrorMessage::getXMLHeader(""));
}
else if (_settings._xml2)
{
reportErr(ErrorLogger::ErrorMessage::getXMLHeader(" version=\"2\""));
reportErr(ErrorLogger::ErrorMessage::getXMLHeader(_settings._xml_version));
}
unsigned int returnValue = 0;
@ -121,7 +117,7 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
returnValue = executor.check();
}
if (_settings._xml || _settings._xml2)
if (_settings._xml)
{
reportErr(ErrorLogger::ErrorMessage::getXMLFooter());
}
@ -186,9 +182,9 @@ void CppCheckExecutor::reportStatus(unsigned int index, unsigned int max)
void CppCheckExecutor::reportErr(const ErrorLogger::ErrorMessage &msg)
{
if (_settings._xml || _settings._xml2)
if (_settings._xml)
{
reportErr(msg.toXML(_settings._verbose, _settings._xml2));
reportErr(msg.toXML(_settings._verbose, _settings._xml_version));
}
else
{

View File

@ -110,7 +110,7 @@ public:
*/
static void reportError(const ErrorLogger::ErrorMessage &errmsg)
{
std::cout << errmsg.toXML(true, false) << std::endl;
std::cout << errmsg.toXML(true, 1) << std::endl;
}
protected:

View File

@ -363,7 +363,7 @@ void CppCheck::reportStatus(unsigned int /*index*/, unsigned int /*max*/)
void CppCheck::getErrorMessages()
{
// call all "getErrorMessages" in all registered Check classes
std::cout << ErrorLogger::ErrorMessage::getXMLHeader("");
std::cout << ErrorLogger::ErrorMessage::getXMLHeader(1);
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
{
(*it)->getErrorMessages();

View File

@ -129,10 +129,14 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
return true;
}
std::string ErrorLogger::ErrorMessage::getXMLHeader(const std::string &ver)
std::string ErrorLogger::ErrorMessage::getXMLHeader(int version)
{
std::ostringstream strver;
if (version > 1)
strver << " version=\"" << version << "\"";
return "<?xml version=\"1.0\"?>\n"
"<results" + ver + ">";
"<results" + strver.str() + ">";
}
std::string ErrorLogger::ErrorMessage::getXMLFooter()
@ -161,11 +165,11 @@ static std::string stringToXml(std::string s)
return s;
}
std::string ErrorLogger::ErrorMessage::toXML(bool verbose, bool xml2) const
std::string ErrorLogger::ErrorMessage::toXML(bool verbose, int version) const
{
std::ostringstream xml;
if (!xml2)
if (version == 1)
{
xml << "<error";
if (!_callStack.empty())
@ -178,7 +182,7 @@ std::string ErrorLogger::ErrorMessage::toXML(bool verbose, bool xml2) const
xml << " msg=\"" << stringToXml(verbose ? _verboseMessage : _shortMessage) << "\"";
xml << "/>";
}
else
else if (version == 2)
{
xml << " <error";
xml << " id=\"" << _id << "\"";

View File

@ -124,11 +124,11 @@ public:
/**
* Format the error message in XML format
* @param verbose use verbose message
* @param xml2 use xml2 format
* @param ver xml version
*/
std::string toXML(bool verbose, bool xml2) const;
std::string toXML(bool verbose, int ver) const;
static std::string getXMLHeader(const std::string &ver);
static std::string getXMLHeader(int ver);
static std::string getXMLFooter();
/**

View File

@ -2403,11 +2403,11 @@ void Preprocessor::getErrorMessages(std::ostream &ostr)
Severity::style,
"Include file: \"\" not found.",
"missingInclude");
ostr << errmsg.toXML(false, false) << std::endl;
ostr << errmsg.toXML(false, 1) << std::endl;
const ErrorLogger::ErrorMessage errmsg2(locationList,
Severity::error,
"#error ...",
"preprocessorErrorDirective");
ostr << errmsg2.toXML(false, false) << std::endl;
ostr << errmsg2.toXML(false, 1) << std::endl;
}

View File

@ -35,7 +35,7 @@ Settings::Settings()
_verbose = false;
_force = false;
_xml = false;
_xml2 = false;
_xml_version = 1;
_jobs = 1;
_exitCode = 0;
_showtime = 0; // TODO: use enum

View File

@ -87,8 +87,8 @@ public:
/** @brief write xml results (--xml) */
bool _xml;
/** @brief write xml2 results (--xml2) */
bool _xml2;
/** @brief xml version (--xmlver=..) */
bool _xml_version;
/** @brief How many processes/threads should do checking at the same
time. Default is 1. (-j N) */

View File

@ -389,7 +389,7 @@ private:
// Test the errorlogger..
ErrorLogger::ErrorMessage errorMessage;
errorMessage.setmsg("ab<cd>ef");
ASSERT_EQUALS("<error id=\"\" severity=\"style\" msg=\"ab&lt;cd&gt;ef\"/>", errorMessage.toXML(false,false));
ASSERT_EQUALS("<error id=\"\" severity=\"style\" msg=\"ab&lt;cd&gt;ef\"/>", errorMessage.toXML(false,1));
}
@ -400,7 +400,7 @@ private:
loc.setfile("ab/cd/../ef.h");
errorMessage._callStack.push_back(loc);
const std::string fname(Path::toNativeSeparators("ab/ef.h"));
ASSERT_EQUALS("<error file=\"" + fname + "\" line=\"0\" id=\"\" severity=\"style\" msg=\"\"/>", errorMessage.toXML(false,false));
ASSERT_EQUALS("<error file=\"" + fname + "\" line=\"0\" id=\"\" severity=\"style\" msg=\"\"/>", errorMessage.toXML(false,1));
ASSERT_EQUALS("[" + fname + ":0]: ", errorMessage.toString(false));
}
@ -415,7 +415,7 @@ private:
errorMessage._severity = Severity::fromString("error");
errorMessage.setmsg("long testMessage");
const std::string fname(Path::toNativeSeparators("some/{file}file.cpp"));
ASSERT_EQUALS("<error file=\"" + fname + "\" line=\"10\" id=\"testId\" severity=\"error\" msg=\"long testMessage\"/>", errorMessage.toXML(false,false));
ASSERT_EQUALS("<error file=\"" + fname + "\" line=\"10\" id=\"testId\" severity=\"error\" msg=\"long testMessage\"/>", errorMessage.toXML(false,1));
ASSERT_EQUALS("[" + fname + ":10]: (error) long testMessage", errorMessage.toString(false));
ASSERT_EQUALS("testId-" + fname + ",error.10?{long testMessage}", errorMessage.toString(false, "{id}-{file},{severity}.{line}?{{message}}"));
}