GUI: Removed XML format version 1

This commit is contained in:
PKEuS 2017-07-29 19:36:01 +02:00
parent ae563f65fb
commit 2aa1523a2d
6 changed files with 11 additions and 292 deletions

View File

@ -106,7 +106,6 @@ HEADERS += aboutdialog.h \
translationhandler.h \
txtreport.h \
xmlreport.h \
xmlreportv1.h \
xmlreportv2.h \
librarydialog.h \
cppchecklibrarydata.h \
@ -144,7 +143,6 @@ SOURCES += aboutdialog.cpp \
translationhandler.cpp \
txtreport.cpp \
xmlreport.cpp \
xmlreportv1.cpp \
xmlreportv2.cpp \
librarydialog.cpp \
cppchecklibrarydata.cpp \

View File

@ -1157,7 +1157,7 @@ void MainWindow::performSelectedFilesCheck(QStringList selectedFilesList)
void MainWindow::save()
{
QString selectedFilter;
const QString filter(tr("XML files version 2 (*.xml);;XML files version 1 (*.xml);;Text files (*.txt);;CSV files (*.csv)"));
const QString filter(tr("XML files (*.xml);;Text files (*.txt);;CSV files (*.csv)"));
QString selectedFile = QFileDialog::getSaveFileName(this,
tr("Save the report file"),
getPath(SETTINGS_LAST_RESULT_PATH),
@ -1166,14 +1166,7 @@ void MainWindow::save()
if (!selectedFile.isEmpty()) {
Report::Type type = Report::TXT;
if (selectedFilter == tr("XML files version 1 (*.xml)")) {
QMessageBox msgBox(QMessageBox::Icon::Warning, tr("Deprecated XML format"), tr("XML format 1 is deprecated and will be removed in cppcheck 1.81."), QMessageBox::StandardButton::Ok);
msgBox.exec();
type = Report::XML;
if (!selectedFile.endsWith(".xml", Qt::CaseInsensitive))
selectedFile += ".xml";
} else if (selectedFilter == tr("XML files version 2 (*.xml)")) {
if (selectedFilter == tr("XML files (*.xml)")) {
type = Report::XMLV2;
if (!selectedFile.endsWith(".xml", Qt::CaseInsensitive))
selectedFile += ".xml";
@ -1187,7 +1180,7 @@ void MainWindow::save()
selectedFile += ".csv";
} else {
if (selectedFile.endsWith(".xml", Qt::CaseInsensitive))
type = Report::XML;
type = Report::XMLV2;
else if (selectedFile.endsWith(".txt", Qt::CaseInsensitive))
type = Report::TXT;
else if (selectedFile.endsWith(".csv", Qt::CaseInsensitive))

View File

@ -35,7 +35,6 @@ public:
enum Type {
TXT,
XML,
XMLV2,
CSV,
};

View File

@ -33,7 +33,6 @@
#include "report.h"
#include "txtreport.h"
#include "xmlreport.h"
#include "xmlreportv1.h"
#include "xmlreportv2.h"
#include "csvreport.h"
#include "printablereport.h"
@ -153,9 +152,6 @@ void ResultsView::save(const QString &filename, Report::Type type) const
case Report::TXT:
report = new TxtReport(filename);
break;
case Report::XML:
report = new XmlReportV1(filename);
break;
case Report::XMLV2:
report = new XmlReportV2(filename);
break;
@ -313,12 +309,15 @@ void ResultsView::readErrorsXml(const QString &filename)
msgBox.exec();
return;
}
if (version == 1) {
QMessageBox msgBox;
msgBox.setText(tr("XML format version 1 is no longer supported."));
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
return;
}
XmlReport *report = NULL;
if (version == 1)
report = new XmlReportV1(filename);
else if (version == 2)
report = new XmlReportV2(filename);
XmlReport *report = new XmlReportV2(filename);
QList<ErrorItem> errors;
if (report) {

View File

@ -1,178 +0,0 @@
/*
* Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2016 Cppcheck team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QObject>
#include <QString>
#include <QList>
#include <QDir>
#include <QXmlStreamWriter>
#include <QDebug>
#include "report.h"
#include "erroritem.h"
#include "xmlreport.h"
#include "xmlreportv1.h"
static const char ResultElementName[] = "results";
static const char ErrorElementName[] = "error";
static const char FilenameAttribute[] = "file";
static const char LineAttribute[] = "line";
static const char IdAttribute[] = "id";
static const char SeverityAttribute[] = "severity";
static const char MsgAttribute[] = "msg";
XmlReportV1::XmlReportV1(const QString &filename) :
XmlReport(filename),
mXmlReader(NULL),
mXmlWriter(NULL)
{
}
XmlReportV1::~XmlReportV1()
{
delete mXmlReader;
delete mXmlWriter;
}
bool XmlReportV1::create()
{
if (Report::create()) {
mXmlWriter = new QXmlStreamWriter(Report::getFile());
return true;
}
return false;
}
bool XmlReportV1::open()
{
if (Report::open()) {
mXmlReader = new QXmlStreamReader(Report::getFile());
return true;
}
return false;
}
void XmlReportV1::writeHeader()
{
mXmlWriter->setAutoFormatting(true);
mXmlWriter->writeStartDocument();
mXmlWriter->writeStartElement(ResultElementName);
}
void XmlReportV1::writeFooter()
{
mXmlWriter->writeEndElement();
mXmlWriter->writeEndDocument();
}
void XmlReportV1::writeError(const ErrorItem &error)
{
/*
Error example from the core program in xml
<error file="gui/test.cpp" line="14" id="mismatchAllocDealloc" severity="error" msg="Mismatching allocation and deallocation: k"/>
The callstack seems to be ignored here as well, instead last item of the stack is used
*/
// Don't write inconclusive errors to XML V1
if (error.inconclusive)
return;
mXmlWriter->writeStartElement(ErrorElementName);
QString file = QDir::toNativeSeparators(error.errorPath.back().file);
file = XmlReport::quoteMessage(file);
mXmlWriter->writeAttribute(FilenameAttribute, file);
const QString line = QString::number(error.errorPath.back().line);
mXmlWriter->writeAttribute(LineAttribute, line);
mXmlWriter->writeAttribute(IdAttribute, error.errorId);
// Don't localize severity so we can read these files
mXmlWriter->writeAttribute(SeverityAttribute, GuiSeverity::toString(error.severity));
const QString message = XmlReport::quoteMessage(error.message);
mXmlWriter->writeAttribute(MsgAttribute, message);
mXmlWriter->writeEndElement();
}
QList<ErrorItem> XmlReportV1::read()
{
QList<ErrorItem> errors;
bool insideResults = false;
if (!mXmlReader) {
qDebug() << "You must Open() the file before reading it!";
return errors;
}
while (!mXmlReader->atEnd()) {
switch (mXmlReader->readNext()) {
case QXmlStreamReader::StartElement:
if (mXmlReader->name() == ResultElementName)
insideResults = true;
// Read error element from inside result element
if (insideResults && mXmlReader->name() == ErrorElementName) {
ErrorItem item = readError(mXmlReader);
errors.append(item);
}
break;
case QXmlStreamReader::EndElement:
if (mXmlReader->name() == ResultElementName)
insideResults = false;
break;
// Not handled
case QXmlStreamReader::NoToken:
case QXmlStreamReader::Invalid:
case QXmlStreamReader::StartDocument:
case QXmlStreamReader::EndDocument:
case QXmlStreamReader::Characters:
case QXmlStreamReader::Comment:
case QXmlStreamReader::DTD:
case QXmlStreamReader::EntityReference:
case QXmlStreamReader::ProcessingInstruction:
break;
}
}
return errors;
}
ErrorItem XmlReportV1::readError(QXmlStreamReader *reader)
{
ErrorItem item;
if (reader->name().toString() == ErrorElementName) {
QXmlStreamAttributes attribs = reader->attributes();
QString file = attribs.value("", FilenameAttribute).toString();
file = XmlReport::unquoteMessage(file);
QErrorPathItem e;
e.file = file;
e.line = attribs.value("", LineAttribute).toString().toUInt();
item.errorPath << e;
item.errorId = attribs.value("", IdAttribute).toString();
item.severity = GuiSeverity::fromString(attribs.value("", SeverityAttribute).toString());
// NOTE: This duplicates the message to Summary-field. But since
// old XML format doesn't have separate summary and verbose messages
// we must add same message to both data so it shows up in GUI.
// Check if there is full stop and cut the summary to it.
QString summary = attribs.value("", MsgAttribute).toString();
const int ind = summary.indexOf('.');
if (ind != -1)
summary = summary.left(ind + 1);
item.summary = XmlReport::unquoteMessage(summary);
QString message = attribs.value("", MsgAttribute).toString();
item.message = XmlReport::unquoteMessage(message);
}
return item;
}

View File

@ -1,92 +0,0 @@
/*
* Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2016 Cppcheck team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XML_REPORTV1_H
#define XML_REPORTV1_H
#include <QString>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include "xmlreport.h"
/// @addtogroup GUI
/// @{
/**
* @brief XML file report version 1.
* This report outputs XML-formatted report, version 1. The XML format must match command
* line version's XML output.
*/
class XmlReportV1 : public XmlReport {
public:
explicit XmlReportV1(const QString &filename);
virtual ~XmlReportV1();
/**
* @brief Create the report (file).
* @return true if succeeded, false if file could not be created.
*/
virtual bool create();
/**
* @brief Open existing report file.
*/
bool open();
/**
* @brief Write report header.
*/
virtual void writeHeader();
/**
* @brief Write report footer.
*/
virtual void writeFooter();
/**
* @brief Write error to report.
* @param error Error data.
*/
virtual void writeError(const ErrorItem &error);
/**
* @brief Read contents of the report file.
*/
virtual QList<ErrorItem> read();
protected:
/**
* @brief Read and parse error item from XML stream.
* @param reader XML stream reader to use.
*/
ErrorItem readError(QXmlStreamReader *reader);
private:
/**
* @brief XML stream reader for reading the report in XML format.
*/
QXmlStreamReader *mXmlReader;
/**
* @brief XML stream writer for writing the report in XML format.
*/
QXmlStreamWriter *mXmlWriter;
};
/// @}
#endif // XML_REPORTV1_H