summaryrefslogtreecommitdiffstats
path: root/api/logic/java
diff options
context:
space:
mode:
Diffstat (limited to 'api/logic/java')
-rw-r--r--api/logic/java/JavaChecker.cpp250
-rw-r--r--api/logic/java/JavaChecker.h66
-rw-r--r--api/logic/java/JavaCheckerJob.cpp32
-rw-r--r--api/logic/java/JavaCheckerJob.h52
-rw-r--r--api/logic/java/JavaInstall.cpp28
-rw-r--r--api/logic/java/JavaInstall.h48
-rw-r--r--api/logic/java/JavaInstallList.cpp222
-rw-r--r--api/logic/java/JavaInstallList.h58
-rw-r--r--api/logic/java/JavaUtils.cpp514
-rw-r--r--api/logic/java/JavaUtils.h12
-rw-r--r--api/logic/java/JavaVersion.cpp164
-rw-r--r--api/logic/java/JavaVersion.h68
-rw-r--r--api/logic/java/JavaVersion_test.cpp194
-rw-r--r--api/logic/java/launch/CheckJava.cpp194
-rw-r--r--api/logic/java/launch/CheckJava.h28
15 files changed, 965 insertions, 965 deletions
diff --git a/api/logic/java/JavaChecker.cpp b/api/logic/java/JavaChecker.cpp
index f0b71e48..9ba3933f 100644
--- a/api/logic/java/JavaChecker.cpp
+++ b/api/logic/java/JavaChecker.cpp
@@ -16,149 +16,149 @@ JavaChecker::JavaChecker(QObject *parent) : QObject(parent)
void JavaChecker::performCheck()
{
- QString checkerJar = FS::PathCombine(ENV.getJarsPath(), "JavaCheck.jar");
-
- QStringList args;
-
- process.reset(new QProcess());
- if(m_args.size())
- {
- auto extraArgs = Commandline::splitArgs(m_args);
- args.append(extraArgs);
- }
- if(m_minMem != 0)
- {
- args << QString("-Xms%1m").arg(m_minMem);
- }
- if(m_maxMem != 0)
- {
- args << QString("-Xmx%1m").arg(m_maxMem);
- }
- if(m_permGen != 64)
- {
- args << QString("-XX:PermSize=%1m").arg(m_permGen);
- }
-
- args.append({"-jar", checkerJar});
- process->setArguments(args);
- process->setProgram(m_path);
- process->setProcessChannelMode(QProcess::SeparateChannels);
- process->setProcessEnvironment(CleanEnviroment());
- qDebug() << "Running java checker: " + m_path + args.join(" ");;
-
- connect(process.get(), SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(finished(int, QProcess::ExitStatus)));
- connect(process.get(), SIGNAL(error(QProcess::ProcessError)), this, SLOT(error(QProcess::ProcessError)));
- connect(process.get(), SIGNAL(readyReadStandardOutput()), this, SLOT(stdoutReady()));
- connect(process.get(), SIGNAL(readyReadStandardError()), this, SLOT(stderrReady()));
- connect(&killTimer, SIGNAL(timeout()), SLOT(timeout()));
- killTimer.setSingleShot(true);
- killTimer.start(15000);
- process->start();
+ QString checkerJar = FS::PathCombine(ENV.getJarsPath(), "JavaCheck.jar");
+
+ QStringList args;
+
+ process.reset(new QProcess());
+ if(m_args.size())
+ {
+ auto extraArgs = Commandline::splitArgs(m_args);
+ args.append(extraArgs);
+ }
+ if(m_minMem != 0)
+ {
+ args << QString("-Xms%1m").arg(m_minMem);
+ }
+ if(m_maxMem != 0)
+ {
+ args << QString("-Xmx%1m").arg(m_maxMem);
+ }
+ if(m_permGen != 64)
+ {
+ args << QString("-XX:PermSize=%1m").arg(m_permGen);
+ }
+
+ args.append({"-jar", checkerJar});
+ process->setArguments(args);
+ process->setProgram(m_path);
+ process->setProcessChannelMode(QProcess::SeparateChannels);
+ process->setProcessEnvironment(CleanEnviroment());
+ qDebug() << "Running java checker: " + m_path + args.join(" ");;
+
+ connect(process.get(), SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(finished(int, QProcess::ExitStatus)));
+ connect(process.get(), SIGNAL(error(QProcess::ProcessError)), this, SLOT(error(QProcess::ProcessError)));
+ connect(process.get(), SIGNAL(readyReadStandardOutput()), this, SLOT(stdoutReady()));
+ connect(process.get(), SIGNAL(readyReadStandardError()), this, SLOT(stderrReady()));
+ connect(&killTimer, SIGNAL(timeout()), SLOT(timeout()));
+ killTimer.setSingleShot(true);
+ killTimer.start(15000);
+ process->start();
}
void JavaChecker::stdoutReady()
{
- QByteArray data = process->readAllStandardOutput();
- QString added = QString::fromLocal8Bit(data);
- added.remove('\r');
- m_stdout += added;
+ QByteArray data = process->readAllStandardOutput();
+ QString added = QString::fromLocal8Bit(data);
+ added.remove('\r');
+ m_stdout += added;
}
void JavaChecker::stderrReady()
{
- QByteArray data = process->readAllStandardError();
- QString added = QString::fromLocal8Bit(data);
- added.remove('\r');
- m_stderr += added;
+ QByteArray data = process->readAllStandardError();
+ QString added = QString::fromLocal8Bit(data);
+ added.remove('\r');
+ m_stderr += added;
}
void JavaChecker::finished(int exitcode, QProcess::ExitStatus status)
{
- killTimer.stop();
- QProcessPtr _process;
- _process.swap(process);
-
- JavaCheckResult result;
- {
- result.path = m_path;
- result.id = m_id;
- }
- result.errorLog = m_stderr;
- result.outLog = m_stdout;
- qDebug() << "STDOUT" << m_stdout;
- qWarning() << "STDERR" << m_stderr;
- qDebug() << "Java checker finished with status " << status << " exit code " << exitcode;
-
- if (status == QProcess::CrashExit || exitcode == 1)
- {
- result.validity = JavaCheckResult::Validity::Errored;
- emit checkFinished(result);
- return;
- }
-
- bool success = true;
-
- QMap<QString, QString> results;
- QStringList lines = m_stdout.split("\n", QString::SkipEmptyParts);
- for(QString line : lines)
- {
- line = line.trimmed();
-
- auto parts = line.split('=', QString::SkipEmptyParts);
- if(parts.size() != 2 || parts[0].isEmpty() || parts[1].isEmpty())
- {
- success = false;
- }
- else
- {
- results.insert(parts[0], parts[1]);
- }
- }
-
- if(!results.contains("os.arch") || !results.contains("java.version") || !success)
- {
- result.validity = JavaCheckResult::Validity::ReturnedInvalidData;
- emit checkFinished(result);
- return;
- }
-
- auto os_arch = results["os.arch"];
- auto java_version = results["java.version"];
- bool is_64 = os_arch == "x86_64" || os_arch == "amd64";
-
-
- result.validity = JavaCheckResult::Validity::Valid;
- result.is_64bit = is_64;
- result.mojangPlatform = is_64 ? "64" : "32";
- result.realPlatform = os_arch;
- result.javaVersion = java_version;
- qDebug() << "Java checker succeeded.";
- emit checkFinished(result);
+ killTimer.stop();
+ QProcessPtr _process;
+ _process.swap(process);
+
+ JavaCheckResult result;
+ {
+ result.path = m_path;
+ result.id = m_id;
+ }
+ result.errorLog = m_stderr;
+ result.outLog = m_stdout;
+ qDebug() << "STDOUT" << m_stdout;
+ qWarning() << "STDERR" << m_stderr;
+ qDebug() << "Java checker finished with status " << status << " exit code " << exitcode;
+
+ if (status == QProcess::CrashExit || exitcode == 1)
+ {
+ result.validity = JavaCheckResult::Validity::Errored;
+ emit checkFinished(result);
+ return;
+ }
+
+ bool success = true;
+
+ QMap<QString, QString> results;
+ QStringList lines = m_stdout.split("\n", QString::SkipEmptyParts);
+ for(QString line : lines)
+ {
+ line = line.trimmed();
+
+ auto parts = line.split('=', QString::SkipEmptyParts);
+ if(parts.size() != 2 || parts[0].isEmpty() || parts[1].isEmpty())
+ {
+ success = false;
+ }
+ else
+ {
+ results.insert(parts[0], parts[1]);
+ }
+ }
+
+ if(!results.contains("os.arch") || !results.contains("java.version") || !success)
+ {
+ result.validity = JavaCheckResult::Validity::ReturnedInvalidData;
+ emit checkFinished(result);
+ return;
+ }
+
+ auto os_arch = results["os.arch"];
+ auto java_version = results["java.version"];
+ bool is_64 = os_arch == "x86_64" || os_arch == "amd64";
+
+
+ result.validity = JavaCheckResult::Validity::Valid;
+ result.is_64bit = is_64;
+ result.mojangPlatform = is_64 ? "64" : "32";
+ result.realPlatform = os_arch;
+ result.javaVersion = java_version;
+ qDebug() << "Java checker succeeded.";
+ emit checkFinished(result);
}
void JavaChecker::error(QProcess::ProcessError err)
{
- if(err == QProcess::FailedToStart)
- {
- killTimer.stop();
- qDebug() << "Java checker has failed to start.";
- JavaCheckResult result;
- {
- result.path = m_path;
- result.id = m_id;
- }
-
- emit checkFinished(result);
- return;
- }
+ if(err == QProcess::FailedToStart)
+ {
+ killTimer.stop();
+ qDebug() << "Java checker has failed to start.";
+ JavaCheckResult result;
+ {
+ result.path = m_path;
+ result.id = m_id;
+ }
+
+ emit checkFinished(result);
+ return;
+ }
}
void JavaChecker::timeout()
{
- // NO MERCY. NO ABUSE.
- if(process)
- {
- qDebug() << "Java checker has been killed by timeout.";
- process->kill();
- }
+ // NO MERCY. NO ABUSE.
+ if(process)
+ {
+ qDebug() << "Java checker has been killed by timeout.";
+ process->kill();
+ }
}
diff --git a/api/logic/java/JavaChecker.h b/api/logic/java/JavaChecker.h
index c6bd697c..d5d4b0de 100644
--- a/api/logic/java/JavaChecker.h
+++ b/api/logic/java/JavaChecker.h
@@ -11,50 +11,50 @@ class JavaChecker;
struct MULTIMC_LOGIC_EXPORT JavaCheckResult
{
- QString path;
- QString mojangPlatform;
- QString realPlatform;
- JavaVersion javaVersion;
- QString outLog;
- QString errorLog;
- bool is_64bit = false;
- int id;
- enum class Validity
- {
- Errored,
- ReturnedInvalidData,
- Valid
- } validity = Validity::Errored;
+ QString path;
+ QString mojangPlatform;
+ QString realPlatform;
+ JavaVersion javaVersion;
+ QString outLog;
+ QString errorLog;
+ bool is_64bit = false;
+ int id;
+ enum class Validity
+ {
+ Errored,
+ ReturnedInvalidData,
+ Valid
+ } validity = Validity::Errored;
};
typedef std::shared_ptr<QProcess> QProcessPtr;
typedef std::shared_ptr<JavaChecker> JavaCheckerPtr;
class MULTIMC_LOGIC_EXPORT JavaChecker : public QObject
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit JavaChecker(QObject *parent = 0);
- void performCheck();
+ explicit JavaChecker(QObject *parent = 0);
+ void performCheck();
- QString m_path;
- QString m_args;
- int m_id = 0;
- int m_minMem = 0;
- int m_maxMem = 0;
- int m_permGen = 64;
+ QString m_path;
+ QString m_args;
+ int m_id = 0;
+ int m_minMem = 0;
+ int m_maxMem = 0;
+ int m_permGen = 64;
signals:
- void checkFinished(JavaCheckResult result);
+ void checkFinished(JavaCheckResult result);
private:
- QProcessPtr process;
- QTimer killTimer;
- QString m_stdout;
- QString m_stderr;
+ QProcessPtr process;
+ QTimer killTimer;
+ QString m_stdout;
+ QString m_stderr;
public
slots:
- void timeout();
- void finished(int exitcode, QProcess::ExitStatus);
- void error(QProcess::ProcessError);
- void stdoutReady();
- void stderrReady();
+ void timeout();
+ void finished(int exitcode, QProcess::ExitStatus);
+ void error(QProcess::ProcessError);
+ void stdoutReady();
+ void stderrReady();
};
diff --git a/api/logic/java/JavaCheckerJob.cpp b/api/logic/java/JavaCheckerJob.cpp
index fabb5aaa..a26846f2 100644
--- a/api/logic/java/JavaCheckerJob.cpp
+++ b/api/logic/java/JavaCheckerJob.cpp
@@ -19,26 +19,26 @@
void JavaCheckerJob::partFinished(JavaCheckResult result)
{
- num_finished++;
- qDebug() << m_job_name.toLocal8Bit() << "progress:" << num_finished << "/"
- << javacheckers.size();
- setProgress(num_finished, javacheckers.size());
+ num_finished++;
+ qDebug() << m_job_name.toLocal8Bit() << "progress:" << num_finished << "/"
+ << javacheckers.size();
+ setProgress(num_finished, javacheckers.size());
- javaresults.replace(result.id, result);
+ javaresults.replace(result.id, result);
- if (num_finished == javacheckers.size())
- {
- emitSucceeded();
- }
+ if (num_finished == javacheckers.size())
+ {
+ emitSucceeded();
+ }
}
void JavaCheckerJob::executeTask()
{
- qDebug() << m_job_name.toLocal8Bit() << " started.";
- for (auto iter : javacheckers)
- {
- javaresults.append(JavaCheckResult());
- connect(iter.get(), SIGNAL(checkFinished(JavaCheckResult)), SLOT(partFinished(JavaCheckResult)));
- iter->performCheck();
- }
+ qDebug() << m_job_name.toLocal8Bit() << " started.";
+ for (auto iter : javacheckers)
+ {
+ javaresults.append(JavaCheckResult());
+ connect(iter.get(), SIGNAL(checkFinished(JavaCheckResult)), SLOT(partFinished(JavaCheckResult)));
+ iter->performCheck();
+ }
}
diff --git a/api/logic/java/JavaCheckerJob.h b/api/logic/java/JavaCheckerJob.h
index 64ac58a1..e52970c1 100644
--- a/api/logic/java/JavaCheckerJob.h
+++ b/api/logic/java/JavaCheckerJob.h
@@ -25,37 +25,37 @@ typedef std::shared_ptr<JavaCheckerJob> JavaCheckerJobPtr;
// FIXME: this just seems horribly redundant
class JavaCheckerJob : public Task
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit JavaCheckerJob(QString job_name) : Task(), m_job_name(job_name) {};
- virtual ~JavaCheckerJob() {};
-
- bool addJavaCheckerAction(JavaCheckerPtr base)
- {
- javacheckers.append(base);
- // if this is already running, the action needs to be started right away!
- if (isRunning())
- {
- setProgress(num_finished, javacheckers.size());
- connect(base.get(), &JavaChecker::checkFinished, this, &JavaCheckerJob::partFinished);
- base->performCheck();
- }
- return true;
- }
- QList<JavaCheckResult> getResults()
- {
- return javaresults;
- }
+ explicit JavaCheckerJob(QString job_name) : Task(), m_job_name(job_name) {};
+ virtual ~JavaCheckerJob() {};
+
+ bool addJavaCheckerAction(JavaCheckerPtr base)
+ {
+ javacheckers.append(base);
+ // if this is already running, the action needs to be started right away!
+ if (isRunning())
+ {
+ setProgress(num_finished, javacheckers.size());
+ connect(base.get(), &JavaChecker::checkFinished, this, &JavaCheckerJob::partFinished);
+ base->performCheck();
+ }
+ return true;
+ }
+ QList<JavaCheckResult> getResults()
+ {
+ return javaresults;
+ }
private slots:
- void partFinished(JavaCheckResult result);
+ void partFinished(JavaCheckResult result);
protected:
- virtual void executeTask() override;
+ virtual void executeTask() override;
private:
- QString m_job_name;
- QList<JavaCheckerPtr> javacheckers;
- QList<JavaCheckResult> javaresults;
- int num_finished = 0;
+ QString m_job_name;
+ QList<JavaCheckerPtr> javacheckers;
+ QList<JavaCheckResult> javaresults;
+ int num_finished = 0;
};
diff --git a/api/logic/java/JavaInstall.cpp b/api/logic/java/JavaInstall.cpp
index bb262b6e..5bcf7bcb 100644
--- a/api/logic/java/JavaInstall.cpp
+++ b/api/logic/java/JavaInstall.cpp
@@ -3,26 +3,26 @@
bool JavaInstall::operator<(const JavaInstall &rhs)
{
- auto archCompare = Strings::naturalCompare(arch, rhs.arch, Qt::CaseInsensitive);
- if(archCompare != 0)
- return archCompare < 0;
- if(id < rhs.id)
- {
- return true;
- }
- if(id > rhs.id)
- {
- return false;
- }
- return Strings::naturalCompare(path, rhs.path, Qt::CaseInsensitive) < 0;
+ auto archCompare = Strings::naturalCompare(arch, rhs.arch, Qt::CaseInsensitive);
+ if(archCompare != 0)
+ return archCompare < 0;
+ if(id < rhs.id)
+ {
+ return true;
+ }
+ if(id > rhs.id)
+ {
+ return false;
+ }
+ return Strings::naturalCompare(path, rhs.path, Qt::CaseInsensitive) < 0;
}
bool JavaInstall::operator==(const JavaInstall &rhs)
{
- return arch == rhs.arch && id == rhs.id && path == rhs.path;
+ return arch == rhs.arch && id == rhs.id && path == rhs.path;
}
bool JavaInstall::operator>(const JavaInstall &rhs)
{
- return (!operator<(rhs)) && (!operator==(rhs));
+ return (!operator<(rhs)) && (!operator==(rhs));
}
diff --git a/api/logic/java/JavaInstall.h b/api/logic/java/JavaInstall.h
index 882c7386..64be40d1 100644
--- a/api/logic/java/JavaInstall.h
+++ b/api/logic/java/JavaInstall.h
@@ -5,34 +5,34 @@
struct JavaInstall : public BaseVersion
{
- JavaInstall(){}
- JavaInstall(QString id, QString arch, QString path)
- : id(id), arch(arch), path(path)
- {
- }
- virtual QString descriptor()
- {
- return id.toString();
- }
+ JavaInstall(){}
+ JavaInstall(QString id, QString arch, QString path)
+ : id(id), arch(arch), path(path)
+ {
+ }
+ virtual QString descriptor()
+ {
+ return id.toString();
+ }
- virtual QString name()
- {
- return id.toString();
- }
+ virtual QString name()
+ {
+ return id.toString();
+ }
- virtual QString typeString() const
- {
- return arch;
- }
+ virtual QString typeString() const
+ {
+ return arch;
+ }
- bool operator<(const JavaInstall & rhs);
- bool operator==(const JavaInstall & rhs);
- bool operator>(const JavaInstall & rhs);
+ bool operator<(const JavaInstall & rhs);
+ bool operator==(const JavaInstall & rhs);
+ bool operator>(const JavaInstall & rhs);
- JavaVersion id;
- QString arch;
- QString path;
- bool recommended = false;
+ JavaVersion id;
+ QString arch;
+ QString path;
+ bool recommended = false;
};
typedef std::shared_ptr<JavaInstall> JavaInstallPtr;
diff --git a/api/logic/java/JavaInstallList.cpp b/api/logic/java/JavaInstallList.cpp
index 9d2e2f8b..605d4c0c 100644
--- a/api/logic/java/JavaInstallList.cpp
+++ b/api/logic/java/JavaInstallList.cpp
@@ -31,111 +31,111 @@ JavaInstallList::JavaInstallList(QObject *parent) : BaseVersionList(parent)
shared_qobject_ptr<Task> JavaInstallList::getLoadTask()
{
- load();
- return getCurrentTask();
+ load();
+ return getCurrentTask();
}
shared_qobject_ptr<Task> JavaInstallList::getCurrentTask()
{
- if(m_status == Status::InProgress)
- {
- return m_loadTask;
- }
- return nullptr;
+ if(m_status == Status::InProgress)
+ {
+ return m_loadTask;
+ }
+ return nullptr;
}
void JavaInstallList::load()
{
- if(m_status != Status::InProgress)
- {
- m_status = Status::InProgress;
- m_loadTask = new JavaListLoadTask(this);
- m_loadTask->start();
- }
+ if(m_status != Status::InProgress)
+ {
+ m_status = Status::InProgress;
+ m_loadTask = new JavaListLoadTask(this);
+ m_loadTask->start();
+ }
}
const BaseVersionPtr JavaInstallList::at(int i) const
{
- return m_vlist.at(i);
+ return m_vlist.at(i);
}
bool JavaInstallList::isLoaded()
{
- return m_status == JavaInstallList::Status::Done;
+ return m_status == JavaInstallList::Status::Done;
}
int JavaInstallList::count() const
{
- return m_vlist.count();
+ return m_vlist.count();
}
QVariant JavaInstallList::data(const QModelIndex &index, int role) const
{
- if (!index.isValid())
- return QVariant();
-
- if (index.row() > count())
- return QVariant();
-
- auto version = std::dynamic_pointer_cast<JavaInstall>(m_vlist[index.row()]);
- switch (role)
- {
- case VersionPointerRole:
- return qVariantFromValue(m_vlist[index.row()]);
- case VersionIdRole:
- return version->descriptor();
- case VersionRole:
- return version->id.toString();
- case RecommendedRole:
- return version->recommended;
- case PathRole:
- return version->path;
- case ArchitectureRole:
- return version->arch;
- default:
- return QVariant();
- }
+ if (!index.isValid())
+ return QVariant();
+
+ if (index.row() > count())
+ return QVariant();
+
+ auto version = std::dynamic_pointer_cast<JavaInstall>(m_vlist[index.row()]);
+ switch (role)
+ {
+ case VersionPointerRole:
+ return qVariantFromValue(m_vlist[index.row()]);
+ case VersionIdRole:
+ return version->descriptor();
+ case VersionRole:
+ return version->id.toString();
+ case RecommendedRole:
+ return version->recommended;
+ case PathRole:
+ return version->path;
+ case ArchitectureRole:
+ return version->arch;
+ default:
+ return QVariant();
+ }
}
BaseVersionList::RoleList JavaInstallList::providesRoles() const
{
- return {VersionPointerRole, VersionIdRole, VersionRole, RecommendedRole, PathRole, ArchitectureRole};
+ return {VersionPointerRole, VersionIdRole, VersionRole, RecommendedRole, PathRole, ArchitectureRole};
}
void JavaInstallList::updateListData(QList<BaseVersionPtr> versions)
{
- beginResetModel();
- m_vlist = versions;
- sortVersions();
- if(m_vlist.size())
- {
- auto best = std::dynamic_pointer_cast<JavaInstall>(m_vlist[0]);
- best->recommended = true;
- }
- endResetModel();
- m_status = Status::Done;
- m_loadTask.reset();
+ beginResetModel();
+ m_vlist = versions;
+ sortVersions();
+ if(m_vlist.size())
+ {
+ auto best = std::dynamic_pointer_cast<JavaInstall>(m_vlist[0]);
+ best->recommended = true;
+ }
+ endResetModel();
+ m_status = Status::Done;
+ m_loadTask.reset();
}
bool sortJavas(BaseVersionPtr left, BaseVersionPtr right)
{
- auto rleft = std::dynamic_pointer_cast<JavaInstall>(left);
- auto rright = std::dynamic_pointer_cast<JavaInstall>(right);
- return (*rleft) > (*rright);
+ auto rleft = std::dynamic_pointer_cast<JavaInstall>(left);
+ auto rright = std::dynamic_pointer_cast<JavaInstall>(right);
+ return (*rleft) > (*rright);
}
void JavaInstallList::sortVersions()
{
- beginResetModel();
- std::sort(m_vlist.begin(), m_vlist.end(), sortJavas);
- endResetModel();
+ beginResetModel();
+ std::sort(m_vlist.begin(), m_vlist.end(), sortJavas);
+ endResetModel();
}
JavaListLoadTask::JavaListLoadTask(JavaInstallList *vlist) : Task()
{
- m_list = vlist;
- m_currentRecommended = NULL;
+ m_list = vlist;
+ m_currentRecommended = NULL;
}
JavaListLoadTask::~JavaListLoadTask()
@@ -144,65 +144,65 @@ JavaListLoadTask::~JavaListLoadTask()
void JavaListLoadTask::executeTask()
{
- setStatus(tr("Detecting Java installations..."));
+ setStatus(tr("Detecting Java installations..."));
- JavaUtils ju;
- QList<QString> candidate_paths = ju.FindJavaPaths();
+ JavaUtils ju;
+ QList<QString> candidate_paths = ju.FindJavaPaths();
- m_job = std::shared_ptr<JavaCheckerJob>(new JavaCheckerJob("Java detection"));
- connect(m_job.get(), &Task::finished, this, &JavaListLoadTask::javaCheckerFinished);
- connect(m_job.get(), &Task::progress, this, &Task::setProgress);
+ m_job = std::shared_ptr<JavaCheckerJob>(new JavaCheckerJob("Java detection"));
+ connect(m_job.get(), &Task::finished, this, &JavaListLoadTask::javaCheckerFinished);
+ connect(m_job.get(), &Task::progress, this, &Task::setProgress);
- qDebug() << "Probing the following Java paths: ";
- int id = 0;
- for(QString candidate : candidate_paths)
- {
- qDebug() << " " << candidate;
+ qDebug() << "Probing the following Java paths: ";
+ int id = 0;
+ for(QString candidate : candidate_paths)
+ {
+ qDebug() << " " << candidate;
- auto candidate_checker = new JavaChecker();
- candidate_checker->m_path = candidate;
- candidate_checker->m_id = id;
- m_job->addJavaCheckerAction(JavaCheckerPtr(candidate_checker));
+ auto candidate_checker = new JavaChecker();
+ candidate_checker->m_path = candidate;
+ candidate_checker->m_id = id;
+ m_job->addJavaCheckerAction(JavaCheckerPtr(candidate_checker));
- id++;
- }
+ id++;
+ }
- m_job->start();
+ m_job->start();
}
void JavaListLoadTask::javaCheckerFinished()
{
- QList<JavaInstallPtr> candidates;
- auto results = m_job->getResults();
-
- qDebug() << "Found the following valid Java installations:";
- for(JavaCheckResult result : results)
- {
- if(result.validity == JavaCheckResult::Validity::Valid)
- {
- JavaInstallPtr javaVersion(new JavaInstall());
-
- javaVersion->id = result.javaVersion;
- javaVersion->arch = result.mojangPlatform;
- javaVersion->path = result.path;
- candidates.append(javaVersion);
-
- qDebug() << " " << javaVersion->id.toString() << javaVersion->arch << javaVersion->path;
- }
- }
-
- QList<BaseVersionPtr> javas_bvp;
- for (auto java : candidates)
- {
- //qDebug() << java->id << java->arch << " at " << java->path;
- BaseVersionPtr bp_java = std::dynamic_pointer_cast<BaseVersion>(java);
-
- if (bp_java)
- {
- javas_bvp.append(java);
- }
- }
-
- m_list->updateListData(javas_bvp);
- emitSucceeded();
+ QList<JavaInstallPtr> candidates;
+ auto results = m_job->getResults();
+
+ qDebug() << "Found the following valid Java installations:";
+ for(JavaCheckResult result : results)
+ {
+ if(result.validity == JavaCheckResult::Validity::Valid)
+ {
+ JavaInstallPtr javaVersion(new JavaInstall());
+
+ javaVersion->id = result.javaVersion;
+ javaVersion->arch = result.mojangPlatform;
+ javaVersion->path = result.path;
+ candidates.append(javaVersion);
+
+ qDebug() << " " << javaVersion->id.toString() << javaVersion->arch << javaVersion->path;
+ }
+ }
+
+ QList<BaseVersionPtr> javas_bvp;
+ for (auto java : candidates)
+ {
+ //qDebug() << java->id << java->arch << " at " << java->path;
+ BaseVersionPtr bp_java = std::dynamic_pointer_cast<BaseVersion>(java);
+
+ if (bp_java)
+ {
+ javas_bvp.append(java);
+ }
+ }
+
+ m_list->updateListData(javas_bvp);
+ emitSucceeded();
}
diff --git a/api/logic/java/JavaInstallList.h b/api/logic/java/JavaInstallList.h
index 9ec12f87..7e72b5ef 100644
--- a/api/logic/java/JavaInstallList.h
+++ b/api/logic/java/JavaInstallList.h
@@ -30,52 +30,52 @@ class JavaListLoadTask;
class MULTIMC_LOGIC_EXPORT JavaInstallList : public BaseVersionList
{
- Q_OBJECT
- enum class Status
- {
- NotDone,
- InProgress,
- Done
- };
+ Q_OBJECT
+ enum class Status
+ {
+ NotDone,
+ InProgress,
+ Done
+ };
public:
- explicit JavaInstallList(QObject *parent = 0);
+ explicit JavaInstallList(QObject *parent = 0);
- shared_qobject_ptr<Task> getLoadTask() override;
- bool isLoaded() override;
- const BaseVersionPtr at(int i) const override;
- int count() const override;
- void sortVersions() override;
+ shared_qobject_ptr<Task> getLoadTask() override;
+ bool isLoaded() override;
+ const BaseVersionPtr at(int i) const override;
+ int count() const override;
+ void sortVersions() override;
- QVariant data(const QModelIndex &index, int role) const override;
- RoleList providesRoles() const override;
+ QVariant data(const QModelIndex &index, int role) const override;
+ RoleList providesRoles() const override;
public slots:
- void updateListData(QList<BaseVersionPtr> versions) override;
+ void updateListData(QList<BaseVersionPtr> versions) override;
protected:
- void load();
- shared_qobject_ptr<Task> getCurrentTask();
+ void load();
+ shared_qobject_ptr<Task> getCurrentTask();
protected:
- Status m_status = Status::NotDone;
- shared_qobject_ptr<JavaListLoadTask> m_loadTask;
- QList<BaseVersionPtr> m_vlist;
+ Status m_status = Status::NotDone;
+ shared_qobject_ptr<JavaListLoadTask> m_loadTask;
+ QList<BaseVersionPtr> m_vlist;
};
class JavaListLoadTask : public Task
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit JavaListLoadTask(JavaInstallList *vlist);
- virtual ~JavaListLoadTask();
+ explicit JavaListLoadTask(JavaInstallList *vlist);
+ virtual ~JavaListLoadTask();
- void executeTask() override;
+ void executeTask() override;
public slots:
- void javaCheckerFinished();
+ void javaCheckerFinished();
protected:
- std::shared_ptr<JavaCheckerJob> m_job;
- JavaInstallList *m_list;
- JavaInstall *m_currentRecommended;
+ std::shared_ptr<JavaCheckerJob> m_job;
+ JavaInstallList *m_list;
+ JavaInstall *m_currentRecommended;
};
diff --git a/api/logic/java/JavaUtils.cpp b/api/logic/java/JavaUtils.cpp
index 798c80e8..9f7fdcb0 100644
--- a/api/logic/java/JavaUtils.cpp
+++ b/api/logic/java/JavaUtils.cpp
@@ -34,312 +34,312 @@ JavaUtils::JavaUtils()
#ifdef Q_OS_LINUX
static QString processLD_LIBRARY_PATH(const QString & LD_LIBRARY_PATH)
{
- QDir mmcBin(QCoreApplication::applicationDirPath());
- auto items = LD_LIBRARY_PATH.split(':');
- QStringList final;
- for(auto & item: items)
- {
- QDir test(item);
- if(test == mmcBin)
- {
- qDebug() << "Env:LD_LIBRARY_PATH ignoring path" << item;
- continue;
- }
- final.append(item);
- }
- return final.join(':');
+ QDir mmcBin(QCoreApplication::applicationDirPath());
+ auto items = LD_LIBRARY_PATH.split(':');
+ QStringList final;
+ for(auto & item: items)
+ {
+ QDir test(item);
+ if(test == mmcBin)
+ {
+ qDebug() << "Env:LD_LIBRARY_PATH ignoring path" << item;
+ continue;
+ }
+ final.append(item);
+ }
+ return final.join(':');
}
#endif
QProcessEnvironment CleanEnviroment()
{
- // prepare the process environment
- QProcessEnvironment rawenv = QProcessEnvironment::systemEnvironment();
- QProcessEnvironment env;
-
- QStringList ignored =
- {
- "JAVA_ARGS",
- "CLASSPATH",
- "CONFIGPATH",
- "JAVA_HOME",
- "JRE_HOME",
- "_JAVA_OPTIONS",
- "JAVA_OPTIONS",
- "JAVA_TOOL_OPTIONS"
- };
- for(auto key: rawenv.keys())
- {
- auto value = rawenv.value(key);
- // filter out dangerous java crap
- if(ignored.contains(key))
- {
- qDebug() << "Env: ignoring" << key << value;
- continue;
- }
- // filter MultiMC-related things
- if(key.startsWith("QT_"))
- {
- qDebug() << "Env: ignoring" << key << value;
- continue;
- }
+ // prepare the process environment
+ QProcessEnvironment rawenv = QProcessEnvironment::systemEnvironment();
+ QProcessEnvironment env;
+
+ QStringList ignored =
+ {
+ "JAVA_ARGS",
+ "CLASSPATH",
+ "CONFIGPATH",
+ "JAVA_HOME",
+ "JRE_HOME",
+ "_JAVA_OPTIONS",
+ "JAVA_OPTIONS",
+ "JAVA_TOOL_OPTIONS"
+ };
+ for(auto key: rawenv.keys())
+ {
+ auto value = rawenv.value(key);
+ // filter out dangerous java crap
+ if(ignored.contains(key))
+ {
+ qDebug() << "Env: ignoring" << key << value;
+ continue;
+ }
+ // filter MultiMC-related things
+ if(key.startsWith("QT_"))
+ {
+ qDebug() << "Env: ignoring" << key << value;
+ continue;
+ }
#ifdef Q_OS_LINUX
- // Do not pass LD_* variables to java. They were intended for MultiMC
- if(key.startsWith("LD_"))
- {
- qDebug() << "Env: ignoring" << key << value;
- continue;
- }
- // Strip IBus
- // IBus is a Linux IME framework. For some reason, it breaks MC?
- if (key == "XMODIFIERS" && value.contains(IBUS))
- {
- QString save = value;
- value.replace(IBUS, "");
- qDebug() << "Env: stripped" << IBUS << "from" << save << ":" << value;
- }
- if(key == "GAME_PRELOAD")
- {
- env.insert("LD_PRELOAD", value);
- continue;
- }
- if(key == "GAME_LIBRARY_PATH")
- {
- env.insert("LD_LIBRARY_PATH", processLD_LIBRARY_PATH(value));
- continue;
- }
+ // Do not pass LD_* variables to java. They were intended for MultiMC
+ if(key.startsWith("LD_"))
+ {
+ qDebug() << "Env: ignoring" << key << value;
+ continue;
+ }
+ // Strip IBus
+ // IBus is a Linux IME framework. For some reason, it breaks MC?
+ if (key == "XMODIFIERS" && value.contains(IBUS))
+ {
+ QString save = value;
+ value.replace(IBUS, "");
+ qDebug() << "Env: stripped" << IBUS << "from" << save << ":" << value;
+ }
+ if(key == "GAME_PRELOAD")
+ {
+ env.insert("LD_PRELOAD", value);
+ continue;
+ }
+ if(key == "GAME_LIBRARY_PATH")
+ {
+ env.insert("LD_LIBRARY_PATH", processLD_LIBRARY_PATH(value));
+ continue;
+ }
#endif
- // qDebug() << "Env: " << key << value;
- env.insert(key, value);
- }
+ // qDebug() << "Env: " << key << value;
+ env.insert(key, value);
+ }
#ifdef Q_OS_LINUX
- // HACK: Workaround for QTBUG42500
- if(!env.contains("LD_LIBRARY_PATH"))
- {
- env.insert("LD_LIBRARY_PATH", "");
- }
+ // HACK: Workaround for QTBUG42500
+ if(!env.contains("LD_LIBRARY_PATH"))
+ {
+ env.insert("LD_LIBRARY_PATH", "");
+ }
#endif
- return env;
+ return env;
}
JavaInstallPtr JavaUtils::MakeJavaPtr(QString path, QString id, QString arch)
{
- JavaInstallPtr javaVersion(new JavaInstall());
+ JavaInstallPtr javaVersion(new JavaInstall());
- javaVersion->id = id;
- javaVersion->arch = arch;
- javaVersion->path = path;
+ javaVersion->id = id;
+ javaVersion->arch = arch;
+ javaVersion->path = path;
- return javaVersion;
+ return javaVersion;
}
JavaInstallPtr JavaUtils::GetDefaultJava()
{
- JavaInstallPtr javaVersion(new JavaInstall());
+ JavaInstallPtr javaVersion(new JavaInstall());
- javaVersion->id = "java";
- javaVersion->arch = "unknown";
+ javaVersion->id = "java";
+ javaVersion->arch = "unknown";
#if defined(Q_OS_WIN32)
- javaVersion->path = "javaw";
+ javaVersion->path = "javaw";
#else
- javaVersion->path = "java";
+ javaVersion->path = "java";
#endif
- return javaVersion;
+ return javaVersion;
}
#if defined(Q_OS_WIN32)
QList<JavaInstallPtr> JavaUtils::FindJavaFromRegistryKey(DWORD keyType, QString keyName)
{
- QList<JavaInstallPtr> javas;
-
- QString archType = "unknown";
- if (keyType == KEY_WOW64_64KEY)
- archType = "64";
- else if (keyType == KEY_WOW64_32KEY)
- archType = "32";
-
- HKEY jreKey;
- if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, keyName.toStdString().c_str(), 0,
- KEY_READ | keyType | KEY_ENUMERATE_SUB_KEYS, &jreKey) == ERROR_SUCCESS)
- {
- // Read the current type version from the registry.
- // This will be used to find any key that contains the JavaHome value.
- char *value = new char[0];
- DWORD valueSz = 0;
- if (RegQueryValueExA(jreKey, "CurrentVersion", NULL, NULL, (BYTE *)value, &valueSz) ==
- ERROR_MORE_DATA)
- {
- value = new char[valueSz];
- RegQueryValueExA(jreKey, "CurrentVersion", NULL, NULL, (BYTE *)value, &valueSz);
- }
-
- QString recommended = value;
-
- TCHAR subKeyName[255];
- DWORD subKeyNameSize, numSubKeys, retCode;
-
- // Get the number of subkeys
- RegQueryInfoKey(jreKey, NULL, NULL, NULL, &numSubKeys, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL);
-
- // Iterate until RegEnumKeyEx fails
- if (numSubKeys > 0)
- {
- for (DWORD i = 0; i < numSubKeys; i++)
- {
- subKeyNameSize = 255;
- retCode = RegEnumKeyEx(jreKey, i, subKeyName, &subKeyNameSize, NULL, NULL, NULL,
- NULL);
- if (retCode == ERROR_SUCCESS)
- {
- // Now open the registry key for the version that we just got.
- QString newKeyName = keyName + "\\" + subKeyName;
-
- HKEY newKey;
- if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, newKeyName.toStdString().c_str(), 0,
- KEY_READ | KEY_WOW64_64KEY, &newKey) == ERROR_SUCCESS)
- {
- // Read the JavaHome value to find where Java is installed.
- value = new char[0];
- valueSz = 0;
- if (RegQueryValueEx(newKey, "JavaHome", NULL, NULL, (BYTE *)value,
- &valueSz) == ERROR_MORE_DATA)
- {
- value = new char[valueSz];
- RegQueryValueEx(newKey, "JavaHome", NULL, NULL, (BYTE *)value,
- &valueSz);
-
- // Now, we construct the version object and add it to the list.
- JavaInstallPtr javaVersion(new JavaInstall());
-
- javaVersion->id = subKeyName;
- javaVersion->arch = archType;
- javaVersion->path =
- QDir(FS::PathCombine(value, "bin")).absoluteFilePath("javaw.exe");
- javas.append(javaVersion);
- }
-
- RegCloseKey(newKey);
- }
- }
- }
- }
-
- RegCloseKey(jreKey);
- }
-
- return javas;
+ QList<JavaInstallPtr> javas;
+
+ QString archType = "unknown";
+ if (keyType == KEY_WOW64_64KEY)
+ archType = "64";
+ else if (keyType == KEY_WOW64_32KEY)
+ archType = "32";
+
+ HKEY jreKey;
+ if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, keyName.toStdString().c_str(), 0,
+ KEY_READ | keyType | KEY_ENUMERATE_SUB_KEYS, &jreKey) == ERROR_SUCCESS)
+ {
+ // Read the current type version from the registry.
+ // This will be used to find any key that contains the JavaHome value.
+ char *value = new char[0];
+ DWORD valueSz = 0;
+ if (RegQueryValueExA(jreKey, "CurrentVersion", NULL, NULL, (BYTE *)value, &valueSz) ==
+ ERROR_MORE_DATA)
+ {
+ value = new char[valueSz];
+ RegQueryValueExA(jreKey, "CurrentVersion", NULL, NULL, (BYTE *)value, &valueSz);
+ }
+
+ QString recommended = value;
+
+ TCHAR subKeyName[255];
+ DWORD subKeyNameSize, numSubKeys, retCode;
+
+ // Get the number of subkeys
+ RegQueryInfoKey(jreKey, NULL, NULL, NULL, &numSubKeys, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL);
+
+ // Iterate until RegEnumKeyEx fails
+ if (numSubKeys > 0)
+ {
+ for (DWORD i = 0; i < numSubKeys; i++)
+ {
+ subKeyNameSize = 255;
+ retCode = RegEnumKeyEx(jreKey, i, subKeyName, &subKeyNameSize, NULL, NULL, NULL,
+ NULL);
+ if (retCode == ERROR_SUCCESS)
+ {
+ // Now open the registry key for the version that we just got.
+ QString newKeyName = keyName + "\\" + subKeyName;
+
+ HKEY newKey;
+ if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, newKeyName.toStdString().c_str(), 0,
+ KEY_READ | KEY_WOW64_64KEY, &newKey) == ERROR_SUCCESS)
+ {
+ // Read the JavaHome value to find where Java is installed.
+ value = new char[0];
+ valueSz = 0;
+ if (RegQueryValueEx(newKey, "JavaHome", NULL, NULL, (BYTE *)value,
+ &valueSz) == ERROR_MORE_DATA)
+ {
+ value = new char[valueSz];
+ RegQueryValueEx(newKey, "JavaHome", NULL, NULL, (BYTE *)value,
+ &valueSz);
+
+ // Now, we construct the version object and add it to the list.
+ JavaInstallPtr javaVersion(new JavaInstall());
+
+ javaVersion->id = subKeyName;
+ javaVersion->arch = archType;
+ javaVersion->path =
+ QDir(FS::PathCombine(value, "bin")).absoluteFilePath("javaw.exe");
+ javas.append(javaVersion);
+ }
+
+ RegCloseKey(newKey);
+ }
+ }
+ }
+ }
+
+ RegCloseKey(jreKey);
+ }
+
+ return javas;
}
QList<QString> JavaUtils::FindJavaPaths()
{
- QList<JavaInstallPtr> java_candidates;
-
- QList<JavaInstallPtr> JRE64s = this->FindJavaFromRegistryKey(
- KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment");
- QList<JavaInstallPtr> JDK64s = this->FindJavaFromRegistryKey(
- KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Development Kit");
- QList<JavaInstallPtr> JRE32s = this->FindJavaFromRegistryKey(
- KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment");
- QList<JavaInstallPtr> JDK32s = this->FindJavaFromRegistryKey(
- KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Development Kit");
-
- java_candidates.append(JRE64s);
- java_candidates.append(MakeJavaPtr("C:/Program Files/Java/jre8/bin/javaw.exe"));
- java_candidates.append(MakeJavaPtr("C:/Program Files/Java/jre7/bin/javaw.exe"));
- java_candidates.append(MakeJavaPtr("C:/Program Files/Java/jre6/bin/javaw.exe"));
- java_candidates.append(JDK64s);
- java_candidates.append(JRE32s);
- java_candidates.append(MakeJavaPtr("C:/Program Files (x86)/Java/jre8/bin/javaw.exe"));
- java_candidates.append(MakeJavaPtr("C:/Program Files (x86)/Java/jre7/bin/javaw.exe"));
- java_candidates.append(MakeJavaPtr("C:/Program Files (x86)/Java/jre6/bin/javaw.exe"));
- java_candidates.append(JDK32s);
- java_candidates.append(MakeJavaPtr(this->GetDefaultJava()->path));
-
- QList<QString> candidates;
- for(JavaInstallPtr java_candidate : java_candidates)
- {
- if(!candidates.contains(java_candidate->path))
- {
- candidates.append(java_candidate->path);
- }
- }
-
- return candidates;
+ QList<JavaInstallPtr> java_candidates;
+
+ QList<JavaInstallPtr> JRE64s = this->FindJavaFromRegistryKey(
+ KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment");
+ QList<JavaInstallPtr> JDK64s = this->FindJavaFromRegistryKey(
+ KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Development Kit");
+ QList<JavaInstallPtr> JRE32s = this->FindJavaFromRegistryKey(
+ KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment");
+ QList<JavaInstallPtr> JDK32s = this->FindJavaFromRegistryKey(
+ KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Development Kit");
+
+ java_candidates.append(JRE64s);
+ java_candidates.append(MakeJavaPtr("C:/Program Files/Java/jre8/bin/javaw.exe"));
+ java_candidates.append(MakeJavaPtr("C:/Program Files/Java/jre7/bin/javaw.exe"));
+ java_candidates.append(MakeJavaPtr("C:/Program Files/Java/jre6/bin/javaw.exe"));
+ java_candidates.append(JDK64s);
+ java_candidates.append(JRE32s);
+ java_candidates.append(MakeJavaPtr("C:/Program Files (x86)/Java/jre8/bin/javaw.exe"));
+ java_candidates.append(MakeJavaPtr("C:/Program Files (x86)/Java/jre7/bin/javaw.exe"));
+ java_candidates.append(MakeJavaPtr("C:/Program Files (x86)/Java/jre6/bin/javaw.exe"));
+ java_candidates.append(JDK32s);
+ java_candidates.append(MakeJavaPtr(this->GetDefaultJava()->path));
+
+ QList<QString> candidates;
+ for(JavaInstallPtr java_candidate : java_candidates)
+ {
+ if(!candidates.contains(java_candidate->path))
+ {
+ candidates.append(java_candidate->path);
+ }
+ }
+
+ return candidates;
}
#elif defined(Q_OS_MAC)
QList<QString> JavaUtils::FindJavaPaths()
{
- QList<QString> javas;
- javas.append(this->GetDefaultJava()->path);
- javas.append("/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/MacOS/itms/java/bin/java");
- javas.append("/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java");
- javas.append("/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java");
- QDir libraryJVMDir("/Library/Java/JavaVirtualMachines/");
- QStringList libraryJVMJavas = libraryJVMDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
- foreach (const QString &java, libraryJVMJavas) {
- javas.append(libraryJVMDir.absolutePath() + "/" + java + "/Contents/Home/bin/java");
- javas.append(libraryJVMDir.absolutePath() + "/" + java + "/Contents/Home/jre/bin/java");
- }
- QDir systemLibraryJVMDir("/System/Library/Java/JavaVirtualMachines/");
- QStringList systemLibraryJVMJavas = systemLibraryJVMDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
- foreach (const QString &java, systemLibraryJVMJavas) {
- javas.append(systemLibraryJVMDir.absolutePath() + "/" + java + "/Contents/Home/bin/java");
- javas.append(systemLibraryJVMDir.absolutePath() + "/" + java + "/Contents/Commands/java");
- }
- return javas;
+ QList<QString> javas;
+ javas.append(this->GetDefaultJava()->path);
+ javas.append("/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/MacOS/itms/java/bin/java");
+ javas.append("/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java");
+ javas.append("/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java");
+ QDir libraryJVMDir("/Library/Java/JavaVirtualMachines/");
+ QStringList libraryJVMJavas = libraryJVMDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
+ foreach (const QString &java, libraryJVMJavas) {
+ javas.append(libraryJVMDir.absolutePath() + "/" + java + "/Contents/Home/bin/java");
+ javas.append(libraryJVMDir.absolutePath() + "/" + java + "/Contents/Home/jre/bin/java");
+ }
+ QDir systemLibraryJVMDir("/System/Library/Java/JavaVirtualMachines/");
+ QStringList systemLibraryJVMJavas = systemLibraryJVMDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
+ foreach (const QString &java, systemLibraryJVMJavas) {
+ javas.append(systemLibraryJVMDir.absolutePath() + "/" + java + "/Contents/Home/bin/java");
+ javas.append(systemLibraryJVMDir.absolutePath() + "/" + java + "/Contents/Commands/java");
+ }
+ return javas;
}
#elif defined(Q_OS_LINUX)
QList<QString> JavaUtils::FindJavaPaths()
{
- qDebug() << "Linux Java detection incomplete - defaulting to \"java\"";
-
- QList<QString> javas;
- javas.append(this->GetDefaultJava()->path);
- auto scanJavaDir = [&](const QString & dirPath)
- {
- QDir dir(dirPath);
- if(!dir.exists())
- return;
- auto entries = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
- for(auto & entry: entries)
- {
-
- QString prefix;
- if(entry.isAbsolute())
- {
- prefix = entry.absoluteFilePath();
- }
- else
- {
- prefix = entry.filePath();
- }
-
- javas.append(FS::PathCombine(prefix, "jre/bin/java"));
- javas.append(FS::PathCombine(prefix, "bin/java"));
- }
- };
- // oracle RPMs
- scanJavaDir("/usr/java");
- // general locations used by distro packaging
- scanJavaDir("/usr/lib/jvm");
- scanJavaDir("/usr/lib32/jvm");
- // javas stored in MultiMC's folder
- scanJavaDir("java");
- return javas;
+ qDebug() << "Linux Java detection incomplete - defaulting to \"java\"";
+
+ QList<QString> javas;
+ javas.append(this->GetDefaultJava()->path);
+ auto scanJavaDir = [&](const QString & dirPath)
+ {
+ QDir dir(dirPath);
+ if(!dir.exists())
+ return;
+ auto entries = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
+ for(auto & entry: entries)
+ {
+
+ QString prefix;
+ if(entry.isAbsolute())
+ {
+ prefix = entry.absoluteFilePath();
+ }
+ else
+ {
+ prefix = entry.filePath();
+ }
+
+ javas.append(FS::PathCombine(prefix, "jre/bin/java"));
+ javas.append(FS::PathCombine(prefix, "bin/java"));
+ }
+ };
+ // oracle RPMs
+ scanJavaDir("/usr/java");
+ // general locations used by distro packaging
+ scanJavaDir("/usr/lib/jvm");
+ scanJavaDir("/usr/lib32/jvm");
+ // javas stored in MultiMC's folder
+ scanJavaDir("java");
+ return javas;
}
#else
QList<QString> JavaUtils::FindJavaPaths()
{
- qDebug() << "Unknown operating system build - defaulting to \"java\"";
+ qDebug() << "Unknown operating system build - defaulting to \"java\"";
- QList<QString> javas;
- javas.append(this->GetDefaultJava()->path);
+ QList<QString> javas;
+ javas.append(this->GetDefaultJava()->path);
- return javas;
+ return javas;
}
#endif
diff --git a/api/logic/java/JavaUtils.h b/api/logic/java/JavaUtils.h
index b43e93cf..40745ad6 100644
--- a/api/logic/java/JavaUtils.h
+++ b/api/logic/java/JavaUtils.h
@@ -30,15 +30,15 @@ QProcessEnvironment CleanEnviroment();
class MULTIMC_LOGIC_EXPORT JavaUtils : public QObject
{
- Q_OBJECT
+ Q_OBJECT
public:
- JavaUtils();
+ JavaUtils();
- JavaInstallPtr MakeJavaPtr(QString path, QString id = "unknown", QString arch = "unknown");
- QList<QString> FindJavaPaths();
- JavaInstallPtr GetDefaultJava();
+ JavaInstallPtr MakeJavaPtr(QString path, QString id = "unknown", QString arch = "unknown");
+ QList<QString> FindJavaPaths();
+ JavaInstallPtr GetDefaultJava();
#ifdef Q_OS_WIN
- QList<JavaInstallPtr> FindJavaFromRegistryKey(DWORD keyType, QString keyName);
+ QList<JavaInstallPtr> FindJavaFromRegistryKey(DWORD keyType, QString keyName);
#endif
};
diff --git a/api/logic/java/JavaVersion.cpp b/api/logic/java/JavaVersion.cpp
index 27050da3..179ccd8d 100644
--- a/api/logic/java/JavaVersion.cpp
+++ b/api/logic/java/JavaVersion.cpp
@@ -6,116 +6,116 @@
JavaVersion & JavaVersion::operator=(const QString & javaVersionString)
{
- m_string = javaVersionString;
+ m_string = javaVersionString;
- auto getCapturedInteger = [](const QRegularExpressionMatch & match, const QString &what) -> int
- {
- auto str = match.captured(what);
- if(str.isEmpty())
- {
- return 0;
- }
- return str.toInt();
- };
+ 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]+))?");
- }
+ 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]+))?");
+ }
- 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");
- return *this;
+ 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");
+ return *this;
}
JavaVersion::JavaVersion(const QString &rhs)
{
- operator=(rhs);
+ operator=(rhs);
}
QString JavaVersion::toString()
{
- return m_string;
+ return m_string;
}
bool JavaVersion::requiresPermGen()
{
- if(m_parseable)
- {
- return m_major < 8;
- }
- return true;
+ if(m_parseable)
+ {
+ return m_major < 8;
+ }
+ return true;
}
bool JavaVersion::operator<(const JavaVersion &rhs)
{
- if(m_parseable && rhs.m_parseable)
- {
- auto major = m_major;
- auto rmajor = rhs.m_major;
+ if(m_parseable && rhs.m_parseable)
+ {
+ auto major = m_major;
+ auto rmajor = rhs.m_major;
- // HACK: discourage using java 9
- if(major > 8)
- major = -major;
- if(rmajor > 8)
- rmajor = -rmajor;
+ // HACK: discourage using java 9
+ if(major > 8)
+ major = -major;
+ if(rmajor > 8)
+ rmajor = -rmajor;
- if(major < rmajor)
- return true;
- if(major > rmajor)
- return false;
- if(m_minor < rhs.m_minor)
- return true;
- if(m_minor > rhs.m_minor)
- return false;
- if(m_security < rhs.m_security)
- return true;
- if(m_security > rhs.m_security)
- return false;
+ if(major < rmajor)
+ return true;
+ if(major > rmajor)
+ return false;
+ if(m_minor < rhs.m_minor)
+ return true;
+ if(m_minor > rhs.m_minor)
+ return false;
+ if(m_security < rhs.m_security)
+ return true;
+ if(m_security > rhs.m_security)
+ return false;
- // everything else being equal, consider prerelease status
- bool thisPre = !m_prerelease.isEmpty();
- bool rhsPre = !rhs.m_prerelease.isEmpty();
- 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...
- return Strings::naturalCompare(m_prerelease, rhs.m_prerelease, Qt::CaseSensitive) < 0;
- }
- // neither is prerelease, so they are the same -> this cannot be less than rhs
- return false;
- }
- else return Strings::naturalCompare(m_string, rhs.m_string, Qt::CaseSensitive) < 0;
+ // everything else being equal, consider prerelease status
+ bool thisPre = !m_prerelease.isEmpty();
+ bool rhsPre = !rhs.m_prerelease.isEmpty();
+ 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...
+ return Strings::naturalCompare(m_prerelease, rhs.m_prerelease, Qt::CaseSensitive) < 0;
+ }
+ // neither is prerelease, so they are the same -> this cannot be less than rhs
+ return false;
+ }
+ else return Strings::naturalCompare(m_string, rhs.m_string, Qt::CaseSensitive) < 0;
}
bool JavaVersion::operator==(const JavaVersion &rhs)
{
- if(m_parseable && rhs.m_parseable)
- {
- return m_major == rhs.m_major && m_minor == rhs.m_minor && m_security == rhs.m_security && m_prerelease == rhs.m_prerelease;
- }
- return m_string == rhs.m_string;
+ if(m_parseable && rhs.m_parseable)
+ {
+ return m_major == rhs.m_major && m_minor == rhs.m_minor && m_security == rhs.m_security && m_prerelease == rhs.m_prerelease;
+ }
+ return m_string == rhs.m_string;
}
bool JavaVersion::operator>(const JavaVersion &rhs)
{
- return (!operator<(rhs)) && (!operator==(rhs));
+ return (!operator<(rhs)) && (!operator==(rhs));
}
diff --git a/api/logic/java/JavaVersion.h b/api/logic/java/JavaVersion.h
index de13998c..8589c21a 100644
--- a/api/logic/java/JavaVersion.h
+++ b/api/logic/java/JavaVersion.h
@@ -5,46 +5,46 @@
// NOTE: apparently the GNU C library pollutes the global namespace with these... undef them.
#ifdef major
- #undef major
+ #undef major
#endif
#ifdef minor
- #undef minor
+ #undef minor
#endif
class MULTIMC_LOGIC_EXPORT JavaVersion
{
- friend class JavaVersionTest;
+ friend class JavaVersionTest;
public:
- JavaVersion() {};
- JavaVersion(const QString & rhs);
-
- JavaVersion & operator=(const QString & rhs);
-
- bool operator<(const JavaVersion & rhs);
- bool operator==(const JavaVersion & rhs);
- bool operator>(const JavaVersion & rhs);
-
- bool requiresPermGen();
-
- QString toString();
-
- int major()
- {
- return m_major;
- }
- int minor()
- {
- return m_minor;
- }
- int security()
- {
- return m_security;
- }
+ JavaVersion() {};
+ JavaVersion(const QString & rhs);
+
+ JavaVersion & operator=(const QString & rhs);
+
+ bool operator<(const JavaVersion & rhs);
+ bool operator==(const JavaVersion & rhs);
+ bool operator>(const JavaVersion & rhs);
+
+ bool requiresPermGen();
+
+ QString toString();
+
+ int major()
+ {
+ return m_major;
+ }
+ int minor()
+ {
+ return m_minor;
+ }
+ int security()
+ {
+ return m_security;
+ }
private:
- QString m_string;
- int m_major = 0;
- int m_minor = 0;
- int m_security = 0;
- bool m_parseable = false;
- QString m_prerelease;
+ QString m_string;
+ int m_major = 0;
+ int m_minor = 0;
+ int m_security = 0;
+ bool m_parseable = false;
+ QString m_prerelease;
};
diff --git a/api/logic/java/JavaVersion_test.cpp b/api/logic/java/JavaVersion_test.cpp
index e719ffc8..10ae13a7 100644
--- a/api/logic/java/JavaVersion_test.cpp
+++ b/api/logic/java/JavaVersion_test.cpp
@@ -5,110 +5,110 @@
class JavaVersionTest : public QObject
{
- Q_OBJECT
+ Q_OBJECT
private
slots:
- void test_Parse_data()
- {
- QTest::addColumn<QString>("string");
- QTest::addColumn<int>("major");
- QTest::addColumn<int>("minor");
- QTest::addColumn<int>("security");
- QTest::addColumn<QString>("prerelease");
+ void test_Parse_data()
+ {
+ QTest::addColumn<QString>("string");
+ QTest::addColumn<int>("major");
+ QTest::addColumn<int>("minor");
+ QTest::addColumn<int>("security");
+ QTest::addColumn<QString>("prerelease");
- QTest::newRow("old format") << "1.6.0_33" << 6 << 0 << 33 << QString();
- QTest::newRow("old format prerelease") << "1.9.0_1-ea" << 9 << 0 << 1 << "ea";
+ QTest::newRow("old format") << "1.6.0_33" << 6 << 0 << 33 << QString();
+ QTest::newRow("old format prerelease") << "1.9.0_1-ea" << 9 << 0 << 1 << "ea";
- QTest::newRow("new format major") << "9" << 9 << 0 << 0 << QString();
- QTest::newRow("new format minor") << "9.1" << 9 << 1 << 0 << QString();
- QTest::newRow("new format security") << "9.0.1" << 9 << 0 << 1 << QString();
- QTest::newRow("new format prerelease") << "9-ea" << 9 << 0 << 0 << "ea";
- QTest::newRow("new format long prerelease") << "9.0.1-ea" << 9 << 0 << 1 << "ea";
- }
- void test_Parse()
- {
- QFETCH(QString, string);
- QFETCH(int, major);
- QFETCH(int, minor);
- QFETCH(int, security);
- QFETCH(QString, prerelease);
+ QTest::newRow("new format major") << "9" << 9 << 0 << 0 << QString();
+ QTest::newRow("new format minor") << "9.1" << 9 << 1 << 0 << QString();
+ QTest::newRow("new format security") << "9.0.1" << 9 << 0 << 1 << QString();
+ QTest::newRow("new format prerelease") << "9-ea" << 9 << 0 << 0 << "ea";
+ QTest::newRow("new format long prerelease") << "9.0.1-ea" << 9 << 0 << 1 << "ea";
+ }
+ void test_Parse()
+ {
+ QFETCH(QString, string);
+ QFETCH(int, major);
+ QFETCH(int, minor);
+ QFETCH(int, security);
+ QFETCH(QString, prerelease);
- JavaVersion test(string);
- QCOMPARE(test.m_string, string);
- QCOMPARE(test.toString(), string);
- QCOMPARE(test.m_major, major);
- QCOMPARE(test.m_minor, minor);
- QCOMPARE(test.m_security, security);
- QCOMPARE(test.m_prerelease, prerelease);
- }
+ JavaVersion test(string);
+ QCOMPARE(test.m_string, string);
+ QCOMPARE(test.toString(), string);
+ QCOMPARE(test.m_major, major);
+ QCOMPARE(test.m_minor, minor);
+ QCOMPARE(test.m_security, security);
+ QCOMPARE(test.m_prerelease, prerelease);
+ }
- void test_Sort_data()
- {
- QTest::addColumn<QString>("lhs");
- QTest::addColumn<QString>("rhs");
- QTest::addColumn<bool>("smaller");
- QTest::addColumn<bool>("equal");
- QTest::addColumn<bool>("bigger");
+ void test_Sort_data()
+ {
+ QTest::addColumn<QString>("lhs");
+ QTest::addColumn<QString>("rhs");
+ QTest::addColumn<bool>("smaller");
+ QTest::addColumn<bool>("equal");
+ QTest::addColumn<bool>("bigger");
- // old format and new format equivalence
- QTest::newRow("1.6.0_33 == 6.0.33") << "1.6.0_33" << "6.0.33" << false << true << false;
- // old format major version
- QTest::newRow("1.5.0_33 < 1.6.0_33") << "1.5.0_33" << "1.6.0_33" << true << false << false;
- // new format - first release vs first security patch
- QTest::newRow("9 < 9.0.1") << "9" << "9.0.1" << true << false << false;
- QTest::newRow("9.0.1 > 9") << "9.0.1" << "9" << false << false << true;
- // new format - first minor vs first release/security patch
- QTest::newRow("9.1 > 9.0.1") << "9.1" << "9.0.1" << false << false << true;
- QTest::newRow("9.0.1 < 9.1") << "9.0.1" << "9.1" << true << false << false;
- QTest::newRow("9.1 > 9") << "9.1" << "9" << false << false << true;
- QTest::newRow("9 > 9.1") << "9" << "9.1" << true << false << false;
- // new format - omitted numbers
- QTest::newRow("9 == 9.0") << "9" << "9.0" << false << true << false;
- QTest::newRow("9 == 9.0.0") << "9" << "9.0.0" << false << true << false;
- QTest::newRow("9.0 == 9.0.0") << "9.0" << "9.0.0" << false << true << false;
- // early access and prereleases compared to final release
- QTest::newRow("9-ea < 9") << "9-ea" << "9" << true << false << false;
- QTest::newRow("9 < 9.0.1-ea") << "9" << "9.0.1-ea" << true << false << false;
- QTest::newRow("9.0.1-ea > 9") << "9.0.1-ea" << "9" << false << false << true;
- // prerelease difference only testing
- QTest::newRow("9-1 == 9-1") << "9-1" << "9-1" << false << true << false;
- QTest::newRow("9-1 < 9-2") << "9-1" << "9-2" << true << false << false;
- QTest::newRow("9-5 < 9-20") << "9-5" << "9-20" << true << false << false;
- QTest::newRow("9-rc1 < 9-rc2") << "9-rc1" << "9-rc2" << true << false << false;
- QTest::newRow("9-rc5 < 9-rc20") << "9-rc5" << "9-rc20" << true << false << false;
- QTest::newRow("9-rc < 9-rc2") << "9-rc" << "9-rc2" << true << false << false;
- QTest::newRow("9-ea < 9-rc") << "9-ea" << "9-rc" << true << false << false;
- }
- void test_Sort()
- {
- QFETCH(QString, lhs);
- QFETCH(QString, rhs);
- QFETCH(bool, smaller);
- QFETCH(bool, equal);
- QFETCH(bool, bigger);
- JavaVersion lver(lhs);
- JavaVersion rver(rhs);
- QCOMPARE(lver < rver, smaller);
- QCOMPARE(lver == rver, equal);
- QCOMPARE(lver > rver, bigger);
- }
- void test_PermGen_data()
- {
- QTest::addColumn<QString>("version");
- QTest::addColumn<bool>("needs_permgen");
- QTest::newRow("1.6.0_33") << "1.6.0_33" << true;
- QTest::newRow("1.7.0_60") << "1.7.0_60" << true;
- QTest::newRow("1.8.0_22") << "1.8.0_22" << false;
- QTest::newRow("9-ea") << "9-ea" << false;
- QTest::newRow("9.2.4") << "9.2.4" << false;
- }
- void test_PermGen()
- {
- QFETCH(QString, version);
- QFETCH(bool, needs_permgen);
- JavaVersion v(version);
- QCOMPARE(needs_permgen, v.requiresPermGen());
- }
+ // old format and new format equivalence
+ QTest::newRow("1.6.0_33 == 6.0.33") << "1.6.0_33" << "6.0.33" << false << true << false;
+ // old format major version
+ QTest::newRow("1.5.0_33 < 1.6.0_33") << "1.5.0_33" << "1.6.0_33" << true << false << false;
+ // new format - first release vs first security patch
+ QTest::newRow("9 < 9.0.1") << "9" << "9.0.1" << true << false << false;
+ QTest::newRow("9.0.1 > 9") << "9.0.1" << "9" << false << false << true;
+ // new format - first minor vs first release/security patch
+ QTest::newRow("9.1 > 9.0.1") << "9.1" << "9.0.1" << false << false << true;
+ QTest::newRow("9.0.1 < 9.1") << "9.0.1" << "9.1" << true << false << false;
+ QTest::newRow("9.1 > 9") << "9.1" << "9" << false << false << true;
+ QTest::newRow("9 > 9.1") << "9" << "9.1" << true << false << false;
+ // new format - omitted numbers
+ QTest::newRow("9 == 9.0") << "9" << "9.0" << false << true << false;
+ QTest::newRow("9 == 9.0.0") << "9" << "9.0.0" << false << true << false;
+ QTest::newRow("9.0 == 9.0.0") << "9.0" << "9.0.0" << false << true << false;
+ // early access and prereleases compared to final release
+ QTest::newRow("9-ea < 9") << "9-ea" << "9" << true << false << false;
+ QTest::newRow("9 < 9.0.1-ea") << "9" << "9.0.1-ea" << true << false << false;
+ QTest::newRow("9.0.1-ea > 9") << "9.0.1-ea" << "9" << false << false << true;
+ // prerelease difference only testing
+ QTest::newRow("9-1 == 9-1") << "9-1" << "9-1" << false << true << false;
+ QTest::newRow("9-1 < 9-2") << "9-1" << "9-2" << true << false << false;
+ QTest::newRow("9-5 < 9-20") << "9-5" << "9-20" << true << false << false;
+ QTest::newRow("9-rc1 < 9-rc2") << "9-rc1" << "9-rc2" << true << false << false;
+ QTest::newRow("9-rc5 < 9-rc20") << "9-rc5" << "9-rc20" << true << false << false;
+ QTest::newRow("9-rc < 9-rc2") << "9-rc" << "9-rc2" << true << false << false;
+ QTest::newRow("9-ea < 9-rc") << "9-ea" << "9-rc" << true << false << false;
+ }
+ void test_Sort()
+ {
+ QFETCH(QString, lhs);
+ QFETCH(QString, rhs);
+ QFETCH(bool, smaller);
+ QFETCH(bool, equal);
+ QFETCH(bool, bigger);
+ JavaVersion lver(lhs);
+ JavaVersion rver(rhs);
+ QCOMPARE(lver < rver, smaller);
+ QCOMPARE(lver == rver, equal);
+ QCOMPARE(lver > rver, bigger);
+ }
+ void test_PermGen_data()
+ {
+ QTest::addColumn<QString>("version");
+ QTest::addColumn<bool>("needs_permgen");
+ QTest::newRow("1.6.0_33") << "1.6.0_33" << true;
+ QTest::newRow("1.7.0_60") << "1.7.0_60" << true;
+ QTest::newRow("1.8.0_22") << "1.8.0_22" << false;
+ QTest::newRow("9-ea") << "9-ea" << false;
+ QTest::newRow("9.2.4") << "9.2.4" << false;
+ }
+ void test_PermGen()
+ {
+ QFETCH(QString, version);
+ QFETCH(bool, needs_permgen);
+ JavaVersion v(version);
+ QCOMPARE(needs_permgen, v.requiresPermGen());
+ }
};
QTEST_GUILESS_MAIN(JavaVersionTest)
diff --git a/api/logic/java/launch/CheckJava.cpp b/api/logic/java/launch/CheckJava.cpp
index 24f26682..4ea40084 100644
--- a/api/logic/java/launch/CheckJava.cpp
+++ b/api/logic/java/launch/CheckJava.cpp
@@ -22,115 +22,115 @@
void CheckJava::executeTask()
{
- auto instance = m_parent->instance();
- auto settings = instance->settings();
- m_javaPath = FS::ResolveExecutable(settings->get("JavaPath").toString());
- bool perInstance = settings->get("OverrideJava").toBool() || settings->get("OverrideJavaLocation").toBool();
+ auto instance = m_parent->instance();
+ auto settings = instance->settings();
+ m_javaPath = FS::ResolveExecutable(settings->get("JavaPath").toString());
+ bool perInstance = settings->get("OverrideJava").toBool() || settings->get("OverrideJavaLocation").toBool();
- auto realJavaPath = QStandardPaths::findExecutable(m_javaPath);
- if (realJavaPath.isEmpty())
- {
- if (perInstance)
- {
- emit logLine(
- tr("The java binary \"%1\" couldn't be found. Please fix the java path "
- "override in the instance's settings or disable it.").arg(m_javaPath),
- MessageLevel::Warning);
- }
- else
- {
- emit logLine(tr("The java binary \"%1\" couldn't be found. Please set up java in "
- "the settings.").arg(m_javaPath),
- MessageLevel::Warning);
- }
- emitFailed(tr("Java path is not valid."));
- return;
- }
- else
- {
- emit logLine("Java path is:\n" + m_javaPath + "\n\n", MessageLevel::MultiMC);
- }
+ auto realJavaPath = QStandardPaths::findExecutable(m_javaPath);
+ if (realJavaPath.isEmpty())
+ {
+ if (perInstance)
+ {
+ emit logLine(
+ tr("The java binary \"%1\" couldn't be found. Please fix the java path "
+ "override in the instance's settings or disable it.").arg(m_javaPath),
+ MessageLevel::Warning);
+ }
+ else
+ {
+ emit logLine(tr("The java binary \"%1\" couldn't be found. Please set up java in "
+ "the settings.").arg(m_javaPath),
+ MessageLevel::Warning);
+ }
+ emitFailed(tr("Java path is not valid."));
+ return;
+ }
+ else
+ {
+ emit logLine("Java path is:\n" + m_javaPath + "\n\n", MessageLevel::MultiMC);
+ }
- QFileInfo javaInfo(realJavaPath);
- qlonglong javaUnixTime = javaInfo.lastModified().toMSecsSinceEpoch();
- auto storedUnixTime = settings->get("JavaTimestamp").toLongLong();
- auto storedArchitecture = settings->get("JavaArchitecture").toString();
- auto storedVersion = settings->get("JavaVersion").toString();
- m_javaUnixTime = javaUnixTime;
- // if timestamps are not the same, or something is missing, check!
- if (javaUnixTime != storedUnixTime || storedVersion.size() == 0 || storedArchitecture.size() == 0)
- {
- m_JavaChecker = std::make_shared<JavaChecker>();
- emit logLine(tr("Checking Java version..."), MessageLevel::MultiMC);
- connect(m_JavaChecker.get(), &JavaChecker::checkFinished, this, &CheckJava::checkJavaFinished);
- m_JavaChecker->m_path = realJavaPath;
- m_JavaChecker->performCheck();
- return;
- }
- else
- {
- auto verString = instance->settings()->get("JavaVersion").toString();
- auto archString = instance->settings()->get("JavaArchitecture").toString();
- printJavaInfo(verString, archString);
- }
- emitSucceeded();
+ QFileInfo javaInfo(realJavaPath);
+ qlonglong javaUnixTime = javaInfo.lastModified().toMSecsSinceEpoch();
+ auto storedUnixTime = settings->get("JavaTimestamp").toLongLong();
+ auto storedArchitecture = settings->get("JavaArchitecture").toString();
+ auto storedVersion = settings->get("JavaVersion").toString();
+ m_javaUnixTime = javaUnixTime;
+ // if timestamps are not the same, or something is missing, check!
+ if (javaUnixTime != storedUnixTime || storedVersion.size() == 0 || storedArchitecture.size() == 0)
+ {
+ m_JavaChecker = std::make_shared<JavaChecker>();
+ emit logLine(tr("Checking Java version..."), MessageLevel::MultiMC);
+ connect(m_JavaChecker.get(), &JavaChecker::checkFinished, this, &CheckJava::checkJavaFinished);
+ m_JavaChecker->m_path = realJavaPath;
+ m_JavaChecker->performCheck();
+ return;
+ }
+ else
+ {
+ auto verString = instance->settings()->get("JavaVersion").toString();
+ auto archString = instance->settings()->get("JavaArchitecture").toString();
+ printJavaInfo(verString, archString);
+ }
+ emitSucceeded();
}
void CheckJava::checkJavaFinished(JavaCheckResult result)
{
- switch (result.validity)
- {
- case JavaCheckResult::Validity::Errored:
- {
- // Error message displayed if java can't start
- emit logLine(tr("Could not start java:"), MessageLevel::Error);
- emit logLines(result.errorLog.split('\n'), MessageLevel::Error);
- emit logLine("\nCheck your MultiMC Java settings.", MessageLevel::MultiMC);
- printSystemInfo(false, false);
- emitFailed(tr("Could not start java!"));
- return;
- }
- case JavaCheckResult::Validity::ReturnedInvalidData:
- {
- emit logLine(tr("Java checker returned some invalid data MultiMC doesn't understand:"), MessageLevel::Error);
- emit logLines(result.outLog.split('\n'), MessageLevel::Warning);
- emit logLine("\nMinecraft might not start properly.", MessageLevel::MultiMC);
- printSystemInfo(false, false);
- emitSucceeded();
- return;
- }
- case JavaCheckResult::Validity::Valid:
- {
- auto instance = m_parent->instance();
- printJavaInfo(result.javaVersion.toString(), result.mojangPlatform);
- instance->settings()->set("JavaVersion", result.javaVersion.toString());
- instance->settings()->set("JavaArchitecture", result.mojangPlatform);
- instance->settings()->set("JavaTimestamp", m_javaUnixTime);
- emitSucceeded();
- return;
- }
- }
+ switch (result.validity)
+ {
+ case JavaCheckResult::Validity::Errored:
+ {
+ // Error message displayed if java can't start
+ emit logLine(tr("Could not start java:"), MessageLevel::Error);
+ emit logLines(result.errorLog.split('\n'), MessageLevel::Error);
+ emit logLine("\nCheck your MultiMC Java settings.", MessageLevel::MultiMC);
+ printSystemInfo(false, false);
+ emitFailed(tr("Could not start java!"));
+ return;
+ }
+ case JavaCheckResult::Validity::ReturnedInvalidData:
+ {
+ emit logLine(tr("Java checker returned some invalid data MultiMC doesn't understand:"), MessageLevel::Error);
+ emit logLines(result.outLog.split('\n'), MessageLevel::Warning);
+ emit logLine("\nMinecraft might not start properly.", MessageLevel::MultiMC);
+ printSystemInfo(false, false);
+ emitSucceeded();
+ return;
+ }
+ case JavaCheckResult::Validity::Valid:
+ {
+ auto instance = m_parent->instance();
+ printJavaInfo(result.javaVersion.toString(), result.mojangPlatform);
+ instance->settings()->set("JavaVersion", result.javaVersion.toString());
+ instance->settings()->set("JavaArchitecture", result.mojangPlatform);
+ instance->settings()->set("JavaTimestamp", m_javaUnixTime);
+ emitSucceeded();
+ return;
+ }
+ }
}
void CheckJava::printJavaInfo(const QString& version, const QString& architecture)
{
- emit logLine(tr("Java is version %1, using %2-bit architecture.\n\n").arg(version, architecture), MessageLevel::MultiMC);
- printSystemInfo(true, architecture == "64");
+ emit logLine(tr("Java is version %1, using %2-bit architecture.\n\n").arg(version, architecture), MessageLevel::MultiMC);
+ printSystemInfo(true, architecture == "64");
}
void CheckJava::printSystemInfo(bool javaIsKnown, bool javaIs64bit)
{
- auto cpu64 = Sys::isCPU64bit();
- auto system64 = Sys::isSystem64bit();
- if(cpu64 != system64)
- {
- emit logLine(tr("Your CPU architecture is not matching your system architecture. You might want to install a 64bit Operating System.\n\n"), MessageLevel::Error);
- }
- if(javaIsKnown)
- {
- if(javaIs64bit != system64)
- {
- emit logLine(tr("Your Java architecture is not matching your system architecture. You might want to install a 64bit Java version.\n\n"), MessageLevel::Error);
- }
- }
+ auto cpu64 = Sys::isCPU64bit();
+ auto system64 = Sys::isSystem64bit();
+ if(cpu64 != system64)
+ {
+ emit logLine(tr("Your CPU architecture is not matching your system architecture. You might want to install a 64bit Operating System.\n\n"), MessageLevel::Error);
+ }
+ if(javaIsKnown)
+ {
+ if(javaIs64bit != system64)
+ {
+ emit logLine(tr("Your Java architecture is not matching your system architecture. You might want to install a 64bit Java version.\n\n"), MessageLevel::Error);
+ }
+ }
}
diff --git a/api/logic/java/launch/CheckJava.h b/api/logic/java/launch/CheckJava.h
index 82508cd4..be247a1b 100644
--- a/api/logic/java/launch/CheckJava.h
+++ b/api/logic/java/launch/CheckJava.h
@@ -21,25 +21,25 @@
class CheckJava: public LaunchStep
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit CheckJava(LaunchTask *parent) :LaunchStep(parent){};
- virtual ~CheckJava() {};
+ explicit CheckJava(LaunchTask *parent) :LaunchStep(parent){};
+ virtual ~CheckJava() {};
- virtual void executeTask();
- virtual bool canAbort() const
- {
- return false;
- }
+ virtual void executeTask();
+ virtual bool canAbort() const
+ {
+ return false;
+ }
private slots:
- void checkJavaFinished(JavaCheckResult result);
+ void checkJavaFinished(JavaCheckResult result);
private:
- void printJavaInfo(const QString & version, const QString & architecture);
- void printSystemInfo(bool javaIsKnown, bool javaIs64bit);
+ void printJavaInfo(const QString & version, const QString & architecture);
+ void printSystemInfo(bool javaIsKnown, bool javaIs64bit);
private:
- QString m_javaPath;
- qlonglong m_javaUnixTime;
- JavaCheckerPtr m_JavaChecker;
+ QString m_javaPath;
+ qlonglong m_javaUnixTime;
+ JavaCheckerPtr m_JavaChecker;
};