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

86 lines
3.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package _VisualDVM.Passes.All;
import Common.Passes.Pass;
import Common.Passes.PassException;
import Common.Utils.Utils_;
import _VisualDVM.ComponentsServer.Component.Sapfor.Sapfor;
import _VisualDVM.Global;
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;
import _VisualDVM.Utils;
import org.apache.commons.io.FileUtils;
import java.io.File;
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];
//--
if (Utils_.ContainsCyrillic(file_in.getName()) || Utils_.ContainsForbiddenName(file_in.getName())) {
Log.Writeln_("Имя файла " + Utils_.Brackets(file_in.getName())
+ " содержит запрещённые символы " +
Utils_.printAllForbiddenCharacters() + ", или кириллицу.");
return false;
}
//--
projectFile = new ProjectFile(file_in);
if (!projectFile.fileType.equals(FileType.program) || !projectFile.languageName.equals(group.language)) {
Log.Writeln_("Не удалось распознать файл " + Utils_.Brackets(file_in.getName()) +
" как программу на языке " + group.language.getDescription());
return false;
}
//--
target = new Test();
target.sender_address = Global.mainModule.getAccount().email;
target.sender_name = Global.mainModule.getAccount().name;
target.group_id = group.id;
target.description = Utils_.getNameWithoutExtension(file_in.getName());
target.files = file_in.getName();
return true;
}
public File packTestCode() throws Exception {
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())) {
target.project_archive_bytes = Utils_.fileToBytes(tempArchive);
} else throw new PassException("Не удалось создать архив папки с кодом.");
return tempProject;
}
@Override
protected void body() throws Exception {
ShowMessage1(projectFile.file.getName());
packTestCode();
}
}