package Visual_DVM_2021.Passes.All; import Common.Constants; import Common.Current; import Common.Utils.Files.VDirectoryChooser; import Common.Utils.Utils; import GlobalData.Settings.SettingName; import ProjectData.Files.ProjectFile; import ProjectData.Project.db_project_info; import Repository.Component.Sapfor.Sapfor; import TestingSystem.Common.Group.Group; import TestingSystem.Common.Test.Test; import Visual_DVM_2021.Passes.PassCode_2021; import Visual_DVM_2021.Passes.Pass_2021; import java.io.File; import java.util.Vector; public class CreateTestFromDirectory extends Pass_2021 { VDirectoryChooser directoryChooser = new VDirectoryChooser("Выбор домашней папки теста"); @Override public String getIconPath() { return "/icons/OpenProject.png"; } @Override public String getButtonText() { return ""; } @Override protected boolean needsAnimation() { return from_directory_chooser; } Group group = null; File dir = null; boolean from_directory_chooser=false; Vector project_files = new Vector<>(); @Override protected boolean canStart(Object... args) throws Exception { if (args.length == 0) { from_directory_chooser = true; if (!Current.Check(Log, Current.Group)) return false; Utils.RestoreSelectedDirectory(directoryChooser); dir = directoryChooser.ShowDialog(); group = Current.getGroup(); if (dir == null) { if (from_directory_chooser) Log.Writeln_("Папка не выбрана."); return false; } else { Pass_2021.passes.get(PassCode_2021.UpdateSetting).Do(SettingName.ProjectsSearchDirectory, dir.getParent()); } } else { from_directory_chooser = false; dir = (File) args[0]; group = (Group) args[1]; } //--- File[] files = dir.listFiles(); project_files = new Vector<>(); int subdirs = 0; int bad = 0; int fortran_programs = 0; int headers = 0; int other_project_files = 0; //--- if (dir.getName().equalsIgnoreCase(Constants.data)) { if (from_directory_chooser) Log.Writeln_("Папка " + Utils.Brackets(dir) + " является служебной папкой визуализатора."); return false; } //-- if (files == null) { if (from_directory_chooser) Log.Writeln_("Не удалось получить список файлов для папки " + Utils.Brackets(dir) + "."); return false; } //-- for (File file : files) { if (!Utils.validateProjectFile(file, Log)) { if (from_directory_chooser) Log.Writeln_("Имя файла " + Utils.Brackets(file.getName()) + " содержит запрещённые символы " + Constants.all_forbidden_characters_string + ", или кириллицу."); bad++; } if (file.isDirectory() && !file.getName().equalsIgnoreCase(Constants.data)) { subdirs++; } if (file.isFile()) { ProjectFile projectFile = new ProjectFile(file); project_files.add(projectFile); switch (projectFile.fileType) { case program: if (projectFile.languageName.equals(group.language)) fortran_programs++; else other_project_files++; break; case header: headers++; break; default: other_project_files++; break; } } } //-- if (subdirs > 0) { if (from_directory_chooser) Log.Writeln_("Папка " + Utils.Brackets(dir) + " содержит вложенные подпапки."); return false; } if (bad > 0) { return false; } if (fortran_programs == 0) { if (from_directory_chooser) Log.Writeln_("Папка не содержит ни одной программы на языке " + group.language.getDescription() + "."); return false; } if (other_project_files > 0) { if (from_directory_chooser) Log.Writeln_("Папка содержит файлы, не являющиеся программами на языке FORTRAN, или заголовочными."); return false; } //----- target = new Test(); target.sender_address = Current.getAccount().email; target.sender_name = Current.getAccount().name; target.group_id = group.id; target.description = dir.getName(); Vector filesNames = new Vector<>(); for (ProjectFile projectFile : project_files) filesNames.add(projectFile.file.getName()); target.files = String.join("\n", filesNames); return true; } @Override protected void body() throws Exception { System.out.println("found " + project_files.size()); for (ProjectFile projectFile : project_files) { System.out.println(projectFile.file.getAbsolutePath()); } System.out.println("==================="); //-- db_project_info project = target.packCode(dir); //создание копии папки, и архивация. //-- получить размерность консольным сапфором. папка уже отправлена и чистить ее не нужно!! ShowMessage2("Синтаксический анализ"); if (Sapfor.parse(Current.getSapfor().getFile(), project.Home, Current.getSapfor().getConsoleFlags()) ) { ShowMessage2("Определение размерности"); if (Sapfor.analysis(Current.getSapfor().getFile(), project.Home, PassCode_2021.SPF_GetMaxMinBlockDistribution, Current.getSapfor().getConsoleFlags())) { for (String line : Sapfor.outputLines) { String prefix = "GET_MIN_MAX_BLOCK_DIST: "; if (line.startsWith(prefix)) { String s = line.substring(prefix.length()); System.out.println(Utils.Brackets(s)); String[] data = s.split(" "); target.min_dim = Integer.parseInt(data[0]); target.max_dim = Integer.parseInt(data[1]); } } } else Log.Writeln_("Не удалось определить размерность.проекта " + Utils.Brackets(dir.getName())); } else { Log.Writeln_("Не удалось выполнить синтаксический анализ проекта " + Utils.Brackets(dir.getName())); } //todo получить значение из файла вывода анализа. } @Override protected boolean validate() { return Log.isEmpty(); } @Override protected void performDone() throws Exception { super.performDone(); if (from_directory_chooser) passes.get(PassCode_2021.PublishTest).Do(target); } }