Merge PR #283: Reject duplicate ids in plugin json
This commit is contained in:
commit
3156264787
@ -1238,7 +1238,7 @@ void ThingManagerImplementation::loadPlugins()
|
||||
}
|
||||
|
||||
QJsonObject pluginInfo = loader.metaData().value("MetaData").toObject();
|
||||
PluginMetadata metaData(pluginInfo);
|
||||
PluginMetadata metaData(pluginInfo, false, false);
|
||||
if (!metaData.isValid()) {
|
||||
foreach (const QString &error, metaData.validationErrors()) {
|
||||
qCWarning(dcThingManager()) << error;
|
||||
@ -1413,7 +1413,7 @@ void ThingManagerImplementation::loadConfiguredThings()
|
||||
// Try to load the device class from the cache
|
||||
QJsonObject pluginInfo = PluginInfoCache::loadPluginInfo(pluginId);
|
||||
if (!pluginInfo.empty()) {
|
||||
PluginMetadata pluginMetadata(pluginInfo);
|
||||
PluginMetadata pluginMetadata(pluginInfo, false, false);
|
||||
thingClass = pluginMetadata.thingClasses().findById(thingClassId);
|
||||
if (thingClass.isValid()) {
|
||||
m_supportedThings.insert(thingClassId, thingClass);
|
||||
|
||||
@ -46,7 +46,9 @@ PluginMetadata::PluginMetadata()
|
||||
|
||||
}
|
||||
|
||||
PluginMetadata::PluginMetadata(const QJsonObject &jsonObject, bool isBuiltIn): m_isBuiltIn(isBuiltIn)
|
||||
PluginMetadata::PluginMetadata(const QJsonObject &jsonObject, bool isBuiltIn, bool strict):
|
||||
m_isBuiltIn(isBuiltIn),
|
||||
m_strictRun(strict)
|
||||
{
|
||||
parse(jsonObject);
|
||||
}
|
||||
@ -896,9 +898,12 @@ QPair<bool, Types::InputType> PluginMetadata::loadAndVerifyInputType(const QStri
|
||||
bool PluginMetadata::verifyDuplicateUuid(const QUuid &uuid)
|
||||
{
|
||||
if (m_allUuids.contains(uuid)) {
|
||||
// FIXME: Drop debug, activate return! (see .h for more context)
|
||||
qCWarning(dcPluginMetadata()) << "THIS PLUGIN USES DUPLICATE UUID" << uuid.toString() << "! THIS WILL STOP WORKING SOON.";
|
||||
// return false;
|
||||
// FIXME: Drop non-strict run! (see .h for more context)
|
||||
if (m_strictRun) {
|
||||
return false;
|
||||
} else {
|
||||
qCWarning(dcPluginMetadata()) << "THIS PLUGIN USES DUPLICATE UUID" << uuid.toString() << "! THIS IS NOT SUPPORTED AND MAY CAUSE RUNTIME ISSUES.";
|
||||
}
|
||||
}
|
||||
if (m_currentScopUuids.contains(uuid)) {
|
||||
return false;
|
||||
|
||||
@ -38,7 +38,7 @@ class PluginMetadata
|
||||
{
|
||||
public:
|
||||
PluginMetadata();
|
||||
PluginMetadata(const QJsonObject &jsonObject, bool isBuiltIn = false);
|
||||
PluginMetadata(const QJsonObject &jsonObject, bool isBuiltIn = false, bool strict = true);
|
||||
|
||||
bool isValid() const;
|
||||
QStringList validationErrors() const;
|
||||
@ -80,6 +80,7 @@ private:
|
||||
// As strict as possible without breaking them, but this should be removed ASAP
|
||||
// and only m_allUuids should be used to check for dupes
|
||||
QList<QUuid> m_currentScopUuids;
|
||||
bool m_strictRun = true;
|
||||
|
||||
QStringList m_validationErrors;
|
||||
};
|
||||
|
||||
@ -45,6 +45,7 @@ int main(int argc, char *argv[])
|
||||
parser.addOption({{"o", "output"}, "Write generated output header to <file>.", "file"});
|
||||
parser.addOption({{"e", "extern"}, "Write generated output header (extern definitions) to <file>.", "file"});
|
||||
parser.addOption({{"t", "translations"}, "Write generated translations file stub to <directory>.", "directory"});
|
||||
parser.addOption({{"n", "non-strict"}, "Non-strict run. Don't exit on duplicate UUID warnings."});
|
||||
parser.addPositionalArgument("input", "The input json file");
|
||||
|
||||
parser.process(a);
|
||||
@ -54,9 +55,11 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool strictMode = !parser.isSet("non-strict");
|
||||
|
||||
PluginInfoCompiler pic;
|
||||
|
||||
int ret = pic.compile(parser.positionalArguments().first(), parser.value("output"), parser.value("extern"), parser.value("translations"));
|
||||
int ret = pic.compile(parser.positionalArguments().first(), parser.value("output"), parser.value("extern"), parser.value("translations"), strictMode);
|
||||
|
||||
return ret;
|
||||
|
||||
|
||||
@ -43,7 +43,7 @@ PluginInfoCompiler::PluginInfoCompiler()
|
||||
|
||||
}
|
||||
|
||||
int PluginInfoCompiler::compile(const QString &inputFile, const QString &outputFile, const QString outputFileExtern, const QString &translationsPath)
|
||||
int PluginInfoCompiler::compile(const QString &inputFile, const QString &outputFile, const QString outputFileExtern, const QString &translationsPath, bool strictMode)
|
||||
{
|
||||
// First, process the input json...
|
||||
QFile jsonFile(inputFile);
|
||||
@ -81,7 +81,7 @@ int PluginInfoCompiler::compile(const QString &inputFile, const QString &outputF
|
||||
}
|
||||
QJsonObject jsonObject = QJsonObject::fromVariantMap(jsonDoc.toVariant().toMap());
|
||||
|
||||
PluginMetadata metadata(jsonObject);
|
||||
PluginMetadata metadata(jsonObject, false, strictMode);
|
||||
if (!metadata.isValid()) {
|
||||
foreach (const QString &error, metadata.validationErrors()) {
|
||||
QDebug dbg = qWarning().noquote().nospace();
|
||||
|
||||
@ -42,7 +42,7 @@ class PluginInfoCompiler
|
||||
public:
|
||||
PluginInfoCompiler();
|
||||
|
||||
int compile(const QString &inputFile, const QString &outputFile, const QString outputFileExtern, const QString &translationsPath);
|
||||
int compile(const QString &inputFile, const QString &outputFile, const QString outputFileExtern, const QString &translationsPath, bool strictMode);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user