Files
VisualSapfor/src/Visual_DVM_2021/Passes/All/CreateTestFromFile.java

90 lines
3.5 KiB
Java
Raw Normal View History

package Visual_DVM_2021.Passes.All;
2024-10-11 00:00:30 +03:00
import Common.Utils.Utils_;
2024-10-09 22:01:19 +03:00
import _VisualDVM.Current;
import _VisualDVM.Utils;
2024-10-09 22:21:57 +03:00
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;
2024-10-10 23:57:36 +03:00
import Common.Passes.PassException;
import Common.Passes.Pass;
import org.apache.commons.io.FileUtils;
import java.io.File;
2024-10-09 23:37:58 +03:00
public class CreateTestFromFile extends Pass<Test> {
//----
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];
//--
2024-10-11 00:00:30 +03:00
if (Utils_.ContainsCyrillic(file_in.getName()) || Utils_.ContainsForbiddenName(file_in.getName())) {
Log.Writeln_("Имя файла " + Utils_.Brackets(file_in.getName())
2024-10-07 22:04:09 +03:00
+ " содержит запрещённые символы " +
2024-10-11 00:00:30 +03:00
Utils_.printAllForbiddenCharacters() + ", или кириллицу.");
return false;
}
//--
projectFile = new ProjectFile(file_in);
if (!projectFile.fileType.equals(FileType.program) || !projectFile.languageName.equals(group.language)) {
2024-10-11 00:00:30 +03:00
Log.Writeln_("Не удалось распознать файл " + Utils_.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;
2024-10-11 00:00:30 +03:00
target.description = Utils_.getNameWithoutExtension(file_in.getName());
target.files = file_in.getName();
return true;
}
public File packTestCode() throws Exception {
2024-10-11 00:00:30 +03:00
target.temp_project_name = Utils_.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())) {
2024-10-11 00:00:30 +03:00
target.project_archive_bytes = Utils_.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);
}
}