diff options
author | Kai Koehne <kai.koehne@qt.io> | 2016-10-26 14:40:07 +0200 |
---|---|---|
committer | Kai Koehne <kai.koehne@qt.io> | 2016-10-27 09:32:11 +0000 |
commit | b8113e90e2a1d9ea38a478990a93615f432ac35b (patch) | |
tree | 335f979a5c0666670dfdcca1f977517a8b0ee8e2 /src | |
parent | 56ac0c12ab5e7269e16bcc1248e4241302d91d09 (diff) | |
download | qttools-b8113e90e2a1d9ea38a478990a93615f432ac35b.tar.gz |
attributionscanner: Allow to specify multiple filesv5.8.0-beta1
So far 'Path' was used to specify a whole directory, or a single file.
This introduces a separate 'Files' property, so that one can document
that e.g. two specific files in a directory contain third party code.
'Files' should be relative to 'Path'.
Change-Id: If4213d9a1b1ca706c49ed761027c6af86fbdc02a
Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qtattributionsscanner/jsongenerator.cpp | 1 | ||||
-rw-r--r-- | src/qtattributionsscanner/package.h | 3 | ||||
-rw-r--r-- | src/qtattributionsscanner/qdocgenerator.cpp | 31 | ||||
-rw-r--r-- | src/qtattributionsscanner/scanner.cpp | 4 |
4 files changed, 35 insertions, 4 deletions
diff --git a/src/qtattributionsscanner/jsongenerator.cpp b/src/qtattributionsscanner/jsongenerator.cpp index f50a9c1bf..580fddf57 100644 --- a/src/qtattributionsscanner/jsongenerator.cpp +++ b/src/qtattributionsscanner/jsongenerator.cpp @@ -42,6 +42,7 @@ static QJsonObject generate(Package package) obj.insert(QStringLiteral("Id"), package.id); obj.insert(QStringLiteral("Path"), package.path); + obj.insert(QStringLiteral("Files"), package.files.join(QLatin1Char(' '))); obj.insert(QStringLiteral("QDocModule"), package.qdocModule); obj.insert(QStringLiteral("Name"), package.name); obj.insert(QStringLiteral("QtUsage"), package.qtUsage); diff --git a/src/qtattributionsscanner/package.h b/src/qtattributionsscanner/package.h index 5cf624307..31d95c9fb 100644 --- a/src/qtattributionsscanner/package.h +++ b/src/qtattributionsscanner/package.h @@ -35,7 +35,8 @@ struct Package { QString id; // Usually a lowercase, no-spaces version of the name. Mandatory. QString path; // Source directory. Optional. - // Default is the directory of the qt_attribution.json ile. + // Default is the directory of the qt_attribution.json file. + QStringList files; // Files in path. Optional. QString name; // Descriptive name of the package. Will be used as the title. Mandatory. QString qdocModule; // QDoc module where the documentation should be included. Mandatory. QString qtUsage; // How the package is used in Qt. Any way to disable? Mandatory. diff --git a/src/qtattributionsscanner/qdocgenerator.cpp b/src/qtattributionsscanner/qdocgenerator.cpp index 2651ef947..6fcccee60 100644 --- a/src/qtattributionsscanner/qdocgenerator.cpp +++ b/src/qtattributionsscanner/qdocgenerator.cpp @@ -49,6 +49,23 @@ static bool isSpdxLicenseId(const QString &str) { return true; } +static QString languageJoin(const QStringList &list) +{ + QString result; + for (int i = 0; i < list.size(); ++i) { + QString delimiter = QStringLiteral(", "); + if (i == list.size() - 1) // last item + delimiter.clear(); + else if (list.size() == 2) + delimiter = QStringLiteral(" and "); + else if (list.size() > 2 && i == list.size() - 2) + delimiter = QStringLiteral(", and "); // oxford comma + result += list[i] + delimiter; + } + + return result; +} + static void generate(QTextStream &out, const Package &package, const QDir &baseDir, LogLevel logLevel) { @@ -66,8 +83,18 @@ static void generate(QTextStream &out, const Package &package, const QDir &baseD if (!package.qtUsage.isEmpty()) out << package.qtUsage << "\n\n"; - out << "The sources can be found in " - << baseDir.relativeFilePath(package.path) << ".\n\n"; + QStringList sourcePaths; + if (package.files.isEmpty()) { + sourcePaths << baseDir.relativeFilePath(package.path); + } else { + const QDir packageDir(package.path); + for (const QString &filePath: package.files) { + const QString absolutePath = packageDir.absoluteFilePath(filePath); + sourcePaths << baseDir.relativeFilePath(absolutePath); + } + } + + out << "The sources can be found in " << languageJoin(sourcePaths) << ".\n\n"; if (!package.homepage.isEmpty()) out << "\\l{" << package.homepage << "}{Project Homepage}\n\n"; diff --git a/src/qtattributionsscanner/scanner.cpp b/src/qtattributionsscanner/scanner.cpp index 823d9a8c3..3babfbaef 100644 --- a/src/qtattributionsscanner/scanner.cpp +++ b/src/qtattributionsscanner/scanner.cpp @@ -54,7 +54,7 @@ static Package readPackage(const QJsonObject &object, const QString &filePath, L for (auto iter = object.constBegin(); iter != object.constEnd(); ++iter) { const QString key = iter.key(); - if (!iter.value().isString()) { + if (!iter.value().isString() && key != QLatin1String("files")) { if (logLevel != SilentLog) std::cerr << qPrintable(tr("File %1: Expected JSON string as value of %2.").arg( QDir::toNativeSeparators(filePath), key)) << std::endl; @@ -65,6 +65,8 @@ static Package readPackage(const QJsonObject &object, const QString &filePath, L p.name = value; } else if (key == QLatin1String("Path")) { p.path = QDir(directory).absoluteFilePath(value); + } else if (key == QLatin1String("Files")) { + p.files = value.split(QRegExp(QStringLiteral("\\s")), QString::SkipEmptyParts); } else if (key == QLatin1String("Id")) { p.id = value; } else if (key == QLatin1String("Homepage")) { |