Search in sources :

Example 1 with CCLanguageManager

use of com.jetbrains.edu.coursecreator.CCLanguageManager in project intellij-community by JetBrains.

the class CCCreateCourseArchive method createCourseArchive.

public static void createCourseArchive(final Project project, Module module, String zipName, String locationDir, boolean showMessage) {
    final Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course == null)
        return;
    final VirtualFile baseDir = project.getBaseDir();
    VirtualFile archiveFolder = CCUtils.generateFolder(project, module, zipName);
    if (archiveFolder == null) {
        return;
    }
    CCLanguageManager manager = CCUtils.getStudyLanguageManager(course);
    if (manager == null) {
        return;
    }
    FileFilter filter = pathname -> !manager.doNotPackFile(pathname);
    for (VirtualFile child : baseDir.getChildren()) {
        String name = child.getName();
        File fromFile = new File(child.getPath());
        if (CCUtils.GENERATED_FILES_FOLDER.equals(name) || Project.DIRECTORY_STORE_FOLDER.equals(name) || name.contains("iml") || manager.doNotPackFile(fromFile)) {
            continue;
        }
        copyChild(archiveFolder, filter, child, fromFile);
    }
    ApplicationManager.getApplication().runWriteAction(new Runnable() {

        @Override
        public void run() {
            archiveFolder.refresh(false, true);
            Course courseCopy = course.copy();
            replaceAnswerFilesWithTaskFiles(courseCopy);
            generateJson(archiveFolder, courseCopy);
            VirtualFileManager.getInstance().refreshWithoutFileWatcher(false);
            packCourse(archiveFolder, locationDir, zipName, showMessage);
            synchronize(project);
        }

        private void replaceAnswerFilesWithTaskFiles(Course courseCopy) {
            for (Lesson lesson : courseCopy.getLessons()) {
                String lessonDirName = EduNames.LESSON + String.valueOf(lesson.getIndex());
                final VirtualFile lessonDir = baseDir.findChild(lessonDirName);
                if (lessonDir == null)
                    continue;
                for (Task task : lesson.getTaskList()) {
                    final VirtualFile taskDir = task.getTaskDir(project);
                    if (taskDir == null)
                        continue;
                    String taskDirName = EduNames.TASK + String.valueOf(task.getIndex());
                    VirtualFile studentFileDir = VfsUtil.findRelativeFile(archiveFolder, lessonDirName, taskDirName);
                    if (studentFileDir == null) {
                        continue;
                    }
                    VirtualFile srcDir = studentFileDir.findChild(EduNames.SRC);
                    if (srcDir != null) {
                        studentFileDir = srcDir;
                    }
                    if (task.hasSubtasks()) {
                        transformSubtaskTestsToTextFiles(studentFileDir);
                    }
                    for (String taskFile : task.getTaskFiles().keySet()) {
                        VirtualFile answerFile = taskDir.findFileByRelativePath(taskFile);
                        if (answerFile == null) {
                            continue;
                        }
                        EduUtils.createStudentFile(this, project, answerFile, studentFileDir, task, 0);
                    }
                }
            }
        }

        private void transformSubtaskTestsToTextFiles(VirtualFile studentFileDir) {
            Condition<VirtualFile> isSubtaskTestFile = file -> CCUtils.isTestsFile(project, file) && file.getName().contains(EduNames.SUBTASK_MARKER);
            List<VirtualFile> subtaskTests = ContainerUtil.filter(Arrays.asList(studentFileDir.getChildren()), isSubtaskTestFile);
            for (VirtualFile subtaskTest : subtaskTests) {
                try {
                    subtaskTest.rename(this, subtaskTest.getNameWithoutExtension() + ".txt");
                } catch (IOException e) {
                    LOG.error(e);
                }
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ZipOutputStream(java.util.zip.ZipOutputStream) Arrays(java.util.Arrays) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Presentation(com.intellij.openapi.actionSystem.Presentation) EduUsagesCollector(com.jetbrains.edu.learning.statistics.EduUsagesCollector) ContainerUtil(com.intellij.util.containers.ContainerUtil) GsonBuilder(com.google.gson.GsonBuilder) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) ProjectView(com.intellij.ide.projectView.ProjectView) CreateCourseArchiveDialog(com.jetbrains.edu.coursecreator.ui.CreateCourseArchiveDialog) EduUtils(com.jetbrains.edu.learning.core.EduUtils) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) CCLanguageManager(com.jetbrains.edu.coursecreator.CCLanguageManager) Gson(com.google.gson.Gson) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) Lesson(com.jetbrains.edu.learning.courseFormat.Lesson) StudyTaskManager(com.jetbrains.edu.learning.StudyTaskManager) Task(com.jetbrains.edu.learning.courseFormat.Task) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) List(java.util.List) java.io(java.io) EduNames(com.jetbrains.edu.learning.core.EduNames) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ApplicationManager(com.intellij.openapi.application.ApplicationManager) VfsUtil(com.intellij.openapi.vfs.VfsUtil) LangDataKeys(com.intellij.openapi.actionSystem.LangDataKeys) NotNull(org.jetbrains.annotations.NotNull) ZipUtil(com.intellij.util.io.ZipUtil) CCUtils(com.jetbrains.edu.coursecreator.CCUtils) Course(com.jetbrains.edu.learning.courseFormat.Course) Condition(com.intellij.openapi.util.Condition) Condition(com.intellij.openapi.util.Condition) Task(com.jetbrains.edu.learning.courseFormat.Task) CCLanguageManager(com.jetbrains.edu.coursecreator.CCLanguageManager) Lesson(com.jetbrains.edu.learning.courseFormat.Lesson) List(java.util.List) Course(com.jetbrains.edu.learning.courseFormat.Course) VirtualFile(com.intellij.openapi.vfs.VirtualFile)

Example 2 with CCLanguageManager

use of com.jetbrains.edu.coursecreator.CCLanguageManager in project intellij-community by JetBrains.

the class CCNewSubtaskAction method createTestsForNewSubtask.

private static void createTestsForNewSubtask(Project project, Task task) {
    Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course == null) {
        return;
    }
    CCLanguageManager manager = CCUtils.getStudyLanguageManager(course);
    if (manager == null) {
        return;
    }
    manager.createTestsForNewSubtask(project, task);
}
Also used : CCLanguageManager(com.jetbrains.edu.coursecreator.CCLanguageManager) Course(com.jetbrains.edu.learning.courseFormat.Course)

Aggregations

CCLanguageManager (com.jetbrains.edu.coursecreator.CCLanguageManager)2 Course (com.jetbrains.edu.learning.courseFormat.Course)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 ProjectView (com.intellij.ide.projectView.ProjectView)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)1 LangDataKeys (com.intellij.openapi.actionSystem.LangDataKeys)1 Presentation (com.intellij.openapi.actionSystem.Presentation)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Module (com.intellij.openapi.module.Module)1 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)1 Project (com.intellij.openapi.project.Project)1 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)1 Messages (com.intellij.openapi.ui.Messages)1 Condition (com.intellij.openapi.util.Condition)1 FileUtil (com.intellij.openapi.util.io.FileUtil)1 VfsUtil (com.intellij.openapi.vfs.VfsUtil)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1