forked from qt-creator/qt-creator
Unit tests: Fix ProjectInfoGenerator.* tests
...by adapting to recent mime type changes:
commit e8e46ab553
Plugins: Fix that mimetype definition was not valid JSON
Change-Id: Iac416ab481814e4488fac4d818c51c647c1ec349
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
#include <utils/stringutils.h>
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@@ -631,26 +632,6 @@ static inline QString msgInvalidFormat(const char *key, const QString &content)
|
|||||||
.arg(QLatin1String(key), content);
|
.arg(QLatin1String(key), content);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PluginSpec::readMultiLineString(const QJsonValue &value, QString *out)
|
|
||||||
{
|
|
||||||
QTC_ASSERT(out, return false);
|
|
||||||
if (value.isString()) {
|
|
||||||
*out = value.toString();
|
|
||||||
} else if (value.isArray()) {
|
|
||||||
QJsonArray array = value.toArray();
|
|
||||||
QStringList lines;
|
|
||||||
foreach (const QJsonValue &v, array) {
|
|
||||||
if (!v.isString())
|
|
||||||
return false;
|
|
||||||
lines.append(v.toString());
|
|
||||||
}
|
|
||||||
*out = lines.join(QLatin1Char('\n'));
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\internal
|
\internal
|
||||||
*/
|
*/
|
||||||
@@ -735,7 +716,7 @@ bool PluginSpecPrivate::readMetaData(const QJsonObject &pluginMetaData)
|
|||||||
copyright = value.toString();
|
copyright = value.toString();
|
||||||
|
|
||||||
value = metaData.value(QLatin1String(DESCRIPTION));
|
value = metaData.value(QLatin1String(DESCRIPTION));
|
||||||
if (!value.isUndefined() && !PluginSpec::readMultiLineString(value, &description))
|
if (!value.isUndefined() && !Utils::readMultiLineString(value, &description))
|
||||||
return reportError(msgValueIsNotAString(DESCRIPTION));
|
return reportError(msgValueIsNotAString(DESCRIPTION));
|
||||||
|
|
||||||
value = metaData.value(QLatin1String(URL));
|
value = metaData.value(QLatin1String(URL));
|
||||||
@@ -749,7 +730,7 @@ bool PluginSpecPrivate::readMetaData(const QJsonObject &pluginMetaData)
|
|||||||
category = value.toString();
|
category = value.toString();
|
||||||
|
|
||||||
value = metaData.value(QLatin1String(LICENSE));
|
value = metaData.value(QLatin1String(LICENSE));
|
||||||
if (!value.isUndefined() && !PluginSpec::readMultiLineString(value, &license))
|
if (!value.isUndefined() && !Utils::readMultiLineString(value, &license))
|
||||||
return reportError(msgValueIsNotAMultilineString(LICENSE));
|
return reportError(msgValueIsNotAMultilineString(LICENSE));
|
||||||
|
|
||||||
value = metaData.value(QLatin1String(PLATFORM));
|
value = metaData.value(QLatin1String(PLATFORM));
|
||||||
|
@@ -131,8 +131,6 @@ public:
|
|||||||
bool hasError() const;
|
bool hasError() const;
|
||||||
QString errorString() const;
|
QString errorString() const;
|
||||||
|
|
||||||
static bool readMultiLineString(const QJsonValue &value, QString *out);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PluginSpec();
|
PluginSpec();
|
||||||
|
|
||||||
|
@@ -28,8 +28,11 @@
|
|||||||
#include "hostosinfo.h"
|
#include "hostosinfo.h"
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonValue>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
|
||||||
@@ -246,4 +249,24 @@ QTCREATOR_UTILS_EXPORT QString stripAccelerator(const QString &text)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QTCREATOR_UTILS_EXPORT bool readMultiLineString(const QJsonValue &value, QString *out)
|
||||||
|
{
|
||||||
|
QTC_ASSERT(out, return false);
|
||||||
|
if (value.isString()) {
|
||||||
|
*out = value.toString();
|
||||||
|
} else if (value.isArray()) {
|
||||||
|
QJsonArray array = value.toArray();
|
||||||
|
QStringList lines;
|
||||||
|
foreach (const QJsonValue &v, array) {
|
||||||
|
if (!v.isString())
|
||||||
|
return false;
|
||||||
|
lines.append(v.toString());
|
||||||
|
}
|
||||||
|
*out = lines.join(QLatin1Char('\n'));
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
@@ -28,6 +28,7 @@
|
|||||||
#include "utils_global.h"
|
#include "utils_global.h"
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QJsonValue;
|
||||||
class QStringList;
|
class QStringList;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
@@ -53,6 +54,8 @@ QTCREATOR_UTILS_EXPORT QString withTildeHomePath(const QString &path);
|
|||||||
// Removes first unescaped ampersand in text
|
// Removes first unescaped ampersand in text
|
||||||
QTCREATOR_UTILS_EXPORT QString stripAccelerator(const QString &text);
|
QTCREATOR_UTILS_EXPORT QString stripAccelerator(const QString &text);
|
||||||
|
|
||||||
|
QTCREATOR_UTILS_EXPORT bool readMultiLineString(const QJsonValue &value, QString *out);
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT AbstractMacroExpander
|
class QTCREATOR_UTILS_EXPORT AbstractMacroExpander
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@@ -132,7 +132,7 @@ bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
|||||||
const QJsonObject metaData = plugin->metaData();
|
const QJsonObject metaData = plugin->metaData();
|
||||||
const QJsonValue mimetypes = metaData.value("Mimetypes");
|
const QJsonValue mimetypes = metaData.value("Mimetypes");
|
||||||
QString mimetypeString;
|
QString mimetypeString;
|
||||||
if (ExtensionSystem::PluginSpec::readMultiLineString(mimetypes, &mimetypeString))
|
if (Utils::readMultiLineString(mimetypes, &mimetypeString))
|
||||||
Utils::addMimeTypes(plugin->name() + ".mimetypes", mimetypeString.trimmed().toUtf8());
|
Utils::addMimeTypes(plugin->name() + ".mimetypes", mimetypeString.trimmed().toUtf8());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -32,6 +32,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include <utils/mimetypes/mimedatabase.h>
|
#include <utils/mimetypes/mimedatabase.h>
|
||||||
|
#include <utils/stringutils.h>
|
||||||
|
|
||||||
namespace MimeDataBaseUtilities
|
namespace MimeDataBaseUtilities
|
||||||
{
|
{
|
||||||
@@ -47,9 +48,11 @@ bool addCppToolsMimeTypes()
|
|||||||
if (file.open(QIODevice::ReadOnly)) {
|
if (file.open(QIODevice::ReadOnly)) {
|
||||||
auto doc = QJsonDocument::fromJson(file.readAll());
|
auto doc = QJsonDocument::fromJson(file.readAll());
|
||||||
QJsonValue mimetypes = doc.object().value("Mimetypes");
|
QJsonValue mimetypes = doc.object().value("Mimetypes");
|
||||||
if (!mimetypes.isString())
|
|
||||||
|
QString mimetypeString;
|
||||||
|
if (!Utils::readMultiLineString(mimetypes, &mimetypeString))
|
||||||
return false;
|
return false;
|
||||||
Utils::addMimeTypes(filePath, mimetypes.toString().trimmed().toUtf8());
|
Utils::addMimeTypes(filePath, mimetypeString.trimmed().toUtf8());
|
||||||
alreadyAdded = true;
|
alreadyAdded = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user