Rearrange RawLibrary and OneSixLibrary heavily.

Fix #396
This commit is contained in:
Petr Mrázek 2014-07-26 23:00:35 +02:00
parent 9b82c87c92
commit 03b13b0b3f
12 changed files with 335 additions and 419 deletions

View File

@ -73,7 +73,6 @@ void OneSixFTBInstance::copy(const QDir &newDir)
for (auto library : libraryNames) for (auto library : libraryNames)
{ {
OneSixLibrary *lib = new OneSixLibrary(library); OneSixLibrary *lib = new OneSixLibrary(library);
lib->finalize();
const QString out = QDir::current().absoluteFilePath("libraries/" + lib->storagePath()); const QString out = QDir::current().absoluteFilePath("libraries/" + lib->storagePath());
if (QFile::exists(out)) if (QFile::exists(out))
{ {

View File

@ -85,7 +85,6 @@ void ForgeInstaller::prepare(const QString &filename, const QString &universalUr
// where do we put the library? decode the mojang path // where do we put the library? decode the mojang path
OneSixLibrary lib(libraryName); OneSixLibrary lib(libraryName);
lib.finalize();
auto cacheentry = MMC->metacache()->resolveEntry("libraries", lib.storagePath()); auto cacheentry = MMC->metacache()->resolveEntry("libraries", lib.storagePath());
finalPath = "libraries/" + lib.storagePath(); finalPath = "libraries/" + lib.storagePath();
@ -140,11 +139,11 @@ bool ForgeInstaller::add(OneSixInstance *to)
// for each library in the version we are adding (except for the blacklisted) // for each library in the version we are adding (except for the blacklisted)
for (auto lib : m_forge_json->libraries) for (auto lib : m_forge_json->libraries)
{ {
QString libName = lib->name(); QString libName = lib->artifactId();
QString rawName = lib->rawName(); QString rawName = lib->rawName();
// ignore lwjgl libraries. // ignore lwjgl libraries.
if (g_VersionFilterData.lwjglWhitelist.contains(lib->fullname())) if (g_VersionFilterData.lwjglWhitelist.contains(lib->artifactPrefix()))
continue; continue;
// ignore other blacklisted (realms, authlib) // ignore other blacklisted (realms, authlib)
if (blacklist.contains(libName)) if (blacklist.contains(libName))
@ -156,8 +155,7 @@ bool ForgeInstaller::add(OneSixInstance *to)
{ {
if (libName == "forge") if (libName == "forge")
{ {
lib->m_name.setClassifier("universal"); lib->setClassifier("universal");
lib->finalize();
} }
else if (libName == "minecraftforge") else if (libName == "minecraftforge")
{ {
@ -165,8 +163,7 @@ bool ForgeInstaller::add(OneSixInstance *to)
// using insane form of the MC version... // using insane form of the MC version...
QString longVersion = m_forge_version->mcver + "-" + m_forge_version->jobbuildver; QString longVersion = m_forge_version->mcver + "-" + m_forge_version->jobbuildver;
GradleSpecifier spec(forgeCoord.arg(longVersion)); GradleSpecifier spec(forgeCoord.arg(longVersion));
lib->m_name = spec; lib->setRawName(spec);
lib->finalize();
} }
} }
else else
@ -196,7 +193,7 @@ bool ForgeInstaller::add(OneSixInstance *to)
// find an entry that matches this one // find an entry that matches this one
for (auto tolib : to->getFullVersion()->vanillaLibraries) for (auto tolib : to->getFullVersion()->vanillaLibraries)
{ {
if (tolib->name() != libName) if (tolib->artifactId() != libName)
continue; continue;
found = true; found = true;
if (tolib->toJson() == libObj) if (tolib->toJson() == libObj)
@ -215,7 +212,7 @@ bool ForgeInstaller::add(OneSixInstance *to)
{ {
// add lib // add lib
libObj.insert("insert", QString("prepend")); libObj.insert("insert", QString("prepend"));
if (lib->name() == "minecraftforge" || lib->name() == "forge") if (lib->artifactId() == "minecraftforge" || lib->artifactId() == "forge")
{ {
libObj.insert("MMC-depend", QString("hard")); libObj.insert("MMC-depend", QString("hard"));
} }

View File

@ -53,7 +53,6 @@ bool LiteLoaderInstaller::add(OneSixInstance *to)
{ {
rawLibrary->insertType = RawLibrary::Prepend; rawLibrary->insertType = RawLibrary::Prepend;
OneSixLibrary lib(rawLibrary); OneSixLibrary lib(rawLibrary);
lib.finalize();
libraries.append(lib.toJson()); libraries.append(lib.toJson());
} }
@ -63,7 +62,6 @@ bool LiteLoaderInstaller::add(OneSixInstance *to)
liteloaderLib.setAbsoluteUrl( liteloaderLib.setAbsoluteUrl(
QString("http://dl.liteloader.com/versions/com/mumfrey/liteloader/%1/%2") QString("http://dl.liteloader.com/versions/com/mumfrey/liteloader/%1/%2")
.arg(m_version->mcVersion, m_version->file)); .arg(m_version->mcVersion, m_version->file));
liteloaderLib.finalize();
QJsonObject llLibObj = liteloaderLib.toJson(); QJsonObject llLibObj = liteloaderLib.toJson();
llLibObj.insert("insert", QString("prepend")); llLibObj.insert("insert", QString("prepend"));
llLibObj.insert("MMC-depend", QString("hard")); llLibObj.insert("MMC-depend", QString("hard"));

View File

@ -212,7 +212,7 @@ void LLListLoadTask::listDownloaded()
{ {
auto lib = RawLibrary::fromJson(libobject, "versions.json"); auto lib = RawLibrary::fromJson(libobject, "versions.json");
// hack to make liteloader 1.7.10_00 work // hack to make liteloader 1.7.10_00 work
if(lib->m_name == GradleSpecifier("org.ow2.asm:asm-all:5.0.3")) if(lib->rawName() == GradleSpecifier("org.ow2.asm:asm-all:5.0.3"))
{ {
lib->m_base_url = "http://repo.maven.apache.org/maven2/"; lib->m_base_url = "http://repo.maven.apache.org/maven2/";
} }

View File

@ -101,11 +101,11 @@ struct GradleSpecifier
{ {
return m_groupId + ":" + m_artifactId; return m_groupId + ":" + m_artifactId;
} }
bool matchName(const GradleSpecifier & other) bool matchName(const GradleSpecifier & other) const
{ {
return other.artifactId() == artifactId() && other.groupId() == groupId(); return other.artifactId() == artifactId() && other.groupId() == groupId();
} }
bool operator==(const GradleSpecifier & other) bool operator==(const GradleSpecifier & other) const
{ {
if(m_groupId != other.m_groupId) if(m_groupId != other.m_groupId)
return false; return false;

View File

@ -452,7 +452,7 @@ void MCVListVersionUpdateTask::json_downloaded()
for (auto lib : file->overwriteLibs) for (auto lib : file->overwriteLibs)
{ {
if (g_VersionFilterData.lwjglWhitelist.contains(lib->fullname())) if (g_VersionFilterData.lwjglWhitelist.contains(lib->artifactPrefix()))
{ {
lwjglLibs.append(lib); lwjglLibs.append(lib);
} }

View File

@ -32,198 +32,15 @@ OneSixLibrary::OneSixLibrary(RawLibraryPtr base)
extract_excludes = base->extract_excludes; extract_excludes = base->extract_excludes;
m_native_classifiers = base->m_native_classifiers; m_native_classifiers = base->m_native_classifiers;
m_rules = base->m_rules; m_rules = base->m_rules;
finalize(); dependType = base->dependType;
// these only make sense for raw libraries. OneSix
/*
insertType = base->insertType;
insertData = base->insertData;
*/
} }
OneSixLibraryPtr OneSixLibrary::fromRawLibrary(RawLibraryPtr lib) OneSixLibraryPtr OneSixLibrary::fromRawLibrary(RawLibraryPtr lib)
{ {
return OneSixLibraryPtr(new OneSixLibrary(lib)); return OneSixLibraryPtr(new OneSixLibrary(lib));
} }
void OneSixLibrary::finalize()
{
QString relative;
if (m_rules.empty())
{
m_is_active = true;
}
else
{
RuleAction result = Disallow;
for (auto rule : m_rules)
{
RuleAction temp = rule->apply(this);
if (temp != Defer)
result = temp;
}
m_is_active = (result == Allow);
}
if (isNative())
{
GradleSpecifier nativeSpec = m_name;
m_is_active = m_is_active && m_native_classifiers.contains(currentSystem);
m_decenttype = "Native";
if(m_native_classifiers.contains(currentSystem))
{
nativeSpec.setClassifier(m_native_classifiers[currentSystem]);
}
else
{
nativeSpec.setClassifier("INVALID");
}
relative = nativeSpec.toPath();
}
else
{
relative = m_name.toPath();
m_decenttype = "Java";
}
m_decentname = m_name.artifactId();
m_decentversion = minVersion = m_name.version();
m_storage_path = relative;
if(m_base_url.isEmpty())
m_download_url = QString("https://" + URLConstants::LIBRARY_BASE) + relative;
else
m_download_url = m_base_url + relative;
}
void OneSixLibrary::setName(const QString &name)
{
m_name = name;
}
void OneSixLibrary::setBaseUrl(const QString &base_url)
{
m_base_url = base_url;
}
void OneSixLibrary::addNative(OpSys os, const QString &suffix)
{
m_native_classifiers[os] = suffix;
}
void OneSixLibrary::clearSuffixes()
{
m_native_classifiers.clear();
}
void OneSixLibrary::setRules(QList<std::shared_ptr<Rule>> rules)
{
m_rules = rules;
}
bool OneSixLibrary::isActive() const
{
return m_is_active;
}
QString OneSixLibrary::downloadUrl() const
{
if (m_absolute_url.size())
return m_absolute_url;
return m_download_url;
}
QString OneSixLibrary::storagePath() const
{
return m_storage_path;
}
void OneSixLibrary::setAbsoluteUrl(const QString &absolute_url)
{
m_absolute_url = absolute_url;
}
QString OneSixLibrary::absoluteUrl() const
{
return m_absolute_url;
}
void OneSixLibrary::setHint(const QString &hint)
{
m_hint = hint;
}
QString OneSixLibrary::hint() const
{
return m_hint;
}
QStringList OneSixLibrary::files()
{
QStringList retval;
QString storage = storagePath();
if (storage.contains("${arch}"))
{
QString cooked_storage = storage;
cooked_storage.replace("${arch}", "32");
retval.append(cooked_storage);
cooked_storage = storage;
cooked_storage.replace("${arch}", "64");
retval.append(cooked_storage);
}
else
retval.append(storage);
return retval;
}
bool OneSixLibrary::filesExist(const QDir &base)
{
auto libFiles = files();
for(auto file: libFiles)
{
QFileInfo info(base, file);
QLOG_WARN() << info.absoluteFilePath() << "doesn't exist";
if (!info.exists())
return false;
}
return true;
}
bool OneSixLibrary::extractTo(QString target_dir)
{
QString storage = storagePath();
if (storage.contains("${arch}"))
{
QString cooked_storage = storage;
cooked_storage.replace("${arch}", "32");
QString origin = PathCombine("libraries", cooked_storage);
QString target_dir_cooked = PathCombine(target_dir, "32");
if (!ensureFolderPathExists(target_dir_cooked))
{
QLOG_ERROR() << "Couldn't create folder " + target_dir_cooked;
return false;
}
if (JlCompress::extractWithExceptions(origin, target_dir_cooked, extract_excludes)
.isEmpty())
{
QLOG_ERROR() << "Couldn't extract " + origin;
return false;
}
cooked_storage = storage;
cooked_storage.replace("${arch}", "64");
origin = PathCombine("libraries", cooked_storage);
target_dir_cooked = PathCombine(target_dir, "64");
if (!ensureFolderPathExists(target_dir_cooked))
{
QLOG_ERROR() << "Couldn't create folder " + target_dir_cooked;
return false;
}
if (JlCompress::extractWithExceptions(origin, target_dir_cooked, extract_excludes)
.isEmpty())
{
QLOG_ERROR() << "Couldn't extract " + origin;
return false;
}
}
else
{
if (!ensureFolderPathExists(target_dir))
{
QLOG_ERROR() << "Couldn't create folder " + target_dir;
return false;
}
QString path = PathCombine("libraries", storage);
if (JlCompress::extractWithExceptions(path, target_dir, extract_excludes).isEmpty())
{
QLOG_ERROR() << "Couldn't extract " + path;
return false;
}
}
return true;
}

View File

@ -26,38 +26,18 @@
#include "logic/minecraft/OpSys.h" #include "logic/minecraft/OpSys.h"
#include "logic/minecraft/RawLibrary.h" #include "logic/minecraft/RawLibrary.h"
class Rule;
class OneSixLibrary; class OneSixLibrary;
typedef std::shared_ptr<OneSixLibrary> OneSixLibraryPtr; typedef std::shared_ptr<OneSixLibrary> OneSixLibraryPtr;
/**
* This is a leftover from a previous design.
* All it does is separate the 'Raw' libraries read from files from the 'OneSix' libraries
* used for actually doing things.
*
* DEPRECATED, but still useful to keep the data clean and separated by type.
*/
class OneSixLibrary : public RawLibrary class OneSixLibrary : public RawLibrary
{ {
private:
/// a decent name fit for display
QString m_decentname;
/// a decent version fit for display
QString m_decentversion;
/// a decent type fit for display
QString m_decenttype;
/// where to store the lib locally
QString m_storage_path;
/// where to download the lib from
QString m_download_url;
/// is this lib actually active on the current OS?
bool m_is_active = false;
public:
QString minVersion;
enum DependType
{
Soft,
Hard
};
DependType dependType;
public: public:
/// Constructor /// Constructor
OneSixLibrary(const QString &name, const DependType type = Soft) OneSixLibrary(const QString &name, const DependType type = Soft)
@ -69,62 +49,4 @@ public:
OneSixLibrary(RawLibraryPtr base); OneSixLibrary(RawLibraryPtr base);
static OneSixLibraryPtr fromRawLibrary(RawLibraryPtr lib); static OneSixLibraryPtr fromRawLibrary(RawLibraryPtr lib);
/// Returns the raw name field
QString rawName() const
{
return m_name;
}
/**
* finalize the library, processing the input values into derived values and state
*
* This SHALL be called after all the values are parsed or after any further change.
*/
void finalize();
/// Set the library composite name
void setName(const QString &name);
/// get a decent-looking name
QString name() const
{
return m_decentname;
}
/// get a decent-looking version
QString version() const
{
return m_decentversion;
}
/// what kind of library is it? (for display)
QString type() const
{
return m_decenttype;
}
/// Set the url base for downloads
void setBaseUrl(const QString &base_url);
/// Attach a name suffix to the specified OS native
void addNative(OpSys os, const QString &suffix);
/// Clears all suffixes
void clearSuffixes();
/// Set the load rules
void setRules(QList<std::shared_ptr<Rule>> rules);
/// Returns true if the library should be loaded (or extracted, in case of natives)
bool isActive() const;
/// Get the URL to download the library from
QString downloadUrl() const;
/// Get the relative path where the library should be saved
QString storagePath() const;
/// set an absolute URL for the library. This is an MMC extension.
void setAbsoluteUrl(const QString &absolute_url);
QString absoluteUrl() const;
/// set a hint about how to treat the library. This is an MMC extension.
void setHint(const QString &hint);
QString hint() const;
bool extractTo(QString target_dir);
bool filesExist(const QDir &base);
QStringList files();
}; };

View File

@ -21,7 +21,7 @@
#include <memory> #include <memory>
#include "OpSys.h" #include "OpSys.h"
class OneSixLibrary; class RawLibrary;
class Rule; class Rule;
enum RuleAction enum RuleAction
@ -37,7 +37,7 @@ class Rule
{ {
protected: protected:
RuleAction m_result; RuleAction m_result;
virtual bool applies(OneSixLibrary *parent) = 0; virtual bool applies(const RawLibrary *parent) = 0;
public: public:
Rule(RuleAction result) : m_result(result) Rule(RuleAction result) : m_result(result)
@ -45,14 +45,13 @@ public:
} }
virtual ~Rule() {}; virtual ~Rule() {};
virtual QJsonObject toJson() = 0; virtual QJsonObject toJson() = 0;
RuleAction apply(OneSixLibrary *parent) RuleAction apply(const RawLibrary *parent)
{ {
if (applies(parent)) if (applies(parent))
return m_result; return m_result;
else else
return Defer; return Defer;
} }
;
}; };
class OsRule : public Rule class OsRule : public Rule
@ -64,7 +63,7 @@ private:
QString m_version_regexp; QString m_version_regexp;
protected: protected:
virtual bool applies(OneSixLibrary *) virtual bool applies(const RawLibrary *)
{ {
return (m_system == currentSystem); return (m_system == currentSystem);
} }
@ -85,7 +84,7 @@ public:
class ImplicitRule : public Rule class ImplicitRule : public Rule
{ {
protected: protected:
virtual bool applies(OneSixLibrary *) virtual bool applies(const RawLibrary *)
{ {
return true; return true;
} }

View File

@ -72,44 +72,54 @@ RawLibraryPtr RawLibrary::fromJsonPlus(const QJsonObject &libObj, const QString
if (libObj.contains("insert")) if (libObj.contains("insert"))
{ {
QJsonValue insertVal = ensureExists(libObj.value("insert"), "library insert rule"); QJsonValue insertVal = ensureExists(libObj.value("insert"), "library insert rule");
QString insertString; if (insertVal.isString())
{ {
if (insertVal.isString()) // it's just a simple string rule. OK.
QString insertString = insertVal.toString();
if (insertString == "apply")
{ {
insertString = insertVal.toString(); lib->insertType = RawLibrary::Apply;
} }
else if (insertVal.isObject()) else if (insertString == "prepend")
{ {
QJsonObject insertObj = insertVal.toObject(); lib->insertType = RawLibrary::Prepend;
if (insertObj.isEmpty()) }
{ else if (insertString == "append")
throw JSONValidationError("One library has an empty insert object in " + {
filename); lib->insertType = RawLibrary::Append;
} }
insertString = insertObj.keys().first(); else if (insertString == "replace")
lib->insertData = insertObj.value(insertString).toString(); {
lib->insertType = RawLibrary::Replace;
}
else
{
throw JSONValidationError("A '+' library in " + filename +
" contains an invalid insert type");
} }
} }
if (insertString == "apply") else if (insertVal.isObject())
{ {
lib->insertType = RawLibrary::Apply; // it's a more complex rule, specifying what should be:
} // * replaced (for now only this)
else if (insertString == "prepend") // this was never used, AFAIK. tread carefully.
{ QJsonObject insertObj = insertVal.toObject();
lib->insertType = RawLibrary::Prepend; if (insertObj.isEmpty())
} {
else if (insertString == "append") throw JSONValidationError("Empty compound insert rule in " + filename);
{ }
lib->insertType = RawLibrary::Append; QString insertString = insertObj.keys().first();
} // really, only replace makes sense in combination with
else if (insertString == "replace") if(insertString != "replace")
{ {
lib->insertType = RawLibrary::Replace; throw JSONValidationError("Compound insert rule is not 'replace' in " + filename);
}
lib->insertData = insertObj.value(insertString).toString();
} }
else else
{ {
throw JSONValidationError("A '+' library in " + filename + throw JSONValidationError("A '+' library in " + filename +
" contains an invalid insert type"); " contains an unknown/invalid insert rule");
} }
} }
if (libObj.contains("MMC-depend")) if (libObj.contains("MMC-depend"))
@ -132,12 +142,7 @@ RawLibraryPtr RawLibrary::fromJsonPlus(const QJsonObject &libObj, const QString
return lib; return lib;
} }
bool RawLibrary::isNative() const QJsonObject RawLibrary::toJson() const
{
return m_native_classifiers.size() != 0;
}
QJsonObject RawLibrary::toJson()
{ {
QJsonObject libRoot; QJsonObject libRoot;
libRoot.insert("name", (QString)m_name); libRoot.insert("name", (QString)m_name);
@ -186,7 +191,91 @@ QJsonObject RawLibrary::toJson()
return libRoot; return libRoot;
} }
QString RawLibrary::fullname() QStringList RawLibrary::files() const
{ {
return m_name.artifactPrefix(); QStringList retval;
QString storage = storagePath();
if (storage.contains("${arch}"))
{
QString cooked_storage = storage;
cooked_storage.replace("${arch}", "32");
retval.append(cooked_storage);
cooked_storage = storage;
cooked_storage.replace("${arch}", "64");
retval.append(cooked_storage);
}
else
retval.append(storage);
return retval;
}
bool RawLibrary::filesExist(const QDir &base) const
{
auto libFiles = files();
for(auto file: libFiles)
{
QFileInfo info(base, file);
QLOG_WARN() << info.absoluteFilePath() << "doesn't exist";
if (!info.exists())
return false;
}
return true;
}
QString RawLibrary::downloadUrl() const
{
if (m_absolute_url.size())
return m_absolute_url;
if (m_base_url.isEmpty())
{
return QString("https://" + URLConstants::LIBRARY_BASE) + storagePath();
}
return m_base_url + storagePath();
}
bool RawLibrary::isActive() const
{
bool result = true;
if (m_rules.empty())
{
result = true;
}
else
{
RuleAction ruleResult = Disallow;
for (auto rule : m_rules)
{
RuleAction temp = rule->apply(this);
if (temp != Defer)
ruleResult = temp;
}
result = result && (ruleResult == Allow);
}
if (isNative())
{
result = result && m_native_classifiers.contains(currentSystem);
}
return result;
}
QString RawLibrary::storagePath() const
{
// non-native? use only the gradle specifier
if (!isNative())
{
return m_name.toPath();
}
// otherwise native, override classifiers. Mojang HACK!
GradleSpecifier nativeSpec = m_name;
if(m_native_classifiers.contains(currentSystem))
{
nativeSpec.setClassifier(m_native_classifiers[currentSystem]);
}
else
{
nativeSpec.setClassifier("INVALID");
}
return nativeSpec.toPath();
} }

View File

@ -4,6 +4,7 @@
#include <QList> #include <QList>
#include <QStringList> #include <QStringList>
#include <QMap> #include <QMap>
#include <QDir>
#include <memory> #include <memory>
#include "logic/minecraft/OneSixRule.h" #include "logic/minecraft/OneSixRule.h"
@ -16,36 +17,141 @@ typedef std::shared_ptr<RawLibrary> RawLibraryPtr;
class RawLibrary class RawLibrary
{ {
friend class OneSixLibrary;
public: /* methods */ public: /* methods */
/// read and create a basic library /// read and create a basic library
static RawLibraryPtr fromJson(const QJsonObject &libObj, const QString &filename); static RawLibraryPtr fromJson(const QJsonObject &libObj, const QString &filename);
/// read and create a MultiMC '+' library. Those have some extra fields. /// read and create a MultiMC '+' library. Those have some extra fields.
static RawLibraryPtr fromJsonPlus(const QJsonObject &libObj, const QString &filename); static RawLibraryPtr fromJsonPlus(const QJsonObject &libObj, const QString &filename);
QJsonObject toJson();
/// Convert the library back to an JSON object
QJsonObject toJson() const;
/// Returns the raw name field
const GradleSpecifier & rawName() const
{
return m_name;
}
QString fullname(); void setRawName(const GradleSpecifier & spec)
{
m_name = spec;
}
void setClassifier(const QString & spec)
{
m_name.setClassifier(spec);
}
public: /* data */ /// returns the full group and artifact prefix
QString artifactPrefix() const
{
return m_name.artifactPrefix();
}
/// get the artifact ID
QString artifactId() const
{
return m_name.artifactId();
}
/// get the artifact version
QString version() const
{
return m_name.version();
}
/// Returns true if the library is native
bool isNative() const
{
return m_native_classifiers.size() != 0;
}
/// Set the url base for downloads
void setBaseUrl(const QString &base_url)
{
m_base_url = base_url;
}
/// List of files this library describes. Required because of platform-specificness of native libs
QStringList files() const;
/// List Shortcut for checking if all the above files exist
bool filesExist(const QDir &base) const;
void setAbsoluteUrl(const QString &absolute_url)
{
m_absolute_url = absolute_url;
}
QString absoluteUrl() const
{
return m_absolute_url;
}
void setHint(const QString &hint)
{
m_hint = hint;
}
QString hint() const
{
return m_hint;
}
/// Set the load rules
void setRules(QList<std::shared_ptr<Rule>> rules)
{
m_rules = rules;
}
/// Returns true if the library should be loaded (or extracted, in case of natives)
bool isActive() const;
/// Get the URL to download the library from
QString downloadUrl() const;
/// Get the relative path where the library should be saved
QString storagePath() const;
protected: /* data */
/// the basic gradle dependency specifier.
GradleSpecifier m_name; GradleSpecifier m_name;
/// where to store the lib locally
QString m_storage_path;
/// is this lib actually active on the current OS?
bool m_is_active = false;
public: /* data */
// TODO: make all of these protected, clean up semantics of implicit vs. explicit values.
/// URL where the file can be downloaded
QString m_base_url; QString m_base_url;
/// DEPRECATED: absolute URL. takes precedence the normal download URL, if defined
QString m_absolute_url;
/// type hint - modifies how the library is treated /// type hint - modifies how the library is treated
QString m_hint; QString m_hint;
/// DEPRECATED: absolute URL. takes precedence over m_download_path, if defined
QString m_absolute_url;
/// true if the library had an extract/excludes section (even empty)
bool applyExcludes = false; bool applyExcludes = false;
/// a list of files that shouldn't be extracted from the library
QStringList extract_excludes; QStringList extract_excludes;
/// Returns true if the library is native
bool isNative() const;
/// native suffixes per OS /// native suffixes per OS
QMap<OpSys, QString> m_native_classifiers; QMap<OpSys, QString> m_native_classifiers;
/// true if the library had a rules section (even empty)
bool applyRules = false; bool applyRules = false;
/// rules associated with the library
QList<std::shared_ptr<Rule>> m_rules; QList<std::shared_ptr<Rule>> m_rules;
// used for '+' libraries /// used for '+' libraries, determines how to add them
enum InsertType enum InsertType
{ {
Apply, Apply,
@ -55,10 +161,10 @@ public: /* data */
} insertType = Append; } insertType = Append;
QString insertData; QString insertData;
// soft or hard dependency? hard means 'needs equal', soft means 'needs equal or newer' /// determines how can libraries be applied. conflicting dependencies cause errors.
enum DependType enum DependType
{ {
Soft, Soft, //! needs equal or newer version
Hard Hard //! needs equal version (different versions mean version conflict)
} dependType = Soft; } dependType = Soft;
}; };

View File

@ -23,7 +23,7 @@ int findLibraryByName(QList<OneSixLibraryPtr> haystack, const GradleSpecifier &n
for (int i = 0; i < haystack.size(); ++i) for (int i = 0; i < haystack.size(); ++i)
{ {
if(haystack.at(i)->m_name.matchName(needle)) if(haystack.at(i)->rawName().matchName(needle))
{ {
// only one is allowed. // only one is allowed.
if (retval != -1) if (retval != -1)
@ -375,119 +375,108 @@ void VersionFile::applyTo(InstanceVersion *version)
} }
version->libraries = libs; version->libraries = libs;
} }
for (auto lib : addLibs) for (auto addedLibrary : addLibs)
{ {
switch (lib->insertType) switch (addedLibrary->insertType)
{ {
case RawLibrary::Apply: case RawLibrary::Apply:
{ {
// QLOG_INFO() << "Applying lib " << lib->name; // QLOG_INFO() << "Applying lib " << lib->name;
int index = findLibraryByName(version->libraries, lib->m_name); int index = findLibraryByName(version->libraries, addedLibrary->rawName());
if (index >= 0) if (index >= 0)
{ {
auto library = version->libraries[index]; auto existingLibrary = version->libraries[index];
if (!lib->m_base_url.isNull()) if (!addedLibrary->m_base_url.isNull())
{ {
library->setBaseUrl(lib->m_base_url); existingLibrary->setBaseUrl(addedLibrary->m_base_url);
} }
if (!lib->m_hint.isNull()) if (!addedLibrary->m_hint.isNull())
{ {
library->setHint(lib->m_hint); existingLibrary->setHint(addedLibrary->m_hint);
} }
if (!lib->m_absolute_url.isNull()) if (!addedLibrary->m_absolute_url.isNull())
{ {
library->setAbsoluteUrl(lib->m_absolute_url); existingLibrary->setAbsoluteUrl(addedLibrary->m_absolute_url);
} }
if (lib->applyExcludes) if (addedLibrary->applyExcludes)
{ {
library->extract_excludes = lib->extract_excludes; existingLibrary->extract_excludes = addedLibrary->extract_excludes;
} }
if (lib->isNative()) if (addedLibrary->isNative())
{ {
// library->clearSuffixes(); existingLibrary->m_native_classifiers = addedLibrary->m_native_classifiers;
library->m_native_classifiers = lib->m_native_classifiers;
/*
for (auto native : lib->natives)
{
library->addNative(native.first, native.second);
}
*/
} }
if (lib->applyRules) if (addedLibrary->applyRules)
{ {
library->setRules(lib->m_rules); existingLibrary->setRules(addedLibrary->m_rules);
} }
library->finalize();
} }
else else
{ {
QLOG_WARN() << "Couldn't find" << lib->m_name << "(skipping)"; QLOG_WARN() << "Couldn't find" << addedLibrary->rawName() << "(skipping)";
} }
break; break;
} }
case RawLibrary::Append: case RawLibrary::Append:
case RawLibrary::Prepend: case RawLibrary::Prepend:
{ {
// QLOG_INFO() << "Adding lib " << lib->name; // find the library by name.
const int index = findLibraryByName(version->libraries, lib->m_name); const int index = findLibraryByName(version->libraries, addedLibrary->rawName());
// library not found? just add it.
if (index < 0) if (index < 0)
{ {
if (lib->insertType == RawLibrary::Append) if (addedLibrary->insertType == RawLibrary::Append)
{ {
version->libraries.append(OneSixLibrary::fromRawLibrary(lib)); version->libraries.append(OneSixLibrary::fromRawLibrary(addedLibrary));
} }
else else
{ {
version->libraries.prepend(OneSixLibrary::fromRawLibrary(lib)); version->libraries.prepend(OneSixLibrary::fromRawLibrary(addedLibrary));
}
break;
}
// otherwise apply differences, if allowed
auto existingLibrary = version->libraries.at(index);
const Util::Version addedVersion = addedLibrary->version();
const Util::Version existingVersion = existingLibrary->version();
// if the existing version is a hard dependency we can either use it or
// fail, but we can't change it
if (existingLibrary->dependType == OneSixLibrary::Hard)
{
// we need a higher version, or we're hard to and the versions aren't
// equal
if (addedVersion > existingVersion ||
(addedLibrary->dependType == RawLibrary::Hard && addedVersion != existingVersion))
{
throw VersionBuildError(QObject::tr(
"Error resolving library dependencies between %1 and %2 in %3.")
.arg(existingLibrary->rawName(),
addedLibrary->rawName(), filename));
}
else
{
// the library is already existing, so we don't have to do anything
} }
} }
else else if (existingLibrary->dependType == OneSixLibrary::Soft)
{ {
auto otherLib = version->libraries.at(index); // if we are higher it means we should update
const Util::Version ourVersion = lib->m_name.version(); if (addedVersion > existingVersion)
const Util::Version otherVersion = otherLib->m_name.version();
// if the existing version is a hard dependency we can either use it or
// fail, but we can't change it
if (otherLib->dependType == OneSixLibrary::Hard)
{ {
// we need a higher version, or we're hard to and the versions aren't auto library = OneSixLibrary::fromRawLibrary(addedLibrary);
// equal version->libraries.replace(index, library);
if (ourVersion > otherVersion ||
(lib->dependType == RawLibrary::Hard && ourVersion != otherVersion))
{
throw VersionBuildError(
QObject::tr(
"Error resolving library dependencies between %1 and %2 in %3.")
.arg(otherLib->rawName(), lib->m_name, filename));
}
else
{
// the library is already existing, so we don't have to do anything
}
} }
else if (otherLib->dependType == OneSixLibrary::Soft) else
{ {
// if we are higher it means we should update // our version is smaller than the existing version, but we require
if (ourVersion > otherVersion) // it: fail
if (addedLibrary->dependType == RawLibrary::Hard)
{ {
auto library = OneSixLibrary::fromRawLibrary(lib); throw VersionBuildError(QObject::tr(
if (Util::Version(otherLib->minVersion) < ourVersion) "Error resolving library dependencies between %1 and %2 in %3.")
{ .arg(existingLibrary->rawName(),
library->minVersion = ourVersion.toString(); addedLibrary->rawName(), filename));
}
version->libraries.replace(index, library);
}
else
{
// our version is smaller than the existing version, but we require
// it: fail
if (lib->dependType == RawLibrary::Hard)
{
throw VersionBuildError(QObject::tr(
"Error resolving library dependencies between %1 and %2 in %3.")
.arg(otherLib->rawName(), lib->m_name,
filename));
}
} }
} }
} }
@ -496,19 +485,19 @@ void VersionFile::applyTo(InstanceVersion *version)
case RawLibrary::Replace: case RawLibrary::Replace:
{ {
GradleSpecifier toReplace; GradleSpecifier toReplace;
if (lib->insertData.isEmpty()) if (addedLibrary->insertData.isEmpty())
{ {
toReplace = lib->m_name; toReplace = addedLibrary->rawName();
} }
else else
{ {
toReplace = lib->insertData; toReplace = addedLibrary->insertData;
} }
// QLOG_INFO() << "Replacing lib " << toReplace << " with " << lib->name; // QLOG_INFO() << "Replacing lib " << toReplace << " with " << lib->name;
int index = findLibraryByName(version->libraries, toReplace); int index = findLibraryByName(version->libraries, toReplace);
if (index >= 0) if (index >= 0)
{ {
version->libraries.replace(index, OneSixLibrary::fromRawLibrary(lib)); version->libraries.replace(index, OneSixLibrary::fromRawLibrary(addedLibrary));
} }
else else
{ {