EDU-655 Run Study Tests configuration doesn't work if one of task files is image

(cherry picked from commit 4f9d5c1)
This commit is contained in:
liana.bakradze
2016-06-28 20:54:31 +03:00
committed by Ekaterina Tuzova
parent e1de2dced2
commit 2193e9465a
2 changed files with 31 additions and 7 deletions

View File

@@ -224,7 +224,8 @@ public class CCUtils {
Document patternDocument = StudyUtils.getPatternDocument(entry.getValue(), name);
Document document = FileDocumentManager.getInstance().getDocument(child);
if (document == null || patternDocument == null) {
return;
LOG.info("pattern file for " + child.getPath() + " not found");
continue;
}
DocumentUtil.writeInRunUndoTransparentAction(() -> {
patternDocument.replaceString(0, patternDocument.getTextLength(), document.getCharsSequence());

View File

@@ -10,6 +10,7 @@ import com.intellij.execution.process.ProcessEvent;
import com.intellij.execution.process.ProcessHandler;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
@@ -22,11 +23,13 @@ import com.jetbrains.edu.learning.core.EduNames;
import com.jetbrains.edu.learning.core.EduUtils;
import com.jetbrains.edu.learning.courseFormat.Course;
import com.jetbrains.edu.learning.courseFormat.Task;
import com.jetbrains.edu.learning.courseFormat.TaskFile;
import com.jetbrains.python.run.CommandLinePatcher;
import com.jetbrains.python.run.PythonCommandLineState;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.Map;
public class PyCCCommandLineState extends PythonCommandLineState {
private final PyCCRunTestConfiguration myRunConfiguration;
@@ -58,16 +61,36 @@ public class PyCCCommandLineState extends PythonCommandLineState {
group.addParameter(myRunConfiguration.getPathToTest());
group.addParameter(new File(course.getCourseDirectory()).getPath());
group.addParameter(getFirstTaskFilePath());
String path = getFirstTaskFilePath();
if (path != null) {
group.addParameter(path);
}
}
@NotNull
@Nullable
private String getFirstTaskFilePath() {
String firstTaskFileName = StudyUtils.getFirst(myTask.getTaskFiles().keySet());
for (Map.Entry<String, TaskFile> entry : myTask.getTaskFiles().entrySet()) {
String path = getTaskFilePath(entry.getKey());
if (!entry.getValue().getAnswerPlaceholders().isEmpty()) {
return path;
}
VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(path);
if (virtualFile == null) {
continue;
}
if (TextEditorProvider.isTextFile(virtualFile)) {
return path;
}
}
return null;
}
private String getTaskFilePath(String name) {
String taskDirPath = FileUtil.toSystemDependentName(myTaskDir.getPath());
return myTaskDir.findChild(EduNames.SRC) != null ?
FileUtil.join(taskDirPath, EduNames.SRC, firstTaskFileName) :
FileUtil.join(taskDirPath, firstTaskFileName);
FileUtil.join(taskDirPath, EduNames.SRC, name) :
FileUtil.join(taskDirPath, name);
}
@Override