2022-12-12 16:45:31 +01:00
|
|
|
// Copyright (C) 2022 The Qt Company Ltd.
|
2023-05-24 10:27:35 +02:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2022-11-28 09:48:11 +01:00
|
|
|
|
|
|
|
|
#include "axivionplugin.h"
|
|
|
|
|
|
|
|
|
|
#include "axivionoutputpane.h"
|
2022-12-13 11:17:12 +01:00
|
|
|
#include "axivionprojectsettings.h"
|
2022-12-14 12:11:03 +01:00
|
|
|
#include "axivionresultparser.h"
|
2023-09-15 12:25:04 +02:00
|
|
|
#include "axivionsettings.h"
|
2022-12-13 11:17:12 +01:00
|
|
|
#include "axiviontr.h"
|
2023-07-25 18:48:18 +02:00
|
|
|
#include "dashboard/dto.h"
|
2023-11-24 12:29:17 +01:00
|
|
|
#include "dashboard/error.h"
|
2022-11-28 09:48:11 +01:00
|
|
|
|
2022-12-16 15:12:39 +01:00
|
|
|
#include <coreplugin/editormanager/documentmodel.h>
|
2022-12-16 23:11:46 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2023-09-15 12:25:04 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2022-12-14 12:11:03 +01:00
|
|
|
#include <coreplugin/messagemanager.h>
|
2023-03-01 17:54:39 +01:00
|
|
|
|
2024-01-12 08:38:31 +01:00
|
|
|
#include <extensionsystem/iplugin.h>
|
2022-12-12 16:45:31 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2023-03-01 17:54:39 +01:00
|
|
|
|
2022-12-16 15:12:39 +01:00
|
|
|
#include <projectexplorer/buildsystem.h>
|
2022-12-13 11:17:12 +01:00
|
|
|
#include <projectexplorer/project.h>
|
2023-03-01 17:54:39 +01:00
|
|
|
#include <projectexplorer/projectmanager.h>
|
|
|
|
|
|
2023-11-24 12:29:17 +01:00
|
|
|
#include <solutions/tasking/networkquery.h>
|
|
|
|
|
#include <solutions/tasking/tasktreerunner.h>
|
|
|
|
|
|
2022-12-16 23:11:46 +01:00
|
|
|
#include <texteditor/textdocument.h>
|
|
|
|
|
#include <texteditor/texteditor.h>
|
|
|
|
|
#include <texteditor/textmark.h>
|
2023-03-01 17:54:39 +01:00
|
|
|
|
2023-09-15 12:25:04 +02:00
|
|
|
#include <utils/algorithm.h>
|
2023-11-24 12:29:17 +01:00
|
|
|
#include <utils/async.h>
|
2023-08-29 15:42:08 +02:00
|
|
|
#include <utils/networkaccessmanager.h>
|
2022-12-13 11:17:12 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2023-01-13 14:38:39 +01:00
|
|
|
#include <utils/utilsicons.h>
|
2022-11-28 09:48:11 +01:00
|
|
|
|
2023-01-13 14:38:39 +01:00
|
|
|
#include <QAction>
|
2023-09-15 12:25:04 +02:00
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
|
#include <QNetworkReply>
|
2022-12-14 12:11:03 +01:00
|
|
|
#include <QTimer>
|
2022-12-13 15:13:13 +01:00
|
|
|
|
2023-07-25 18:48:18 +02:00
|
|
|
#include <memory>
|
|
|
|
|
|
2023-01-09 07:31:50 +01:00
|
|
|
constexpr char AxivionTextMarkId[] = "AxivionTextMark";
|
|
|
|
|
|
2024-01-30 14:01:58 +01:00
|
|
|
using namespace Core;
|
2024-02-03 21:05:01 +01:00
|
|
|
using namespace ProjectExplorer;
|
2023-11-24 12:29:17 +01:00
|
|
|
using namespace Tasking;
|
2024-02-02 11:24:48 +01:00
|
|
|
using namespace TextEditor;
|
2023-11-24 12:29:17 +01:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2022-11-28 09:48:11 +01:00
|
|
|
namespace Axivion::Internal {
|
|
|
|
|
|
2024-01-19 13:47:03 +01:00
|
|
|
QIcon iconForIssue(const QString &prefix)
|
|
|
|
|
{
|
|
|
|
|
static QHash<QString, QIcon> prefixToIcon;
|
|
|
|
|
auto it = prefixToIcon.find(prefix);
|
|
|
|
|
|
|
|
|
|
if (it == prefixToIcon.end()) {
|
|
|
|
|
Icon icon({{FilePath::fromString(":/axivion/images/button-" + prefix.toLower() + ".png"),
|
|
|
|
|
Theme::PaletteButtonText}},
|
|
|
|
|
Icon::Tint);
|
|
|
|
|
it = prefixToIcon.insert(prefix, icon.icon());
|
|
|
|
|
}
|
|
|
|
|
return it.value();
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-30 15:15:50 +01:00
|
|
|
QString anyToSimpleString(const Dto::Any &any)
|
|
|
|
|
{
|
|
|
|
|
if (any.isString())
|
|
|
|
|
return any.getString();
|
|
|
|
|
if (any.isBool())
|
|
|
|
|
return QString("%1").arg(any.getBool());
|
|
|
|
|
if (any.isDouble())
|
|
|
|
|
return QString::number(any.getDouble());
|
|
|
|
|
if (any.isNull())
|
|
|
|
|
return QString(); // or NULL??
|
|
|
|
|
if (any.isList()) {
|
|
|
|
|
const std::vector<Dto::Any> anyList = any.getList();
|
|
|
|
|
QStringList list;
|
|
|
|
|
for (const Dto::Any &inner : anyList)
|
|
|
|
|
list << anyToSimpleString(inner);
|
|
|
|
|
return list.join(',');
|
|
|
|
|
}
|
|
|
|
|
if (any.isMap()) { // TODO
|
|
|
|
|
const std::map<QString, Dto::Any> anyMap = any.getMap();
|
|
|
|
|
auto value = anyMap.find("displayName");
|
|
|
|
|
if (value != anyMap.end())
|
|
|
|
|
return anyToSimpleString(value->second);
|
|
|
|
|
value = anyMap.find("name");
|
|
|
|
|
if (value != anyMap.end())
|
|
|
|
|
return anyToSimpleString(value->second);
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 15:06:34 +01:00
|
|
|
QString IssueListSearch::toQuery() const
|
|
|
|
|
{
|
|
|
|
|
if (kind.isEmpty())
|
|
|
|
|
return {};
|
|
|
|
|
QString result;
|
2024-01-30 18:26:21 +01:00
|
|
|
result.append(QString("?kind=%1&offset=%2").arg(kind).arg(offset));
|
|
|
|
|
if (limit)
|
|
|
|
|
result.append(QString("&limit=%1").arg(limit));
|
2024-01-19 15:06:34 +01:00
|
|
|
// TODO other params
|
2024-01-29 11:34:42 +01:00
|
|
|
if (!versionStart.isEmpty()) {
|
|
|
|
|
result.append(QString("&start=%1").arg(
|
2024-01-30 15:15:50 +01:00
|
|
|
QString::fromUtf8(QUrl::toPercentEncoding(versionStart))));
|
2024-01-29 11:34:42 +01:00
|
|
|
}
|
|
|
|
|
if (!versionEnd.isEmpty()) {
|
|
|
|
|
result.append(QString("&end=%1").arg(
|
2024-01-30 15:15:50 +01:00
|
|
|
QString::fromUtf8(QUrl::toPercentEncoding(versionEnd))));
|
|
|
|
|
}
|
2024-01-31 10:53:15 +01:00
|
|
|
if (!owner.isEmpty()) {
|
|
|
|
|
result.append(QString("&user=%1").arg(
|
|
|
|
|
QString::fromUtf8((QUrl::toPercentEncoding(owner)))));
|
|
|
|
|
}
|
2024-01-30 15:15:50 +01:00
|
|
|
if (!filter_path.isEmpty()) {
|
|
|
|
|
result.append(QString("&filter_path=%1").arg(
|
|
|
|
|
QString::fromUtf8(QUrl::toPercentEncoding(filter_path))));
|
2024-01-29 11:34:42 +01:00
|
|
|
}
|
2024-01-31 11:41:01 +01:00
|
|
|
if (!state.isEmpty())
|
|
|
|
|
result.append(QString("&state=%1").arg(state));
|
2024-01-25 11:16:42 +01:00
|
|
|
if (computeTotalRowCount)
|
|
|
|
|
result.append("&computeTotalRowCount=true");
|
2024-01-19 15:06:34 +01:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-14 12:11:03 +01:00
|
|
|
class AxivionPluginPrivate : public QObject
|
2022-11-28 09:48:11 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2023-09-15 12:25:04 +02:00
|
|
|
AxivionPluginPrivate();
|
|
|
|
|
void handleSslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
|
2022-12-16 23:01:01 +01:00
|
|
|
void onStartupProjectChanged();
|
2022-12-14 12:11:03 +01:00
|
|
|
void fetchProjectInfo(const QString &projectName);
|
2024-02-03 21:05:01 +01:00
|
|
|
void handleOpenedDocs(Project *project);
|
2024-01-30 14:01:58 +01:00
|
|
|
void onDocumentOpened(IDocument *doc);
|
|
|
|
|
void onDocumentClosed(IDocument * doc);
|
2022-12-16 22:34:56 +01:00
|
|
|
void clearAllMarks();
|
2022-12-16 23:11:46 +01:00
|
|
|
void handleIssuesForFile(const IssuesList &issues);
|
2024-01-30 21:19:28 +01:00
|
|
|
void fetchIssueInfo(const QString &id);
|
2022-12-14 12:11:03 +01:00
|
|
|
|
2023-11-24 12:29:17 +01:00
|
|
|
NetworkAccessManager m_networkAccessManager;
|
2023-01-09 07:41:22 +01:00
|
|
|
AxivionOutputPane m_axivionOutputPane;
|
2024-01-23 22:29:59 +01:00
|
|
|
std::optional<DashboardInfo> m_dashboardInfo;
|
2023-11-24 12:29:17 +01:00
|
|
|
std::optional<Dto::ProjectInfoDto> m_currentProjectInfo;
|
2023-01-09 07:41:22 +01:00
|
|
|
bool m_runningQuery = false;
|
2023-11-24 12:29:17 +01:00
|
|
|
TaskTreeRunner m_taskTreeRunner;
|
2024-01-30 15:15:50 +01:00
|
|
|
std::unordered_map<IDocument *, std::unique_ptr<TaskTree>> m_docMarksTrees;
|
2024-01-30 21:19:28 +01:00
|
|
|
TaskTreeRunner m_issueInfoRunner;
|
2022-11-28 09:48:11 +01:00
|
|
|
};
|
|
|
|
|
|
2022-12-13 11:17:12 +01:00
|
|
|
static AxivionPluginPrivate *dd = nullptr;
|
|
|
|
|
|
2024-02-02 11:24:48 +01:00
|
|
|
class AxivionTextMark : public TextMark
|
2023-01-13 13:49:40 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2024-02-02 11:23:18 +01:00
|
|
|
AxivionTextMark(const FilePath &filePath, const ShortIssue &issue)
|
2024-02-02 11:24:48 +01:00
|
|
|
: TextMark(filePath, issue.lineNumber, {Tr::tr("Axivion"), AxivionTextMarkId})
|
2024-02-02 11:23:18 +01:00
|
|
|
{
|
|
|
|
|
const QString markText = issue.entity.isEmpty() ? issue.message
|
|
|
|
|
: issue.entity + ": " + issue.message;
|
|
|
|
|
setToolTip(issue.errorNumber + " " + markText);
|
|
|
|
|
setIcon(iconForIssue("SV")); // FIXME adapt to the issue
|
2024-02-02 11:24:48 +01:00
|
|
|
setPriority(TextMark::NormalPriority);
|
2024-02-02 11:23:18 +01:00
|
|
|
setLineAnnotation(markText);
|
|
|
|
|
setActionsProvider([id = issue.id] {
|
|
|
|
|
auto action = new QAction;
|
|
|
|
|
action->setIcon(Utils::Icons::INFO.icon());
|
|
|
|
|
action->setToolTip(Tr::tr("Show rule details"));
|
|
|
|
|
QObject::connect(action, &QAction::triggered, dd, [id] { dd->fetchIssueInfo(id); });
|
|
|
|
|
return QList{action};
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-01-13 13:49:40 +01:00
|
|
|
};
|
|
|
|
|
|
2024-01-12 08:38:31 +01:00
|
|
|
void fetchProjectInfo(const QString &projectName)
|
2022-12-14 12:11:03 +01:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(dd, return);
|
|
|
|
|
dd->fetchProjectInfo(projectName);
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-24 12:29:17 +01:00
|
|
|
std::optional<Dto::ProjectInfoDto> projectInfo()
|
2022-12-14 13:53:00 +01:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(dd, return {});
|
2023-01-09 07:41:22 +01:00
|
|
|
return dd->m_currentProjectInfo;
|
2022-12-14 13:53:00 +01:00
|
|
|
}
|
|
|
|
|
|
2023-09-15 12:25:04 +02:00
|
|
|
// FIXME: extend to give some details?
|
|
|
|
|
// FIXME: move when curl is no more in use?
|
2024-01-12 08:38:31 +01:00
|
|
|
bool handleCertificateIssue()
|
2023-09-15 12:25:04 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(dd, return false);
|
|
|
|
|
const QString serverHost = QUrl(settings().server.dashboard).host();
|
2024-01-30 14:01:58 +01:00
|
|
|
if (QMessageBox::question(ICore::dialogParent(), Tr::tr("Certificate Error"),
|
2023-09-15 12:25:04 +02:00
|
|
|
Tr::tr("Server certificate for %1 cannot be authenticated.\n"
|
|
|
|
|
"Do you want to disable SSL verification for this server?\n"
|
|
|
|
|
"Note: This can expose you to man-in-the-middle attack.")
|
|
|
|
|
.arg(serverHost))
|
|
|
|
|
!= QMessageBox::Yes) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
settings().server.validateCert = false;
|
|
|
|
|
settings().apply();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AxivionPluginPrivate::AxivionPluginPrivate()
|
|
|
|
|
{
|
2023-10-24 13:54:55 +02:00
|
|
|
#if QT_CONFIG(ssl)
|
2023-09-15 12:25:04 +02:00
|
|
|
connect(&m_networkAccessManager, &QNetworkAccessManager::sslErrors,
|
|
|
|
|
this, &AxivionPluginPrivate::handleSslErrors);
|
2023-10-24 13:54:55 +02:00
|
|
|
#endif // ssl
|
2023-09-15 12:25:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AxivionPluginPrivate::handleSslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
|
|
|
|
|
{
|
2023-10-24 13:54:55 +02:00
|
|
|
#if QT_CONFIG(ssl)
|
2023-09-15 12:25:04 +02:00
|
|
|
const QList<QSslError::SslError> accepted{
|
|
|
|
|
QSslError::CertificateNotYetValid, QSslError::CertificateExpired,
|
|
|
|
|
QSslError::InvalidCaCertificate, QSslError::CertificateUntrusted,
|
|
|
|
|
QSslError::HostNameMismatch
|
|
|
|
|
};
|
|
|
|
|
if (Utils::allOf(errors,
|
|
|
|
|
[&accepted](const QSslError &e) { return accepted.contains(e.error()); })) {
|
2024-01-12 08:38:31 +01:00
|
|
|
if (!settings().server.validateCert || handleCertificateIssue())
|
2023-09-15 12:25:04 +02:00
|
|
|
reply->ignoreSslErrors(errors);
|
|
|
|
|
}
|
2023-10-24 13:54:55 +02:00
|
|
|
#else // ssl
|
|
|
|
|
Q_UNUSED(reply)
|
|
|
|
|
Q_UNUSED(errors)
|
|
|
|
|
#endif // ssl
|
2023-09-15 12:25:04 +02:00
|
|
|
}
|
|
|
|
|
|
2022-12-16 23:01:01 +01:00
|
|
|
void AxivionPluginPrivate::onStartupProjectChanged()
|
|
|
|
|
{
|
2024-02-03 21:05:01 +01:00
|
|
|
Project *project = ProjectManager::startupProject();
|
2022-12-16 23:01:01 +01:00
|
|
|
if (!project) {
|
|
|
|
|
clearAllMarks();
|
2023-07-25 18:48:18 +02:00
|
|
|
m_currentProjectInfo = {};
|
2023-01-09 07:41:22 +01:00
|
|
|
m_axivionOutputPane.updateDashboard();
|
2022-12-16 23:01:01 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-17 16:27:44 +02:00
|
|
|
const AxivionProjectSettings *projSettings = AxivionProjectSettings::projectSettings(project);
|
2022-12-16 23:01:01 +01:00
|
|
|
fetchProjectInfo(projSettings->dashboardProjectName());
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-24 12:29:17 +01:00
|
|
|
static QUrl urlForProject(const QString &projectName)
|
|
|
|
|
{
|
|
|
|
|
QString dashboard = settings().server.dashboard;
|
|
|
|
|
if (!dashboard.endsWith(QLatin1Char('/')))
|
|
|
|
|
dashboard += QLatin1Char('/');
|
|
|
|
|
return QUrl(dashboard).resolved(QStringLiteral("api/projects/")).resolved(projectName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static constexpr int httpStatusCodeOk = 200;
|
|
|
|
|
static const QLatin1String jsonContentType{ "application/json" };
|
2024-01-30 21:19:28 +01:00
|
|
|
static const QLatin1String htmlContentType{ "text/html" };
|
|
|
|
|
|
|
|
|
|
static Group fetchHtmlRecipe(const QUrl &url, const std::function<void(const QByteArray &)> &handler)
|
|
|
|
|
{
|
|
|
|
|
struct StorageData
|
|
|
|
|
{
|
|
|
|
|
QByteArray credentials;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const Storage<StorageData> storage;
|
|
|
|
|
|
|
|
|
|
const auto onCredentialSetup = [storage] {
|
|
|
|
|
storage->credentials = QByteArrayLiteral("AxToken ") + settings().server.token.toUtf8();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const auto onQuerySetup = [storage, url](NetworkQuery &query) {
|
|
|
|
|
QNetworkRequest request(url);
|
|
|
|
|
request.setRawHeader(QByteArrayLiteral("Accept"),
|
|
|
|
|
QByteArray(htmlContentType.data(), htmlContentType.size()));
|
|
|
|
|
request.setRawHeader(QByteArrayLiteral("Authorization"),
|
|
|
|
|
storage->credentials);
|
|
|
|
|
const QByteArray ua = QByteArrayLiteral("Axivion")
|
|
|
|
|
+ QCoreApplication::applicationName().toUtf8()
|
|
|
|
|
+ QByteArrayLiteral("Plugin/")
|
|
|
|
|
+ QCoreApplication::applicationVersion().toUtf8();
|
|
|
|
|
request.setRawHeader(QByteArrayLiteral("X-Axivion-User-Agent"), ua);
|
|
|
|
|
query.setRequest(request);
|
|
|
|
|
query.setNetworkAccessManager(&dd->m_networkAccessManager);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const auto onQueryDone = [url, handler](const NetworkQuery &query, DoneWith doneWith) {
|
|
|
|
|
QNetworkReply *reply = query.reply();
|
|
|
|
|
const int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
|
|
|
|
const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader)
|
|
|
|
|
.toString()
|
|
|
|
|
.split(';')
|
|
|
|
|
.constFirst()
|
|
|
|
|
.trimmed()
|
|
|
|
|
.toLower();
|
|
|
|
|
if (doneWith == DoneWith::Success && statusCode == httpStatusCodeOk
|
|
|
|
|
&& contentType == htmlContentType) {
|
|
|
|
|
handler(reply->readAll());
|
|
|
|
|
return DoneResult::Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DoneResult::Error;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const Group recipe {
|
|
|
|
|
storage,
|
|
|
|
|
Sync(onCredentialSetup),
|
|
|
|
|
NetworkQueryTask(onQuerySetup, onQueryDone),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return recipe;
|
|
|
|
|
}
|
2023-11-24 12:29:17 +01:00
|
|
|
|
2024-01-19 19:46:40 +01:00
|
|
|
template<typename SerializableType>
|
|
|
|
|
static Group fetchDataRecipe(const QUrl &url,
|
2024-01-30 21:19:28 +01:00
|
|
|
const std::function<void(const SerializableType &)> &handler)
|
2023-11-24 12:29:17 +01:00
|
|
|
{
|
2023-11-24 13:45:07 +01:00
|
|
|
struct StorageData
|
|
|
|
|
{
|
2024-01-19 19:46:40 +01:00
|
|
|
QByteArray credentials;
|
|
|
|
|
QByteArray serializableData;
|
2023-11-24 13:45:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const Storage<StorageData> storage;
|
|
|
|
|
|
|
|
|
|
const auto onCredentialSetup = [storage] {
|
2024-01-30 21:19:28 +01:00
|
|
|
storage->credentials = QByteArrayLiteral("AxToken ") + settings().server.token.toUtf8();
|
2023-11-24 13:45:07 +01:00
|
|
|
};
|
2023-11-24 12:29:17 +01:00
|
|
|
|
2024-01-19 19:46:40 +01:00
|
|
|
const auto onQuerySetup = [storage, url](NetworkQuery &query) {
|
2023-11-24 12:29:17 +01:00
|
|
|
QNetworkRequest request(url);
|
|
|
|
|
request.setRawHeader(QByteArrayLiteral("Accept"),
|
|
|
|
|
QByteArray(jsonContentType.data(), jsonContentType.size()));
|
|
|
|
|
request.setRawHeader(QByteArrayLiteral("Authorization"),
|
2024-01-19 19:46:40 +01:00
|
|
|
storage->credentials);
|
2023-11-24 12:29:17 +01:00
|
|
|
const QByteArray ua = QByteArrayLiteral("Axivion")
|
|
|
|
|
+ QCoreApplication::applicationName().toUtf8()
|
|
|
|
|
+ QByteArrayLiteral("Plugin/")
|
|
|
|
|
+ QCoreApplication::applicationVersion().toUtf8();
|
|
|
|
|
request.setRawHeader(QByteArrayLiteral("X-Axivion-User-Agent"), ua);
|
|
|
|
|
query.setRequest(request);
|
2024-01-19 19:46:40 +01:00
|
|
|
query.setNetworkAccessManager(&dd->m_networkAccessManager);
|
2023-11-24 12:29:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const auto onQueryDone = [storage, url](const NetworkQuery &query, DoneWith doneWith) {
|
|
|
|
|
QNetworkReply *reply = query.reply();
|
|
|
|
|
const QNetworkReply::NetworkError error = reply->error();
|
|
|
|
|
const int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
|
|
|
|
const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader)
|
|
|
|
|
.toString()
|
|
|
|
|
.split(';')
|
|
|
|
|
.constFirst()
|
|
|
|
|
.trimmed()
|
|
|
|
|
.toLower();
|
|
|
|
|
if (doneWith == DoneWith::Success && statusCode == httpStatusCodeOk
|
|
|
|
|
&& contentType == jsonContentType) {
|
2024-01-19 19:46:40 +01:00
|
|
|
storage->serializableData = reply->readAll();
|
2023-11-24 12:29:17 +01:00
|
|
|
return DoneResult::Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const auto getError = [&]() -> Error {
|
|
|
|
|
if (contentType == jsonContentType) {
|
|
|
|
|
try {
|
|
|
|
|
return DashboardError(reply->url(), statusCode,
|
2024-01-19 19:46:40 +01:00
|
|
|
reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString(),
|
|
|
|
|
Dto::ErrorDto::deserialize(reply->readAll()));
|
2023-11-24 12:29:17 +01:00
|
|
|
} catch (const Dto::invalid_dto_exception &) {
|
|
|
|
|
// ignore
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (statusCode != 0) {
|
|
|
|
|
return HttpError(reply->url(), statusCode,
|
2024-01-19 19:46:40 +01:00
|
|
|
reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString(),
|
|
|
|
|
QString::fromUtf8(reply->readAll())); // encoding?
|
2023-11-24 12:29:17 +01:00
|
|
|
}
|
|
|
|
|
return NetworkError(reply->url(), error, reply->errorString());
|
|
|
|
|
};
|
|
|
|
|
|
2024-01-30 14:01:58 +01:00
|
|
|
MessageManager::writeFlashing(
|
2023-11-24 12:29:17 +01:00
|
|
|
QStringLiteral("Axivion: %1").arg(getError().message()));
|
|
|
|
|
return DoneResult::Error;
|
|
|
|
|
};
|
|
|
|
|
|
2024-01-19 19:46:40 +01:00
|
|
|
const auto onDeserializeSetup = [storage](Async<SerializableType> &task) {
|
|
|
|
|
const auto deserialize = [](QPromise<SerializableType> &promise, const QByteArray &input) {
|
|
|
|
|
promise.addResult(SerializableType::deserialize(input));
|
|
|
|
|
};
|
2023-11-24 12:29:17 +01:00
|
|
|
task.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
|
2024-01-19 19:46:40 +01:00
|
|
|
task.setConcurrentCallData(deserialize, storage->serializableData);
|
2023-11-24 12:29:17 +01:00
|
|
|
};
|
|
|
|
|
|
2024-01-19 19:46:40 +01:00
|
|
|
const auto onDeserializeDone = [handler](const Async<SerializableType> &task,
|
|
|
|
|
DoneWith doneWith) {
|
|
|
|
|
if (doneWith == DoneWith::Success)
|
|
|
|
|
handler(task.future().result());
|
2023-11-24 12:29:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const Group recipe {
|
|
|
|
|
storage,
|
2023-11-24 13:45:07 +01:00
|
|
|
Sync(onCredentialSetup),
|
2023-11-24 12:29:17 +01:00
|
|
|
NetworkQueryTask(onQuerySetup, onQueryDone),
|
2024-01-19 19:46:40 +01:00
|
|
|
AsyncTask<SerializableType>(onDeserializeSetup, onDeserializeDone)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return recipe;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-23 22:29:59 +01:00
|
|
|
static DashboardInfo toDashboardInfo(const QUrl &source, const Dto::DashboardInfoDto &infoDto)
|
|
|
|
|
{
|
|
|
|
|
const QVersionNumber versionNumber = infoDto.dashboardVersionNumber
|
|
|
|
|
? QVersionNumber::fromString(*infoDto.dashboardVersionNumber) : QVersionNumber();
|
|
|
|
|
|
|
|
|
|
QStringList projects;
|
|
|
|
|
QHash<QString, QUrl> projectUrls;
|
|
|
|
|
|
|
|
|
|
if (infoDto.projects) {
|
|
|
|
|
for (const Dto::ProjectReferenceDto &project : *infoDto.projects) {
|
|
|
|
|
projects.push_back(project.name);
|
|
|
|
|
projectUrls.insert(project.name, project.url);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {source, versionNumber, projects, projectUrls, infoDto.checkCredentialsUrl};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Group dashboardInfoRecipe(const DashboardInfoHandler &handler)
|
|
|
|
|
{
|
|
|
|
|
const auto onSetup = [handler] {
|
|
|
|
|
if (dd->m_dashboardInfo) {
|
|
|
|
|
if (handler)
|
|
|
|
|
handler(*dd->m_dashboardInfo);
|
|
|
|
|
return SetupResult::StopWithSuccess;
|
|
|
|
|
}
|
|
|
|
|
return SetupResult::Continue;
|
|
|
|
|
};
|
2024-01-24 12:56:27 +01:00
|
|
|
const auto onDone = [handler] {
|
|
|
|
|
if (handler)
|
2024-01-23 22:29:59 +01:00
|
|
|
handler(make_unexpected(QString("Error"))); // TODO: Collect error message in the storage.
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const QUrl url(settings().server.dashboard);
|
|
|
|
|
|
|
|
|
|
const auto resultHandler = [handler, url](const Dto::DashboardInfoDto &data) {
|
|
|
|
|
dd->m_dashboardInfo = toDashboardInfo(url, data);
|
|
|
|
|
if (handler)
|
|
|
|
|
handler(*dd->m_dashboardInfo);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const Group root {
|
|
|
|
|
onGroupSetup(onSetup), // Stops if cache exists.
|
|
|
|
|
fetchDataRecipe<Dto::DashboardInfoDto>(url, resultHandler),
|
2024-01-24 12:56:27 +01:00
|
|
|
onGroupDone(onDone, CallDoneIf::Error)
|
2024-01-23 22:29:59 +01:00
|
|
|
};
|
|
|
|
|
return root;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-27 13:33:45 +01:00
|
|
|
Group issueTableRecipe(const IssueListSearch &search, const IssueTableHandler &handler)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(dd->m_currentProjectInfo, return {}); // TODO: Call handler with unexpected?
|
|
|
|
|
|
|
|
|
|
const QString query = search.toQuery();
|
|
|
|
|
if (query.isEmpty())
|
|
|
|
|
return {}; // TODO: Call handler with unexpected?
|
|
|
|
|
|
|
|
|
|
const QUrl url = urlForProject(dd->m_currentProjectInfo.value().name + '/')
|
|
|
|
|
.resolved(QString("issues" + query));
|
|
|
|
|
|
|
|
|
|
return fetchDataRecipe<Dto::IssueTableDto>(url, handler);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-30 21:19:28 +01:00
|
|
|
Group issueHtmlRecipe(const QString &issueId, const HtmlHandler &handler)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(dd->m_currentProjectInfo, return {}); // TODO: Call handler with unexpected?
|
|
|
|
|
|
|
|
|
|
QString dashboard = settings().server.dashboard;
|
|
|
|
|
if (!dashboard.endsWith(QLatin1Char('/')))
|
|
|
|
|
dashboard += QLatin1Char('/');
|
|
|
|
|
|
|
|
|
|
const QUrl url = urlForProject(dd->m_currentProjectInfo.value().name + '/')
|
|
|
|
|
.resolved(QString("issues/"))
|
|
|
|
|
.resolved(QString(issueId + '/'))
|
|
|
|
|
.resolved(QString("properties"));
|
|
|
|
|
|
|
|
|
|
return fetchHtmlRecipe(url, handler);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 19:46:40 +01:00
|
|
|
void AxivionPluginPrivate::fetchProjectInfo(const QString &projectName)
|
|
|
|
|
{
|
|
|
|
|
if (m_taskTreeRunner.isRunning()) { // TODO: cache in queue and run when task tree finished
|
|
|
|
|
QTimer::singleShot(3000, this, [this, projectName] { fetchProjectInfo(projectName); });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
clearAllMarks();
|
|
|
|
|
if (projectName.isEmpty()) {
|
|
|
|
|
m_currentProjectInfo = {};
|
|
|
|
|
m_axivionOutputPane.updateDashboard();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-24 00:06:55 +01:00
|
|
|
const auto onTaskTreeSetup = [this, projectName](TaskTree &taskTree) {
|
|
|
|
|
if (!m_dashboardInfo)
|
|
|
|
|
return SetupResult::StopWithError;
|
|
|
|
|
|
|
|
|
|
const auto it = m_dashboardInfo->projectUrls.constFind(projectName);
|
|
|
|
|
if (it == m_dashboardInfo->projectUrls.constEnd())
|
|
|
|
|
return SetupResult::StopWithError;
|
|
|
|
|
|
|
|
|
|
const auto handler = [this](const Dto::ProjectInfoDto &data) {
|
|
|
|
|
m_currentProjectInfo = data;
|
|
|
|
|
m_axivionOutputPane.updateDashboard();
|
|
|
|
|
// handle already opened documents
|
2024-02-03 21:05:01 +01:00
|
|
|
if (auto buildSystem = ProjectManager::startupBuildSystem();
|
2024-01-24 00:06:55 +01:00
|
|
|
!buildSystem || !buildSystem->isParsing()) {
|
|
|
|
|
handleOpenedDocs(nullptr);
|
|
|
|
|
} else {
|
2024-02-03 21:05:01 +01:00
|
|
|
connect(ProjectManager::instance(),
|
|
|
|
|
&ProjectManager::projectFinishedParsing,
|
2024-01-24 00:06:55 +01:00
|
|
|
this, &AxivionPluginPrivate::handleOpenedDocs);
|
|
|
|
|
}
|
|
|
|
|
};
|
2024-01-19 19:46:40 +01:00
|
|
|
|
2024-01-24 00:06:55 +01:00
|
|
|
const QUrl url(settings().server.dashboard);
|
|
|
|
|
taskTree.setRecipe(fetchDataRecipe<Dto::ProjectInfoDto>(url.resolved(*it), handler));
|
|
|
|
|
return SetupResult::Continue;
|
2023-11-24 12:29:17 +01:00
|
|
|
};
|
|
|
|
|
|
2024-01-24 00:06:55 +01:00
|
|
|
const Group root {
|
|
|
|
|
dashboardInfoRecipe(),
|
|
|
|
|
TaskTreeTask(onTaskTreeSetup)
|
|
|
|
|
};
|
|
|
|
|
m_taskTreeRunner.start(root);
|
2022-12-14 12:11:03 +01:00
|
|
|
}
|
|
|
|
|
|
2024-01-27 14:23:39 +01:00
|
|
|
Group tableInfoRecipe(const QString &prefix, const TableInfoHandler &handler)
|
2024-01-19 15:06:34 +01:00
|
|
|
{
|
2024-01-27 14:23:39 +01:00
|
|
|
const QUrl url = urlForProject(dd->m_currentProjectInfo.value().name + '/')
|
|
|
|
|
.resolved(QString("issues_meta?kind=" + prefix));
|
|
|
|
|
return fetchDataRecipe<Dto::TableInfoDto>(url, handler);
|
2024-01-19 15:06:34 +01:00
|
|
|
}
|
|
|
|
|
|
2024-01-30 21:19:28 +01:00
|
|
|
void AxivionPluginPrivate::fetchIssueInfo(const QString &id)
|
2023-01-13 14:38:39 +01:00
|
|
|
{
|
2024-01-30 15:15:50 +01:00
|
|
|
if (!m_currentProjectInfo)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-01-30 21:19:28 +01:00
|
|
|
const auto ruleHandler = [](const QByteArray &htmlText) {
|
2024-02-02 15:24:31 +01:00
|
|
|
QByteArray fixedHtml = htmlText;
|
|
|
|
|
const int idx = htmlText.indexOf("<div class=\"ax-issuedetails-table-container\">");
|
|
|
|
|
if (idx >= 0)
|
|
|
|
|
fixedHtml = "<html><body>" + htmlText.mid(idx);
|
|
|
|
|
dd->m_axivionOutputPane.updateAndShowRule(QString::fromUtf8(fixedHtml));
|
2024-01-30 21:19:28 +01:00
|
|
|
};
|
2023-01-13 14:38:39 +01:00
|
|
|
|
2024-01-30 21:19:28 +01:00
|
|
|
m_issueInfoRunner.start(issueHtmlRecipe(QString("SV") + id, ruleHandler));
|
2023-01-13 14:38:39 +01:00
|
|
|
}
|
|
|
|
|
|
2024-02-03 21:05:01 +01:00
|
|
|
void AxivionPluginPrivate::handleOpenedDocs(Project *project)
|
2022-12-16 15:12:39 +01:00
|
|
|
{
|
2024-02-03 21:05:01 +01:00
|
|
|
if (project && ProjectManager::startupProject() != project)
|
2022-12-16 15:12:39 +01:00
|
|
|
return;
|
2024-01-30 14:01:58 +01:00
|
|
|
const QList<IDocument *> openDocuments = DocumentModel::openedDocuments();
|
|
|
|
|
for (IDocument *doc : openDocuments)
|
2022-12-16 15:12:39 +01:00
|
|
|
onDocumentOpened(doc);
|
|
|
|
|
if (project)
|
2024-02-03 21:05:01 +01:00
|
|
|
disconnect(ProjectManager::instance(), &ProjectManager::projectFinishedParsing,
|
2022-12-16 15:12:39 +01:00
|
|
|
this, &AxivionPluginPrivate::handleOpenedDocs);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-16 22:34:56 +01:00
|
|
|
void AxivionPluginPrivate::clearAllMarks()
|
|
|
|
|
{
|
2024-01-30 14:01:58 +01:00
|
|
|
const QList<IDocument *> openDocuments = DocumentModel::openedDocuments();
|
|
|
|
|
for (IDocument *doc : openDocuments)
|
2022-12-16 22:34:56 +01:00
|
|
|
onDocumentClosed(doc);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-30 14:01:58 +01:00
|
|
|
void AxivionPluginPrivate::onDocumentOpened(IDocument *doc)
|
2022-12-16 23:11:46 +01:00
|
|
|
{
|
2023-07-25 18:48:18 +02:00
|
|
|
if (!m_currentProjectInfo) // we do not have a project info (yet)
|
2022-12-16 23:11:46 +01:00
|
|
|
return;
|
|
|
|
|
|
2024-02-03 21:05:01 +01:00
|
|
|
Project *project = ProjectManager::startupProject();
|
2023-11-24 13:45:07 +01:00
|
|
|
// TODO: Sometimes the isKnownFile() returns false after opening a session.
|
|
|
|
|
// This happens randomly on linux.
|
2022-12-16 23:11:46 +01:00
|
|
|
if (!doc || !project->isKnownFile(doc->filePath()))
|
|
|
|
|
return;
|
|
|
|
|
|
2024-01-30 15:15:50 +01:00
|
|
|
IssueListSearch search;
|
|
|
|
|
search.kind = "SV";
|
|
|
|
|
search.filter_path = doc->filePath().relativeChildPath(project->projectDirectory()).path();
|
2024-01-30 18:26:21 +01:00
|
|
|
search.limit = 0;
|
2024-01-30 15:15:50 +01:00
|
|
|
|
|
|
|
|
const auto issuesHandler = [this](const Dto::IssueTableDto &dto) {
|
|
|
|
|
IssuesList issues;
|
|
|
|
|
const std::vector<std::map<QString, Dto::Any>> &rows = dto.rows;
|
|
|
|
|
for (const auto &row : rows) {
|
|
|
|
|
ShortIssue issue;
|
|
|
|
|
for (auto it = row.cbegin(); it != row.cend(); ++it) {
|
|
|
|
|
if (it->first == "id")
|
|
|
|
|
issue.id = anyToSimpleString(it->second);
|
|
|
|
|
else if (it->first == "state")
|
|
|
|
|
issue.state = anyToSimpleString(it->second);
|
|
|
|
|
else if (it->first == "errorNumber")
|
|
|
|
|
issue.errorNumber = anyToSimpleString(it->second);
|
|
|
|
|
else if (it->first == "message")
|
|
|
|
|
issue.message = anyToSimpleString(it->second);
|
|
|
|
|
else if (it->first == "entity")
|
|
|
|
|
issue.entity = anyToSimpleString(it->second);
|
|
|
|
|
else if (it->first == "path")
|
|
|
|
|
issue.filePath = anyToSimpleString(it->second);
|
|
|
|
|
else if (it->first == "severity")
|
|
|
|
|
issue.severity = anyToSimpleString(it->second);
|
|
|
|
|
else if (it->first == "line")
|
|
|
|
|
issue.lineNumber = anyToSimpleString(it->second).toInt();
|
|
|
|
|
}
|
|
|
|
|
issues.issues << issue;
|
|
|
|
|
}
|
|
|
|
|
handleIssuesForFile(issues);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TaskTree *taskTree = new TaskTree;
|
|
|
|
|
taskTree->setRecipe(issueTableRecipe(search, issuesHandler));
|
|
|
|
|
m_docMarksTrees.insert_or_assign(doc, std::unique_ptr<TaskTree>(taskTree));
|
|
|
|
|
connect(taskTree, &TaskTree::done, this, [this, doc] {
|
|
|
|
|
const auto it = m_docMarksTrees.find(doc);
|
|
|
|
|
QTC_ASSERT(it != m_docMarksTrees.end(), return);
|
|
|
|
|
it->second.release()->deleteLater();
|
|
|
|
|
m_docMarksTrees.erase(it);
|
2022-12-16 23:11:46 +01:00
|
|
|
});
|
2024-01-30 15:15:50 +01:00
|
|
|
taskTree->start();
|
2022-12-16 23:11:46 +01:00
|
|
|
}
|
|
|
|
|
|
2024-01-30 14:01:58 +01:00
|
|
|
void AxivionPluginPrivate::onDocumentClosed(IDocument *doc)
|
2022-12-16 23:11:46 +01:00
|
|
|
{
|
2024-02-02 11:24:48 +01:00
|
|
|
const auto document = qobject_cast<TextDocument *>(doc);
|
2022-12-16 23:11:46 +01:00
|
|
|
if (!document)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-01-30 15:15:50 +01:00
|
|
|
const auto it = m_docMarksTrees.find(doc);
|
|
|
|
|
if (it != m_docMarksTrees.end())
|
|
|
|
|
m_docMarksTrees.erase(it);
|
|
|
|
|
|
2024-02-02 11:26:14 +01:00
|
|
|
const TextMarks &marks = document->marks();
|
|
|
|
|
for (TextMark *mark : marks) {
|
|
|
|
|
if (mark->category().id == AxivionTextMarkId)
|
|
|
|
|
delete mark;
|
2022-12-16 23:11:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AxivionPluginPrivate::handleIssuesForFile(const IssuesList &issues)
|
|
|
|
|
{
|
|
|
|
|
if (issues.issues.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
2024-02-03 21:05:01 +01:00
|
|
|
Project *project = ProjectManager::startupProject();
|
2022-12-16 23:11:46 +01:00
|
|
|
if (!project)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-11-24 12:29:17 +01:00
|
|
|
const FilePath filePath = project->projectDirectory()
|
2022-12-16 23:11:46 +01:00
|
|
|
.pathAppended(issues.issues.first().filePath);
|
|
|
|
|
|
2023-11-24 12:29:17 +01:00
|
|
|
const Id axivionId(AxivionTextMarkId);
|
2022-12-16 23:11:46 +01:00
|
|
|
for (const ShortIssue &issue : std::as_const(issues.issues)) {
|
|
|
|
|
// 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
|
|
|
|
|
// current state of the file - some magic has to happen here
|
2023-01-13 13:49:40 +01:00
|
|
|
new AxivionTextMark(filePath, issue);
|
2022-12-16 23:11:46 +01:00
|
|
|
}
|
2022-12-14 12:11:03 +01:00
|
|
|
}
|
|
|
|
|
|
2024-01-12 08:38:31 +01:00
|
|
|
class AxivionPlugin final : public ExtensionSystem::IPlugin
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Axivion.json")
|
|
|
|
|
|
|
|
|
|
~AxivionPlugin() final
|
|
|
|
|
{
|
|
|
|
|
AxivionProjectSettings::destroyProjectSettings();
|
|
|
|
|
delete dd;
|
|
|
|
|
dd = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void initialize() final
|
|
|
|
|
{
|
|
|
|
|
dd = new AxivionPluginPrivate;
|
|
|
|
|
|
|
|
|
|
AxivionProjectSettings::setupProjectPanel();
|
|
|
|
|
|
2024-02-03 21:05:01 +01:00
|
|
|
connect(ProjectManager::instance(), &ProjectManager::startupProjectChanged,
|
2024-01-12 08:38:31 +01:00
|
|
|
dd, &AxivionPluginPrivate::onStartupProjectChanged);
|
2024-01-30 14:01:58 +01:00
|
|
|
connect(EditorManager::instance(), &EditorManager::documentOpened,
|
2024-01-12 08:38:31 +01:00
|
|
|
dd, &AxivionPluginPrivate::onDocumentOpened);
|
2024-01-30 14:01:58 +01:00
|
|
|
connect(EditorManager::instance(), &EditorManager::documentClosed,
|
2024-01-12 08:38:31 +01:00
|
|
|
dd, &AxivionPluginPrivate::onDocumentClosed);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-11-28 09:48:11 +01:00
|
|
|
} // Axivion::Internal
|
2024-01-12 08:38:31 +01:00
|
|
|
|
|
|
|
|
#include "axivionplugin.moc"
|