From 1b884d0a9dc28d8bca38fe8756482d991d0ea850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 4 May 2015 01:20:48 +0200 Subject: GH-907 improve Java testing and PermGen deprecation handling --- application/JavaCommon.cpp | 107 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 application/JavaCommon.cpp (limited to 'application/JavaCommon.cpp') diff --git a/application/JavaCommon.cpp b/application/JavaCommon.cpp new file mode 100644 index 00000000..d0a3cba3 --- /dev/null +++ b/application/JavaCommon.cpp @@ -0,0 +1,107 @@ +#include "JavaCommon.h" +#include "dialogs/CustomMessageBox.h" +#include + +bool JavaCommon::checkJVMArgs(QString jvmargs, QWidget *parent) +{ + if (jvmargs.contains("-XX:PermSize=") || jvmargs.contains(QRegExp("-Xm[sx]"))) + { + CustomMessageBox::selectable( + parent, QObject::tr("JVM arguments warning"), + QObject::tr("You tried to manually set a JVM memory option (using " + " \"-XX:PermSize\", \"-Xmx\" or \"-Xms\") - there" + " are dedicated boxes for these in the settings (Java" + " tab, in the Memory group at the top).\n" + "Your manual settings will be overridden by the" + " dedicated options.\n" + "This message will be displayed until you remove them" + " from the JVM arguments."), + QMessageBox::Warning)->exec(); + return false; + } + return true; +} + +void JavaCommon::TestCheck::javaWasOk(JavaCheckResult result) +{ + QString text; + text += tr("Java test succeeded!
Platform reported: %1
Java version " + "reported: %2
").arg(result.realPlatform, result.javaVersion); + if (result.stderr.size()) + { + auto htmlError = result.stderr; + htmlError.replace('\n', "
"); + text += tr("
Warnings:
%1").arg(htmlError); + } + CustomMessageBox::selectable(m_parent, tr("Java test success"), text, + QMessageBox::Information)->show(); +} + +void JavaCommon::TestCheck::javaArgsWereBad(JavaCheckResult result) +{ + auto htmlError = result.stderr; + QString text; + htmlError.replace('\n', "
"); + text += tr("The specified java binary didn't work with the arguments you provided:
"); + text += tr("%1").arg(htmlError); + CustomMessageBox::selectable(m_parent, tr("Java test failure"), text, QMessageBox::Warning) + ->show(); +} + +void JavaCommon::TestCheck::javaBinaryWasBad(JavaCheckResult result) +{ + QString text; + text += tr( + "The specified java binary didn't work.
You should use the auto-detect feature, " + "or set the path to the java executable.
"); + CustomMessageBox::selectable(m_parent, tr("Java test failure"), text, QMessageBox::Warning) + ->show(); +} + +void JavaCommon::TestCheck::run() +{ + if (!JavaCommon::checkJVMArgs(m_args, m_parent)) + { + emit finished(); + return; + } + checker.reset(new JavaChecker()); + connect(checker.get(), SIGNAL(checkFinished(JavaCheckResult)), this, + SLOT(checkFinished(JavaCheckResult))); + checker->m_path = m_path; + checker->performCheck(); +} + +void JavaCommon::TestCheck::checkFinished(JavaCheckResult result) +{ + if (!result.valid) + { + javaBinaryWasBad(result); + emit finished(); + return; + } + checker.reset(new JavaChecker()); + connect(checker.get(), SIGNAL(checkFinished(JavaCheckResult)), this, + SLOT(checkFinishedWithArgs(JavaCheckResult))); + checker->m_path = m_path; + checker->m_args = m_args; + checker->m_minMem = m_minMem; + checker->m_maxMem = m_maxMem; + if (Strings::naturalCompare(result.javaVersion, "1.8", Qt::CaseInsensitive) < 0) + { + checker->m_permGen = m_permGen; + } + checker->performCheck(); +} + +void JavaCommon::TestCheck::checkFinishedWithArgs(JavaCheckResult result) +{ + if (result.valid) + { + javaWasOk(result); + emit finished(); + return; + } + javaArgsWereBad(result); + emit finished(); +} -- cgit v1.2.3