2023-11-30 01:25:26 +03:00
package Visual_DVM_2021.Passes.All ;
2024-10-07 14:22:52 +03:00
import Common.Utils.CommonUtils ;
2024-10-07 00:58:29 +03:00
import Common_old.Constants ;
import Common_old.Current ;
import Common_old.Utils.Utils ;
2023-12-01 22:42:40 +03:00
import ProjectData.Files.FileType ;
import ProjectData.Files.ProjectFile ;
import ProjectData.LanguageName ;
import Repository.Component.Sapfor.Sapfor ;
import TestingSystem.Common.Group.Group ;
2023-12-01 19:31:31 +03:00
import TestingSystem.Common.Test.Test ;
2023-12-01 22:42:40 +03:00
import Visual_DVM_2021.Passes.PassException ;
2023-11-30 01:25:26 +03:00
import Visual_DVM_2021.Passes.Pass_2021 ;
2023-12-01 22:42:40 +03:00
import org.apache.commons.io.FileUtils ;
import java.io.File ;
2023-12-01 19:31:31 +03:00
public class CreateTestFromFile extends Pass_2021 < 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-07 14:22:52 +03:00
if ( CommonUtils . ContainsCyrillic ( file_in . getName ( ) ) | | Utils . ContainsForbiddenName ( file_in . getName ( ) ) ) {
Log . Writeln_ ( " Имя файла " + CommonUtils . Brackets ( file_in . getName ( ) ) + " содержит запрещённые символы " + Constants . all_forbidden_characters_string + " , или кириллицу. " ) ;
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-07 14:22:52 +03:00
Log . Writeln_ ( " Н е удалось распознать файл " + CommonUtils . 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 ( ) ;
target . sender_address = Current . getAccount ( ) . email ;
target . sender_name = Current . getAccount ( ) . name ;
target . group_id = group . id ;
2024-10-07 14:22:52 +03:00
target . description = CommonUtils . 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 {
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 {
2023-12-02 15:19:05 +03:00
ShowMessage1 ( projectFile . file . getName ( ) ) ;
2023-12-01 22:42:40 +03:00
//--
2023-12-02 15:19:05 +03:00
File tempProject = packTestCode ( ) ;
2023-12-01 22:42:40 +03:00
ShowMessage2 ( " Синтаксический анализ и определение размерности " ) ;
2023-12-02 15:19:05 +03:00
if ( group . language = = LanguageName . fortran )
2023-12-01 22:42:40 +03:00
Sapfor . getMinMaxDim ( Sapfor . getTempCopy ( Current . getSapfor ( ) . getFile ( ) ) , tempProject , target ) ;
}
2023-11-30 01:25:26 +03:00
}