no message
This commit is contained in:
89
src/_VisualDVM/Passes/All/CreateTestFromFile.java
Normal file
89
src/_VisualDVM/Passes/All/CreateTestFromFile.java
Normal file
@@ -0,0 +1,89 @@
|
||||
package _VisualDVM.Passes.All;
|
||||
import Common.Utils.Utils_;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Utils;
|
||||
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;
|
||||
import Common.Passes.PassException;
|
||||
import Common.Passes.Pass;
|
||||
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());
|
||||
//--
|
||||
File tempProject = packTestCode();
|
||||
ShowMessage2("Синтаксический анализ и определение размерности");
|
||||
if (group.language == LanguageName.fortran)
|
||||
Sapfor.getMinMaxDim(Sapfor.getTempCopy(Global.mainModule.getSapfor().getFile()), tempProject, target);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user