Добавление одного выбранного файла в качестве теста.
This commit is contained in:
@@ -1,5 +1,115 @@
|
||||
package Visual_DVM_2021.Passes.All;
|
||||
import Common.Constants;
|
||||
import Common.Current;
|
||||
import Common.Utils.Files.VFileChooser;
|
||||
import Common.Utils.Utils;
|
||||
import GlobalData.Settings.SettingName;
|
||||
import ProjectData.Files.FileType;
|
||||
import ProjectData.Files.ProjectFile;
|
||||
import ProjectData.LanguageName;
|
||||
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.PassException;
|
||||
import Visual_DVM_2021.Passes.Pass_2021;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
public class CreateTestFromFile extends Pass_2021<Test> {
|
||||
VFileChooser fileChooser = new VFileChooser("Выберите файл для создания теста");
|
||||
//---
|
||||
File file;
|
||||
Group group;
|
||||
boolean from_file_chooser = false;
|
||||
ProjectFile projectFile;
|
||||
//---
|
||||
@Override
|
||||
public String getIconPath() {
|
||||
return "/icons/AddFile.png";
|
||||
}
|
||||
@Override
|
||||
public String getButtonText() {
|
||||
return "";
|
||||
}
|
||||
@Override
|
||||
protected boolean canStart(Object... args) throws Exception {
|
||||
projectFile = null;
|
||||
if (args.length == 0) {
|
||||
from_file_chooser = true;
|
||||
if (!Current.Check(Log, Current.Group))
|
||||
return false;
|
||||
group = Current.getGroup();
|
||||
Utils.RestoreSelectedDirectory(fileChooser);
|
||||
file = fileChooser.ShowDialog();
|
||||
if (file == null) {
|
||||
Log.Writeln_("Файл не выбран");
|
||||
return false;
|
||||
} else {
|
||||
Pass_2021.passes.get(PassCode_2021.UpdateSetting).Do(SettingName.ProjectsSearchDirectory, file.getParent());
|
||||
}
|
||||
} else {
|
||||
from_file_chooser = false;
|
||||
file = (File) args[0];
|
||||
group = (Group) args[1];
|
||||
}
|
||||
if (Utils.ContainsCyrillic(file.getName()) || Utils.ContainsForbiddenName(file.getName())) {
|
||||
Log.Writeln_("Имя файла " + Utils.Brackets(file.getName()) + " содержит запрещённые символы " + Constants.all_forbidden_characters_string + ", или кириллицу.");
|
||||
return false;
|
||||
}
|
||||
//если файл. все недопустимые файлы просто игнорируются.
|
||||
projectFile = new ProjectFile(file);
|
||||
if (!projectFile.fileType.equals(FileType.program) || !projectFile.languageName.equals(group.language)) {
|
||||
Log.Writeln_("Не удалось распознать файл как программу на языке " + 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 = Utils.getNameWithoutExtension(file.getName());
|
||||
target.files = file.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.packFile(tempArchive);
|
||||
} else throw new PassException("Не удалось создать архив папки с кодом.");
|
||||
return tempProject;
|
||||
}
|
||||
@Override
|
||||
protected void body() throws Exception {
|
||||
ShowMessage1(file.getName());
|
||||
//--
|
||||
File tempProject = packTestCode(); //создание копии папки, и архивация.
|
||||
//-- получить размерность консольным сапфором. папка уже отправлена и чистить ее не нужно!!
|
||||
ShowMessage2("Синтаксический анализ и определение размерности");
|
||||
if (group.language == LanguageName.fortran) {//если не определит, будут нули.
|
||||
Sapfor.getMinMaxDim(Sapfor.getTempCopy(Current.getSapfor().getFile()), tempProject, target);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected boolean validate() {
|
||||
return Log.isEmpty();
|
||||
}
|
||||
@Override
|
||||
protected void performDone() throws Exception {
|
||||
super.performDone();
|
||||
if (from_file_chooser)
|
||||
passes.get(PassCode_2021.PublishTest).Do(target);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user