use of cn.edu.zjnu.acm.judge.core.JudgeException in project judge by zjnu-acm.
the class JudgeServiceImpl method execute.
@Override
public void execute(long submissionId) {
Submission submission = submissionMapper.findOne(submissionId);
if (submission == null) {
throw new BusinessException(BusinessCode.SUBMISSION_NOT_FOUND, submissionId);
}
long problemId = submission.getProblem();
Problem problem = problemService.findOneNoI18n(problemId);
try {
RunRecord runRecord = RunRecord.builder().language(languageService.getAvailableLanguage(submission.getLanguage())).source(submissionDetailMapper.findSourceById(submissionId)).memoryLimit(problem.getMemoryLimit()).timeLimit(problem.getTimeLimit()).build();
Path dataDirectory = systemService.getDataDirectory(problemId);
JudgeData judgeData = JudgeData.parse(dataDirectory);
Path specialFile = systemService.getSpecialJudgeExecutable(problemId);
boolean isSpecial = systemService.isSpecialJudge(problemId);
// 建立临时文件
Path work = systemService.getWorkDirectory(submissionId);
final Validator validator = isSpecial ? new SpecialValidator(specialFile.toString(), work) : SimpleValidator.PE_AS_AC;
boolean deleteTempFile = systemService.isDeleteTempFile();
RunResult runResult = judgeRunner.run(runRecord, work, judgeData, validator, deleteTempFile);
SubmissionDetail detail = SubmissionDetail.builder().id(submissionId).compileInfo(runResult.getCompileInfo()).detail(runResult.getDetail()).systemInfo(runResult.getSystemInfo()).build();
if (runResult.getType() == Status.COMPILATION_ERROR) {
submissionMapper.updateResult(submissionId, ResultType.COMPILE_ERROR, 0, 0);
} else {
int score = runResult.getScore();
long time = runResult.getTime();
long memory = runResult.getMemory();
submissionMapper.updateResult(submissionId, score, time, memory);
}
// TODO return value not handled, we can do nothing for the record not exists in the table now.
submissionDetailMapper.update(detail);
updateSubmissionStatus(submission.getUser(), problemId);
} catch (ThreadDeath | VirtualMachineError error) {
throw error;
} catch (JudgeException | IOException | Error ex) {
log.error("got an exception when judging submission {}", submissionId, ex);
submissionMapper.updateResult(submissionId, ResultType.SYSTEM_ERROR, 0, 0);
StringWriter sw = new StringWriter();
try (PrintWriter pw = new PrintWriter(sw)) {
ex.printStackTrace(pw);
}
submissionDetailMapper.update(SubmissionDetail.builder().id(submissionId).systemInfo(sw.toString()).build());
}
}
Aggregations