Resolve merge conflicts
authorValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Wed, 15 Jun 2016 13:04:25 +0000 (16:04 +0300)
committerValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Wed, 15 Jun 2016 13:04:25 +0000 (16:04 +0300)
18 files changed:
1  2 
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/CCRefactoringElementListenerProvider.java
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/CCUtils.java
python/educational-core/student/resources/META-INF/plugin.xml
python/educational-core/student/src/com/jetbrains/edu/learning/StudyTaskManager.java
python/educational-core/student/src/com/jetbrains/edu/learning/StudyUtils.java
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyRefreshAnswerPlaceholder.java
python/educational-core/student/src/com/jetbrains/edu/learning/actions/StudyRefreshTaskFileAction.java
python/educational-core/student/src/com/jetbrains/edu/learning/checker/StudyCheckUtils.java
python/educational-core/student/src/com/jetbrains/edu/learning/checker/StudySmartChecker.java
python/educational-core/student/src/com/jetbrains/edu/learning/courseFormat/Course.java
python/educational-core/student/src/com/jetbrains/edu/learning/courseFormat/Task.java
python/educational-core/student/src/com/jetbrains/edu/learning/courseGeneration/StudyGenerator.java
python/educational-core/student/src/com/jetbrains/edu/learning/courseGeneration/StudyProjectGenerator.java
python/educational-core/student/src/com/jetbrains/edu/learning/stepic/EduStepicConnector.java
python/educational-core/student/src/com/jetbrains/edu/learning/ui/StudyNewProjectPanel.java
python/educational-core/student/src/com/jetbrains/edu/learning/ui/StudyToolWindow.java
python/educational-core/student/student.iml
python/educational-python/student-python/src/com/jetbrains/edu/learning/PyStudyCheckAction.java

index 78f8a7133005f9790976d1dc9202ecec48c19573,a967515323176f7b4f85d90b46a333cdd849e294..175007d52afcc5646cd1132f21fe2ec907b1a0d3
@@@ -36,9 -37,7 +38,10 @@@ import com.intellij.psi.PsiFile
  import com.intellij.ui.JBColor;
  import com.intellij.ui.awt.RelativePoint;
  import com.intellij.ui.content.Content;
+ import com.intellij.util.TimeoutUtil;
 +import com.intellij.util.ObjectUtils;
 +import com.intellij.util.containers.ContainerUtil;
 +import com.intellij.util.text.MarkdownUtil;
  import com.intellij.util.ui.UIUtil;
  import com.jetbrains.edu.learning.checker.StudyExecutor;
  import com.jetbrains.edu.learning.checker.StudyTestRunner;
@@@ -58,9 -57,11 +62,12 @@@ import org.jetbrains.annotations.Nullab
  import javax.swing.*;
  import java.awt.*;
  import java.io.*;
 +import java.util.ArrayList;
  import java.util.Collection;
  import java.util.List;
+ import java.util.concurrent.Callable;
+ import java.util.concurrent.ExecutionException;
+ import java.util.concurrent.Future;
  
  public class StudyUtils {
    private StudyUtils() {
      return null;
    }
  
+   // supposd to be called under progress
+   @Nullable
+   public static <T> T execCancelable(@NotNull final Callable<T> callable) {
+     final Future<T> future = ApplicationManager.getApplication().executeOnPooledThread(callable);
+     while (!future.isCancelled() && !future.isDone()) {
+       ProgressManager.checkCanceled();
+       TimeoutUtil.sleep(500);
+     }
+     T result = null;
+     try {
+       result = future.get();
+     }
+     catch (InterruptedException | ExecutionException e) {
+       LOG.warn(e.getMessage());
+     }
+     return result;
+   }
+   @Nullable
+   public static Task getTaskFromSelectedEditor(Project project) {
+     final StudyEditor editor = getSelectedStudyEditor(project);
+     Task task = null;
+     if (editor != null) {
+       final TaskFile file = editor.getTaskFile();
+       task = file.getTask();
+     }
+     return task;
+   }
++
 +  private static String convertToHtml(@NotNull final String content) {
 +    ArrayList<String> lines = ContainerUtil.newArrayList(content.split("\n|\r|\r\n"));
 +    MarkdownUtil.replaceHeaders(lines);
 +    MarkdownUtil.replaceCodeBlock(lines);
 +    
 +    return new MarkdownProcessor().markdown(StringUtil.join(lines, "\n"));
 +  }
 +  
 +  public static boolean isTaskDescriptionFile(@NotNull final String fileName) {
 +    return EduNames.TASK_HTML.equals(fileName) || EduNames.TASK_MD.equals(fileName);
 +  }
 +  
 +  @Nullable
 +  public static VirtualFile findTaskDescriptionVirtualFile(@NotNull final VirtualFile parent) {
 +    return ObjectUtils.chooseNotNull(parent.findChild(EduNames.TASK_HTML), parent.findChild(EduNames.TASK_MD));
 +  }
 +  
 +  @NotNull
 +  public static String getTaskDescriptionFileName(final boolean useHtml) {
 +    return useHtml ? EduNames.TASK_HTML : EduNames.TASK_MD;    
 +  }
 +  
 +  @Nullable
 +  public static File createTaskDescriptionFile(@NotNull final File parent) {
 +    if(new File(parent, EduNames.TASK_HTML).exists()) {
 +      return new File(parent, EduNames.TASK_HTML);
 +    }
 +    else {
 +      return new File(parent, EduNames.TASK_MD);
 +    }
 +  }
  }
