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;
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;
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