рефакторинг. были дубли сущностей.
This commit is contained in:
@@ -1,26 +1,35 @@
|
||||
package SapforTestingSystem.SapforTest;
|
||||
package SapforTestingSystem;
|
||||
import Common.Constants.Constants;
|
||||
import Common.Global;
|
||||
import Common.Utils.Utils;
|
||||
import GlobalData.Tasks.TaskState;
|
||||
import ProjectData.Project.db_project_info;
|
||||
import SapforTestingSystem.Json.SapforPackage_json;
|
||||
import SapforTestingSystem.Json.SapforVersion_json;
|
||||
import SapforTestingSystem.SapforTask.SapforTask;
|
||||
import Visual_DVM_2021.Passes.PassCode_2021;
|
||||
import Visual_DVM_2021.Passes.PassException;
|
||||
import Visual_DVM_2021.Passes.Pass_2021;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
public class SapforTest {
|
||||
File root;
|
||||
public class PerformSapforTask extends Pass_2021<SapforTask> {
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Запуск задачи SAPFOR";
|
||||
}
|
||||
@Override
|
||||
protected boolean needsAnimation() {
|
||||
return false;
|
||||
}
|
||||
//--
|
||||
File sapfor_drv;
|
||||
String flags;
|
||||
Vector<PassCode_2021> codes;
|
||||
SapforPackage_json sapforPackage_json;
|
||||
//-----
|
||||
File parentTask;
|
||||
File task;
|
||||
@@ -34,13 +43,20 @@ public class SapforTest {
|
||||
Vector<String> outputLines;
|
||||
Vector<String> errorsLines;
|
||||
//---
|
||||
public SapforTask taskResult = null;
|
||||
//---
|
||||
public SapforTest(File sapfor_drv_in, File root_in, String flags_in, List<PassCode_2021> codes_in) {
|
||||
sapfor_drv = sapfor_drv_in;
|
||||
root = root_in;
|
||||
flags = flags_in;
|
||||
codes = new Vector<>(codes_in);
|
||||
@Override
|
||||
protected boolean canStart(Object... args) throws Exception {
|
||||
sapfor_drv = (File) args[0];
|
||||
sapforPackage_json = (SapforPackage_json) args[1];
|
||||
String testDescription = (String) args[2];
|
||||
target = (SapforTask) args[3];
|
||||
//--->>
|
||||
parentTask = Paths.get(Global.Home, sapforPackage_json.id, testDescription).toFile();
|
||||
task = null;
|
||||
//--->>
|
||||
target.sapfortaskspackage_2023_id = Integer.parseInt(sapforPackage_json.id);
|
||||
target.test_description = testDescription;
|
||||
target.root = parentTask.getAbsolutePath();
|
||||
return true;
|
||||
}
|
||||
protected static boolean checkLines(Vector<String> lines) {
|
||||
for (String line : lines) {
|
||||
@@ -70,7 +86,7 @@ public class SapforTest {
|
||||
File file = new File(data_workspace, name + (Global.isWindows ? ".bat" : ".sh"));
|
||||
FileUtils.write(file,
|
||||
Utils.DQuotes(sapfor_drv.getAbsolutePath())
|
||||
+ (flags.isEmpty() ? "" : (" " + flags))
|
||||
+ (sapforPackage_json.flags.isEmpty() ? "" : (" " + sapforPackage_json.flags))
|
||||
+ " -noLogo"
|
||||
+ " " + command +
|
||||
" 1>" +
|
||||
@@ -100,7 +116,7 @@ public class SapforTest {
|
||||
&& (new File(parentTask, "dvm.proj")).exists()) {
|
||||
return true;
|
||||
} else {
|
||||
taskResult.state = TaskState.DoneWithErrors;
|
||||
target.state = TaskState.DoneWithErrors;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -112,13 +128,13 @@ public class SapforTest {
|
||||
"out.txt",
|
||||
"err.txt"
|
||||
)) {
|
||||
taskResult.state = TaskState.Done;
|
||||
taskResult.versions.add(new SapforVersion_json(task.getAbsolutePath(), code.getDescription()));
|
||||
target.state = TaskState.Done;
|
||||
target.versions.add(new SapforVersion_json(task.getAbsolutePath(), code.getDescription()));
|
||||
parentTask = task;
|
||||
return true;
|
||||
}
|
||||
Utils.delete_with_check(task);
|
||||
taskResult.state = TaskState.DoneWithErrors;
|
||||
target.state = TaskState.DoneWithErrors;
|
||||
return false;
|
||||
}
|
||||
protected boolean variants() throws Exception {
|
||||
@@ -131,26 +147,20 @@ public class SapforTest {
|
||||
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))));
|
||||
taskResult.state = TaskState.Done;
|
||||
target.state = TaskState.Done;
|
||||
for (File file : files)
|
||||
taskResult.variants.add(new SapforVersion_json(file.getAbsolutePath(), PassCode_2021.SPF_CreateParallelVariant.getDescription()));
|
||||
target.variants.add(new SapforVersion_json(file.getAbsolutePath(), PassCode_2021.SPF_CreateParallelVariant.getDescription()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
taskResult.state = TaskState.DoneWithErrors;
|
||||
target.state = TaskState.DoneWithErrors;
|
||||
return false;
|
||||
}
|
||||
public void Do() throws Exception {
|
||||
parentTask = root;
|
||||
//--
|
||||
taskResult = new SapforTask();
|
||||
taskResult.test_description = root.getName();
|
||||
taskResult.sapfortaskspackage_2023_id = Integer.parseInt(root.getParentFile().getName());
|
||||
taskResult.versions.add(new SapforVersion_json(parentTask.getAbsolutePath(), "исходная"));
|
||||
//--
|
||||
System.out.println(root.getName() + " " + Utils.Brackets(flags));
|
||||
for (PassCode_2021 code : codes) {
|
||||
System.out.println(code);
|
||||
@Override
|
||||
protected void body() throws Exception {
|
||||
System.out.println(target.root + " " + Utils.Brackets(sapforPackage_json.flags));//!!
|
||||
for (PassCode_2021 code : sapforPackage_json.codes) {
|
||||
System.out.println(code); //!!
|
||||
if (parse()) {
|
||||
if (code.equals(PassCode_2021.CreateParallelVariants))
|
||||
variants();
|
||||
@@ -159,9 +169,11 @@ public class SapforTest {
|
||||
} else
|
||||
break;
|
||||
}
|
||||
//Запись результатов.
|
||||
File data_workspace = new File(root, db_project_info.data);
|
||||
/*
|
||||
//Запись результатов. todo сделать единый файл со списком итогов. уже после выполнения нитей.
|
||||
File data_workspace = new File(target.root, db_project_info.data);
|
||||
Utils.CheckDirectory(data_workspace);
|
||||
Utils.jsonToFile(taskResult, new File(data_workspace, "result.txt"));
|
||||
Utils.jsonToFile(target, new File(data_workspace, "result.txt"));
|
||||
*/
|
||||
}
|
||||
}
|
||||
@@ -19,13 +19,9 @@ public class SapforTask extends DBObject {
|
||||
@Description("DEFAULT ''")
|
||||
@Expose
|
||||
public String test_description = "";
|
||||
//-------------------------------------->>
|
||||
@Description("IGNORE")
|
||||
@Description("DEFAULT ''")
|
||||
@Expose
|
||||
public Vector<SapforVersion_json> versions = new Vector<>();
|
||||
@Description("IGNORE")
|
||||
@Expose
|
||||
public Vector<SapforVersion_json> variants = new Vector<>();
|
||||
public String root = "";
|
||||
//-------------------------------------->>
|
||||
@Description("DEFAULT 'Inactive'")
|
||||
@Expose
|
||||
@@ -33,6 +29,13 @@ public class SapforTask extends DBObject {
|
||||
@Description("DEFAULT '0'")
|
||||
public int versions_tree_built = 0;
|
||||
//-----------
|
||||
@Description("IGNORE")
|
||||
@Expose
|
||||
public Vector<SapforVersion_json> versions = new Vector<>();
|
||||
@Description("IGNORE")
|
||||
@Expose
|
||||
public Vector<SapforVersion_json> variants = new Vector<>();
|
||||
//-----------
|
||||
public SapforTask() {
|
||||
}
|
||||
public SapforTask(SapforTask src) {
|
||||
|
||||
@@ -3,38 +3,40 @@ import Common.Global;
|
||||
import Common.Utils.Utils;
|
||||
import SapforTestingSystem.Json.SapforPackage_json;
|
||||
import SapforTestingSystem.Json.SapforScenario_json;
|
||||
import SapforTestingSystem.SapforTest.SapforTest;
|
||||
import SapforTestingSystem.PerformSapforTask;
|
||||
import SapforTestingSystem.SapforTask.SapforTask;
|
||||
import SapforTestingSystem.ThreadsPlanner.ThreadsPlanner;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Vector;
|
||||
public class SapforTestingPlanner extends ThreadsPlanner {
|
||||
SapforScenario_json scenario_json = null;
|
||||
Vector<SapforTask> tasks = new Vector<>();
|
||||
public SapforTestingPlanner() throws Exception {
|
||||
super(Global.properties.threadsTimeout, Global.properties.threadsNum);
|
||||
scenario_json = (SapforScenario_json) Utils.jsonFromFile(new File(Global.Home, "scenario.txt"), SapforScenario_json.class);
|
||||
//формирование списка задач.
|
||||
File sapfor_drv = new File(Global.Home, scenario_json.sapfor_drv);
|
||||
for (SapforPackage_json sapforPackage_json : scenario_json.packages) {
|
||||
for (String testName : scenario_json.tests) {
|
||||
addThread(() -> {
|
||||
try {
|
||||
new SapforTest(
|
||||
new File(Global.Home, scenario_json.sapfor_drv),
|
||||
Paths.get(Global.Home, sapforPackage_json.id, testName).toFile(),
|
||||
sapforPackage_json.flags,
|
||||
sapforPackage_json.codes).Do();
|
||||
} catch (Exception exception) {
|
||||
Global.Log.PrintException(exception);
|
||||
}
|
||||
});
|
||||
//--- чтобы было можно на нее сослаться после выполнения всех нитей.
|
||||
SapforTask task = new SapforTask();
|
||||
tasks.add(task);
|
||||
//---
|
||||
addThread(() -> new PerformSapforTask().Do(
|
||||
sapfor_drv,
|
||||
sapforPackage_json,
|
||||
testName,
|
||||
task
|
||||
));
|
||||
}
|
||||
}
|
||||
interruptThread.start();
|
||||
}
|
||||
@Override
|
||||
public void Interrupt() throws Exception {
|
||||
System.out.println("killing "+scenario_json.sapfor_drv+"...");
|
||||
String kill_command = Global.isWindows? ("taskkill /FI \"IMAGENAME eq " + scenario_json.sapfor_drv+ "\" /F /T"):
|
||||
System.out.println("killing " + scenario_json.sapfor_drv + "...");
|
||||
String kill_command = Global.isWindows ? ("taskkill /FI \"IMAGENAME eq " + scenario_json.sapfor_drv + "\" /F /T") :
|
||||
("killall -SIGKILL " + scenario_json.sapfor_drv);
|
||||
Process killer = Runtime.getRuntime().exec(kill_command);
|
||||
killer.waitFor();
|
||||
|
||||
@@ -1,182 +0,0 @@
|
||||
package Visual_DVM_2021.Passes.All;
|
||||
import Common.Constants.Constants;
|
||||
import Common.Utils.Utils;
|
||||
import ProjectData.Project.db_project_info;
|
||||
import SapforTestingSystem.Json.SapforVersion_json;
|
||||
import SapforTestingSystem.Json.ScenarioResults_json;
|
||||
import SapforTestingSystem.Json.SapforScenario_json;
|
||||
import SapforTestingSystem.SapforTask.SapforTask;
|
||||
import Visual_DVM_2021.Passes.PassCode_2021;
|
||||
import Visual_DVM_2021.Passes.PassException;
|
||||
import Visual_DVM_2021.Passes.Pass_2021;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Vector;
|
||||
public class PerformSapforTasksPackage extends Pass_2021<SapforScenario_json> {
|
||||
File packageWorkspace;
|
||||
File sapfor_drv;
|
||||
File scenarioFile;
|
||||
//---
|
||||
File parentTask;
|
||||
File task;
|
||||
//---
|
||||
Process process = null;
|
||||
int exit_code = Constants.Nan;
|
||||
//----
|
||||
File outputFile = null;
|
||||
File errorsFile = null;
|
||||
//--
|
||||
Vector<String> outputLines;
|
||||
Vector<String> errorsLines;
|
||||
//--
|
||||
ScenarioResults_json results;
|
||||
//-
|
||||
SapforTask taskResult = null;
|
||||
//--
|
||||
@Override
|
||||
protected boolean canStart(Object... args) throws Exception {
|
||||
//--
|
||||
packageWorkspace = new File((String)args[0]);
|
||||
//---
|
||||
scenarioFile = new File(packageWorkspace, "scenario.txt");
|
||||
sapfor_drv = new File(packageWorkspace, "SAPFOR_F.exe");
|
||||
String packed = FileUtils.readFileToString(scenarioFile, Charset.defaultCharset());
|
||||
target = Utils.gson.fromJson(packed, SapforScenario_json.class);
|
||||
//---
|
||||
results = new ScenarioResults_json();
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
protected void body() throws Exception {
|
||||
for (String test : target.tests) {
|
||||
//--
|
||||
parentTask = new File(packageWorkspace, test);
|
||||
//--
|
||||
taskResult = new SapforTask();
|
||||
taskResult.test_description = test;
|
||||
taskResult.sapfortaskspackage_2023_id = Integer.parseInt(packageWorkspace.getName());
|
||||
taskResult.versions.add(new SapforVersion_json(parentTask.getAbsolutePath(), "исходная"));
|
||||
//--
|
||||
/*
|
||||
for (PassCode_2021 code : target.codes) {
|
||||
if (parse()) {
|
||||
if (code.equals(PassCode_2021.CreateParallelVariants))
|
||||
variants();
|
||||
else if (!transformation(code))
|
||||
break;
|
||||
} else
|
||||
break;
|
||||
}
|
||||
*/
|
||||
//---
|
||||
results.tasks.add(taskResult);
|
||||
}
|
||||
}
|
||||
protected boolean performSapforScript(String name, File workspace, String flags, String command, String outName, String errName) throws Exception {
|
||||
process = null;
|
||||
exit_code = Constants.Nan;
|
||||
//---
|
||||
File data_workspace = new File(workspace, db_project_info.data);
|
||||
Utils.CheckDirectory(data_workspace);
|
||||
outputFile = new File(data_workspace, outName);
|
||||
errorsFile = new File(data_workspace, errName);
|
||||
Utils.delete_with_check(outputFile);
|
||||
Utils.delete_with_check(errorsFile);
|
||||
//---
|
||||
File file = new File(data_workspace, name + ".bat");
|
||||
FileUtils.write(file,
|
||||
Utils.DQuotes(sapfor_drv.getAbsolutePath())
|
||||
+ (flags.isEmpty() ? "" : (" " + flags))
|
||||
+ " -noLogo"
|
||||
+ " " + command +
|
||||
" 1>" +
|
||||
Utils.DQuotes(outputFile.getAbsolutePath()) +
|
||||
" 2>" +
|
||||
Utils.DQuotes(errorsFile.getAbsolutePath()),
|
||||
Charset.defaultCharset());
|
||||
if (!file.setExecutable(true))
|
||||
throw new PassException("Не удалось сделать файл скрипта " + name + " исполняемым!");
|
||||
//--
|
||||
ProcessBuilder procBuilder = new ProcessBuilder(file.getAbsolutePath());
|
||||
procBuilder.directory(workspace);
|
||||
process = procBuilder.start();
|
||||
exit_code = process.waitFor();
|
||||
if (exit_code != 0)
|
||||
throw new PassException("Процесс завершился с кодом " + exit_code);
|
||||
process = null;
|
||||
//---
|
||||
outputLines = new Vector<>(FileUtils.readLines(outputFile));
|
||||
errorsLines = new Vector<>(FileUtils.readLines(errorsFile));
|
||||
return checkLines(outputLines) && checkLines(errorsLines);
|
||||
}
|
||||
protected boolean checkLines(Vector<String> lines) {
|
||||
for (String line : lines) {
|
||||
if (line.toLowerCase().contains("internal error")) {
|
||||
return false;
|
||||
}
|
||||
if (line.toLowerCase().contains("exception")) {
|
||||
return false;
|
||||
}
|
||||
if (line.contains("[ERROR]")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
protected boolean parse() throws Exception {
|
||||
/*
|
||||
if (performSapforScript("parse", parentTask, target.flags,
|
||||
"-parse *.f *.for *.fdv *.f90 *.f77",
|
||||
"parse_out.txt", "parse_err.txt")
|
||||
&& (new File(parentTask, "dvm.proj")).exists()) {
|
||||
return true;
|
||||
} else {
|
||||
taskResult.state = TaskState.DoneWithErrors;
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
protected boolean transformation(PassCode_2021 code) throws Exception {
|
||||
/*
|
||||
task = new File(parentTask, "v1");
|
||||
Utils.CheckAndCleanDirectory(task); //папка для преобразования.
|
||||
if (performSapforScript("transformation", parentTask, target.flags,
|
||||
code.getTestingCommand() + " -F " + Utils.DQuotes(task.getAbsolutePath()),
|
||||
"out.txt",
|
||||
"err.txt"
|
||||
)) {
|
||||
taskResult.state = TaskState.Done;
|
||||
taskResult.versions.add(new SapforVersion_json(task.getAbsolutePath(), code.getDescription()));
|
||||
parentTask = task;
|
||||
return true;
|
||||
}
|
||||
Utils.delete_with_check(task);
|
||||
taskResult.state = TaskState.DoneWithErrors;
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
protected boolean variants() throws Exception {
|
||||
/*
|
||||
if (performSapforScript("create_variants", parentTask, target.flags, " -t 13 -allVars",
|
||||
"out.txt",
|
||||
"err.txt"
|
||||
)) {
|
||||
//найти папки с вариантами.
|
||||
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))));
|
||||
taskResult.state = TaskState.Done;
|
||||
for (File file : files)
|
||||
taskResult.variants.add(new SapforVersion_json(file.getAbsolutePath(), PassCode_2021.SPF_CreateParallelVariant.getDescription()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
taskResult.state = TaskState.DoneWithErrors;
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,6 @@ public enum PassCode_2021 {
|
||||
DeleteSapforTasksPackage,
|
||||
AnalyseSapforPackageResults,
|
||||
OpenSapforTest,
|
||||
PerformSapforTasksPackage,
|
||||
//-
|
||||
//-
|
||||
CheckAccount,
|
||||
@@ -311,8 +310,6 @@ public enum PassCode_2021 {
|
||||
switch (this) {
|
||||
case Undefined:
|
||||
return "?";
|
||||
case PerformSapforTasksPackage:
|
||||
return "Выполнить пакет задач SAPFOR";
|
||||
case CompareSapforPackages:
|
||||
return "Сравнение пакетов задач SAPFOR";
|
||||
case EditProfile:
|
||||
|
||||
Reference in New Issue
Block a user