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);
}
}
}
});
}
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);
}
Aggregations