use of org.stepik.core.StepikProjectManager in project intellij-plugins by StepicOrg.
the class Metrics method postMetrics.
private static void postMetrics(@NotNull Project project, @NotNull Metric metric, @NotNull MetricsStatus status) {
executor.schedule(() -> {
StepikApiClient stepikApiClient;
stepikApiClient = authAndGetStepikApiClient();
if (!isAuthenticated()) {
return;
}
final StepikMetricsPostQuery query = stepikApiClient.metrics().post().timestamp(System.currentTimeMillis() / 1000L).tags(metric.getTags()).data(metric.getData()).name("ide_plugin").tags("name", "S_Union").tags("ide_name", ApplicationInfo.getInstance().getVersionName()).data("ide_version", ApplicationInfo.getInstance().getBuild().toString()).data("plugin_version", PluginUtils.getVersion()).data("session", session).tags("status", status);
StepikProjectManager projectManager = StepikProjectManager.getInstance(project);
if (projectManager != null) {
query.data("project_id", projectManager.getUuid()).tags("project_programming_language", projectManager.getDefaultLang().getName()).data("project_manager_version", projectManager.getVersion());
StudyNode projectRoot = projectManager.getProjectRoot();
if (projectRoot != null) {
Class<? extends StudyNode> projectRootClass = projectRoot.getClass();
query.tags("project_root_class", projectRootClass.getSimpleName()).data("project_root_id", projectRoot.getId());
query.data("course_id", projectRoot.getCourseId(stepikApiClient));
}
}
query.executeAsync().exceptionally((e) -> {
String message = String.format("Failed post metric: %s", query.toString());
logger.warn(message, e);
return null;
});
}, 500, TimeUnit.MILLISECONDS);
}
use of org.stepik.core.StepikProjectManager in project intellij-plugins by StepicOrg.
the class StepikPyProjectGenerator method createCourseFromGenerator.
private void createCourseFromGenerator(@NotNull Project project) {
generator.generateProject(project);
FileUtil.createDirectory(new File(project.getBasePath(), EduNames.SANDBOX_DIR));
StepikProjectManager projectManager = StepikProjectManager.getInstance(project);
if (projectManager == null) {
logger.warn("failed to generate builders: StepikProjectManager is null");
return;
}
projectManager.setDefaultLang(generator.getDefaultLang());
StudyNode root = projectManager.getProjectRoot();
if (root == null) {
logger.warn("failed to generate builders: Root is null");
return;
}
if (root instanceof StepNode) {
getOrCreateSrcDirectory(project, (StepNode) root, true);
} else {
createSubDirectories(project, generator.getDefaultLang(), root, null);
VirtualFileManager.getInstance().syncRefresh();
}
Application application = ApplicationManager.getApplication();
application.invokeLater(() -> DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, () -> application.runWriteAction(() -> {
StudyProjectComponent.getInstance(project).registerStudyToolWindow();
StepikProjectManager.updateAdaptiveSelected(project);
})));
}
use of org.stepik.core.StepikProjectManager in project intellij-plugins by StepicOrg.
the class StepikProjectGenerator method generateProject.
public void generateProject(@NotNull Project project) {
StepikProjectManager stepikProjectManager = StepikProjectManager.getInstance(project);
if (stepikProjectManager == null) {
Metrics.createProject(project, TARGET_NOT_FOUND);
return;
}
stepikProjectManager.setRootNode(projectRoot);
stepikProjectManager.setDefaultLang(getDefaultLang());
stepikProjectManager.setCreatedBy(getCurrentUser().getId());
Metrics.createProject(project, SUCCESSFUL);
}
use of org.stepik.core.StepikProjectManager in project intellij-plugins by StepicOrg.
the class InsertStepikDirectives method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
Project project = e.getProject();
if (project == null) {
return;
}
StudyNode selectedNode = StepikProjectManager.getSelected(project);
if (!(selectedNode instanceof StepNode) || ((StepNode) selectedNode).getType() != CODE) {
return;
}
StepNode targetStepNode = (StepNode) selectedNode;
FileDocumentManager documentManager = FileDocumentManager.getInstance();
for (VirtualFile file : FileEditorManager.getInstance(project).getOpenFiles()) {
Document document = documentManager.getDocument(file);
if (document != null)
documentManager.saveDocument(document);
}
SupportedLanguages currentLang = targetStepNode.getCurrentLang();
VirtualFile src = getOrCreateSrcDirectory(project, targetStepNode, true);
if (src == null) {
return;
}
VirtualFile file = src.findChild(currentLang.getMainFileName());
if (file == null) {
return;
}
String text = getFileText(file);
StepikProjectManager projectManager = StepikProjectManager.getInstance(project);
boolean showHint = projectManager != null && projectManager.getShowHint();
boolean needInsert = !containsDirectives(text, currentLang);
if (needInsert) {
text = insertAmbientCode(text, currentLang, showHint);
Metrics.insertAmbientCodeAction(project, targetStepNode, SUCCESSFUL);
} else {
text = removeAmbientCode(text, showHint, currentLang, true);
Metrics.removeAmbientCodeAction(project, targetStepNode, SUCCESSFUL);
}
writeInToFile(text, file, project);
if (needInsert) {
final Document document = FileDocumentManager.getInstance().getDocument(file);
if (document != null) {
ReformatUtils.reformatSelectedEditor(project, document);
}
}
}
Aggregations