package Visual_DVM_2021.Passes.All; import Common.Utils.CommonUtils; import _VisualDVM.Current; import _VisualDVM.Utils; import _VisualDVM.ProjectData.Files.FileType; import _VisualDVM.ProjectData.Files.ProjectFile; import _VisualDVM.ProjectData.LanguageName; import _VisualDVM.Repository.Component.Sapfor.Sapfor; import _VisualDVM.TestingSystem.Common.Group.Group; import _VisualDVM.TestingSystem.Common.Test.Test; import Visual_DVM_2021.Passes.PassException; import Visual_DVM_2021.Passes.Pass; import org.apache.commons.io.FileUtils; import java.io.File; public class CreateTestFromFile extends Pass { //---- Group group; ProjectFile projectFile; //---- @Override protected boolean needsAnimation() { return true; } @Override public String getIconPath() { return "/icons/AddFile.png"; } @Override public String getButtonText() { return ""; } @Override protected boolean canStart(Object... args) throws Exception { projectFile = null; File file_in = (File) args[0]; group = (Group) args[1]; //-- if (CommonUtils.ContainsCyrillic(file_in.getName()) || CommonUtils.ContainsForbiddenName(file_in.getName())) { Log.Writeln_("Имя файла " + CommonUtils.Brackets(file_in.getName()) + " содержит запрещённые символы " + CommonUtils.printAllForbiddenCharacters() + ", или кириллицу."); return false; } //-- projectFile = new ProjectFile(file_in); if (!projectFile.fileType.equals(FileType.program) || !projectFile.languageName.equals(group.language)) { Log.Writeln_("Не удалось распознать файл " + CommonUtils.Brackets(file_in.getName()) + " как программу на языке " + group.language.getDescription()); return false; } //-- target = new Test(); target.sender_address = Current.getAccount().email; target.sender_name = Current.getAccount().name; target.group_id = group.id; target.description = CommonUtils.getNameWithoutExtension(file_in.getName()); target.files = file_in.getName(); return true; } public File packTestCode() throws Exception { target.temp_project_name = CommonUtils.getDateName("test"); //- File tempProject = target.getTempProject(); File tempArchive = target.getTempArchive(); //- создать бд. FileUtils.forceMkdir(tempProject); //-- File dst = new File(tempProject, projectFile.file.getName()); FileUtils.copyFile(projectFile.file, dst); //--- Utils.ClearProjectData(tempProject); //-- ZipFolderPass zip = new ZipFolderPass(); if (zip.Do(tempProject.getAbsolutePath(), tempArchive.getAbsolutePath())) { target.project_archive_bytes = CommonUtils.fileToBytes(tempArchive); } else throw new PassException("Не удалось создать архив папки с кодом."); return tempProject; } @Override protected void body() throws Exception { ShowMessage1(projectFile.file.getName()); //-- File tempProject = packTestCode(); ShowMessage2("Синтаксический анализ и определение размерности"); if (group.language == LanguageName.fortran) Sapfor.getMinMaxDim(Sapfor.getTempCopy(Current.getSapfor().getFile()), tempProject, target); } }