forked from qt-creator/qt-creator
Axivion: Remove axivionresultparser.{cpp,h}
Rename ShortIssue into Issue and move it to axivionplugin.cpp. Change-Id: I07a43d7ade7a06560ad130cabcf6933cd36c67e0 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -7,7 +7,6 @@ add_qtc_plugin(Axivion
|
|||||||
axivionoutputpane.cpp axivionoutputpane.h
|
axivionoutputpane.cpp axivionoutputpane.h
|
||||||
axivionplugin.cpp axivionplugin.h
|
axivionplugin.cpp axivionplugin.h
|
||||||
axivionprojectsettings.h axivionprojectsettings.cpp
|
axivionprojectsettings.h axivionprojectsettings.cpp
|
||||||
axivionresultparser.h axivionresultparser.cpp
|
|
||||||
axivionsettings.cpp axivionsettings.h
|
axivionsettings.cpp axivionsettings.h
|
||||||
axiviontr.h
|
axiviontr.h
|
||||||
dashboard/dto.cpp dashboard/dto.h
|
dashboard/dto.cpp dashboard/dto.h
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ QtcPlugin {
|
|||||||
"axivionplugin.h",
|
"axivionplugin.h",
|
||||||
"axivionprojectsettings.h",
|
"axivionprojectsettings.h",
|
||||||
"axivionprojectsettings.cpp",
|
"axivionprojectsettings.cpp",
|
||||||
"axivionresultparser.h",
|
|
||||||
"axivionresultparser.cpp",
|
|
||||||
"axivionsettings.cpp",
|
"axivionsettings.cpp",
|
||||||
"axivionsettings.h",
|
"axivionsettings.h",
|
||||||
"axiviontr.h",
|
"axiviontr.h",
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
#include "axivionoutputpane.h"
|
#include "axivionoutputpane.h"
|
||||||
#include "axivionprojectsettings.h"
|
#include "axivionprojectsettings.h"
|
||||||
#include "axivionresultparser.h"
|
|
||||||
#include "axivionsettings.h"
|
#include "axivionsettings.h"
|
||||||
#include "axiviontr.h"
|
#include "axiviontr.h"
|
||||||
#include "dashboard/dto.h"
|
#include "dashboard/dto.h"
|
||||||
@@ -54,6 +53,21 @@ using namespace Utils;
|
|||||||
|
|
||||||
namespace Axivion::Internal {
|
namespace Axivion::Internal {
|
||||||
|
|
||||||
|
class Issue
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QString id;
|
||||||
|
QString state;
|
||||||
|
QString errorNumber;
|
||||||
|
QString message;
|
||||||
|
QString entity;
|
||||||
|
QString filePath;
|
||||||
|
QString severity;
|
||||||
|
int lineNumber = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
using Issues = QList<Issue>;
|
||||||
|
|
||||||
QIcon iconForIssue(const QString &prefix)
|
QIcon iconForIssue(const QString &prefix)
|
||||||
{
|
{
|
||||||
static QHash<QString, QIcon> prefixToIcon;
|
static QHash<QString, QIcon> prefixToIcon;
|
||||||
@@ -140,7 +154,7 @@ public:
|
|||||||
void onDocumentOpened(IDocument *doc);
|
void onDocumentOpened(IDocument *doc);
|
||||||
void onDocumentClosed(IDocument * doc);
|
void onDocumentClosed(IDocument * doc);
|
||||||
void clearAllMarks();
|
void clearAllMarks();
|
||||||
void handleIssuesForFile(const IssuesList &issues);
|
void handleIssuesForFile(const Issues &issues);
|
||||||
void fetchIssueInfo(const QString &id);
|
void fetchIssueInfo(const QString &id);
|
||||||
|
|
||||||
NetworkAccessManager m_networkAccessManager;
|
NetworkAccessManager m_networkAccessManager;
|
||||||
@@ -159,7 +173,7 @@ static AxivionPluginPrivate *dd = nullptr;
|
|||||||
class AxivionTextMark : public TextMark
|
class AxivionTextMark : public TextMark
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AxivionTextMark(const FilePath &filePath, const ShortIssue &issue)
|
AxivionTextMark(const FilePath &filePath, const Issue &issue)
|
||||||
: TextMark(filePath, issue.lineNumber, {Tr::tr("Axivion"), AxivionTextMarkId})
|
: TextMark(filePath, issue.lineNumber, {Tr::tr("Axivion"), AxivionTextMarkId})
|
||||||
{
|
{
|
||||||
const QString markText = issue.entity.isEmpty() ? issue.message
|
const QString markText = issue.entity.isEmpty() ? issue.message
|
||||||
@@ -583,10 +597,10 @@ void AxivionPluginPrivate::onDocumentOpened(IDocument *doc)
|
|||||||
search.limit = 0;
|
search.limit = 0;
|
||||||
|
|
||||||
const auto issuesHandler = [this](const Dto::IssueTableDto &dto) {
|
const auto issuesHandler = [this](const Dto::IssueTableDto &dto) {
|
||||||
IssuesList issues;
|
Issues issues;
|
||||||
const std::vector<std::map<QString, Dto::Any>> &rows = dto.rows;
|
const std::vector<std::map<QString, Dto::Any>> &rows = dto.rows;
|
||||||
for (const auto &row : rows) {
|
for (const auto &row : rows) {
|
||||||
ShortIssue issue;
|
Issue issue;
|
||||||
for (auto it = row.cbegin(); it != row.cend(); ++it) {
|
for (auto it = row.cbegin(); it != row.cend(); ++it) {
|
||||||
if (it->first == "id")
|
if (it->first == "id")
|
||||||
issue.id = anyToSimpleString(it->second);
|
issue.id = anyToSimpleString(it->second);
|
||||||
@@ -605,7 +619,7 @@ void AxivionPluginPrivate::onDocumentOpened(IDocument *doc)
|
|||||||
else if (it->first == "line")
|
else if (it->first == "line")
|
||||||
issue.lineNumber = anyToSimpleString(it->second).toInt();
|
issue.lineNumber = anyToSimpleString(it->second).toInt();
|
||||||
}
|
}
|
||||||
issues.issues << issue;
|
issues << issue;
|
||||||
}
|
}
|
||||||
handleIssuesForFile(issues);
|
handleIssuesForFile(issues);
|
||||||
};
|
};
|
||||||
@@ -639,9 +653,9 @@ void AxivionPluginPrivate::onDocumentClosed(IDocument *doc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AxivionPluginPrivate::handleIssuesForFile(const IssuesList &issues)
|
void AxivionPluginPrivate::handleIssuesForFile(const Issues &issues)
|
||||||
{
|
{
|
||||||
if (issues.issues.isEmpty())
|
if (issues.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Project *project = ProjectManager::startupProject();
|
Project *project = ProjectManager::startupProject();
|
||||||
@@ -649,10 +663,10 @@ void AxivionPluginPrivate::handleIssuesForFile(const IssuesList &issues)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
const FilePath filePath = project->projectDirectory()
|
const FilePath filePath = project->projectDirectory()
|
||||||
.pathAppended(issues.issues.first().filePath);
|
.pathAppended(issues.first().filePath);
|
||||||
|
|
||||||
const Id axivionId(AxivionTextMarkId);
|
const Id axivionId(AxivionTextMarkId);
|
||||||
for (const ShortIssue &issue : std::as_const(issues.issues)) {
|
for (const Issue &issue : issues) {
|
||||||
// FIXME the line location can be wrong (even the whole issue could be wrong)
|
// FIXME the line location can be wrong (even the whole issue could be wrong)
|
||||||
// depending on whether this line has been changed since the last axivion run and the
|
// depending on whether this line has been changed since the last axivion run and the
|
||||||
// current state of the file - some magic has to happen here
|
// current state of the file - some magic has to happen here
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
// Copyright (C) 2022 The Qt Company Ltd.
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
||||||
|
|
||||||
#include "axivionresultparser.h"
|
|
||||||
|
|
||||||
#include <utils/qtcassert.h>
|
|
||||||
|
|
||||||
#include <QRegularExpression>
|
|
||||||
|
|
||||||
namespace Axivion::Internal {
|
|
||||||
|
|
||||||
static std::pair<QByteArray, QByteArray> splitHeaderAndBody(const QByteArray &input)
|
|
||||||
{
|
|
||||||
QByteArray header;
|
|
||||||
QByteArray json;
|
|
||||||
int emptyLine = input.indexOf("\r\n\r\n"); // we always get \r\n as line separator
|
|
||||||
if (emptyLine != -1) {
|
|
||||||
header = input.left(emptyLine);
|
|
||||||
json = input.mid(emptyLine + 4);
|
|
||||||
} else {
|
|
||||||
json = input;
|
|
||||||
}
|
|
||||||
return {header, json};
|
|
||||||
}
|
|
||||||
|
|
||||||
static int httpStatus(const QByteArray &header)
|
|
||||||
{
|
|
||||||
int firstHeaderEnd = header.indexOf("\r\n");
|
|
||||||
if (firstHeaderEnd == -1)
|
|
||||||
return 600; // unexpected header
|
|
||||||
const QString firstLine = QString::fromUtf8(header.first(firstHeaderEnd));
|
|
||||||
static const QRegularExpression regex(R"(^HTTP/\d\.\d (\d{3}) .*$)");
|
|
||||||
const QRegularExpressionMatch match = regex.match(firstLine);
|
|
||||||
return match.hasMatch() ? match.captured(1).toInt() : 601;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BaseResult prehandleHeader(const QByteArray &header, const QByteArray &body)
|
|
||||||
{
|
|
||||||
BaseResult result;
|
|
||||||
if (header.isEmpty()) {
|
|
||||||
result.error = QString::fromUtf8(body); // we likely had a curl problem
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
int status = httpStatus(header);
|
|
||||||
if ((status > 399) || (status > 299 && body.isEmpty())) { // FIXME handle some explicitly?
|
|
||||||
const QString statusStr = QString::number(status);
|
|
||||||
if (body.isEmpty() || body.startsWith('<')) // likely an html response or redirect
|
|
||||||
result.error = QLatin1String("(%1)").arg(statusStr);
|
|
||||||
else
|
|
||||||
result.error = QLatin1String("%1 (%2)").arg(QString::fromUtf8(body)).arg(statusStr);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace ResultParser {
|
|
||||||
|
|
||||||
QString parseRuleInfo(const QByteArray &input) // html result!
|
|
||||||
{
|
|
||||||
auto [header, body] = splitHeaderAndBody(input);
|
|
||||||
BaseResult headerResult = prehandleHeader(header, body);
|
|
||||||
if (!headerResult.error.isEmpty())
|
|
||||||
return QString();
|
|
||||||
return QString::fromLocal8Bit(body);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // ResultParser
|
|
||||||
|
|
||||||
} // Axivion::Internal
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
// Copyright (C) 2022 The Qt Company Ltd.
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <utils/expected.h>
|
|
||||||
|
|
||||||
#include <QList>
|
|
||||||
|
|
||||||
namespace Axivion::Internal {
|
|
||||||
|
|
||||||
class BaseResult
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
QString error;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ShortIssue : public BaseResult
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
QString id;
|
|
||||||
QString state;
|
|
||||||
QString errorNumber;
|
|
||||||
QString message;
|
|
||||||
QString entity;
|
|
||||||
QString filePath;
|
|
||||||
QString severity;
|
|
||||||
int lineNumber = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class IssuesList : public BaseResult
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
QList<ShortIssue> issues;
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace ResultParser {
|
|
||||||
|
|
||||||
QString parseRuleInfo(const QByteArray &input);
|
|
||||||
|
|
||||||
} // ResultParser
|
|
||||||
|
|
||||||
} // Axivion::Internal
|
|
||||||
Reference in New Issue
Block a user