package SapforTestingSystem.Json; import Common.Constants; import Common.Global; import Common.Utils.Utils; import ProjectData.Files.FileState; import ProjectData.Files.FileType; import ProjectData.Files.ProjectFile; import com.google.gson.annotations.Expose; import org.apache.commons.io.FileUtils; import java.io.File; import java.io.Serializable; import java.nio.charset.Charset; import java.nio.file.Paths; import java.util.LinkedHashMap; import java.util.Vector; public class SapforVersion_json implements Serializable { @Expose public String version = ""; @Expose public String description = ""; public boolean success = true; //поля для отображения деревьев. public File Home = null; public LinkedHashMap files = new LinkedHashMap<>(); //- public SapforVersion_json(String version_in, String description_in) { version = version_in; description = description_in; } public SapforVersion_json(String root_in, String version_in, String description_in) { version = version_in.substring(root_in.length() + 1); description = description_in; } @Override public String toString() { return Home.getName() + " : " + Utils.Brackets(description); } public void init(File configurationRoot) { String relativePath = Global.isWindows ? Utils.toW(version) : version; Home = Paths.get(configurationRoot.getAbsolutePath(), relativePath).toFile(); files = new LinkedHashMap<>(); //-- File[] files_ = Home.listFiles(); if (files_ != null) { for (File file : files_) { if (file.isFile()) { ProjectFile projectFile = new ProjectFile(file); if (!projectFile.fileType.equals(FileType.forbidden) && !projectFile.state.equals(FileState.Excluded) ) { files.put(projectFile.file.getName(), projectFile); } } } } //теперь файлы вывода. Vector out_files = new Vector<>(); out_files.add(Paths.get(Home.getAbsolutePath(), Constants.data, Constants.parse_out_file).toFile()); out_files.add(Paths.get(Home.getAbsolutePath(), Constants.data, Constants.parse_err_file).toFile()); out_files.add(Paths.get(Home.getAbsolutePath(), Constants.data, Constants.out_file).toFile()); out_files.add(Paths.get(Home.getAbsolutePath(), Constants.data, Constants.err_file).toFile()); //-- for (File file : out_files) { if (file.exists()) { // System.out.println(file.getAbsolutePath()); ProjectFile projectFile = new ProjectFile(file); files.put(projectFile.file.getName(), projectFile); } } } public boolean isMatch(SapforVersion_json version_json) { if (!description.equals(version_json.description)) { System.out.println("не совпадение описания версии"); return false; } if (files.size() != version_json.files.size()) { System.out.println("не совпадение количества файлов"); return false; } 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; } }