Добавление одного выбранного файла в качестве теста.
This commit is contained in:
@@ -7,6 +7,7 @@ public class TestsMenuBar extends DataMenuBar {
|
||||
//PassCode_2021.PublishTest,
|
||||
PassCode_2021.CreateTestFromProject,
|
||||
PassCode_2021.CreateTestFromDirectory,
|
||||
PassCode_2021.CreateTestFromFile,
|
||||
PassCode_2021.EditTest,
|
||||
PassCode_2021.DownloadTest,
|
||||
PassCode_2021.DeleteTest);
|
||||
|
||||
@@ -2,7 +2,7 @@ package Common.Utils;
|
||||
import Common.Constants;
|
||||
import Common.Global;
|
||||
import Common.UI.UI;
|
||||
import Common.Utils.Files.VDirectoryChooser;
|
||||
import Common.Utils.Files.VFileChooser_;
|
||||
import GlobalData.Settings.SettingName;
|
||||
import GlobalData.Tasks.TaskState;
|
||||
import ProjectData.Files.DBProjectFile;
|
||||
@@ -1120,7 +1120,7 @@ public class Utils {
|
||||
}
|
||||
return res;
|
||||
}
|
||||
public static void RestoreSelectedDirectory(VDirectoryChooser directoryChooser) {
|
||||
public static void RestoreSelectedDirectory(VFileChooser_ directoryChooser) {
|
||||
String last_dir_home =
|
||||
Global.db.settings.get(SettingName.ProjectsSearchDirectory).Value;
|
||||
if (!last_dir_home.isEmpty())
|
||||
|
||||
@@ -67,7 +67,7 @@ public class CreateTestFromDirectory extends Pass_2021<Test> {
|
||||
return false;
|
||||
}
|
||||
//--
|
||||
if (!Utils.validateProjectFile(dir, Log)) {
|
||||
if (Utils.ContainsCyrillic(dir.getName()) || Utils.ContainsForbiddenName(dir.getName())) {
|
||||
Log.Writeln_("Имя папки " + Utils.Brackets(dir.getName()) + " содержит запрещённые символы " + Constants.all_forbidden_characters_string + ", или кириллицу.");
|
||||
return false;
|
||||
}
|
||||
@@ -90,16 +90,12 @@ public class CreateTestFromDirectory extends Pass_2021<Test> {
|
||||
} else if (file.isFile() && !Utils.ContainsCyrillic(file.getName()) && !Utils.ContainsForbiddenName(file.getName())) {
|
||||
//если файл. все недопустимые файлы просто игнорируются.
|
||||
ProjectFile projectFile = new ProjectFile(file);
|
||||
System.out.println(projectFile.file);
|
||||
System.out.println("1");
|
||||
if (isNotExcluded(projectFile)) {
|
||||
System.out.println("1.5");
|
||||
switch (projectFile.fileType) {
|
||||
case program:
|
||||
if (projectFile.languageName.equals(group.language)) {
|
||||
active_programs++;
|
||||
project_files.add(projectFile);
|
||||
System.out.println("2");
|
||||
} else
|
||||
other_project_files++;
|
||||
break;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,6 @@ public class CreateTestFromProject extends CreateTestFromDirectory {
|
||||
project = (db_project_info) args[0];
|
||||
group = (Group) args[1];
|
||||
from_directory_chooser = false;
|
||||
// project.Open();
|
||||
// project.Close();
|
||||
return super.canStart(project.Home, group);
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user