Files
VisualSapfor/src/TestingSystem/SAPFOR/PackageModeSupervisor.java
2023-12-25 02:07:37 +03:00

96 lines
4.2 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 TestingSystem.SAPFOR;
import Common.Constants;
import Common.Global;
import Common.Utils.Utils;
import TestingSystem.Common.TaskThread;
import TestingSystem.Common.ThreadsPlanner.ThreadsPlanner;
import TestingSystem.SAPFOR.Json.SapforConfiguration_json;
import TestingSystem.SAPFOR.Json.SapforPackage_json;
import TestingSystem.SAPFOR.Json.SapforTest_json;
import TestingSystem.SAPFOR.Json.SapforTestingSet_json;
import TestingSystem.SAPFOR.SapforTask.SapforTask;
import Visual_DVM_2021.Passes.PassCode_2021;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.nio.charset.Charset;
import java.util.Date;
import java.util.Vector;
public class PackageModeSupervisor extends ThreadsPlanner {
SapforPackage_json package_json = null;
File sapfor_drv = null;
public PackageModeSupervisor() throws Exception {
super(2000);
package_json = (SapforPackage_json) Utils.jsonFromFile(new File(Constants.package_json), SapforPackage_json.class);
//--
File sapfor_src = new File(package_json.sapfor_drv);
sapfor_drv = new File(Global.Home, Utils.getDateName("SAPFOR_F"));
FileUtils.copyFile(sapfor_src, sapfor_drv);
if (!sapfor_drv.setExecutable(true))
throw new Exception("Не удалось сделать файл " + sapfor_drv.getName() + " исполняемым!");
File PID = new File("PID");
FileUtils.writeStringToFile(PID, sapfor_drv.getName(), Charset.defaultCharset());
//---
Date startDate = new Date();
File started = new File(Constants.STARTED);
FileUtils.writeStringToFile(started, String.valueOf(startDate));
//формирование списка задач.
setMaxKernels(package_json.kernels);
int max_rask_id = 0;
for (SapforTestingSet_json set_json : package_json.testingSets) {
for (SapforConfiguration_json sapforConfiguration_json : set_json.configurations) {
for (SapforTest_json test : set_json.tests) {
//--- чтобы было можно на нее сослаться после выполнения всех нитей.
SapforTask task = new SapforTask();
task.id = max_rask_id++;
task.group_description = test.group_description;
task.test_description = test.description;
task.flags = sapforConfiguration_json.flags;
task.set_id = set_json.id;
task.sapfor_configuration_id = sapforConfiguration_json.id;
task.sapfortaskspackage_id = Integer.parseInt(new File(Global.Home).getName());
package_json.tasks.add(task);
Vector<String> codes_s = new Vector<>();
for (PassCode_2021 code : sapforConfiguration_json.codes) {
codes_s.add(code.toString());
}
task.codes = String.join(" ", codes_s);
//---
addThread(new TaskThread(task,
sapfor_drv,
set_json,
sapforConfiguration_json)
);
}
}
}
interruptThread.start();
}
@Override
public String printThread(Integer id) {
TaskThread taskThread = (TaskThread) threads.get(id);
return taskThread.task.getSummary();
}
@Override
protected void finalize() {
//записать результаты всех задач.
try {
Utils.jsonToFile(package_json, new File(Constants.package_json));
FileUtils.writeStringToFile(new File(Constants.DONE), "");
//--
//Очистка
//очистка служебных файлов.
Utils.deleteFilesByExtensions(new File(Global.Home),
"proj", "dep", "jar"
// ,"sh", "exe", "bat"
);
//удаление сапфора
if (sapfor_drv.exists())
FileUtils.forceDelete(sapfor_drv);
} catch (Exception e) {
Global.Log.PrintException(e);
}
System.exit(0);
}
}