EDU-198 Exception on "Run tests" action
authorLiana Bakradze <liana.bakradze@jetbrains.com>
Mon, 29 Sep 2014 10:51:30 +0000 (14:51 +0400)
committerLiana Bakradze <liana.bakradze@jetbrains.com>
Mon, 29 Sep 2014 10:51:30 +0000 (14:51 +0400)
python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/CCRunTests.java

index efb520ba51f0f02b440a11ddd9ce06d723d45ba9..eba98f96da19e6397830414c37dd7c14667cb77d 100644 (file)
@@ -224,8 +224,9 @@ public class CCRunTests extends AnAction {
     VirtualFile ideaDir = project.getBaseDir().findChild(".idea");
     assert ideaDir != null;
     try {
-      VirtualFile taskResourceDir = ideaDir.createChildDirectory(project, "course").createChildDirectory(project, lessonDir.getName())
-        .createChildDirectory(project, taskDir.getName());
+      VirtualFile courseResourceDir = findOrCreateDir(project, ideaDir, "course");
+      VirtualFile lessonResourceDir = findOrCreateDir(project, courseResourceDir, lessonDir.getName());
+      VirtualFile taskResourceDir = findOrCreateDir(project, lessonResourceDir, taskDir.getName());
       if (CCProjectService.indexIsValid(lessonIndex, course.getLessons())) {
         Lesson lesson = course.getLessons().get(lessonIndex);
         if (CCProjectService.indexIsValid(index, lesson.getTaskList())) {
@@ -243,6 +244,14 @@ public class CCRunTests extends AnAction {
     }
   }
 
+  private static VirtualFile findOrCreateDir(@NotNull final Project project, @NotNull final VirtualFile dir, String name) throws IOException {
+    VirtualFile targetDir = dir.findChild(name);
+    if (targetDir == null) {
+      targetDir = dir.createChildDirectory(project, name);
+    }
+    return targetDir;
+  }
+
   @SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
   public static VirtualFile flushWindows(TaskFile taskFile, VirtualFile file) {
     VirtualFile taskDir = file.getParent();