CppcheckExecutor: use dedicated ErrorLogger for printing error messages XML (#4985)
This starts to untangle the `ErrorLogger` implementation in `CppcheckExecutor` which handles three different cases and makes things unnecessarily complicated.
This commit is contained in:
parent
5ea1bca99f
commit
f1749ab7ad
|
@ -67,8 +67,23 @@
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO: do not directly write to stdout
|
class XMLErrorMessagesLogger : public ErrorLogger
|
||||||
|
{
|
||||||
|
void reportOut(const std::string & outmsg, Color /*c*/ = Color::Reset) override
|
||||||
|
{
|
||||||
|
std::cout << outmsg << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void reportErr(const ErrorMessage &msg) override
|
||||||
|
{
|
||||||
|
reportOut(msg.toXML());
|
||||||
|
}
|
||||||
|
|
||||||
|
void reportProgress(const std::string & /*filename*/, const char /*stage*/[], const std::size_t /*value*/) override
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: do not directly write to stdout
|
||||||
|
|
||||||
/*static*/ FILE* CppCheckExecutor::mExceptionOutput = stdout;
|
/*static*/ FILE* CppCheckExecutor::mExceptionOutput = stdout;
|
||||||
|
|
||||||
|
@ -97,9 +112,9 @@ bool CppCheckExecutor::parseFromArgs(Settings &settings, int argc, const char* c
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parser.getShowErrorMessages()) {
|
if (parser.getShowErrorMessages()) {
|
||||||
mShowAllErrors = true;
|
XMLErrorMessagesLogger xmlLogger;
|
||||||
std::cout << ErrorMessage::getXMLHeader(settings.cppcheckCfgProductName);
|
std::cout << ErrorMessage::getXMLHeader(settings.cppcheckCfgProductName);
|
||||||
CppCheck::getErrorMessages(*this);
|
CppCheck::getErrorMessages(xmlLogger);
|
||||||
std::cout << ErrorMessage::getXMLFooter() << std::endl;
|
std::cout << ErrorMessage::getXMLFooter() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -409,11 +424,6 @@ void CppCheckExecutor::reportProgress(const std::string &filename, const char st
|
||||||
|
|
||||||
void CppCheckExecutor::reportErr(const ErrorMessage &msg)
|
void CppCheckExecutor::reportErr(const ErrorMessage &msg)
|
||||||
{
|
{
|
||||||
if (mShowAllErrors) {
|
|
||||||
reportOut(msg.toXML());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(mSettings != nullptr);
|
assert(mSettings != nullptr);
|
||||||
|
|
||||||
// Alert only about unique errors
|
// Alert only about unique errors
|
||||||
|
|
|
@ -180,11 +180,6 @@ private:
|
||||||
* Error output
|
* Error output
|
||||||
*/
|
*/
|
||||||
std::ofstream* mErrorOutput{};
|
std::ofstream* mErrorOutput{};
|
||||||
|
|
||||||
/**
|
|
||||||
* Has --errorlist been given?
|
|
||||||
*/
|
|
||||||
bool mShowAllErrors{};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CPPCHECKEXECUTOR_H
|
#endif // CPPCHECKEXECUTOR_H
|
||||||
|
|
Loading…
Reference in New Issue