2024-10-14 12:14:01 +03:00
|
|
|
|
package _VisualDVM.Passes.All;
|
2024-10-14 15:19:13 +03:00
|
|
|
|
import Common.Passes.Pass;
|
|
|
|
|
|
import Common.Passes.PassException;
|
2024-10-11 00:00:30 +03:00
|
|
|
|
import Common.Utils.Utils_;
|
2025-02-18 16:21:20 +03:00
|
|
|
|
import _VisualDVM.ComponentsServer.Component.Sapfor.Sapfor;
|
2024-10-13 22:08:13 +03:00
|
|
|
|
import _VisualDVM.Global;
|
2024-10-09 22:21:57 +03:00
|
|
|
|
import _VisualDVM.ProjectData.Files.FileType;
|
|
|
|
|
|
import _VisualDVM.ProjectData.Files.ProjectFile;
|
|
|
|
|
|
import _VisualDVM.ProjectData.LanguageName;
|
|
|
|
|
|
import _VisualDVM.TestingSystem.Common.Group.Group;
|
|
|
|
|
|
import _VisualDVM.TestingSystem.Common.Test.Test;
|
2024-10-14 15:19:13 +03:00
|
|
|
|
import _VisualDVM.Utils;
|
2023-12-01 22:42:40 +03:00
|
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
2024-10-09 23:37:58 +03:00
|
|
|
|
public class CreateTestFromFile extends Pass<Test> {
|
2023-12-02 15:19:05 +03:00
|
|
|
|
//----
|
2023-12-01 22:42:40 +03:00
|
|
|
|
Group group;
|
|
|
|
|
|
ProjectFile projectFile;
|
2023-12-02 15:19:05 +03:00
|
|
|
|
//----
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected boolean needsAnimation() {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2023-12-01 22:42:40 +03:00
|
|
|
|
@Override
|
|
|
|
|
|
public String getIconPath() {
|
|
|
|
|
|
return "/icons/AddFile.png";
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public String getButtonText() {
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected boolean canStart(Object... args) throws Exception {
|
|
|
|
|
|
projectFile = null;
|
2023-12-02 15:19:05 +03:00
|
|
|
|
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() + ", или кириллицу.");
|
2023-12-01 22:42:40 +03:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2023-12-02 15:19:05 +03:00
|
|
|
|
//--
|
|
|
|
|
|
projectFile = new ProjectFile(file_in);
|
2023-12-01 22:42:40 +03:00
|
|
|
|
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()) +
|
2023-12-02 15:19:05 +03:00
|
|
|
|
" как программу на языке " + group.language.getDescription());
|
2023-12-01 22:42:40 +03:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2023-12-02 15:19:05 +03:00
|
|
|
|
//--
|
2023-12-01 22:42:40 +03:00
|
|
|
|
target = new Test();
|
2024-10-13 22:08:13 +03:00
|
|
|
|
target.sender_address = Global.mainModule.getAccount().email;
|
|
|
|
|
|
target.sender_name = Global.mainModule.getAccount().name;
|
2023-12-01 22:42:40 +03:00
|
|
|
|
target.group_id = group.id;
|
2024-10-11 00:00:30 +03:00
|
|
|
|
target.description = Utils_.getNameWithoutExtension(file_in.getName());
|
2023-12-02 15:19:05 +03:00
|
|
|
|
target.files = file_in.getName();
|
2023-12-01 22:42:40 +03:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
public File packTestCode() throws Exception {
|
2024-10-11 00:00:30 +03:00
|
|
|
|
target.temp_project_name = Utils_.getDateName("test");
|
2023-12-01 22:42:40 +03:00
|
|
|
|
//-
|
|
|
|
|
|
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);
|
2023-12-01 22:42:40 +03:00
|
|
|
|
} else throw new PassException("Не удалось создать архив папки с кодом.");
|
|
|
|
|
|
return tempProject;
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void body() throws Exception {
|
2023-12-02 15:19:05 +03:00
|
|
|
|
ShowMessage1(projectFile.file.getName());
|
2025-03-06 21:48:51 +03:00
|
|
|
|
packTestCode();
|
2023-12-01 22:42:40 +03:00
|
|
|
|
}
|
2023-11-30 01:25:26 +03:00
|
|
|
|
}
|