File indexing completed on 2024-03-24 17:21:31

0001 /*
0002  *  SPDX-FileCopyrightText: 2019  Andreas Cord-Landwehr <cordlandwehr@kde.org>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #ifndef LICENSEREGISTRY_H
0008 #define LICENSEREGISTRY_H
0009 
0010 #include <QMap>
0011 #include <QObject>
0012 #include <QRegularExpression>
0013 #include <QVector>
0014 
0015 class LicenseRegistry : public QObject
0016 {
0017     Q_OBJECT
0018 public:
0019     using SpdxIdentifier = QString;
0020     using SpdxExpression = QString;
0021     const static QString ToClarifyLicense;
0022     const static QString UnknownLicense;
0023     const static QString MissingLicense;
0024     const static QString AmbigiousLicense;
0025     const static QString MissingLicenseForGeneratedFile;
0026 
0027     explicit LicenseRegistry(QObject *parent = nullptr);
0028 
0029     /**
0030      * @brief list of all detectable SPDX expressions
0031      */
0032     QVector<SpdxExpression> expressions() const;
0033 
0034     /**
0035      * @brief list of all known SPDX identifiers
0036      */
0037     QVector<SpdxIdentifier> identifiers() const;
0038 
0039     QMap<SpdxIdentifier, QString> licenseFiles() const;
0040 
0041     QVector<QString> headerTexts(const SpdxExpression &identifier) const;
0042 
0043     QVector<QRegularExpression> headerTextRegExps(const SpdxExpression &identifier) const;
0044 
0045     /**
0046      * @param expression is the expression to check against license strings (this does not support syntax parameters like "OR"
0047      * @return true if this is a non-license, e.g. "TO-CLARIFY" string"
0048      */
0049     bool isFakeLicenseMarker(const QString &expression) const;
0050 
0051 private:
0052     void loadLicenseHeaders();
0053     void loadLicenseFiles();
0054     QMap<SpdxExpression, QVector<QString>> m_registry;
0055     mutable QMap<SpdxExpression, QVector<QRegularExpression>> m_regexpsCache;
0056     mutable QMap<SpdxIdentifier, QString> m_licenseFiles;
0057 };
0058 
0059 #endif // LICENSEREGISTRY_H