diff options
author | Lucie GĂ©rard <lucie.gerard@qt.io> | 2023-08-31 13:22:26 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-09-11 11:25:15 +0000 |
commit | b0bb1bf334d69368e176a9ae2b6e953cb2618a0f (patch) | |
tree | b3f664ed0d35dab8a00677eb4d9ae143e032e3bb | |
parent | 18f9224e7adc3565c0e451f149f6c03ecacc7035 (diff) |
Change qtattributionsscanner to accept string arrays for Copyright
Task-number: QTBUG-111873
Change-Id: Ibdc03955d6e5942deb6dab37a70fdaefec68ccec
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
(cherry picked from commit 687bbd584cc36fb8d213cb99a9098178e3701ce8)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/qtattributionsscanner/scanner.cpp | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/qtattributionsscanner/scanner.cpp b/src/qtattributionsscanner/scanner.cpp index 460e21a7f..f936ec0d2 100644 --- a/src/qtattributionsscanner/scanner.cpp +++ b/src/qtattributionsscanner/scanner.cpp @@ -124,6 +124,20 @@ static std::optional<QStringList> toStringList(const QJsonValue &value) return result; } +static std::optional<QString> arrayToMultiLineString(const QJsonValue &value) +{ + if (!value.isArray()) + return std::nullopt; + QString result; + for (const auto &iter : value.toArray()) { + if (iter.type() != QJsonValue::String) + return std::nullopt; + result.append(iter.toString()); + result.append(QLatin1StringView("\n")); + } + return result; +} + // Extracts SPDX license ids from a SPDX license expression. // For "(BSD-3-Clause AND BeerWare)" this function returns { "BSD-3-Clause", "BeerWare" }. static QStringList extractLicenseIdsFromSPDXExpression(QString expression) @@ -211,7 +225,8 @@ static std::optional<Package> readPackage(const QJsonObject &object, const QStri const QString key = iter.key(); if (!iter.value().isString() && key != "QtParts"_L1 && key != "SecurityCritical"_L1 - && key != "Files"_L1 && key != "LicenseFiles"_L1 && key != "Comment"_L1) { + && key != "Files"_L1 && key != "LicenseFiles"_L1 && key != "Comment"_L1 + && key != "Copyright"_L1) { if (logLevel != SilentLog) std::cerr << qPrintable(tr("File %1: Expected JSON string as value of %2.").arg( QDir::toNativeSeparators(filePath), key)) << std::endl; @@ -273,7 +288,24 @@ static std::optional<Package> readPackage(const QJsonObject &object, const QStri for (const auto &iter : std::as_const(strings.value())) p.licenseFiles.push_back(dir.absoluteFilePath(iter)); } else if (key == "Copyright"_L1) { - p.copyright = value; + QJsonValueConstRef jsonValue = iter.value(); + if (jsonValue.isArray()) { + // Array joined with new lines + auto maybeString = arrayToMultiLineString(jsonValue); + if (maybeString) + p.copyright = maybeString.value(); + } else if (jsonValue.isString()) { + // Legacy format: multiple values separated by space in one string. + p.copyright = value; + } else { + if (logLevel != SilentLog) { + std::cerr << qPrintable(tr("File %1: Expected JSON array of string or" + "string as value of %2.").arg( + QDir::toNativeSeparators(filePath), key)) << std::endl; + validPackage = false; + continue; + } + } } else if (key == "CopyrightFile"_L1) { p.copyrightFile = QDir(directory).absoluteFilePath(value); } else if (key == "PackageComment"_L1) { |