EDU-338 Add supported python versions info to the course.json

This commit is contained in:
liana.bakradze
2016-07-16 11:18:55 +03:00
parent b29c18c606
commit 7038e3e9aa
6 changed files with 95 additions and 16 deletions
@@ -44,7 +44,7 @@ public class CCUtils {
@Nullable
public static CCLanguageManager getStudyLanguageManager(@NotNull final Course course) {
Language language = Language.findLanguageByID(course.getLanguage());
Language language = Language.findLanguageByID(course.getLanguageID());
return language == null ? null : CCLanguageManager.INSTANCE.forLanguage(language);
}
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.jetbrains.edu.coursecreator.ui.CCNewProjectPanel">
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="4" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="666" height="488"/>
@@ -26,7 +26,7 @@
</component>
<component id="ec56c" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false">
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="80" height="-1"/>
</grid>
</constraints>
@@ -52,7 +52,7 @@
</component>
<component id="389a7" class="javax.swing.JTextArea" binding="myDescription">
<constraints>
<grid row="2" column="1" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="3" indent="0" use-parent-layout="false">
<grid row="3" column="1" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="-1" height="50"/>
</grid>
</constraints>
@@ -60,6 +60,20 @@
<lineWrap value="true"/>
</properties>
</component>
<component id="aa51f" class="javax.swing.JLabel" binding="myLanguageLevelLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Label"/>
</properties>
</component>
<component id="cfe00" class="com.intellij.openapi.ui.ComboBox" binding="myLanguageLevelCombobox">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
</form>
@@ -1,10 +1,12 @@
package com.jetbrains.edu.coursecreator.ui;
import com.intellij.facet.ui.FacetValidatorsManager;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.DocumentAdapter;
import com.intellij.ui.JBColor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
@@ -14,10 +16,14 @@ public class CCNewProjectPanel {
private JTextArea myDescription;
private JTextField myName;
private JTextField myAuthorField;
private JLabel myLanguageLevelLabel;
private ComboBox<String> myLanguageLevelCombobox;
private FacetValidatorsManager myValidationManager;
public CCNewProjectPanel() {
myLanguageLevelLabel.setVisible(false);
myLanguageLevelCombobox.setVisible(false);
final String userName = System.getProperty("user.name");
if (userName != null) {
myAuthorField.setText(userName);
@@ -81,4 +87,20 @@ public class CCNewProjectPanel {
public JTextField getNameField() {
return myName;
}
public JLabel getLanguageLevelLabel() {
return myLanguageLevelLabel;
}
public ComboBox<String> getLanguageLevelCombobox() {
return myLanguageLevelCombobox;
}
@Nullable
public String getLanguageVersion() {
if (!myLanguageLevelCombobox.isVisible() || myLanguageLevelCombobox.getItemCount() == 0) {
return null;
}
return (String)myLanguageLevelCombobox.getSelectedItem();
}
}
@@ -10,6 +10,7 @@ import com.jetbrains.edu.learning.core.EduUtils;
import com.jetbrains.edu.learning.stepic.StepicUser;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
@@ -122,9 +123,14 @@ public class Course {
}
public Language getLanguageById() {
return Language.findLanguageByID(myLanguage);
return Language.findLanguageByID(getLanguageID());
}
/**
* This method should be used by serialized only
* Use {@link #getLanguageID()} and {@link #getLanguageVersion()} methods instead
*/
@Deprecated
public String getLanguage() {
return myLanguage;
}
@@ -133,6 +139,19 @@ public class Course {
myLanguage = language;
}
public String getLanguageID() {
return myLanguage.split(" ")[0];
}
@Nullable
public String getLanguageVersion() {
String[] split = myLanguage.split(" ");
if (split.length <= 1) {
return null;
}
return split[1];
}
public void setAuthors(List<StepicUser> authors) {
this.authors = authors;
}
@@ -12,6 +12,7 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.platform.DirectoryProjectGenerator;
@@ -27,6 +28,7 @@ import com.jetbrains.edu.learning.courseFormat.Course;
import com.jetbrains.edu.learning.statistics.EduUsagesCollector;
import com.jetbrains.python.PythonLanguage;
import com.jetbrains.python.newProject.PythonProjectGenerator;
import com.jetbrains.python.psi.LanguageLevel;
import icons.CourseCreatorPythonIcons;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
@@ -38,6 +40,9 @@ import java.io.File;
public class PyCCProjectGenerator extends PythonProjectGenerator implements DirectoryProjectGenerator {
private static final Logger LOG = Logger.getInstance(PyCCProjectGenerator.class);
public static final String ALL_VERSIONS = "All versions";
public static final String PYTHON_3 = "3x";
public static final String PYTHON_2 = "2x";
private CCNewProjectPanel mySettingsPanel;
@Nls
@@ -56,14 +61,11 @@ public class PyCCProjectGenerator extends PythonProjectGenerator implements Dire
@Override
public void generateProject(@NotNull final Project project, @NotNull final VirtualFile baseDir,
@Nullable Object settings, @NotNull Module module) {
generateProject(project, baseDir, mySettingsPanel.getName(),
mySettingsPanel.getAuthors(), mySettingsPanel.getDescription());
generateProject(project, baseDir, mySettingsPanel);
}
public static void generateProject(@NotNull final Project project, @NotNull final VirtualFile baseDir,
@NotNull final String name, @NotNull final String[] authors,
@NotNull final String description) {
final Course course = getCourse(project, name, authors, description);
public static void generateProject(@NotNull final Project project, @NotNull final VirtualFile baseDir, CCNewProjectPanel settingsPanel) {
final Course course = getCourse(project, settingsPanel);
EduUsagesCollector.projectTypeCreated(CCUtils.COURSE_MODE);
final PsiDirectory projectDir = PsiManager.getInstance(project).findDirectory(baseDir);
@@ -94,12 +96,19 @@ public class PyCCProjectGenerator extends PythonProjectGenerator implements Dire
}
@NotNull
private static Course getCourse(@NotNull Project project, @NotNull String name, @NotNull String[] authors, @NotNull String description) {
private static Course getCourse(@NotNull Project project, @NotNull CCNewProjectPanel settingsPanel) {
final Course course = new Course();
String name = settingsPanel.getName();
course.setName(name);
course.setAuthors(authors);
course.setDescription(description);
course.setLanguage(PythonLanguage.getInstance().getID());
course.setAuthors(settingsPanel.getAuthors());
course.setDescription(settingsPanel.getDescription());
String language = PythonLanguage.getInstance().getID();
String version = settingsPanel.getLanguageVersion();
if (version != null && !ALL_VERSIONS.equals(version)) {
language += " " + version;
}
course.setLanguage(language);
course.setCourseMode(CCUtils.COURSE_MODE);
File coursesDir = new File(PathManager.getConfigPath(), "courses");
@@ -125,6 +134,7 @@ public class PyCCProjectGenerator extends PythonProjectGenerator implements Dire
@Override
public JPanel extendBasePanel() throws ProcessCanceledException {
mySettingsPanel = new CCNewProjectPanel();
setupLanguageLevels(mySettingsPanel);
mySettingsPanel.registerValidators(new FacetValidatorsManager() {
public void registerValidator(FacetEditorValidator validator, JComponent... componentsToWatch) {
throw new UnsupportedOperationException();
@@ -136,4 +146,18 @@ public class PyCCProjectGenerator extends PythonProjectGenerator implements Dire
});
return mySettingsPanel.getMainPanel();
}
private static void setupLanguageLevels(CCNewProjectPanel panel) {
JLabel languageLevelLabel = panel.getLanguageLevelLabel();
languageLevelLabel.setText("Python Version:");
languageLevelLabel.setVisible(true);
ComboBox<String> languageLevelCombobox = panel.getLanguageLevelCombobox();
languageLevelCombobox.addItem(ALL_VERSIONS);
languageLevelCombobox.addItem(PYTHON_3);
languageLevelCombobox.addItem(PYTHON_2);
for (LanguageLevel level : LanguageLevel.values()) {
languageLevelCombobox.addItem(level.toString());
}
languageLevelCombobox.setVisible(true);
}
}
@@ -34,6 +34,6 @@ public class PyStudyPluginConfigurator extends StudyBasePluginConfigurator {
StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
if (taskManager == null) return false;
Course course = taskManager.getCourse();
return course != null && "Python".equals(course.getLanguage()) && "PyCharm".equals(course.getCourseType());
return course != null && "Python".equals(course.getLanguageID()) && "PyCharm".equals(course.getCourseType());
}
}