промежуточный. рефакторинг. готовлюсь к использованию анализа из консоли

This commit is contained in:
2023-11-24 00:23:12 +03:00
parent 509c858b1a
commit 1907f24100
5 changed files with 100 additions and 287 deletions

10
.idea/workspace.xml generated
View File

@@ -8,14 +8,10 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="e42177c3-2328-4b27-8a01-35779b2beb99" name="Default Changelist" comment=""> <list default="true" id="e42177c3-2328-4b27-8a01-35779b2beb99" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ProjectData/Project/db_project_info.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ProjectData/Project/db_project_info.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/Repository/Component/Sapfor/Sapfor.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Repository/Component/Sapfor/Sapfor.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/TestingSystem/Common/Test/Test.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/TestingSystem/Common/Test/Test.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/TestingSystem/Common/Test/Test.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/TestingSystem/Common/Test/Test.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/CreateGroupFromDirectory.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/CreateGroupFromDirectory.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/TestingSystem/SAPFOR/PerformSapforTask.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/TestingSystem/SAPFOR/PerformSapforTask.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/CreateTestFromDirectory.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/CreateTestFromFolder.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/CreateTestFromFolder.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/CreateTestFromFolder.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/CreateTestFromFolder.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/CreateTestsGroupFromSelectedVersions.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/CreateTestsGroupFromSelectedVersions.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/PublishTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/PublishTest.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/PassCode_2021.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/PassCode_2021.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -113,11 +109,11 @@
<recent name="C:\Users\misha\Documents\visual_dvm_2020\src\icons\Transformations" /> <recent name="C:\Users\misha\Documents\visual_dvm_2020\src\icons\Transformations" />
</key> </key>
<key name="MoveMembersDialog.RECENTS_KEY"> <key name="MoveMembersDialog.RECENTS_KEY">
<recent name="Repository.Component.Sapfor.Sapfor" />
<recent name="TestingSystem.Group.GroupsDBTable" /> <recent name="TestingSystem.Group.GroupsDBTable" />
<recent name="Common.Constants" /> <recent name="Common.Constants" />
<recent name="SapforTestingSystem.SapforTask.SapforTask" /> <recent name="SapforTestingSystem.SapforTask.SapforTask" />
<recent name="TestingSystem.TestingServer" /> <recent name="TestingSystem.TestingServer" />
<recent name="Common.Constants.Constants" />
</key> </key>
<key name="MoveFile.RECENT_KEYS"> <key name="MoveFile.RECENT_KEYS">
<recent name="C:\Users\misha\Documents\visual_sapfor_2023\src\icons" /> <recent name="C:\Users\misha\Documents\visual_sapfor_2023\src\icons" />

View File

@@ -17,6 +17,7 @@ import Visual_DVM_2021.Passes.Pass_2021;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import java.io.File; import java.io.File;
import java.nio.charset.Charset;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Vector; import java.util.Vector;
@@ -489,5 +490,76 @@ public abstract class Sapfor extends OSDComponent {
} }
return res; return res;
} }
//--
//-------------------------------------------------------------------------------------------------------------------
public static 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;
}
if (line.toLowerCase().contains("segmentation fault")) {
return false;
}
}
return true;
}
public static boolean performScript(String name, //имя скрипта
File sapfor_drv, //путь к сапфору
File workspace, //проект
String command, //проход
String flags, //флаги
String outName,
String errName) throws Exception {
Process process = null;
int exit_code = Constants.Nan;
//---
File data_workspace = new File(workspace, Constants.data);
Utils.CheckDirectory(data_workspace);
File outputFile = new File(data_workspace, outName);
File errorsFile = new File(data_workspace, errName);
Utils.delete_with_check(outputFile);
Utils.delete_with_check(errorsFile);
//---
File file = new File(data_workspace, name + (Global.isWindows ? ".bat" : ".sh"));
FileUtils.write(file,
Utils.DQuotes(sapfor_drv)
+ (flags.isEmpty() ? "" : (" " + flags))
+ " -noLogo"
+ " " + command +
" 1>" +
Utils.DQuotes(outputFile.getAbsolutePath()) +
" 2>" +
Utils.DQuotes(errorsFile.getAbsolutePath()),
Charset.defaultCharset());
if (!file.setExecutable(true))
throw new Exception("Не удалось сделать файл скрипта " + name + " исполняемым!");
//--
boolean flag = false;
do {
try {
ProcessBuilder procBuilder = new ProcessBuilder(file.getAbsolutePath());
procBuilder.directory(workspace);
process = procBuilder.start();
exit_code = process.waitFor();
flag = true;
} catch (Exception ex) {
Global.Log.PrintException(ex);
Utils.sleep(1000);
}
}
while (!flag);
process = null;
//---
Vector<String> outputLines = new Vector<>(FileUtils.readLines(outputFile));
Vector<String> errorsLines = new Vector<>(FileUtils.readLines(errorsFile));
return (exit_code == 0) &&
checkLines(outputLines) &&
checkLines(errorsLines);
}
} }

