промежуточный. Рефакторинг публикации теста из текущего проекта.
This commit is contained in:
@@ -5,9 +5,17 @@ import Common.Database.DBObject;
|
||||
import Common.Database.riDBObject;
|
||||
import Common.Global;
|
||||
import Common.UI.UI;
|
||||
import Common.Utils.Utils;
|
||||
import ProjectData.Project.db_project_info;
|
||||
import Repository.RepositoryRefuseException;
|
||||
import Visual_DVM_2021.Passes.All.UnzipFolderPass;
|
||||
import Visual_DVM_2021.Passes.All.ZipFolderPass;
|
||||
import Visual_DVM_2021.Passes.PassException;
|
||||
import com.sun.org.glassfish.gmbal.Description;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
public class Test extends riDBObject {
|
||||
@Description("DEFAULT 1")
|
||||
public int dim = 1; //размерность теста. для удобства пусть будет и внешним полем.
|
||||
@@ -23,6 +31,14 @@ public class Test extends riDBObject {
|
||||
args = t.args;
|
||||
group_id = t.group_id;
|
||||
}
|
||||
@Description("DEFAULT ''")
|
||||
public String files = ""; //файлы теста
|
||||
//--------------------------------------------->>>
|
||||
@Description("IGNORE")
|
||||
public String temp_project_name = "";
|
||||
@Description("IGNORE")
|
||||
public byte[] project_archive_bytes = null;
|
||||
//--------------------------------------------->>>
|
||||
public Test(Test test) {
|
||||
this.SynchronizeFields(test);
|
||||
}
|
||||
@@ -50,4 +66,60 @@ public class Test extends riDBObject {
|
||||
public File getHomePath() {
|
||||
return new File(Global.visualiser.getWorkspace(), String.valueOf(id));
|
||||
}
|
||||
//--
|
||||
public File getTempArchive() {
|
||||
return new File(Global.TempDirectory, temp_project_name + ".zip");
|
||||
}
|
||||
public File getTempProject() {
|
||||
return new File(Global.TempDirectory, temp_project_name);
|
||||
}
|
||||
//--
|
||||
public void packProject(db_project_info project) throws Exception {
|
||||
temp_project_name = Utils.getDateName("test");
|
||||
//-
|
||||
File tempProject = getTempProject();
|
||||
File tempArchive = getTempArchive();
|
||||
//-
|
||||
FileUtils.forceMkdir(tempProject);
|
||||
project.Clone(tempProject, false);
|
||||
//--
|
||||
FileUtils.copyFile(project.db.getFile(),
|
||||
Paths.get(tempProject.getAbsolutePath(), Constants.data, project.db.getFile().getName()).toFile());
|
||||
//--
|
||||
ZipFolderPass zip = new ZipFolderPass();
|
||||
if (zip.Do(tempProject.getAbsolutePath(), tempArchive.getAbsolutePath())) {
|
||||
project_archive_bytes = Utils.packFile(tempArchive);
|
||||
} else throw new PassException("Не удалось создать архив проекта");
|
||||
}
|
||||
public boolean unpackProjectOnServer() throws Exception {
|
||||
File tmpArchive = new File(Global.TempDirectory, temp_project_name + ".zip");
|
||||
File tmpProject = new File(Global.TempDirectory, temp_project_name);
|
||||
File testProject = new File(Global.TestsDirectory, String.valueOf(id));
|
||||
File testArchive = new File(Global.TestsDirectory, id + ".zip");
|
||||
//--
|
||||
if (tmpArchive.exists())
|
||||
FileUtils.forceDelete(tmpArchive);
|
||||
if (tmpProject.exists())
|
||||
FileUtils.forceDelete(tmpProject);
|
||||
if (testProject.exists())
|
||||
FileUtils.forceDelete(testProject);
|
||||
if (testArchive.exists())
|
||||
FileUtils.forceDelete(testArchive);
|
||||
//--
|
||||
Utils.unpackFile(project_archive_bytes, tmpArchive); // распаковка байтов.
|
||||
//--
|
||||
UnzipFolderPass unzipFolderPass = new UnzipFolderPass();
|
||||
if (!unzipFolderPass.Do(
|
||||
tmpArchive.getAbsolutePath(),
|
||||
Global.TempDirectory.getAbsolutePath())) {
|
||||
return false;
|
||||
}
|
||||
//--
|
||||
FileUtils.moveDirectory(tmpProject, testProject);
|
||||
//--
|
||||
ZipFolderPass zip = new ZipFolderPass();
|
||||
if (!zip.Do(testProject.getAbsolutePath(), testArchive.getAbsolutePath()))
|
||||
throw new RepositoryRefuseException("Не удалось переписать архив проекта");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user