Search in sources :

Example 1 with SandboxModuleBuilder

use of org.stepik.plugin.projectWizard.idea.SandboxModuleBuilder in project intellij-plugins by StepicOrg.

the class StepikProjectManager method refreshCourse.

private void refreshCourse() {
    if (project == null || root == null) {
        return;
    }
    root.setProject(project);
    executor.execute(() -> {
        StepikApiClient stepikApiClient = authAndGetStepikApiClient();
        if (isAuthenticated()) {
            root.reloadData(project, stepikApiClient);
        }
        ProgressManager.getInstance().run(new Task.Backgroundable(project, "Synchronize Project") {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                if (project.isDisposed()) {
                    return;
                }
                repairProjectFiles(root);
                repairSandbox();
                ApplicationManager.getApplication().invokeLater(() -> {
                    VirtualFileManager.getInstance().syncRefresh();
                    setSelected(selected, false);
                });
            }

            private void repairSandbox() {
                VirtualFile projectDir = project.getBaseDir();
                if (projectDir != null && projectDir.findChild(EduNames.SANDBOX_DIR) == null) {
                    Application application = ApplicationManager.getApplication();
                    ModifiableModuleModel model = application.runReadAction((Computable<ModifiableModuleModel>) () -> ModuleManager.getInstance(project).getModifiableModel());
                    application.invokeLater(() -> application.runWriteAction(() -> {
                        try {
                            new SandboxModuleBuilder(projectDir.getPath()).createModule(model);
                            model.commit();
                        } catch (IOException | ConfigurationException | JDOMException | ModuleWithNameAlreadyExists e) {
                            logger.warn("Failed repair Sandbox", e);
                        }
                    }));
                }
            }
        });
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StepikAuthManager.authAndGetStepikApiClient(org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient) StepikApiClient(org.stepik.api.client.StepikApiClient) Task(com.intellij.openapi.progress.Task) SandboxModuleBuilder(org.stepik.plugin.projectWizard.idea.SandboxModuleBuilder) ModuleWithNameAlreadyExists(com.intellij.openapi.module.ModuleWithNameAlreadyExists) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) ConfigurationException(com.intellij.openapi.options.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Application(com.intellij.openapi.application.Application) Computable(com.intellij.openapi.util.Computable)

Aggregations

Application (com.intellij.openapi.application.Application)1 ModifiableModuleModel (com.intellij.openapi.module.ModifiableModuleModel)1 ModuleWithNameAlreadyExists (com.intellij.openapi.module.ModuleWithNameAlreadyExists)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 Computable (com.intellij.openapi.util.Computable)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 JDOMException (org.jdom.JDOMException)1 StepikApiClient (org.stepik.api.client.StepikApiClient)1 StepikAuthManager.authAndGetStepikApiClient (org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient)1 SandboxModuleBuilder (org.stepik.plugin.projectWizard.idea.SandboxModuleBuilder)1