Files
VisualSapfor/src/_VisualDVM/TestingSystem/SAPFOR/PerformSapforTask.java
2024-10-10 23:57:36 +03:00

130 lines
4.9 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package _VisualDVM.TestingSystem.SAPFOR;
import Common.Utils.CommonUtils;
import _VisualDVM.Constants;
import _VisualDVM.Utils;
import _VisualDVM.GlobalData.Tasks.TaskState;
import _VisualDVM.Repository.Component.Sapfor.Sapfor;
import _VisualDVM.TestingSystem.SAPFOR.Json.SapforVersion_json;
import _VisualDVM.TestingSystem.SAPFOR.SapforTask.SapforTask;
import Visual_DVM_2021.Passes.PassCode;
import Common.Passes.Pass;
import java.io.File;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.util.Vector;
public class PerformSapforTask extends Pass<SapforTask> {
@Override
public String getDescription() {
return "";
// "Запуск задачи SAPFOR"; Оставляем пустое описание чтобы не засорять журнал.
}
@Override
protected boolean needsAnimation() {
return false;
}
//--
File sapfor_drv;
SapforVersion_json version_json;
//-----
File root;
File parentTask;
File task;
//-----
@Override
protected boolean canStart(Object... args) throws Exception {
//--
target = (SapforTask) args[0];
sapfor_drv = (File) args[1];
//--
version_json = null;
//--->>
parentTask = Paths.get(CommonUtils.getHomePath(),
String.valueOf(target.set_id),
String.valueOf(target.sapfor_configuration_id),
target.test_description).toFile();
root = Paths.get(CommonUtils.getHomePath(), String.valueOf(target.set_id), String.valueOf(target.sapfor_configuration_id)).toFile();
task = null;
//--->>
return true;
}
protected boolean parse() throws Exception {
if (Sapfor.parse(sapfor_drv, parentTask, target.flags)) {
return true;
} else {
target.state = TaskState.DoneWithErrors;
return false;
}
}
//слегка изменить подход.
protected boolean transformation(PassCode code) throws Exception {
task = new File(parentTask, "v1");
Utils.CheckAndCleanDirectory(task); //папка для преобразования.
//если версия пустая, это тоже результат тестирования. Поэтому должна учитываться в древе.
target.versions.add(version_json = new SapforVersion_json(
root.getAbsolutePath(),
task.getAbsolutePath(), code.getDescription()));
//---
if (Sapfor.performScript(
"transformation",
sapfor_drv,
parentTask,
code.getTestingCommand() + " -F " + CommonUtils.DQuotes(task.getAbsolutePath()),
target.flags,
Constants.out_file,
Constants.err_file
)) {
target.state = TaskState.Done;
parentTask = task;
return true;
}
target.state = TaskState.DoneWithErrors;
return false;
}
protected void variants() throws Exception {
//папки вариантов создается самим сапфором.
target.state = Sapfor.performScript(
"create_variants",
sapfor_drv,
parentTask,
" -t 13 -allVars",// -tinfo",
target.flags,
Constants.out_file,
Constants.err_file
) ? TaskState.Done : TaskState.DoneWithErrors;
//найти папки с вариантами.
File[] files_ = parentTask.listFiles((dir, name) -> dir.isDirectory() && Utils.isParallelVersionName(name));
if ((files_ != null) && (files_.length > 0)) {
Vector<File> files = new Vector<>(Arrays.asList(files_));
files.sort(Comparator.comparingInt(o -> Integer.parseInt(o.getName().substring(1))));
for (File file : files)
target.variants.add(
new SapforVersion_json(
root.getAbsolutePath(),
file.getAbsolutePath(), PassCode.SPF_CreateParallelVariant.getDescription()));
}
}
//-------------------------------------------------->>
@Override
protected void body() throws Exception {
target.StartDate = new Date().getTime();
target.versions.add(version_json = new SapforVersion_json(target.test_description, "исходная"));
String [] data = target.codes.split(" ");
for (String code_s: data){
PassCode code = PassCode.valueOf(code_s);
//--
if (parse()) {
if (code.equals(PassCode.CreateParallelVariants))
variants();
else if (!transformation(code))
break;
} else
break;
//--
}
target.ChangeDate = new Date().getTime();
}
}