EDU-655 Run Study Tests configuration doesn't work if one of task files is image
authorliana.bakradze <liana.bakradze@jetbrains.com>
Tue, 28 Jun 2016 17:54:31 +0000 (20:54 +0300)
committerEkaterina Tuzova <Ekaterina.Tuzova@jetbrains.com>
Wed, 29 Jun 2016 08:45:53 +0000 (11:45 +0300)
(cherry picked from commit 4f9d5c1)

python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/CCUtils.java
python/educational-python/course-creator-python/src/com/jetbrains/edu/coursecreator/run/PyCCCommandLineState.java

index 66e036be3f03a11a71608d015710eb77112642e2..c3cce2b1be2a9e3d7d737e8c3fb25fefd3ba64d9 100644 (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) {
       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());
       }
       DocumentUtil.writeInRunUndoTransparentAction(() -> {
         patternDocument.replaceString(0, patternDocument.getTextLength(), document.getCharsSequence());
index f4678a97a665e606122b483e5e8fa720f4324d13..bb2264dbc18d042bd0069140f62582253b25d620 100644 (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.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.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.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 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.io.File;
+import java.util.Map;
 
 public class PyCCCommandLineState extends PythonCommandLineState {
   private final PyCCRunTestConfiguration myRunConfiguration;
 
 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(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() {
   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 ?
     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
   }
 
   @Override