Merge remote-tracking branch 'origin/master'

This commit is contained in:
Vitaliy.Bibaev
2016-12-16 16:17:22 +03:00
8 changed files with 145 additions and 68 deletions
@@ -15,7 +15,6 @@
*/
package com.intellij.compiler;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.AbstractProjectComponent;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.project.Project;
@@ -29,7 +28,6 @@ import org.jetbrains.annotations.Nullable;
public abstract class CompilerReferenceService extends AbstractProjectComponent {
public static final RegistryValue IS_ENABLED_KEY = Registry.get("compiler.ref.index");
public static volatile boolean enabledInTests = false;
protected CompilerReferenceService(Project project) {
super(project);
@@ -55,6 +53,6 @@ public abstract class CompilerReferenceService extends AbstractProjectComponent
@NotNull FileType searchFileType);
public static boolean isEnabled() {
return (!ApplicationManager.getApplication().isHeadlessEnvironment() || enabledInTests) && IS_ENABLED_KEY.asBoolean();
return IS_ENABLED_KEY.asBoolean();
}
}
@@ -44,7 +44,6 @@ import com.intellij.ui.FocusTrackback;
import com.intellij.ui.ScreenUtil;
import com.intellij.ui.components.JBLayeredPane;
import com.intellij.util.ui.JBInsets;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -383,9 +382,10 @@ public class GlassPaneDialogWrapperPeer extends DialogWrapperPeer implements Foc
private JComponent myContentPane;
private MyRootPane myRootPane;
private BufferedImage shadow;
private int shadowWidth;
private int shadowHeight;
private final JLayeredPane myTransparentPane;
private JButton myDefaultButton;
private Dimension myShadowSize = null;
private final Container myWrapperPane;
private Component myPreviouslyFocusedComponent;
private Dimension myCachedSize = null;
@@ -468,10 +468,6 @@ public class GlassPaneDialogWrapperPeer extends DialogWrapperPeer implements Foc
return result;
}
public Container getTransparentPane() {
return myTransparentPane;
}
private TransparentLayeredPane getExistingTransparentPane() {
for (int i = 0; i < myPane.getComponentCount(); i++) {
Component c = myPane.getComponent(i);
@@ -570,15 +566,13 @@ public class GlassPaneDialogWrapperPeer extends DialogWrapperPeer implements Foc
}
super.setBounds(x, y, width, height);
if (myShadowSize == null || !myShadowSize.equals(getSize())) {
createShadow();
myShadowSize = getSize();
if (RemoteDesktopDetector.isRemoteSession()) {
shadow = null;
}
}
private void createShadow() {
if (!RemoteDesktopDetector.isRemoteSession() && !JBUI.isHiDPI()) {
shadow = ShadowBorderPainter.createShadow(this, getWidth(), getHeight());
else if (shadow == null || shadowWidth != width || shadowHeight != height) {
shadow = ShadowBorderPainter.createShadow(this, width, height);
shadowWidth = width;
shadowHeight = height;
}
}
@@ -310,7 +310,11 @@ public class StudyUtils {
if (manager == null) {
return false;
}
return manager.getTestFileName().equals(name);
String testFileName = manager.getTestFileName();
if (name.equals(testFileName)) {
return true;
}
return name.startsWith(FileUtil.getNameWithoutExtension(testFileName)) && name.contains(EduNames.SUBTASK_MARKER);
}
@Nullable
@@ -39,6 +39,7 @@ public class Task implements StudyItem {
private String text;
private Map<String, String> testsText = new HashMap<>();
private Map<String, String> taskTexts = new HashMap<>();
@Transient private Lesson myLesson;
@Expose @SerializedName("update_date") private Date myUpdateDate;
@@ -95,10 +96,18 @@ public class Task implements StudyItem {
return testsText;
}
public Map<String, String> getTaskTexts() {
return taskTexts;
}
public void addTestsTexts(String name, String text) {
testsText.put(name, text);
}
public void addTaskText(String name, String text) {
taskTexts.put(name, text);
}
public Map<String, TaskFile> getTaskFiles() {
return taskFiles;
}
@@ -222,9 +222,11 @@ public class StudyProjectGenerator {
flushCourseJson(course, courseDirectory);
int lessonIndex = 1;
List<Lesson> additionalLessons = new ArrayList<>();
for (Lesson lesson : course.getLessons()) {
if (lesson.getName().equals(EduNames.PYCHARM_ADDITIONAL)) {
flushAdditionalFiles(courseDirectory, lesson);
additionalLessons.add(lesson);
}
else {
final File lessonDirectory = new File(courseDirectory, EduNames.LESSON + String.valueOf(lessonIndex));
@@ -232,6 +234,9 @@ public class StudyProjectGenerator {
lessonIndex += 1;
}
}
for (Lesson lesson : additionalLessons) {
course.getLessons().remove(lesson);
}
}
private static void flushAdditionalFiles(File courseDirectory, Lesson lesson) {
@@ -284,30 +289,43 @@ public class StudyProjectGenerator {
}
}
catch (IOException e) {
LOG.error("ERROR copying file " + name);
LOG.error(e);
}
}
final Map<String, String> testsText = task.getTestsText();
for (Map.Entry<String, String> entry : testsText.entrySet()) {
final File testsFile = new File(taskDirectory, entry.getKey());
if (testsFile.exists()) {
FileUtil.delete(testsFile);
}
FileUtil.createIfDoesntExist(testsFile);
try {
FileUtil.writeToFile(testsFile, entry.getValue());
}
catch (IOException e) {
LOG.error("ERROR copying tests file");
}
createFiles(taskDirectory, task.getTestsText());
if (task.getTaskTexts().isEmpty()) {
createTaskHtml(task, taskDirectory);
return;
}
final File taskText = new File(taskDirectory, "task.html");
task.setText(null);
createFiles(taskDirectory, task.getTaskTexts());
}
private static void createTaskHtml(@NotNull Task task, @NotNull File taskDirectory) {
final File taskText = new File(taskDirectory, EduNames.TASK_HTML);
FileUtil.createIfDoesntExist(taskText);
try {
FileUtil.writeToFile(taskText, task.getText());
}
catch (IOException e) {
LOG.error("ERROR copying tests file");
LOG.error(e);
}
}
private static void createFiles(@NotNull File taskDirectory, Map<String, String> files) {
for (Map.Entry<String, String> entry : files.entrySet()) {
final File file = new File(taskDirectory, entry.getKey());
if (file.exists()) {
FileUtil.delete(file);
}
FileUtil.createIfDoesntExist(file);
try {
FileUtil.writeToFile(file, entry.getValue());
}
catch (IOException e) {
LOG.error(e);
}
}
}
@@ -432,7 +432,7 @@ public class EduAdaptiveStepicConnector {
}
if (step.options.test != null) {
for (StepicWrappers.TestFileWrapper wrapper : step.options.test) {
for (StepicWrappers.FileWrapper wrapper : step.options.test) {
task.addTestsTexts(wrapper.name, wrapper.text);
}
}
@@ -230,17 +230,17 @@ public class EduStepicConnector {
public static List<Lesson> getLessons(@NotNull Project project, int sectionId) throws IOException {
final StepicWrappers.SectionContainer
sectionContainer = EduStepicClient.getFromStepic(EduStepicNames.SECTIONS + String.valueOf(sectionId),
StepicWrappers.SectionContainer.class);
sectionContainer = getFromStepic(EduStepicNames.SECTIONS + String.valueOf(sectionId),
StepicWrappers.SectionContainer.class, project);
List<Integer> unitIds = sectionContainer.sections.get(0).units;
final List<Lesson> lessons = new ArrayList<>();
for (Integer unitId : unitIds) {
StepicWrappers.UnitContainer
unit = EduStepicClient.getFromStepic(EduStepicNames.UNITS + "/" + String.valueOf(unitId), StepicWrappers.UnitContainer.class);
unit = getFromStepic(EduStepicNames.UNITS + "/" + String.valueOf(unitId), StepicWrappers.UnitContainer.class, project);
int lessonID = unit.units.get(0).lesson;
StepicWrappers.LessonContainer
lessonContainer = EduStepicClient.getFromStepic(EduStepicNames.LESSONS + String.valueOf(lessonID),
StepicWrappers.LessonContainer.class);
lessonContainer = getFromStepic(EduStepicNames.LESSONS + String.valueOf(lessonID),
StepicWrappers.LessonContainer.class, project);
Lesson lesson = lessonContainer.lessons.get(0);
lesson.taskList = new ArrayList<>();
for (int stepId : lesson.steps) {
@@ -257,6 +257,17 @@ public class EduStepicConnector {
return lessons;
}
private static <T> T getFromStepic(String link, final Class<T> container, @Nullable final Project project) throws IOException{
if (project != null) {
final StepicUser user = StudyTaskManager.getInstance(project).getUser();
final boolean isAuthorized = user.getAccessToken() != null;
if (isAuthorized) {
return EduStepicAuthorizedClient.getFromStepic(link, container, user);
}
}
return EduStepicClient.getFromStepic(link, container);
}
@Nullable
public static Task createTask(@NotNull Project project, int stepicId) throws IOException {
final StepicWrappers.StepSource step = getStep(project, stepicId);
@@ -269,11 +280,17 @@ public class EduStepicConnector {
task.setStepId(stepicId);
task.setUpdateDate(step.update_date);
task.setName(block.options != null ? block.options.title : (PYCHARM_PREFIX + CURRENT_VERSION));
task.setText(block.text);
task.setLastSubtaskIndex(block.options.lastSubtaskIndex);
for (StepicWrappers.TestFileWrapper wrapper : block.options.test) {
for (StepicWrappers.FileWrapper wrapper : block.options.test) {
task.addTestsTexts(wrapper.name, wrapper.text);
}
if (block.options.text != null) {
for (StepicWrappers.FileWrapper wrapper : block.options.text) {
task.addTaskText(wrapper.name, wrapper.text);
}
} else {
task.setText(block.text);
}
task.taskFiles = new HashMap<>(); // TODO: it looks like we don't need taskFiles as map anymore
if (block.options.files != null) {
@@ -285,16 +302,8 @@ public class EduStepicConnector {
}
public static StepicWrappers.StepSource getStep(@NotNull Project project, int step) throws IOException {
final StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
final boolean isAuthorized = taskManager.getUser().getAccessToken() != null;
if (isAuthorized) {
return EduStepicAuthorizedClient.getFromStepic(EduStepicNames.STEPS + String.valueOf(step),
return getFromStepic(EduStepicNames.STEPS + String.valueOf(step),
StepicWrappers.StepContainer.class, project).steps.get(0);
}
else {
return EduStepicClient.getFromStepic(EduStepicNames.STEPS + String.valueOf(step),
StepicWrappers.StepContainer.class).steps.get(0);
}
}
public static void postSolution(@NotNull final Task task, boolean passed, @NotNull final Project project) {
@@ -7,7 +7,9 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.jetbrains.edu.learning.StudyUtils;
import com.jetbrains.edu.learning.core.EduNames;
import com.jetbrains.edu.learning.core.EduUtils;
import com.jetbrains.edu.learning.courseFormat.Course;
@@ -21,6 +23,7 @@ import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.stream.Collectors;
public class StepicWrappers {
private static final Logger LOG = Logger.getInstance(StepOptions.class);
@@ -44,10 +47,10 @@ public class StepicWrappers {
}
public static class StepOptions {
@Expose List<TestFileWrapper> test;
@Expose List<FileWrapper> test;
@Expose String title;
@Expose List<TaskFile> files;
@Expose String text;
@Expose List<FileWrapper> text;
@Expose List<List<String>> samples;
@Expose Integer executionMemoryLimit;
@Expose Integer executionTimeLimit;
@@ -61,6 +64,7 @@ public class StepicWrappers {
final StepOptions source = new StepOptions();
source.lastSubtaskIndex = task.getLastSubtaskIndex();
setTests(task, source, project);
setTaskTexts(task, source, project);
source.files = new ArrayList<>();
source.title = task.getName();
for (final Map.Entry<String, TaskFile> entry : task.getTaskFiles().entrySet()) {
@@ -104,22 +108,63 @@ public class StepicWrappers {
return source;
}
private static void setTests(@NotNull final Task task, @NotNull final StepOptions source, @NotNull final Project project) {
private static void setTaskTexts(@NotNull Task task, @NotNull StepOptions stepOptions, @NotNull Project project) {
stepOptions.text = new ArrayList<>();
VirtualFile taskDir = task.getTaskDir(project);
if (taskDir == null) {
return;
}
List<VirtualFile> taskDescriptionFiles = Arrays.stream(taskDir.getChildren())
.filter(virtualFile -> StudyUtils.isTaskDescriptionFile(virtualFile.getName()))
.collect(Collectors.toList());
for (VirtualFile taskDescriptionFile : taskDescriptionFiles) {
addFileWrapper(taskDescriptionFile, stepOptions.text);
}
}
private static void setTests(@NotNull Task task, @NotNull StepOptions source, @NotNull Project project) {
final Map<String, String> testsText = task.getTestsText();
source.test = new ArrayList<>();
if (testsText.isEmpty()) {
ApplicationManager.getApplication().runReadAction(() -> {
source.test = Collections.singletonList(new TestFileWrapper(EduNames.TESTS_FILE, task.getTestsText(project)));
});
List<VirtualFile> testFiles = getTestFiles(task, project);
for (VirtualFile testFile : testFiles) {
addFileWrapper(testFile, source.test);
}
}
else {
source.test = new ArrayList<>();
for (Map.Entry<String, String> entry : testsText.entrySet()) {
source.test.add(new TestFileWrapper(entry.getKey(), entry.getValue()));
source.test.add(new FileWrapper(entry.getKey(), entry.getValue()));
}
}
}
}
private static void addFileWrapper(@NotNull VirtualFile file, List<FileWrapper> wrappers) {
try {
wrappers.add(new FileWrapper(file.getName(), VfsUtilCore.loadText(file)));
}
catch (IOException e) {
LOG.error(e);
}
}
private static List<VirtualFile> getTestFiles(@NotNull Task task, @NotNull Project project) {
List<VirtualFile> testFiles = new ArrayList<>();
VirtualFile taskDir = task.getTaskDir(project);
if (taskDir == null) {
return testFiles;
}
if (!task.hasSubtasks()) {
VirtualFile testFile = taskDir.findChild(EduNames.TESTS_FILE);
testFiles.add(testFile);
return testFiles;
}
testFiles.addAll(Arrays.stream(taskDir.getChildren())
.filter(file -> StudyUtils.isTestsFile(project, file.getName()))
.collect(Collectors.toList()));
return testFiles;
}
static class CodeTemplatesWrapper {
String python3;
String python27;
@@ -191,11 +236,11 @@ public class StepicWrappers {
}
}
static class TestFileWrapper {
static class FileWrapper {
@Expose public final String name;
@Expose public final String text;
public TestFileWrapper(String name, String text) {
public FileWrapper(String name, String text) {
this.name = name;
this.text = text;
}
@@ -269,12 +314,12 @@ public class StepicWrappers {
public Attempt(int step) {
this.step = step;
}
public boolean isActive() {
return status.equals("active");
}
}
static class Dataset {
boolean is_multiple_choice;
List<String> options;
@@ -382,7 +427,7 @@ public class StepicWrappers {
public SubmissionToPostWrapper(@NotNull String attemptId, @NotNull String language, @NotNull String code) {
submission = new Submission(attemptId, new Submission.CodeReply(language, code));
}
public SubmissionToPostWrapper(@NotNull String attemptId, boolean[] choices) {
submission = new Submission(attemptId, new Submission.ChoiceReply(choices));
}
@@ -396,11 +441,11 @@ public class StepicWrappers {
this.reply = reply;
}
interface Reply {
}
static class CodeReply implements Reply {
String language;
String code;
@@ -410,7 +455,7 @@ public class StepicWrappers {
this.code = code;
}
}
static class ChoiceReply implements Reply {
boolean[] choices;