Use temporary files for the java checker

This commit is contained in:
Petr Mrázek 2013-12-13 00:02:58 +01:00
parent 45aa858090
commit bf34aa7fbd
2 changed files with 13 additions and 7 deletions

View File

@ -2,6 +2,7 @@
#include <QFile>
#include <QProcess>
#include <QMap>
#include <QTemporaryFile>
#define CHECKER_FILE "JavaChecker.jar"
@ -11,14 +12,15 @@ JavaChecker::JavaChecker(QObject *parent) : QObject(parent)
void JavaChecker::performCheck()
{
if(QFile::exists(CHECKER_FILE))
{
QFile::remove(CHECKER_FILE);
}
// extract the checker
QFile(":/java/checker.jar").copy(CHECKER_FILE);
checkerJar.setFileTemplate("checker_XXXXXX.jar");
checkerJar.open();
QFile inner(":/java/checker.jar");
inner.open(QIODevice::ReadOnly);
checkerJar.write(inner.readAll());
inner.close();
checkerJar.close();
QStringList args = {"-jar", CHECKER_FILE};
QStringList args = {"-jar", checkerJar.fileName()};
process.reset(new QProcess());
process->setArguments(args);
@ -40,6 +42,7 @@ void JavaChecker::finished(int exitcode, QProcess::ExitStatus status)
killTimer.stop();
QProcessPtr _process;
_process.swap(process);
checkerJar.remove();
JavaCheckResult result;
{

View File

@ -1,10 +1,12 @@
#pragma once
#include <QProcess>
#include <QTimer>
#include <QTemporaryFile>
#include <memory>
class JavaChecker;
struct JavaCheckResult
{
QString path;
@ -31,6 +33,7 @@ signals:
private:
QProcessPtr process;
QTimer killTimer;
QTemporaryFile checkerJar;
public
slots:
void timeout();