2023-09-21 20:55:14 +03:00
|
|
|
package SapforTestingSystem.Json;
|
2023-11-02 23:27:38 +03:00
|
|
|
import Common.Constants;
|
2023-10-30 22:37:03 +03:00
|
|
|
import Common.Global;
|
|
|
|
|
import Common.Utils.Utils;
|
2023-10-31 01:02:11 +03:00
|
|
|
import ProjectData.Files.FileType;
|
2023-10-31 01:51:08 +03:00
|
|
|
import ProjectData.Files.ProjectFile;
|
2023-09-17 22:13:42 +03:00
|
|
|
import com.google.gson.annotations.Expose;
|
2023-11-08 03:05:29 +03:00
|
|
|
import org.apache.commons.io.FileUtils;
|
2023-10-25 16:33:02 +03:00
|
|
|
|
2023-10-30 22:37:03 +03:00
|
|
|
import java.io.File;
|
2023-10-25 16:33:02 +03:00
|
|
|
import java.io.Serializable;
|
2023-11-08 03:05:29 +03:00
|
|
|
import java.nio.charset.Charset;
|
2023-10-30 22:37:03 +03:00
|
|
|
import java.nio.file.Paths;
|
2023-11-08 02:05:21 +03:00
|
|
|
import java.util.LinkedHashMap;
|
2023-10-25 16:33:02 +03:00
|
|
|
public class SapforVersion_json implements Serializable {
|
2023-09-17 22:13:42 +03:00
|
|
|
@Expose
|
|
|
|
|
public String version = "";
|
|
|
|
|
@Expose
|
|
|
|
|
public String description = "";
|
2023-11-03 02:00:17 +03:00
|
|
|
public boolean success = true;
|
2023-10-31 01:02:11 +03:00
|
|
|
//поля для отображения деревьев.
|
|
|
|
|
public File Home = null;
|
2023-11-08 02:05:21 +03:00
|
|
|
public LinkedHashMap<String, ProjectFile> files = new LinkedHashMap<>();
|
2023-11-09 19:20:51 +03:00
|
|
|
//--
|
|
|
|
|
public String parse_out = "";
|
|
|
|
|
public String parse_err = "";
|
|
|
|
|
public String out = "";
|
|
|
|
|
public String err = "";
|
|
|
|
|
//--
|
2023-09-17 22:13:42 +03:00
|
|
|
public SapforVersion_json(String version_in, String description_in) {
|
|
|
|
|
version = version_in;
|
|
|
|
|
description = description_in;
|
|
|
|
|
}
|
2023-10-29 01:03:37 +03:00
|
|
|
public SapforVersion_json(String root_in, String version_in, String description_in) {
|
|
|
|
|
version = version_in.substring(root_in.length() + 1);
|
|
|
|
|
description = description_in;
|
|
|
|
|
}
|
2023-10-30 22:37:03 +03:00
|
|
|
@Override
|
|
|
|
|
public String toString() {
|
2023-10-31 01:02:11 +03:00
|
|
|
return Home.getName() + " : " + Utils.Brackets(description);
|
2023-10-30 22:37:03 +03:00
|
|
|
}
|
2023-10-31 01:02:11 +03:00
|
|
|
public void init(File configurationRoot) {
|
2023-10-30 22:37:03 +03:00
|
|
|
String relativePath = Global.isWindows ? Utils.toW(version) : version;
|
|
|
|
|
Home = Paths.get(configurationRoot.getAbsolutePath(), relativePath).toFile();
|
2023-11-08 02:05:21 +03:00
|
|
|
files = new LinkedHashMap<>();
|
2023-10-31 01:02:11 +03:00
|
|
|
//--
|
|
|
|
|
File[] files_ = Home.listFiles();
|
|
|
|
|
if (files_ != null) {
|
2023-11-02 23:27:38 +03:00
|
|
|
for (File file : files_) {
|
2023-10-31 01:02:11 +03:00
|
|
|
if (file.isFile()) {
|
2023-10-31 01:51:08 +03:00
|
|
|
ProjectFile projectFile = new ProjectFile(file);
|
2023-11-09 19:20:51 +03:00
|
|
|
if (!projectFile.fileType.equals(FileType.forbidden)
|
2023-11-08 02:05:21 +03:00
|
|
|
) {
|
|
|
|
|
files.put(projectFile.file.getName(), projectFile);
|
2023-10-31 01:02:11 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-09 19:20:51 +03:00
|
|
|
File parse_out_file = Paths.get(Home.getAbsolutePath(), Constants.data, Constants.parse_out_file).toFile();
|
|
|
|
|
File parse_err_file = Paths.get(Home.getAbsolutePath(), Constants.data, Constants.parse_err_file).toFile();
|
|
|
|
|
File out_file = Paths.get(Home.getAbsolutePath(), Constants.data, Constants.out_file).toFile();
|
|
|
|
|
File err_file = Paths.get(Home.getAbsolutePath(), Constants.data, Constants.err_file).toFile();
|
2023-11-02 23:27:38 +03:00
|
|
|
//--
|
2023-11-09 19:20:51 +03:00
|
|
|
try {
|
|
|
|
|
if (parse_out_file.exists())
|
|
|
|
|
parse_out = FileUtils.readFileToString(parse_out_file);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
if (parse_err_file.exists())
|
|
|
|
|
parse_err = FileUtils.readFileToString(parse_err_file);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
if (out_file.exists())
|
|
|
|
|
out = FileUtils.readFileToString(out_file);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
if (err_file.exists())
|
|
|
|
|
err = FileUtils.readFileToString(err_file);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
2023-11-02 23:27:38 +03:00
|
|
|
}
|
2023-10-30 22:37:03 +03:00
|
|
|
}
|
2023-11-08 02:05:21 +03:00
|
|
|
public boolean isMatch(SapforVersion_json version_json) {
|
2023-11-08 03:05:29 +03:00
|
|
|
if (!description.equals(version_json.description)) {
|
2023-11-08 02:05:21 +03:00
|
|
|
System.out.println("не совпадение описания версии");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (files.size() != version_json.files.size()) {
|
|
|
|
|
System.out.println("не совпадение количества файлов");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-11-08 03:05:29 +03:00
|
|
|
for (String name1 : files.keySet()) {
|
|
|
|
|
if (!version_json.files.containsKey(name1)) {
|
|
|
|
|
System.out.println("Файл " + Utils.Brackets(name1) + " не найден в версии " + version_json.Home);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (String name1 : files.keySet()) {
|
|
|
|
|
ProjectFile file1 = files.get(name1);
|
|
|
|
|
ProjectFile file2 = version_json.files.get(name1);
|
|
|
|
|
//---
|
|
|
|
|
String text1 = "";
|
|
|
|
|
String text2 = "";
|
|
|
|
|
try {
|
|
|
|
|
text1 = FileUtils.readFileToString(file1.file, Charset.defaultCharset());
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
text2 = FileUtils.readFileToString(file2.file, Charset.defaultCharset());
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
if (!text1.equals(text2)) {
|
|
|
|
|
System.out.println("различие текста файла " + Utils.Brackets(file1.file.getName()));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2023-11-08 02:05:21 +03:00
|
|
|
}
|
2023-09-17 22:13:42 +03:00
|
|
|
}
|