2016-01-02 05:05:54 +05:30
|
|
|
#include "JavaVersion.h"
|
|
|
|
#include <MMCStrings.h>
|
|
|
|
|
|
|
|
#include <QRegularExpression>
|
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
JavaVersion & JavaVersion::operator=(const QString & javaVersionString)
|
|
|
|
{
|
2016-06-16 05:50:23 +05:30
|
|
|
m_string = javaVersionString;
|
2016-01-02 05:05:54 +05:30
|
|
|
|
|
|
|
auto getCapturedInteger = [](const QRegularExpressionMatch & match, const QString &what) -> int
|
|
|
|
{
|
|
|
|
auto str = match.captured(what);
|
|
|
|
if(str.isEmpty())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return str.toInt();
|
|
|
|
};
|
|
|
|
|
|
|
|
QRegularExpression pattern;
|
|
|
|
if(javaVersionString.startsWith("1."))
|
|
|
|
{
|
|
|
|
pattern = QRegularExpression ("1[.](?<major>[0-9]+)([.](?<minor>[0-9]+))?(_(?<security>[0-9]+)?)?(-(?<prerelease>[a-zA-Z0-9]+))?");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pattern = QRegularExpression("(?<major>[0-9]+)([.](?<minor>[0-9]+))?([.](?<security>[0-9]+))?(-(?<prerelease>[a-zA-Z0-9]+))?");
|
|
|
|
}
|
|
|
|
|
2016-06-16 05:50:23 +05:30
|
|
|
auto match = pattern.match(m_string);
|
|
|
|
m_parseable = match.hasMatch();
|
|
|
|
m_major = getCapturedInteger(match, "major");
|
|
|
|
m_minor = getCapturedInteger(match, "minor");
|
|
|
|
m_security = getCapturedInteger(match, "security");
|
|
|
|
m_prerelease = match.captured("prerelease");
|
2016-01-02 05:05:54 +05:30
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
JavaVersion::JavaVersion(const QString &rhs)
|
|
|
|
{
|
|
|
|
operator=(rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString JavaVersion::toString()
|
|
|
|
{
|
2016-06-16 05:50:23 +05:30
|
|
|
return m_string;
|
2016-01-02 05:05:54 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
bool JavaVersion::requiresPermGen()
|
|
|
|
{
|
2016-06-16 05:50:23 +05:30
|
|
|
if(m_parseable)
|
2016-01-02 05:05:54 +05:30
|
|
|
{
|
2016-06-16 05:50:23 +05:30
|
|
|
return m_major < 8;
|
2016-01-02 05:05:54 +05:30
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JavaVersion::operator<(const JavaVersion &rhs)
|
|
|
|
{
|
2016-06-16 05:50:23 +05:30
|
|
|
if(m_parseable && rhs.m_parseable)
|
2016-01-02 05:05:54 +05:30
|
|
|
{
|
2016-06-16 05:50:23 +05:30
|
|
|
if(m_major < rhs.m_major)
|
2016-01-02 05:05:54 +05:30
|
|
|
return true;
|
2016-06-16 05:50:23 +05:30
|
|
|
if(m_major > rhs.m_major)
|
2016-01-02 05:05:54 +05:30
|
|
|
return false;
|
2016-06-16 05:50:23 +05:30
|
|
|
if(m_minor < rhs.m_minor)
|
2016-01-02 05:05:54 +05:30
|
|
|
return true;
|
2016-06-16 05:50:23 +05:30
|
|
|
if(m_minor > rhs.m_minor)
|
2016-01-02 05:05:54 +05:30
|
|
|
return false;
|
2016-06-16 05:50:23 +05:30
|
|
|
if(m_security < rhs.m_security)
|
2016-01-02 05:05:54 +05:30
|
|
|
return true;
|
2016-06-16 05:50:23 +05:30
|
|
|
if(m_security > rhs.m_security)
|
2016-01-02 05:05:54 +05:30
|
|
|
return false;
|
|
|
|
|
|
|
|
// everything else being equal, consider prerelease status
|
2016-06-16 05:50:23 +05:30
|
|
|
bool thisPre = !m_prerelease.isEmpty();
|
|
|
|
bool rhsPre = !rhs.m_prerelease.isEmpty();
|
2016-01-02 05:05:54 +05:30
|
|
|
if(thisPre && !rhsPre)
|
|
|
|
{
|
|
|
|
// this is a prerelease and the other one isn't -> lesser
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if(!thisPre && rhsPre)
|
|
|
|
{
|
|
|
|
// this isn't a prerelease and the other one is -> greater
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if(thisPre && rhsPre)
|
|
|
|
{
|
|
|
|
// both are prereleases - use natural compare...
|
2016-06-16 05:50:23 +05:30
|
|
|
return Strings::naturalCompare(m_prerelease, rhs.m_prerelease, Qt::CaseSensitive) < 0;
|
2016-01-02 05:05:54 +05:30
|
|
|
}
|
|
|
|
// neither is prerelease, so they are the same -> this cannot be less than rhs
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-16 05:50:23 +05:30
|
|
|
else return Strings::naturalCompare(m_string, rhs.m_string, Qt::CaseSensitive) < 0;
|
2016-01-02 05:05:54 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
bool JavaVersion::operator==(const JavaVersion &rhs)
|
|
|
|
{
|
2016-06-16 05:50:23 +05:30
|
|
|
if(m_parseable && rhs.m_parseable)
|
2016-01-02 05:05:54 +05:30
|
|
|
{
|
2016-06-16 05:50:23 +05:30
|
|
|
return m_major == rhs.m_major && m_minor == rhs.m_minor && m_security == rhs.m_security && m_prerelease == rhs.m_prerelease;
|
2016-01-02 05:05:54 +05:30
|
|
|
}
|
2016-06-16 05:50:23 +05:30
|
|
|
return m_string == rhs.m_string;
|
2016-01-02 05:05:54 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
bool JavaVersion::operator>(const JavaVersion &rhs)
|
|
|
|
{
|
|
|
|
return (!operator<(rhs)) && (!operator==(rhs));
|
|
|
|
}
|