View File

@@ -76,28 +76,7 @@ public class Test extends riDBObject {
return new File(Global.TempDirectory, temp_project_name); return new File(Global.TempDirectory, temp_project_name);
} }
//-- //--
/* public db_project_info packCode(File dir) throws Exception {
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.clearData();
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 void packCode(File dir) throws Exception {
temp_project_name = Utils.getDateName("test"); temp_project_name = Utils.getDateName("test");
//- //-
File tempProject = getTempProject(); File tempProject = getTempProject();
@@ -116,6 +95,7 @@ public class Test extends riDBObject {
if (zip.Do(tempProject.getAbsolutePath(), tempArchive.getAbsolutePath())) { if (zip.Do(tempProject.getAbsolutePath(), tempArchive.getAbsolutePath())) {
project_archive_bytes = Utils.packFile(tempArchive); project_archive_bytes = Utils.packFile(tempArchive);
} else throw new PassException("Не удалось создать архив папки с кодом."); } else throw new PassException("Не удалось создать архив папки с кодом.");
return project;
} }
public boolean unpackProjectOnServer() throws Exception { public boolean unpackProjectOnServer() throws Exception {
File tmpArchive = new File(Global.TempDirectory, temp_project_name + ".zip"); File tmpArchive = new File(Global.TempDirectory, temp_project_name + ".zip");
@@ -148,7 +128,7 @@ public class Test extends riDBObject {
throw new RepositoryRefuseException("Не удалось переписать архив проекта"); throw new RepositoryRefuseException("Не удалось переписать архив проекта");
return true; return true;
} }
public String getFilesForTable(){ public String getFilesForTable() {
return files.replace("\n", ";"); return files.replace("\n", ";");
} }
} }

View File

@@ -3,23 +3,19 @@ import Common.Constants;
import Common.Global; import Common.Global;
import Common.Utils.Utils; import Common.Utils.Utils;
import GlobalData.Tasks.TaskState; import GlobalData.Tasks.TaskState;
import ProjectData.Messages.Errors.MessageError; import Repository.Component.Sapfor.Sapfor;
import TestingSystem.SAPFOR.Json.SapforConfiguration_json; import TestingSystem.SAPFOR.Json.SapforConfiguration_json;
import TestingSystem.SAPFOR.Json.SapforVersion_json; import TestingSystem.SAPFOR.Json.SapforVersion_json;
import TestingSystem.SAPFOR.SapforTask.SapforTask; import TestingSystem.SAPFOR.SapforTask.SapforTask;
import Visual_DVM_2021.Passes.PassCode_2021; import Visual_DVM_2021.Passes.PassCode_2021;
import Visual_DVM_2021.Passes.Pass_2021; import Visual_DVM_2021.Passes.Pass_2021;
import org.apache.commons.io.FileUtils;
import java.io.File; import java.io.File;
import java.nio.charset.Charset;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.Vector; import java.util.Vector;
import static java.lang.Character.isDigit;
public class PerformSapforTask extends Pass_2021<SapforTask> { public class PerformSapforTask extends Pass_2021<SapforTask> {
@Override @Override
public String getDescription() { public String getDescription() {
@@ -38,15 +34,6 @@ public class PerformSapforTask extends Pass_2021<SapforTask> {
File parentTask; File parentTask;
File task; File task;
//----- //-----
Process process = null;
int exit_code = Constants.Nan;
//----
File outputFile = null;
File errorsFile = null;
//--
Vector<String> outputLines;
Vector<String> errorsLines;
//---
@Override @Override
protected boolean canStart(Object... args) throws Exception { protected boolean canStart(Object... args) throws Exception {
sapfor_drv = (File) args[0]; sapfor_drv = (File) args[0];
@@ -59,73 +46,13 @@ public class PerformSapforTask extends Pass_2021<SapforTask> {
//--->> //--->>
return true; return true;
} }
protected static 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;
}
if (line.toLowerCase().contains("segmentation fault")) {
return false;
}
}
return true;
}
protected boolean performSapforScript(String name, File workspace, String command, String outName, String errName) throws Exception {
process = null;
exit_code = Constants.Nan;
//---
File data_workspace = new File(workspace, Constants.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 + (Global.isWindows ? ".bat" : ".sh"));
FileUtils.write(file,
Utils.DQuotes(sapfor_drv.getAbsolutePath())
+ (target.flags.isEmpty() ? "" : (" " + target.flags))
+ " -noLogo"
+ " " + command +
" 1>" +
Utils.DQuotes(outputFile.getAbsolutePath()) +
" 2>" +
Utils.DQuotes(errorsFile.getAbsolutePath()),
Charset.defaultCharset());
if (!file.setExecutable(true))
throw new Exception("Не удалось сделать файл скрипта " + name + " исполняемым!");
//--
boolean flag = false;
do {
try {
ProcessBuilder procBuilder = new ProcessBuilder(file.getAbsolutePath());
procBuilder.directory(workspace);
process = procBuilder.start();
exit_code = process.waitFor();
flag = true;
} catch (Exception ex) {
Global.Log.PrintException(ex);
Utils.sleep(1000);
}
}
while (!flag);
process = null;
//---
outputLines = new Vector<>(FileUtils.readLines(outputFile));
errorsLines = new Vector<>(FileUtils.readLines(errorsFile));
return (exit_code == 0) &&
checkLines(outputLines) &&
checkLines(errorsLines);
}
protected boolean parse() throws Exception { protected boolean parse() throws Exception {
if (performSapforScript("parse", parentTask, if (Sapfor.performScript(
"parse",
sapfor_drv,
parentTask,
"-parse *.f *.for *.fdv *.f90 *.f77", "-parse *.f *.for *.fdv *.f90 *.f77",
target.flags,
Constants.parse_out_file, Constants.parse_out_file,
Constants.parse_err_file) Constants.parse_err_file)
&& (new File(parentTask, "dvm.proj")).exists()) { && (new File(parentTask, "dvm.proj")).exists()) {
@@ -144,8 +71,12 @@ public class PerformSapforTask extends Pass_2021<SapforTask> {
root.getAbsolutePath(), root.getAbsolutePath(),
task.getAbsolutePath(), code.getDescription())); task.getAbsolutePath(), code.getDescription()));
//--- //---
if (performSapforScript("transformation", parentTask, if (Sapfor.performScript(
"transformation",
sapfor_drv,
parentTask,
code.getTestingCommand() + " -F " + Utils.DQuotes(task.getAbsolutePath()), code.getTestingCommand() + " -F " + Utils.DQuotes(task.getAbsolutePath()),
target.flags,
Constants.out_file, Constants.out_file,
Constants.err_file Constants.err_file
)) { )) {
@@ -158,9 +89,12 @@ public class PerformSapforTask extends Pass_2021<SapforTask> {
} }
protected void variants() throws Exception { protected void variants() throws Exception {
//папки вариантов создается самим сапфором. //папки вариантов создается самим сапфором.
target.state = performSapforScript("create_variants", parentTask, " -t 13 -allVars" target.state = Sapfor.performScript(
+ " -tinfo" "create_variants",
, sapfor_drv,
parentTask,
" -t 13 -allVars -tinfo",
target.flags,
Constants.out_file, Constants.out_file,
Constants.err_file Constants.err_file
) ? TaskState.Done : TaskState.DoneWithErrors; ) ? TaskState.Done : TaskState.DoneWithErrors;
@@ -178,176 +112,6 @@ public class PerformSapforTask extends Pass_2021<SapforTask> {
} }
} }
//-------------------------------------------------->> //-------------------------------------------------->>
public MessageError unpackMessage(String line_in) throws Exception {
MessageError res = new MessageError();
res.file = "";
res.line = Constants.Nan;
res.value = "";
String line = line_in.substring(9);
//System.out.println(line);
int i = 0;
int s = 0;
String lexeme = "";
//#1020: red43.fdv: line 988]: Active DVM directives are not supported (turn on DVM-directive support option)
for (char c : line.toCharArray()) {
// System.out.print("<s=" + s + ">");
// System.out.println(c);
switch (s) {
case 0:
//поиск groups_s
if (c == '#') {
s = 1;
lexeme = "";
} else return null;
break;
case 1:
//group_s
if (isDigit(c)) {
res.group_s += c;
lexeme += c;
} else if (c == ':') {
s = 2;
res.group = Integer.parseInt(lexeme);
} else return null;
break;
case 2:
//поиск filename
if (c == ' ') {
s = 3;
} else return null;
break;
case 3:
//filename
if (c == ':') {
s = 4;
} else {
res.file += c;
}
break;
case 4:
//поиск line
if (c == ' ') {
s = 5;
lexeme = "";
} else return null;
break;
case 5:
//line
if (c == ' ') {
if (!lexeme.equals("line"))
return null;
else {
s = 6;
lexeme = "";
}
} else {
lexeme += c;
}
break;
case 6:
//line number
if (isDigit(c)) {
lexeme += c;
} else if (c == ']') {
res.line = Integer.parseInt(lexeme);
s = 7;
} else return null;
break;
case 7:
//Поиск value
if (c == ':') {
s = 8;
} else return null;
break;
case 8:
if (c == ' ') {
s = 9;
} else return null;
break;
case 9:
//value
res.value += c;
break;
}
;
++i;
}
//--
if (s != 9)
return null;
//--
return res;
}
public void readMessagesFromFileDump(File file, Vector<MessageError> messages) throws Exception {
//Образец запакованного сообщения
//ERROR - [#1020: red43.fdv: line 988]: Active DVM directives are not supported (turn on DVM-directive support option)
Vector<String> lines = new Vector<>(FileUtils.readLines(file));
if (!lines.isEmpty()) {
for (int i = lines.size() - 1; i >= 0; --i) {
String line = lines.get(i);
if (line.startsWith("ERROR - ")) {
MessageError message = unpackMessage(line);
if (message != null)
messages.add(message);
//--
} else break;
}
}
}
//--
/*
protected void createVersionProjectData(SapforVersion_json version, boolean isTransformation) throws Exception {
db_project_info project = new db_project_info();
project.Home = new File(version.version);
project.name = project.Home.getName();
project.description = version.description;
project.languageName = LanguageName.fortran;
project.creationDate = Utils.getDateNumber();
//--
Vector<MessageError> messages = new Vector<>();
//--
if (isTransformation) {
File p_out = Paths.get(project.Home.getAbsolutePath(), Constants.data, Constants.parse_out_file).toFile();
File p_err = Paths.get(project.Home.getAbsolutePath(), Constants.data, Constants.parse_err_file).toFile();
File out = Paths.get(project.Home.getAbsolutePath(), Constants.data, Constants.out_file).toFile();
File err = Paths.get(project.Home.getAbsolutePath(), Constants.data, Constants.err_file).toFile();
//--
if (p_out.exists()) {
project.Log += (FileUtils.readFileToString(p_out));
readMessagesFromFileDump(p_out, messages);
}
if (out.exists()) {
project.Log += "\n" + FileUtils.readFileToString(out);
readMessagesFromFileDump(out, messages);
}
//в потоки ошибок идет информация от операционной системы. сообщений там быть не должно.
if (p_err.exists())
project.Log += (FileUtils.readFileToString(p_err));
if (err.exists())
project.Log += "\n" + FileUtils.readFileToString(err);
//--
}
project.CreateVisualiserData();
//---
if (isTransformation && !messages.isEmpty()) {
project.Open(); //нельзя!!! сначала надо определиться с версиями. И только потом, получать файлы.
//а так же, убрать dep и txt
project.db.BeginTransaction();
for (MessageError m : messages) {
if (project.db.files.containsKey(m.file)) {
DBProjectFile file = project.db.files.Data.get(m.file);
file.CreateAndAddNewMessage(1, m.value, m.line, m.group);
//update file
project.db.Update(file);
}
}
project.db.Commit();
project.db.Disconnect();
}
}
*/
//-------------------------------------------------->>
@Override @Override
protected void body() throws Exception { protected void body() throws Exception {
target.StartDate = new Date().getTime(); target.StartDate = new Date().getTime();

View File

@@ -4,6 +4,7 @@ import Common.Current;
import Common.Utils.Files.VDirectoryChooser; import Common.Utils.Files.VDirectoryChooser;
import Common.Utils.Utils; import Common.Utils.Utils;
import ProjectData.Files.ProjectFile; import ProjectData.Files.ProjectFile;
import ProjectData.Project.db_project_info;
import TestingSystem.Common.Group.Group; import TestingSystem.Common.Group.Group;
import TestingSystem.Common.Test.Test; import TestingSystem.Common.Test.Test;
import Visual_DVM_2021.Passes.PassCode_2021; import Visual_DVM_2021.Passes.PassCode_2021;
@@ -131,8 +132,8 @@ public class CreateTestFromFolder extends Pass_2021<Test> {
} }
System.out.println("==================="); System.out.println("===================");
//-- //--
target.packCode(dir); //создание копии папки, и архивация. db_project_info project = target.packCode(dir); //создание копии папки, и архивация.
//-- //-- получить размерность консольным сапфором.
} }
@Override @Override
protected void performDone() throws Exception { protected void performDone() throws Exception {