summaryrefslogtreecommitdiffstats
path: root/api/logic/java
diff options
context:
space:
mode:
Diffstat (limited to 'api/logic/java')
-rw-r--r--api/logic/java/JavaChecker.cpp2
-rw-r--r--api/logic/java/JavaCheckerJob.cpp7
-rw-r--r--api/logic/java/JavaCheckerJob.h36
-rw-r--r--api/logic/java/JavaInstallList.cpp7
-rw-r--r--api/logic/java/JavaInstallList.h4
-rw-r--r--api/logic/java/JavaUtils.cpp95
-rw-r--r--api/logic/java/JavaUtils.h5
-rw-r--r--api/logic/java/JavaVersion.cpp13
-rw-r--r--api/logic/java/launch/CheckJava.cpp2
-rw-r--r--api/logic/java/launch/CheckJava.h2
10 files changed, 126 insertions, 47 deletions
diff --git a/api/logic/java/JavaChecker.cpp b/api/logic/java/JavaChecker.cpp
index ebbd80be..f0b71e48 100644
--- a/api/logic/java/JavaChecker.cpp
+++ b/api/logic/java/JavaChecker.cpp
@@ -1,4 +1,5 @@
#include "JavaChecker.h"
+#include "JavaUtils.h"
#include <FileSystem.h>
#include <Commandline.h>
#include <QFile>
@@ -42,6 +43,7 @@ void JavaChecker::performCheck()
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)));
diff --git a/api/logic/java/JavaCheckerJob.cpp b/api/logic/java/JavaCheckerJob.cpp
index 01b5b28d..fabb5aaa 100644
--- a/api/logic/java/JavaCheckerJob.cpp
+++ b/api/logic/java/JavaCheckerJob.cpp
@@ -1,4 +1,4 @@
-/* Copyright 2013-2017 MultiMC Contributors
+/* Copyright 2013-2018 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,20 +22,19 @@ void JavaCheckerJob::partFinished(JavaCheckResult result)
num_finished++;
qDebug() << m_job_name.toLocal8Bit() << "progress:" << num_finished << "/"
<< javacheckers.size();
- emit progress(num_finished, javacheckers.size());
+ setProgress(num_finished, javacheckers.size());
javaresults.replace(result.id, result);
if (num_finished == javacheckers.size())
{
- emit finished(javaresults);
+ emitSucceeded();
}
}
void JavaCheckerJob::executeTask()
{
qDebug() << m_job_name.toLocal8Bit() << " started.";
- m_running = true;
for (auto iter : javacheckers)
{
javaresults.append(JavaCheckResult());
diff --git a/api/logic/java/JavaCheckerJob.h b/api/logic/java/JavaCheckerJob.h
index 58a98190..cac2b638 100644
--- a/api/logic/java/JavaCheckerJob.h
+++ b/api/logic/java/JavaCheckerJob.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2017 MultiMC Contributors
+/* Copyright 2013-2018 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
class JavaCheckerJob;
typedef std::shared_ptr<JavaCheckerJob> JavaCheckerJobPtr;
+// FIXME: this just seems horribly redundant
class JavaCheckerJob : public Task
{
Q_OBJECT
@@ -31,41 +32,19 @@ public:
bool addJavaCheckerAction(JavaCheckerPtr base)
{
javacheckers.append(base);
- total_progress++;
// if this is already running, the action needs to be started right away!
if (isRunning())
{
- setProgress(current_progress, total_progress);
- connect(base.get(), SIGNAL(checkFinished(JavaCheckResult)), SLOT(partFinished(JavaCheckResult)));
-
+ setProgress(num_finished, javacheckers.size());
+ connect(base.get(), &JavaChecker::checkFinished, this, &JavaCheckerJob::partFinished);
base->performCheck();
}
return true;
}
-
- JavaCheckerPtr operator[](int index)
+ QList<JavaCheckResult> getResults()
{
- return javacheckers[index];
+ return javaresults;
}
- ;
- JavaCheckerPtr first()
- {
- if (javacheckers.size())
- return javacheckers[0];
- return JavaCheckerPtr();
- }
- int size() const
- {
- return javacheckers.size();
- }
- virtual bool isRunning() const override
- {
- return m_running;
- }
-
-signals:
- void started();
- void finished(QList<JavaCheckResult>);
private slots:
void partFinished(JavaCheckResult result);
@@ -77,8 +56,5 @@ private:
QString m_job_name;
QList<JavaCheckerPtr> javacheckers;
QList<JavaCheckResult> javaresults;
- qint64 current_progress = 0;
- qint64 total_progress = 0;
int num_finished = 0;
- bool m_running = false;
};
diff --git a/api/logic/java/JavaInstallList.cpp b/api/logic/java/JavaInstallList.cpp
index 44ac861d..9d2e2f8b 100644
--- a/api/logic/java/JavaInstallList.cpp
+++ b/api/logic/java/JavaInstallList.cpp
@@ -1,4 +1,4 @@
-/* Copyright 2013-2017 MultiMC Contributors
+/* Copyright 2013-2018 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -150,7 +150,7 @@ void JavaListLoadTask::executeTask()
QList<QString> candidate_paths = ju.FindJavaPaths();
m_job = std::shared_ptr<JavaCheckerJob>(new JavaCheckerJob("Java detection"));
- connect(m_job.get(), SIGNAL(finished(QList<JavaCheckResult>)), this, SLOT(javaCheckerFinished(QList<JavaCheckResult>)));
+ connect(m_job.get(), &Task::finished, this, &JavaListLoadTask::javaCheckerFinished);
connect(m_job.get(), &Task::progress, this, &Task::setProgress);
qDebug() << "Probing the following Java paths: ";
@@ -170,9 +170,10 @@ void JavaListLoadTask::executeTask()
m_job->start();
}
-void JavaListLoadTask::javaCheckerFinished(QList<JavaCheckResult> results)
+void JavaListLoadTask::javaCheckerFinished()
{
QList<JavaInstallPtr> candidates;
+ auto results = m_job->getResults();
qDebug() << "Found the following valid Java installations:";
for(JavaCheckResult result : results)
diff --git a/api/logic/java/JavaInstallList.h b/api/logic/java/JavaInstallList.h
index 934e588b..39f37b80 100644
--- a/api/logic/java/JavaInstallList.h
+++ b/api/logic/java/JavaInstallList.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2017 MultiMC Contributors
+/* Copyright 2013-2018 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -72,7 +72,7 @@ public:
void executeTask() override;
public slots:
- void javaCheckerFinished(QList<JavaCheckResult> results);
+ void javaCheckerFinished();
protected:
std::shared_ptr<JavaCheckerJob> m_job;
diff --git a/api/logic/java/JavaUtils.cpp b/api/logic/java/JavaUtils.cpp
index 0c2e72d7..4a77bc7e 100644
--- a/api/logic/java/JavaUtils.cpp
+++ b/api/logic/java/JavaUtils.cpp
@@ -1,4 +1,4 @@
-/* Copyright 2013-2017 MultiMC Contributors
+/* Copyright 2013-2018 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,14 +22,105 @@
#include <QDebug>
#include "java/JavaUtils.h"
-#include "java/JavaCheckerJob.h"
#include "java/JavaInstallList.h"
#include "FileSystem.h"
+#define IBUS "@im=ibus"
+
JavaUtils::JavaUtils()
{
}
+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(':');
+}
+
+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;
+ }
+#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;
+ }
+#endif
+ // 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", "");
+ }
+#endif
+
+ return env;
+}
+
JavaInstallPtr JavaUtils::MakeJavaPtr(QString path, QString id, QString arch)
{
JavaInstallPtr javaVersion(new JavaInstall());
diff --git a/api/logic/java/JavaUtils.h b/api/logic/java/JavaUtils.h
index 4418ac26..b43e93cf 100644
--- a/api/logic/java/JavaUtils.h
+++ b/api/logic/java/JavaUtils.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2017 MultiMC Contributors
+/* Copyright 2013-2018 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
#include <QStringList>
-#include "JavaCheckerJob.h"
#include "JavaChecker.h"
#include "JavaInstallList.h"
@@ -27,6 +26,8 @@
#include "multimc_logic_export.h"
+QProcessEnvironment CleanEnviroment();
+
class MULTIMC_LOGIC_EXPORT JavaUtils : public QObject
{
Q_OBJECT
diff --git a/api/logic/java/JavaVersion.cpp b/api/logic/java/JavaVersion.cpp
index 8c1bb430..27050da3 100644
--- a/api/logic/java/JavaVersion.cpp
+++ b/api/logic/java/JavaVersion.cpp
@@ -60,9 +60,18 @@ bool JavaVersion::operator<(const JavaVersion &rhs)
{
if(m_parseable && rhs.m_parseable)
{
- if(m_major < rhs.m_major)
+ auto major = m_major;
+ auto rmajor = rhs.m_major;
+
+ // HACK: discourage using java 9
+ if(major > 8)
+ major = -major;
+ if(rmajor > 8)
+ rmajor = -rmajor;
+
+ if(major < rmajor)
return true;
- if(m_major > rhs.m_major)
+ if(major > rmajor)
return false;
if(m_minor < rhs.m_minor)
return true;
diff --git a/api/logic/java/launch/CheckJava.cpp b/api/logic/java/launch/CheckJava.cpp
index f78e1cff..24f26682 100644
--- a/api/logic/java/launch/CheckJava.cpp
+++ b/api/logic/java/launch/CheckJava.cpp
@@ -1,4 +1,4 @@
-/* Copyright 2013-2017 MultiMC Contributors
+/* Copyright 2013-2018 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/api/logic/java/launch/CheckJava.h b/api/logic/java/launch/CheckJava.h
index 3c812277..82508cd4 100644
--- a/api/logic/java/launch/CheckJava.h
+++ b/api/logic/java/launch/CheckJava.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2017 MultiMC Contributors
+/* Copyright 2013-2018 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.