EDU-342 Add non-py tasks to the task directory
authorLiana Bakradze <liana.bakradze@jetbrains.com>
Wed, 15 Jul 2015 12:38:33 +0000 (15:38 +0300)
committerLiana Bakradze <liana.bakradze@jetbrains.com>
Wed, 15 Jul 2015 12:38:33 +0000 (15:38 +0300)
python/edu/course-creator-python/src/com/jetbrains/edu/coursecreator/PyCCLanguageManager.java
python/educational/course-creator/src/com/jetbrains/edu/coursecreator/CCLanguageManager.java
python/educational/course-creator/src/com/jetbrains/edu/coursecreator/actions/CCCreateCourseArchive.java

index 2f6db75f6dccc4ac374496f2779af3950fc928d4..967bff6c260ceda12f4f2b5f942586b66533f0de 100644 (file)
@@ -31,14 +31,9 @@ public class PyCCLanguageManager implements CCLanguageManager {
   }
 
   @Override
-  public boolean packFile(File pathname) {
+  public boolean doNotPackFile(File pathname) {
     String name = pathname.getName();
-    return !name.contains("__pycache__") && !name.contains(".pyc");
-  }
-
-  @Override
-  public String[] getAdditionalFilesToPack() {
-    return new String[]{"test_helper.py"};
+    return name.contains("__pycache__") || name.contains(".pyc");
   }
 
   private static FileTemplate getInternalTemplateByName(@NotNull final Project project, String name) {
index 98029f4dbb8141ccffb8c330d497d832d8ba9b53..5ab5f5591ed850529bf5d9ac55e09f1b647e291e 100644 (file)
@@ -20,7 +20,5 @@ public interface CCLanguageManager {
   @Nullable
   FileTemplate getTestsTemplate(@NotNull final Project project);
 
-  boolean packFile(File pathname);
-
-  String[] getAdditionalFilesToPack();
+  boolean doNotPackFile(File pathname);
 }
index 446756bd10e9f56ce4cc4a6700f4dc0a86eb066d..23cfece28509f8f853fe16806ba10b15a9f76589 100644 (file)
@@ -93,6 +93,7 @@ public class CCCreateCourseArchive extends DumbAwareAction {
       }
     }
     generateJson(project);
+    VirtualFileManager.getInstance().refreshWithoutFileWatcher(false);
     packCourse(baseDir, course);
     synchronize(project);
   }
@@ -104,32 +105,24 @@ public class CCCreateCourseArchive extends DumbAwareAction {
 
   private void packCourse(@NotNull final VirtualFile baseDir, @NotNull final Course course) {
     try {
-      File zipFile = new File(myLocationDir, myZipName + ".zip");
+      final File zipFile = new File(myLocationDir, myZipName + ".zip");
       ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
       final CCLanguageManager manager = CCUtils.getStudyLanguageManager(course);
-      for (Lesson lesson : course.getLessons()) {
-        final VirtualFile lessonDir = baseDir.findChild(EduNames.LESSON + String.valueOf(lesson.getIndex()));
-        if (lessonDir == null) continue;
-        ZipUtil.addFileOrDirRecursively(zos, null, new File(lessonDir.getPath()), lessonDir.getName(), new FileFilter() {
+      VirtualFile[] courseFiles = baseDir.getChildren();
+      for (VirtualFile file : courseFiles) {
+        ZipUtil.addFileOrDirRecursively(zos, null, new File(file.getPath()), file.getName(), new FileFilter() {
           @Override
           public boolean accept(File pathname) {
             String name = pathname.getName();
             String nameWithoutExtension = FileUtil.getNameWithoutExtension(pathname);
-            if (nameWithoutExtension.endsWith(".answer") || name.contains("_windows")) {
+            if (nameWithoutExtension.endsWith(".answer") || name.contains("_windows") || name.contains(".idea")
+              || FileUtil.filesEqual(pathname, zipFile)) {
               return false;
             }
-            return manager == null || manager.packFile(pathname);
+            return manager != null && !manager.doNotPackFile(pathname);
           }
         }, null);
       }
-      packFile("hints", zos, baseDir);
-      packFile("course.json", zos, baseDir);
-      if (manager != null) {
-        String[] additionalFilesToPack = manager.getAdditionalFilesToPack();
-        for (String filename: additionalFilesToPack) {
-          packFile(filename, zos, baseDir);
-        }
-      }
       zos.close();
       Messages.showInfoMessage("Course archive was saved to " + zipFile.getPath(), "Course Archive Was Created Successfully");
     }
@@ -165,19 +158,4 @@ public class CCCreateCourseArchive extends DumbAwareAction {
       }
     }
   }
-
-  private static void packFile(@NotNull final String filename,
-                               @NotNull final ZipOutputStream zipOutputStream,
-                               @NotNull final VirtualFile baseDir) {
-    try {
-      File file = new File(baseDir.getPath(), filename);
-      if (!file.exists()) {
-        return;
-      }
-      ZipUtil.addFileOrDirRecursively(zipOutputStream, null, file, filename, null, null);
-    }
-    catch (IOException e) {
-      LOG.error(e);
-    }
-  }
 }
\ No newline at end of file