Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar committed Jan 30, 2024
1 parent 72c3c2a commit 520aa8d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
45 changes: 22 additions & 23 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,24 +910,28 @@ void MainWindow::loadAddon(Settings &settings, const QString &filesDir, const QS
const QString addonFilePath = fromNativePath(ProjectFile::getAddonFilePath(filesDir, addon));

picojson::object obj;
if (addonFilePath.isEmpty())
if (addonFilePath.isEmpty()) {
// Addon not found => add data to addons and addonInfos so that fileNotFound error(s) are reported during analysis
obj["script"] = picojson::value(addon.toStdString());
else {
obj["script"] = picojson::value(addonFilePath.toStdString());
if (!pythonCmd.isEmpty())
obj["python"] = picojson::value(pythonCmd.toStdString());

if (!isCppcheckPremium() && addon == "misra") {
const QString misraFile = fromNativePath(mSettings->value(SETTINGS_MISRA_FILE).toString());
if (!misraFile.isEmpty()) {
QString arg;
if (misraFile.endsWith(".pdf", Qt::CaseInsensitive))
arg = "--misra-pdf=" + misraFile;
else
arg = "--rule-texts=" + misraFile;
obj["args"] = picojson::value(arg.toStdString());
}
settings.addons.emplace("file not found: " + addon.toStdString());
AddonInfo addonInfo;
addonInfo.name = addon.toStdString();
settings.addonInfos.emplace_back(std::move(addonInfo));
return;
}

obj["script"] = picojson::value(addonFilePath.toStdString());
if (!pythonCmd.isEmpty())
obj["python"] = picojson::value(pythonCmd.toStdString());

if (!isCppcheckPremium() && addon == "misra") {
const QString misraFile = fromNativePath(mSettings->value(SETTINGS_MISRA_FILE).toString());
if (!misraFile.isEmpty()) {
QString arg;
if (misraFile.endsWith(".pdf", Qt::CaseInsensitive))
arg = "--misra-pdf=" + misraFile;
else
arg = "--rule-texts=" + misraFile;
obj["args"] = picojson::value(arg.toStdString());
}
}

Expand All @@ -936,12 +940,7 @@ void MainWindow::loadAddon(Settings &settings, const QString &filesDir, const QS
std::string json_str = json.serialize();

AddonInfo addonInfo;
if (addonFilePath.isEmpty()) {
// name will be shown in the fileNotFound error message
addonInfo.name = addon.toStdString();
} else {
addonInfo.getAddonInfo(json_str, settings.exename); // TODO: handle error
}
addonInfo.getAddonInfo(json_str, settings.exename); // TODO: handle error
settings.addonInfos.emplace_back(std::move(addonInfo));

settings.addons.emplace(std::move(json_str));
Expand Down
3 changes: 2 additions & 1 deletion gui/test/projectfile/testprojectfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,15 @@ void TestProjectFile::getAddonFilePath() const

QFile file(filepath);
QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text));
file.write("");
file.close();

// Relative path to addon
QCOMPARE(ProjectFile::getAddonFilePath(tempdir.path(), "addon"), filepath);
QCOMPARE(ProjectFile::getAddonFilePath(tempdir.path(), "not exist"), QString());

// Absolute path to addon
QCOMPARE(ProjectFile::getAddonFilePath("/not/exist", filepath), filepath);
QCOMPARE(ProjectFile::getAddonFilePath(tempdir.path(), filepath), filepath);
}

QTEST_MAIN(TestProjectFile)

0 comments on commit 520aa8d

Please sign in to comment.