index 16201112691646e3be6200f9d9ed9696b6e315b8,53d7a78b3034cf7b65c152cc81a99c99b241974f..03dbc110882c5f6d523a4f212f7b324887bc2f9b
@@@ -76,8 -72,13 +72,8 @@@ public class Course 
      return authors;
    }
  
-   public static String getAuthorsString(@NotNull List<CourseInfo.Author> authors) {
+   public static String getAuthorsString(@NotNull List<StepicUser> authors) {
 -    return StringUtil.join(authors, new Function<StepicUser, String>() {
 -      @Override
 -      public String fun(StepicUser author) {
 -        return author.getName();
 -      }
 -    }, ", ");
 +    return StringUtil.join(authors, author -> author.getName(), ", ");
    }
  
    public void setAuthors(String[] authors) {
index 57b84b9f6df1de65db6f85ebb209bcfccbddb32f,fe5cd4e65c40b909b67504145b8ba6ae9139667a..6e031380977b1b9021ddbdcb20bf089f1d3ff156
@@@ -106,30 -108,32 +106,30 @@@ public class StudyGenerator 
    public static void createCourse(@NotNull final Course course, @NotNull final VirtualFile baseDir, @NotNull final File resourceRoot,
                                    @NotNull final Project project) {
  
-               try {
-                 final List<Lesson> lessons = course.getLessons();
-                 for (int i = 1; i <= lessons.size(); i++) {
-                   Lesson lesson = lessons.get(i - 1);
-                   lesson.setIndex(i);
-                   createLesson(lesson, baseDir, resourceRoot, project);
-                 }
-                 baseDir.createChildDirectory(project, EduNames.SANDBOX_DIR);
-                 File[] files = resourceRoot.listFiles(
-                   (dir, name) -> !name.contains(EduNames.LESSON) && !name.equals(EduNames.COURSE_META_FILE) && !name.equals(EduNames.HINTS));
-                 for (File file : files) {
-                   File dir = new File(baseDir.getPath(), file.getName());
-                   if (file.isDirectory()) {
-                     FileUtil.copyDir(file, dir);
-                     continue;
-                   }
-                   FileUtil.copy(file, dir);
-                 }
-               }
-               catch (IOException e) {
-                 LOG.error(e);
-               }
+     try {
+       final List<Lesson> lessons = course.getLessons();
+       for (int i = 1; i <= lessons.size(); i++) {
+         Lesson lesson = lessons.get(i - 1);
+         lesson.setIndex(i);
+         createLesson(lesson, baseDir, resourceRoot, project);
+       }
+       baseDir.createChildDirectory(project, EduNames.SANDBOX_DIR);
 -      File[] files = resourceRoot.listFiles(new FilenameFilter() {
 -        @Override
 -        public boolean accept(File dir, String name) {
 -          return !name.contains(EduNames.LESSON) && !name.equals(EduNames.COURSE_META_FILE) && !name.equals(EduNames.HINTS);
 -        }
 -      });
++      File[] files = resourceRoot.listFiles(
++        (dir, name) -> !name.contains(EduNames.LESSON) && !name.equals(EduNames.COURSE_META_FILE) && !name.equals(EduNames.HINTS));
+       for (File file : files) {
+         File dir = new File(baseDir.getPath(), file.getName());
+         if (file.isDirectory()) {
+           FileUtil.copyDir(file, dir);
+           continue;
+         }
 -
++  
+         FileUtil.copy(file, dir);
++  
+       }
+     }
+     catch (IOException e) {
+       LOG.error(e);
+     }
    }
 +
  }
index 8a20545cfc2ed02c9a2b6522c6ff54bc60c9cc13,8326b670e12c23ad3173979792e234d189e511d3..f796dddbaad9e1cf0445bdd266b8e86431f913bf
@@@ -270,8 -302,10 +301,9 @@@ public class EduStepicConnector 
      return null;
    }
  
 -
    public static List<Lesson> getLessons(int sectionId) throws IOException {
-     final SectionContainer sectionContainer = getFromStepic("sections/" + String.valueOf(sectionId), SectionContainer.class);
+     final StepicWrappers.SectionContainer
+       sectionContainer = getFromStepic("sections/" + String.valueOf(sectionId), StepicWrappers.SectionContainer.class);
      List<Integer> unitIds = sectionContainer.sections.get(0).units;
      final List<Lesson> lessons = new ArrayList<Lesson>();
      for (Integer unitId : unitIds) {
      final HttpPost request = new HttpPost(stepicApiUrl + "step-sources");
      setHeaders(request, "application/json");
      final Gson gson = new GsonBuilder().setPrettyPrinting().excludeFieldsWithoutExposeAnnotation().create();
 -    ApplicationManager.getApplication().invokeLater(new Runnable() {
 -      @Override
 -      public void run() {
 -        final String requestBody = gson.toJson(new StepicWrappers.StepSourceWrapper(project, task, lessonId));
 -        request.setEntity(new StringEntity(requestBody, ContentType.APPLICATION_JSON));
 +    ApplicationManager.getApplication().invokeLater(() -> {
-       final String requestBody = gson.toJson(new StepSourceWrapper(project, task, lessonId));
++      final String requestBody = gson.toJson(new StepicWrappers.StepSourceWrapper(project, task, lessonId));
 +      request.setEntity(new StringEntity(requestBody, ContentType.APPLICATION_JSON));
  
 -        try {
 -          final CloseableHttpResponse response = ourClient.execute(request);
 -          final StatusLine line = response.getStatusLine();
 -          if (line.getStatusCode() != HttpStatus.SC_CREATED) {
 -            final HttpEntity responseEntity = response.getEntity();
 -            final String responseString = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
 -            LOG.error("Failed to push " + responseString);
 -          }
 -        }
 -        catch (IOException e) {
 -          LOG.error(e.getMessage());
 +      try {
 +        final CloseableHttpResponse response = ourClient.execute(request);
 +        final StatusLine line = response.getStatusLine();
 +        if (line.getStatusCode() != HttpStatus.SC_CREATED) {
 +          final HttpEntity responseEntity = response.getEntity();
 +          final String responseString = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
 +          LOG.error("Failed to push " + responseString);
          }
        }
 +      catch (IOException e) {
 +        LOG.error(e.getMessage());
 +      }
      });
    }
  
index 846b93633f8749ab5fd84e061b0350d261b3cb17,1aad834bb9fc3cc01cfeaac28f63dd0efb680555..d47ef138d30884dbbcb0cbd8c6cd8ef19f7e621e
@@@ -33,8 -33,10 +33,9 @@@ import com.intellij.ui.JBCardLayout
  import com.intellij.ui.OnePixelSplitter;
  import com.intellij.util.ui.JBUI;
  import com.jetbrains.edu.learning.*;
 -import com.jetbrains.edu.learning.core.EduNames;
  import com.jetbrains.edu.learning.courseFormat.Course;
  import com.jetbrains.edu.learning.courseFormat.TaskFile;
+ import com.jetbrains.edu.learning.stepic.StepicAdaptiveReactionsPanel;
  import org.jetbrains.annotations.NotNull;
  
  import javax.swing.*;
index bbd07b593eaeeabee1da043dc63737671e3c6b2d,0758b722ce7cd9d1e561d9e3bb1988276414bea8..5fff6115855f89dcc70fcfebd6c6f4934f66a94a
@@@ -21,7 -21,8 +21,9 @@@
          <SOURCES />
        </library>
      </orderEntry>
+     <orderEntry type="module" module-name="platform-api" />
+     <orderEntry type="module" module-name="python-community" />
      <orderEntry type="module" module-name="xml" />
 +    <orderEntry type="library" name="markdownj" level="project" />
    </component>
  </module>
index 7fb403665248f1e345da751c62b0f585a167d011,14aac4c80d4ef679d4a6a0676cb46089e7ba829a..60e91394b8ab251ab30db2d704b6cb0568b1931d
@@@ -31,47 -32,49 +32,47 @@@ public class PyStudyCheckAction extend
    public static final String ACTION_ID = "PyCheckAction";
    
    public void check(@NotNull Project project) {
 -    ApplicationManager.getApplication().runWriteAction(() -> {
 -      CommandProcessor.getInstance().runUndoTransparentAction(() -> {
 -        final StudyEditor selectedEditor = StudyUtils.getSelectedStudyEditor(project);
 -        if (selectedEditor == null) return;
 -        final StudyState studyState = new StudyState(selectedEditor);
 -        if (!studyState.isValid()) {
 -          LOG.info("StudyCheckAction was invoked outside study editor");
 -          return;
 -        }
 -        if (StudyCheckUtils.hasBackgroundProcesses(project)) return;
 +    ApplicationManager.getApplication().runWriteAction(() -> CommandProcessor.getInstance().runUndoTransparentAction(() -> {
 +      final StudyEditor selectedEditor = StudyUtils.getSelectedStudyEditor(project);
 +      if (selectedEditor == null) return;
 +      final StudyState studyState = new StudyState(selectedEditor);
 +      if (!studyState.isValid()) {
 +        LOG.info("StudyCheckAction was invoked outside study editor");
 +        return;
 +      }
 +      if (StudyCheckUtils.hasBackgroundProcesses(project)) return;
  
-       if (!runTask(project)) return;
 -        final Course course = StudyTaskManager.getInstance(project).getCourse();
 -        if (course != null && !course.isAdaptive() && !runTask(project)) return;
++      final Course course = StudyTaskManager.getInstance(project).getCourse();
++      if (course != null && !course.isAdaptive() && !runTask(project)) return;
  
 -        final Task task = studyState.getTask();
 -        final VirtualFile taskDir = studyState.getTaskDir();
 -        StudyCheckUtils.flushWindows(task, taskDir);
 +      final Task task = studyState.getTask();
 +      final VirtualFile taskDir = studyState.getTaskDir();
 +      StudyCheckUtils.flushWindows(task, taskDir);
  
  
 -        ApplicationManager.getApplication().invokeLater(
 -          () -> IdeFocusManager.getInstance(project).requestFocus(studyState.getEditor().getComponent(), true));
 +      ApplicationManager.getApplication().invokeLater(
 +        () -> IdeFocusManager.getInstance(project).requestFocus(studyState.getEditor().getComponent(), true));
  
 -        final StudyTestRunner testRunner = StudyUtils.getTestRunner(task, taskDir);
 -        Process testProcess = null;
 -        String commandLine = "";
 -        try {
 -          final VirtualFile executablePath = getTaskVirtualFile(studyState, task, taskDir);
 -          if (executablePath != null) {
 -            commandLine = executablePath.getPath();
 -            testProcess = testRunner.createCheckProcess(project, commandLine);
 -          }
 -        }
 -        catch (ExecutionException e) {
 -          LOG.error(e);
 -        }
 -        if (testProcess == null) {
 -          return;
 +      final StudyTestRunner testRunner = StudyUtils.getTestRunner(task, taskDir);
 +      Process testProcess = null;
 +      String commandLine = "";
 +      try {
 +        final VirtualFile executablePath = getTaskVirtualFile(studyState, task, taskDir);
 +        if (executablePath != null) {
 +          commandLine = executablePath.getPath();
 +          testProcess = testRunner.createCheckProcess(project, commandLine);
          }
 -        myCheckInProgress.set(true);
 -        StudyCheckTask checkTask = getCheckTask(project, studyState, testRunner, testProcess, commandLine);
 -        ProgressManager.getInstance().run(checkTask);
 -      });
 -    });
 +      }
 +      catch (ExecutionException e) {
 +        LOG.error(e);
 +      }
 +      if (testProcess == null) {
 +        return;
 +      }
 +      myCheckInProgress.set(true);
 +      StudyCheckTask checkTask = getCheckTask(project, studyState, testRunner, testProcess, commandLine);
 +      ProgressManager.getInstance().run(checkTask);
 +    }));
    }
  
    private static boolean runTask(@NotNull Project project) {