mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
EDU-853 IOException when failing any subtask with several placeholders
This commit is contained in:
@@ -215,7 +215,10 @@ public class StudyUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void deleteFile(@NotNull final VirtualFile file) {
|
||||
public static void deleteFile(@Nullable final VirtualFile file) {
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
file.delete(StudyUtils.class);
|
||||
}
|
||||
|
||||
+11
-7
@@ -131,15 +131,19 @@ public class StudyCheckUtils {
|
||||
}
|
||||
VirtualFile answerFile = pair.getFirst();
|
||||
TaskFile answerTaskFile = pair.getSecond();
|
||||
for (final AnswerPlaceholder answerPlaceholder : answerTaskFile.getActivePlaceholders()) {
|
||||
final Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
|
||||
if (document == null) {
|
||||
continue;
|
||||
try {
|
||||
for (final AnswerPlaceholder answerPlaceholder : answerTaskFile.getActivePlaceholders()) {
|
||||
final Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
|
||||
if (document == null) {
|
||||
continue;
|
||||
}
|
||||
StudySmartChecker.smartCheck(answerPlaceholder, project, answerFile, answerTaskFile, taskFile, testRunner,
|
||||
virtualFile, document);
|
||||
}
|
||||
StudySmartChecker.smartCheck(answerPlaceholder, project, answerFile, answerTaskFile, taskFile, testRunner,
|
||||
virtualFile, document);
|
||||
}
|
||||
StudyUtils.deleteFile(answerFile);
|
||||
finally {
|
||||
StudyUtils.deleteFile(answerFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+14
-14
@@ -39,17 +39,17 @@ public class StudySmartChecker {
|
||||
@NotNull final StudyTestRunner testRunner,
|
||||
@NotNull final VirtualFile virtualFile,
|
||||
@NotNull final Document usersDocument) {
|
||||
|
||||
VirtualFile fileWindows = null;
|
||||
File resourceFile = null;
|
||||
VirtualFile windowCopy = null;
|
||||
try {
|
||||
final int index = placeholder.getIndex();
|
||||
String windowCopyName = answerFile.getNameWithoutExtension() + index + EduNames.WINDOW_POSTFIX + answerFile.getExtension();
|
||||
final VirtualFile windowCopy =
|
||||
answerFile.copy(project, answerFile.getParent(), windowCopyName);
|
||||
windowCopy = answerFile.copy(project, answerFile.getParent(), windowCopyName);
|
||||
final FileDocumentManager documentManager = FileDocumentManager.getInstance();
|
||||
final Document windowDocument = documentManager.getDocument(windowCopy);
|
||||
if (windowDocument != null) {
|
||||
final File resourceFile =
|
||||
StudyUtils.copyResourceFile(virtualFile.getName(), windowCopy.getName(), project, usersTaskFile.getTask());
|
||||
resourceFile = StudyUtils.copyResourceFile(virtualFile.getName(), windowCopy.getName(), project, usersTaskFile.getTask());
|
||||
TaskFile windowTaskFile = answerTaskFile.getTask().copy().getTaskFile(StudyUtils.pathRelativeToTask(virtualFile));
|
||||
if (windowTaskFile == null) {
|
||||
return;
|
||||
@@ -58,13 +58,13 @@ public class StudySmartChecker {
|
||||
windowDocument.addDocumentListener(listener);
|
||||
int start = placeholder.getOffset();
|
||||
int end = start + placeholder.getRealLength();
|
||||
final AnswerPlaceholder userAnswerPlaceholder = usersTaskFile.getActivePlaceholders().get(placeholder.getIndex());
|
||||
final AnswerPlaceholder userAnswerPlaceholder = usersTaskFile.getAnswerPlaceholders().get(placeholder.getIndex());
|
||||
int userStart = userAnswerPlaceholder.getOffset();
|
||||
int userEnd = userStart + userAnswerPlaceholder.getRealLength();
|
||||
String text = usersDocument.getText(new TextRange(userStart, userEnd));
|
||||
windowDocument.replaceString(start, end, text);
|
||||
ApplicationManager.getApplication().runWriteAction(() -> documentManager.saveDocument(windowDocument));
|
||||
VirtualFile fileWindows = EduUtils.flushWindows(windowTaskFile, windowCopy);
|
||||
fileWindows = EduUtils.flushWindows(windowTaskFile, windowCopy);
|
||||
Process smartTestProcess = testRunner.createCheckProcess(project, windowCopy.getPath());
|
||||
final CapturingProcessHandler handler = new CapturingProcessHandler(smartTestProcess, null, windowCopy.getPath());
|
||||
final ProcessOutput output = handler.runProcess();
|
||||
@@ -72,18 +72,18 @@ public class StudySmartChecker {
|
||||
if (course != null) {
|
||||
boolean res = StudyTestsOutputParser.getTestsOutput(output, course.isAdaptive()).isSuccess();
|
||||
StudyTaskManager.getInstance(project).setStatus(userAnswerPlaceholder, res ? StudyStatus.Solved : StudyStatus.Failed);
|
||||
StudyUtils.deleteFile(windowCopy);
|
||||
if (fileWindows != null) {
|
||||
StudyUtils.deleteFile(fileWindows);
|
||||
}
|
||||
if (!resourceFile.delete()) {
|
||||
LOG.error("failed to delete", resourceFile.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (ExecutionException | IOException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
finally {
|
||||
StudyUtils.deleteFile(windowCopy);
|
||||
StudyUtils.deleteFile(fileWindows);
|
||||
if (resourceFile != null && resourceFile.exists() && !resourceFile.delete()) {
|
||||
LOG.error("failed to delete", resourceFile.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user