NOISSUE improve GradleSpecifier and handle broken library names
This commit is contained in:
parent
fbe9d15875
commit
7246d8a779
@ -18,32 +18,35 @@ struct GradleSpecifier
|
|||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
org.gradle.test.classifiers : service : 1.0 : jdk15 @ jar
|
org.gradle.test.classifiers : service : 1.0 : jdk15 @ jar
|
||||||
DEBUG 0 "org.gradle.test.classifiers:service:1.0:jdk15@jar"
|
0 "org.gradle.test.classifiers:service:1.0:jdk15@jar"
|
||||||
DEBUG 1 "org.gradle.test.classifiers"
|
1 "org.gradle.test.classifiers"
|
||||||
DEBUG 2 "service"
|
2 "service"
|
||||||
DEBUG 3 "1.0"
|
3 "1.0"
|
||||||
DEBUG 4 ":jdk15"
|
4 "jdk15"
|
||||||
DEBUG 5 "jdk15"
|
5 "jar"
|
||||||
DEBUG 6 "@jar"
|
|
||||||
DEBUG 7 "jar"
|
|
||||||
*/
|
*/
|
||||||
QRegExp matcher("([^:@]+):([^:@]+):([^:@]+)" "(:([^:@]+))?" "(@([^:@]+))?");
|
QRegExp matcher("([^:@]+):([^:@]+):([^:@]+)" "(?::([^:@]+))?" "(?:@([^:@]+))?");
|
||||||
m_valid = matcher.exactMatch(value);
|
m_valid = matcher.exactMatch(value);
|
||||||
|
if(!m_valid) {
|
||||||
|
m_invalidValue = value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
auto elements = matcher.capturedTexts();
|
auto elements = matcher.capturedTexts();
|
||||||
m_groupId = elements[1];
|
m_groupId = elements[1];
|
||||||
m_artifactId = elements[2];
|
m_artifactId = elements[2];
|
||||||
m_version = elements[3];
|
m_version = elements[3];
|
||||||
m_classifier = elements[5];
|
m_classifier = elements[4];
|
||||||
if(!elements[7].isEmpty())
|
if(!elements[5].isEmpty())
|
||||||
{
|
{
|
||||||
m_extension = elements[7];
|
m_extension = elements[5];
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
operator QString() const
|
QString serialize() const
|
||||||
{
|
{
|
||||||
if(!m_valid)
|
if(!m_valid) {
|
||||||
return "INVALID";
|
return m_invalidValue;
|
||||||
|
}
|
||||||
QString retval = m_groupId + ":" + m_artifactId + ":" + m_version;
|
QString retval = m_groupId + ":" + m_artifactId + ":" + m_version;
|
||||||
if(!m_classifier.isEmpty())
|
if(!m_classifier.isEmpty())
|
||||||
{
|
{
|
||||||
@ -57,6 +60,9 @@ struct GradleSpecifier
|
|||||||
}
|
}
|
||||||
QString getFileName() const
|
QString getFileName() const
|
||||||
{
|
{
|
||||||
|
if(!m_valid) {
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
QString filename = m_artifactId + '-' + m_version;
|
QString filename = m_artifactId + '-' + m_version;
|
||||||
if(!m_classifier.isEmpty())
|
if(!m_classifier.isEmpty())
|
||||||
{
|
{
|
||||||
@ -67,8 +73,9 @@ struct GradleSpecifier
|
|||||||
}
|
}
|
||||||
QString toPath(const QString & filenameOverride = QString()) const
|
QString toPath(const QString & filenameOverride = QString()) const
|
||||||
{
|
{
|
||||||
if(!m_valid)
|
if(!m_valid) {
|
||||||
return "INVALID";
|
return QString();
|
||||||
|
}
|
||||||
QString filename;
|
QString filename;
|
||||||
if(filenameOverride.isEmpty())
|
if(filenameOverride.isEmpty())
|
||||||
{
|
{
|
||||||
@ -134,6 +141,7 @@ struct GradleSpecifier
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
|
QString m_invalidValue;
|
||||||
QString m_groupId;
|
QString m_groupId;
|
||||||
QString m_artifactId;
|
QString m_artifactId;
|
||||||
QString m_version;
|
QString m_version;
|
||||||
|
@ -31,7 +31,7 @@ slots:
|
|||||||
{
|
{
|
||||||
QFETCH(QString, through);
|
QFETCH(QString, through);
|
||||||
|
|
||||||
QString converted = GradleSpecifier(through);
|
QString converted = GradleSpecifier(through).serialize();
|
||||||
|
|
||||||
QCOMPARE(converted, through);
|
QCOMPARE(converted, through);
|
||||||
}
|
}
|
||||||
@ -68,7 +68,8 @@ slots:
|
|||||||
|
|
||||||
GradleSpecifier spec(input);
|
GradleSpecifier spec(input);
|
||||||
QVERIFY(!spec.valid());
|
QVERIFY(!spec.valid());
|
||||||
QCOMPARE(spec.operator QString(), QString("INVALID"));
|
QCOMPARE(spec.serialize(), input);
|
||||||
|
QCOMPARE(spec.toPath(), QString());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -94,13 +94,13 @@ QList< std::shared_ptr< NetAction > > Library::getDownloads(
|
|||||||
auto rawSha1 = QByteArray::fromHex(sha1.toLatin1());
|
auto rawSha1 = QByteArray::fromHex(sha1.toLatin1());
|
||||||
auto dl = Net::Download::makeCached(url, entry, options);
|
auto dl = Net::Download::makeCached(url, entry, options);
|
||||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1));
|
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1));
|
||||||
qDebug() << "Checksummed Download for:" << rawName() << "storage:" << storage << "url:" << url;
|
qDebug() << "Checksummed Download for:" << rawName().serialize() << "storage:" << storage << "url:" << url;
|
||||||
out.append(dl);
|
out.append(dl);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
out.append(Net::Download::makeCached(url, entry, options));
|
out.append(Net::Download::makeCached(url, entry, options));
|
||||||
qDebug() << "Download for:" << rawName() << "storage:" << storage << "url:" << url;
|
qDebug() << "Download for:" << rawName().serialize() << "storage:" << storage << "url:" << url;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
@ -145,7 +145,7 @@ QList< std::shared_ptr< NetAction > > Library::getDownloads(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
qDebug() << "Ignoring native library" << m_name << "because it has no classifier for current OS";
|
qDebug() << "Ignoring native library" << m_name.serialize() << "because it has no classifier for current OS";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -157,7 +157,7 @@ QList< std::shared_ptr< NetAction > > Library::getDownloads(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
qDebug() << "Ignoring java library" << m_name << "because it has no artifact";
|
qDebug() << "Ignoring java library" << m_name.serialize() << "because it has no artifact";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,8 @@ private:
|
|||||||
jsonFile.open(QIODevice::ReadOnly);
|
jsonFile.open(QIODevice::ReadOnly);
|
||||||
auto data = jsonFile.readAll();
|
auto data = jsonFile.readAll();
|
||||||
jsonFile.close();
|
jsonFile.close();
|
||||||
return MojangVersionFormat::libraryFromJson(QJsonDocument::fromJson(data).object(), file);
|
ProblemContainer problems;
|
||||||
|
return MojangVersionFormat::libraryFromJson(problems, QJsonDocument::fromJson(data).object(), file);
|
||||||
}
|
}
|
||||||
// get absolute path to expected storage, assuming default cache prefix
|
// get absolute path to expected storage, assuming default cache prefix
|
||||||
QStringList getStorage(QString relative)
|
QStringList getStorage(QString relative)
|
||||||
|
@ -220,7 +220,7 @@ VersionFilePtr MojangVersionFormat::versionFileFromJson(const QJsonDocument &doc
|
|||||||
{
|
{
|
||||||
auto libObj = requireObject(libVal);
|
auto libObj = requireObject(libVal);
|
||||||
|
|
||||||
auto lib = MojangVersionFormat::libraryFromJson(libObj, filename);
|
auto lib = MojangVersionFormat::libraryFromJson(*out, libObj, filename);
|
||||||
out->libraries.append(lib);
|
out->libraries.append(lib);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -283,14 +283,18 @@ QJsonDocument MojangVersionFormat::versionFileToJson(const VersionFilePtr &patch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LibraryPtr MojangVersionFormat::libraryFromJson(const QJsonObject &libObj, const QString &filename)
|
LibraryPtr MojangVersionFormat::libraryFromJson(ProblemContainer & problems, const QJsonObject &libObj, const QString &filename)
|
||||||
{
|
{
|
||||||
LibraryPtr out(new Library());
|
LibraryPtr out(new Library());
|
||||||
if (!libObj.contains("name"))
|
if (!libObj.contains("name"))
|
||||||
{
|
{
|
||||||
throw JSONValidationError(filename + "contains a library that doesn't have a 'name' field");
|
throw JSONValidationError(filename + "contains a library that doesn't have a 'name' field");
|
||||||
}
|
}
|
||||||
out->m_name = libObj.value("name").toString();
|
auto rawName = libObj.value("name").toString();
|
||||||
|
out->m_name = rawName;
|
||||||
|
if(!out->m_name.valid()) {
|
||||||
|
problems.addProblem(ProblemSeverity::Error, QObject::tr("Library %1 name is broken and cannot be processed.").arg(rawName));
|
||||||
|
}
|
||||||
|
|
||||||
Bits::readString(libObj, "url", out->m_repositoryURL);
|
Bits::readString(libObj, "url", out->m_repositoryURL);
|
||||||
if (libObj.contains("extract"))
|
if (libObj.contains("extract"))
|
||||||
@ -333,7 +337,7 @@ LibraryPtr MojangVersionFormat::libraryFromJson(const QJsonObject &libObj, const
|
|||||||
QJsonObject MojangVersionFormat::libraryToJson(Library *library)
|
QJsonObject MojangVersionFormat::libraryToJson(Library *library)
|
||||||
{
|
{
|
||||||
QJsonObject libRoot;
|
QJsonObject libRoot;
|
||||||
libRoot.insert("name", (QString)library->m_name);
|
libRoot.insert("name", library->m_name.serialize());
|
||||||
if (!library->m_repositoryURL.isEmpty())
|
if (!library->m_repositoryURL.isEmpty())
|
||||||
{
|
{
|
||||||
libRoot.insert("url", library->m_repositoryURL);
|
libRoot.insert("url", library->m_repositoryURL);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <minecraft/VersionFile.h>
|
#include <minecraft/VersionFile.h>
|
||||||
#include <minecraft/Library.h>
|
#include <minecraft/Library.h>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
|
#include <ProblemProvider.h>
|
||||||
|
|
||||||
#include "multimc_logic_export.h"
|
#include "multimc_logic_export.h"
|
||||||
|
|
||||||
@ -20,6 +21,6 @@ public:
|
|||||||
static QJsonDocument versionFileToJson(const VersionFilePtr &patch);
|
static QJsonDocument versionFileToJson(const VersionFilePtr &patch);
|
||||||
|
|
||||||
// libraries
|
// libraries
|
||||||
static LibraryPtr libraryFromJson(const QJsonObject &libObj, const QString &filename);
|
static LibraryPtr libraryFromJson(ProblemContainer & problems, const QJsonObject &libObj, const QString &filename);
|
||||||
static QJsonObject libraryToJson(Library *library);
|
static QJsonObject libraryToJson(Library *library);
|
||||||
};
|
};
|
||||||
|
@ -13,9 +13,9 @@ static void readString(const QJsonObject &root, const QString &key, QString &var
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LibraryPtr OneSixVersionFormat::libraryFromJson(const QJsonObject &libObj, const QString &filename)
|
LibraryPtr OneSixVersionFormat::libraryFromJson(ProblemContainer & problems, const QJsonObject &libObj, const QString &filename)
|
||||||
{
|
{
|
||||||
LibraryPtr out = MojangVersionFormat::libraryFromJson(libObj, filename);
|
LibraryPtr out = MojangVersionFormat::libraryFromJson(problems, libObj, filename);
|
||||||
readString(libObj, "MMC-hint", out->m_hint);
|
readString(libObj, "MMC-hint", out->m_hint);
|
||||||
readString(libObj, "MMC-absulute_url", out->m_absoluteURL);
|
readString(libObj, "MMC-absulute_url", out->m_absoluteURL);
|
||||||
readString(libObj, "MMC-absoluteUrl", out->m_absoluteURL);
|
readString(libObj, "MMC-absoluteUrl", out->m_absoluteURL);
|
||||||
@ -115,7 +115,7 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc
|
|||||||
{
|
{
|
||||||
QJsonObject libObj = requireObject(libVal);
|
QJsonObject libObj = requireObject(libVal);
|
||||||
// parse the jarmod
|
// parse the jarmod
|
||||||
auto lib = OneSixVersionFormat::jarModFromJson(libObj, filename);
|
auto lib = OneSixVersionFormat::jarModFromJson(*out, libObj, filename);
|
||||||
// and add to jar mods
|
// and add to jar mods
|
||||||
out->jarMods.append(lib);
|
out->jarMods.append(lib);
|
||||||
}
|
}
|
||||||
@ -126,7 +126,7 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc
|
|||||||
{
|
{
|
||||||
QJsonObject libObj = requireObject(libVal);
|
QJsonObject libObj = requireObject(libVal);
|
||||||
// parse the jarmod
|
// parse the jarmod
|
||||||
auto lib = OneSixVersionFormat::plusJarModFromJson(libObj, filename, out->name);
|
auto lib = OneSixVersionFormat::plusJarModFromJson(*out, libObj, filename, out->name);
|
||||||
// and add to jar mods
|
// and add to jar mods
|
||||||
out->jarMods.append(lib);
|
out->jarMods.append(lib);
|
||||||
}
|
}
|
||||||
@ -138,20 +138,20 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc
|
|||||||
{
|
{
|
||||||
QJsonObject libObj = requireObject(libVal);
|
QJsonObject libObj = requireObject(libVal);
|
||||||
// parse the jarmod
|
// parse the jarmod
|
||||||
auto lib = OneSixVersionFormat::modFromJson(libObj, filename);
|
auto lib = OneSixVersionFormat::modFromJson(*out, libObj, filename);
|
||||||
// and add to jar mods
|
// and add to jar mods
|
||||||
out->mods.append(lib);
|
out->mods.append(lib);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto readLibs = [&](const char * which, QList<LibraryPtr> & out)
|
auto readLibs = [&](const char * which, QList<LibraryPtr> & outList)
|
||||||
{
|
{
|
||||||
for (auto libVal : requireArray(root.value(which)))
|
for (auto libVal : requireArray(root.value(which)))
|
||||||
{
|
{
|
||||||
QJsonObject libObj = requireObject(libVal);
|
QJsonObject libObj = requireObject(libVal);
|
||||||
// parse the library
|
// parse the library
|
||||||
auto lib = libraryFromJson(libObj, filename);
|
auto lib = libraryFromJson(*out, libObj, filename);
|
||||||
out.append(lib);
|
outList.append(lib);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
bool hasPlusLibs = root.contains("+libraries");
|
bool hasPlusLibs = root.contains("+libraries");
|
||||||
@ -180,7 +180,7 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc
|
|||||||
if(root.contains("mainJar"))
|
if(root.contains("mainJar"))
|
||||||
{
|
{
|
||||||
QJsonObject libObj = requireObject(root, "mainJar");
|
QJsonObject libObj = requireObject(root, "mainJar");
|
||||||
out->mainJar = libraryFromJson(libObj, filename);
|
out->mainJar = libraryFromJson(*out, libObj, filename);
|
||||||
}
|
}
|
||||||
// else reconstruct it from downloads and id ... if that's available
|
// else reconstruct it from downloads and id ... if that's available
|
||||||
else if(!out->minecraftVersion.isEmpty())
|
else if(!out->minecraftVersion.isEmpty())
|
||||||
@ -330,8 +330,12 @@ QJsonDocument OneSixVersionFormat::versionFileToJson(const VersionFilePtr &patch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LibraryPtr OneSixVersionFormat::plusJarModFromJson(const QJsonObject &libObj, const QString &filename, const QString &originalName)
|
LibraryPtr OneSixVersionFormat::plusJarModFromJson(
|
||||||
{
|
ProblemContainer & problems,
|
||||||
|
const QJsonObject &libObj,
|
||||||
|
const QString &filename,
|
||||||
|
const QString &originalName
|
||||||
|
) {
|
||||||
LibraryPtr out(new Library());
|
LibraryPtr out(new Library());
|
||||||
if (!libObj.contains("name"))
|
if (!libObj.contains("name"))
|
||||||
{
|
{
|
||||||
@ -366,9 +370,9 @@ LibraryPtr OneSixVersionFormat::plusJarModFromJson(const QJsonObject &libObj, co
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
LibraryPtr OneSixVersionFormat::jarModFromJson(const QJsonObject& libObj, const QString& filename)
|
LibraryPtr OneSixVersionFormat::jarModFromJson(ProblemContainer & problems, const QJsonObject& libObj, const QString& filename)
|
||||||
{
|
{
|
||||||
return libraryFromJson(libObj, filename);
|
return libraryFromJson(problems, libObj, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -377,9 +381,9 @@ QJsonObject OneSixVersionFormat::jarModtoJson(Library *jarmod)
|
|||||||
return libraryToJson(jarmod);
|
return libraryToJson(jarmod);
|
||||||
}
|
}
|
||||||
|
|
||||||
LibraryPtr OneSixVersionFormat::modFromJson(const QJsonObject& libObj, const QString& filename)
|
LibraryPtr OneSixVersionFormat::modFromJson(ProblemContainer & problems, const QJsonObject& libObj, const QString& filename)
|
||||||
{
|
{
|
||||||
return libraryFromJson(libObj, filename);
|
return libraryFromJson(problems, libObj, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject OneSixVersionFormat::modtoJson(Library *jarmod)
|
QJsonObject OneSixVersionFormat::modtoJson(Library *jarmod)
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <minecraft/PackProfile.h>
|
#include <minecraft/PackProfile.h>
|
||||||
#include <minecraft/Library.h>
|
#include <minecraft/Library.h>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
|
#include <ProblemProvider.h>
|
||||||
|
|
||||||
class OneSixVersionFormat
|
class OneSixVersionFormat
|
||||||
{
|
{
|
||||||
@ -13,17 +14,17 @@ public:
|
|||||||
static QJsonDocument versionFileToJson(const VersionFilePtr &patch);
|
static QJsonDocument versionFileToJson(const VersionFilePtr &patch);
|
||||||
|
|
||||||
// libraries
|
// libraries
|
||||||
static LibraryPtr libraryFromJson(const QJsonObject &libObj, const QString &filename);
|
static LibraryPtr libraryFromJson(ProblemContainer & problems, const QJsonObject &libObj, const QString &filename);
|
||||||
static QJsonObject libraryToJson(Library *library);
|
static QJsonObject libraryToJson(Library *library);
|
||||||
|
|
||||||
// DEPRECATED: old 'plus' jar mods generated by the application
|
// DEPRECATED: old 'plus' jar mods generated by the application
|
||||||
static LibraryPtr plusJarModFromJson(const QJsonObject &libObj, const QString &filename, const QString &originalName);
|
static LibraryPtr plusJarModFromJson(ProblemContainer & problems, const QJsonObject &libObj, const QString &filename, const QString &originalName);
|
||||||
|
|
||||||
// new jar mods derived from libraries
|
// new jar mods derived from libraries
|
||||||
static LibraryPtr jarModFromJson(const QJsonObject &libObj, const QString &filename);
|
static LibraryPtr jarModFromJson(ProblemContainer & problems, const QJsonObject &libObj, const QString &filename);
|
||||||
static QJsonObject jarModtoJson(Library * jarmod);
|
static QJsonObject jarModtoJson(Library * jarmod);
|
||||||
|
|
||||||
// mods, also derived from libraries
|
// mods, also derived from libraries
|
||||||
static LibraryPtr modFromJson(const QJsonObject &libObj, const QString &filename);
|
static LibraryPtr modFromJson(ProblemContainer & problems, const QJsonObject &libObj, const QString &filename);
|
||||||
static QJsonObject modtoJson(Library * jarmod);
|
static QJsonObject modtoJson(Library * jarmod);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user