diff options
author | Kai Koehne <kai.koehne@qt.io> | 2016-07-19 10:37:03 +0200 |
---|---|---|
committer | Kai Koehne <kai.koehne@qt.io> | 2016-08-08 11:47:27 +0000 |
commit | de8c576b24852764de2fe1a295b9c9def473ac80 (patch) | |
tree | 814cc1e71e76349cfcb18950b0d90d4b388e59bd /src/qtattributionsscanner | |
parent | 032a1a640b75bcff83ff2c43c1290f4017cf0e1f (diff) |
qtattributionsscanner: Support setting & filtering qdoc module
This is needed e.g. for qtbase, where there are multiple help
projects.
Change-Id: Ia31ac4818ad6780a301fa6f7371a3f33ee21df48
Reviewed-by: Topi Reiniƶ <topi.reinio@theqtcompany.com>
Diffstat (limited to 'src/qtattributionsscanner')
-rw-r--r-- | src/qtattributionsscanner/jsongenerator.cpp | 1 | ||||
-rw-r--r-- | src/qtattributionsscanner/main.cpp | 18 | ||||
-rw-r--r-- | src/qtattributionsscanner/package.h | 1 | ||||
-rw-r--r-- | src/qtattributionsscanner/packagefilter.cpp | 54 | ||||
-rw-r--r-- | src/qtattributionsscanner/packagefilter.h | 47 | ||||
-rw-r--r-- | src/qtattributionsscanner/qdocgenerator.cpp | 1 | ||||
-rw-r--r-- | src/qtattributionsscanner/qtattributionsscanner.pro | 2 | ||||
-rw-r--r-- | src/qtattributionsscanner/scanner.cpp | 4 |
8 files changed, 126 insertions, 2 deletions
diff --git a/src/qtattributionsscanner/jsongenerator.cpp b/src/qtattributionsscanner/jsongenerator.cpp index 9873e231e..f50a9c1bf 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("QDocModule"), package.qdocModule); obj.insert(QStringLiteral("Name"), package.name); obj.insert(QStringLiteral("QtUsage"), package.qtUsage); diff --git a/src/qtattributionsscanner/main.cpp b/src/qtattributionsscanner/main.cpp index a5647e375..cd9bc1fed 100644 --- a/src/qtattributionsscanner/main.cpp +++ b/src/qtattributionsscanner/main.cpp @@ -28,6 +28,7 @@ #include "jsongenerator.h" #include "logging.h" +#include "packagefilter.h" #include "qdocgenerator.h" #include "scanner.h" @@ -56,6 +57,9 @@ int main(int argc, char *argv[]) tr("Output format (\"qdoc\", \"json\")."), QStringLiteral("generator"), QStringLiteral("qdoc")); + QCommandLineOption filterOption(QStringLiteral("filter"), + tr("Filter packages according to <filter> (e.g. QDocModule=qtcore)"), + QStringLiteral("expression")); QCommandLineOption outputOption({ QStringLiteral("o"), QStringLiteral("output") }, tr("Write generated data to <file>."), QStringLiteral("file")); @@ -65,6 +69,7 @@ int main(int argc, char *argv[]) tr("Minimal output.")); parser.addOption(generatorOption); + parser.addOption(filterOption); parser.addOption(outputOption); parser.addOption(verboseOption); parser.addOption(silentOption); @@ -93,6 +98,15 @@ int main(int argc, char *argv[]) QVector<Package> packages = Scanner::scanDirectory(directory, logLevel); + if (parser.isSet(filterOption)) { + PackageFilter filter(parser.value(filterOption)); + if (filter.type == PackageFilter::InvalidFilter) + return 4; + packages.erase(std::remove_if(packages.begin(), packages.end(), + [&filter](const Package &p) { return !filter(p); }), + packages.end()); + } + if (logLevel == VerboseLog) std::cerr << qPrintable(tr("%1 packages found.").arg(packages.size())) << std::endl; @@ -103,7 +117,7 @@ int main(int argc, char *argv[]) std::cerr << qPrintable(tr("Cannot open %1 for writing.").arg( QDir::toNativeSeparators(outFile.fileName()))) << std::endl; - return 4; + return 5; } out.setDevice(&outFile); } @@ -117,7 +131,7 @@ int main(int argc, char *argv[]) JsonGenerator::generate(out, packages, logLevel); } else { std::cerr << qPrintable(tr("Unknown output-format %1.").arg(generator)) << std::endl; - return 5; + return 6; } if (logLevel == VerboseLog) diff --git a/src/qtattributionsscanner/package.h b/src/qtattributionsscanner/package.h index 3dbd95494..5cf624307 100644 --- a/src/qtattributionsscanner/package.h +++ b/src/qtattributionsscanner/package.h @@ -37,6 +37,7 @@ struct Package { QString path; // Source directory. Optional. // Default is the directory of the qt_attribution.json ile. 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. QString description; // A short description of what the package is and is used for. Optional. diff --git a/src/qtattributionsscanner/packagefilter.cpp b/src/qtattributionsscanner/packagefilter.cpp new file mode 100644 index 000000000..30dd3daef --- /dev/null +++ b/src/qtattributionsscanner/packagefilter.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the tools applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "logging.h" +#include "packagefilter.h" +#include <iostream> + +PackageFilter::PackageFilter(const QString &expression) + : type(InvalidFilter) +{ + if (expression.startsWith(QLatin1String("QDocModule="))) { + type = QDocModuleFilter; + this->expression = expression.mid(strlen("QDocModule=")); + } else { + std::cerr << qPrintable(tr("Invalid filter expression \"%1\"").arg(expression)) << std::endl; + std::cerr << qPrintable(tr("Currently only \"QDocModule=*\" is supported.")) << std::endl; + } +} + +bool PackageFilter::operator()(const Package &p) +{ + switch (type) { + case InvalidFilter: + return true; + case QDocModuleFilter: + return p.qdocModule == expression; + } + return false; +} diff --git a/src/qtattributionsscanner/packagefilter.h b/src/qtattributionsscanner/packagefilter.h new file mode 100644 index 000000000..968449445 --- /dev/null +++ b/src/qtattributionsscanner/packagefilter.h @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the tools applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PACKAGEFILTER_H +#define PACKAGEFILTER_H + +#include "package.h" + +struct PackageFilter +{ + PackageFilter(const QString &expression); + + bool operator()(const Package &p); + + enum { + InvalidFilter, + QDocModuleFilter + } type; + QString expression; +}; + +#endif // PACKAGEFILTER_H diff --git a/src/qtattributionsscanner/qdocgenerator.cpp b/src/qtattributionsscanner/qdocgenerator.cpp index 8115069a7..215f775fa 100644 --- a/src/qtattributionsscanner/qdocgenerator.cpp +++ b/src/qtattributionsscanner/qdocgenerator.cpp @@ -39,6 +39,7 @@ static void generate(QTextStream &out, const Package &package, const QDir &baseD { out << "/*!\n\n"; out << "\\contentspage attributions.html\n"; + out << "\\ingroup attributions-" << package.qdocModule << "\n"; out << "\\page attribution-" << package.id << ".html attribution\n"; out << "\\target "<< package.id << "\n\n"; out << "\\title " << package.name << "\n"; diff --git a/src/qtattributionsscanner/qtattributionsscanner.pro b/src/qtattributionsscanner/qtattributionsscanner.pro index 5e4315a79..d5368b679 100644 --- a/src/qtattributionsscanner/qtattributionsscanner.pro +++ b/src/qtattributionsscanner/qtattributionsscanner.pro @@ -3,6 +3,7 @@ CONFIG += console SOURCES += \ jsongenerator.cpp \ main.cpp \ + packagefilter.cpp \ qdocgenerator.cpp \ scanner.cpp @@ -10,6 +11,7 @@ HEADERS += \ jsongenerator.h \ logging.h \ package.h \ + packagefilter.h \ qdocgenerator.h \ scanner.h diff --git a/src/qtattributionsscanner/scanner.cpp b/src/qtattributionsscanner/scanner.cpp index 7ad8145b2..823d9a8c3 100644 --- a/src/qtattributionsscanner/scanner.cpp +++ b/src/qtattributionsscanner/scanner.cpp @@ -81,6 +81,8 @@ static Package readPackage(const QJsonObject &object, const QString &filePath, L p.licenseFile = QDir(directory).absoluteFilePath(value); } else if (key == QLatin1String("Copyright")) { p.copyright = value; + } else if (key == QLatin1String("QDocModule")) { + p.qdocModule = value; } else if (key == QLatin1String("Description")) { p.description = value; } else if (key == QLatin1String("QtUsage")) { @@ -98,6 +100,8 @@ static Package readPackage(const QJsonObject &object, const QString &filePath, L missingPropertyWarning(filePath, QStringLiteral("Name")); if (p.id.isEmpty()) missingPropertyWarning(filePath, QStringLiteral("Id")); + if (p.qdocModule.isEmpty()) + missingPropertyWarning(filePath, QStringLiteral("QDocModule")); if (p.qtUsage.isEmpty()) missingPropertyWarning(filePath, QStringLiteral("QtUsage")); if (p.license.isEmpty()) |