рефакторинг. ввел оберточные методы работы с json объектами
This commit is contained in:
@@ -2,6 +2,7 @@ package Common.Constants;
|
||||
import java.util.regex.Pattern;
|
||||
public class Constants {
|
||||
public static final int Nan = -1;
|
||||
public static char toStrike = (char) 822;
|
||||
public static final Pattern VALID_EMAIL_ADDRESS_REGEX =
|
||||
Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
|
||||
public static char[] forbidden_file_name_characters = new char[]{
|
||||
|
||||
@@ -497,6 +497,6 @@ public enum Current {
|
||||
Normal,
|
||||
Server,
|
||||
Testing,
|
||||
Package
|
||||
Scenario
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package Common;
|
||||
import Common.Database.DataSet;
|
||||
import Common.ModesSupervisors.PackageModeSupervisor;
|
||||
import Common.UI.Menus_2023.ComponentsMenuBar.ComponentsMenuBar;
|
||||
import Common.UI.UI;
|
||||
import Common.Utils.Utils;
|
||||
@@ -14,16 +13,15 @@ import Repository.Component.Sapfor.MessagesServer;
|
||||
import Repository.Component.Sapfor.Sapfor_F;
|
||||
import Repository.Component.Sapfor.TransformationPermission;
|
||||
import Repository.Server.ComponentsServer;
|
||||
import SapforTestingSystem.SapforTestingPlaner.SapforTestingPlanner;
|
||||
import TestingSystem.TestingServer;
|
||||
import Visual_DVM_2021.Passes.PassCode_2021;
|
||||
import Visual_DVM_2021.Passes.Pass_2021;
|
||||
import Visual_DVM_2021.UI.Interface.Loggable;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory;
|
||||
import org.fife.ui.rsyntaxtextarea.TokenMakerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Vector;
|
||||
public class Global {
|
||||
@@ -106,15 +104,11 @@ public class Global {
|
||||
//------------------------------------------------------------------------
|
||||
public static Loggable Log;
|
||||
public static void SynschronizeProperties() {
|
||||
//---- NEW -----
|
||||
try {
|
||||
File new_propertiesFile = Paths.get(Home, "properties").toFile();
|
||||
if (new_propertiesFile.exists()) {
|
||||
String packed = FileUtils.readFileToString(new_propertiesFile, Charset.defaultCharset());
|
||||
properties = Utils.gson.fromJson(packed, GlobalProperties.class);
|
||||
}
|
||||
//пусть всегда в него пишет. с учетом того, что новые настройки могут появиться.
|
||||
FileUtils.writeStringToFile(new_propertiesFile, Utils.jsonToPrettyFormat(Utils.gson.toJson(properties)));
|
||||
if (new_propertiesFile.exists())
|
||||
properties = (GlobalProperties) Utils.jsonFromFile(new_propertiesFile, GlobalProperties.class);
|
||||
Utils.jsonToFile(properties, new_propertiesFile);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@@ -350,6 +344,21 @@ public class Global {
|
||||
testingServer.Start();
|
||||
System.exit(0);
|
||||
}
|
||||
public static void ScenarioMode() throws Exception {
|
||||
Log = new Loggable() {
|
||||
@Override
|
||||
public String getLogHomePath() {
|
||||
return Home;
|
||||
}
|
||||
@Override
|
||||
public String getLogName() {
|
||||
return "Scenario";
|
||||
}
|
||||
};
|
||||
Log.ClearLog();
|
||||
SapforTestingPlanner planner = new SapforTestingPlanner();
|
||||
//planner.Start();
|
||||
}
|
||||
//---
|
||||
public static void Init(String... args) {
|
||||
System.out.println("VisualSapfor.jar started..");
|
||||
@@ -370,19 +379,8 @@ public class Global {
|
||||
case Testing:
|
||||
TestingSystemMode();
|
||||
break;
|
||||
case Package:
|
||||
Log = new Loggable() {
|
||||
@Override
|
||||
public String getLogHomePath() {
|
||||
return Home;
|
||||
}
|
||||
@Override
|
||||
public String getLogName() {
|
||||
return "PackageMode";
|
||||
}
|
||||
};
|
||||
Log.ClearLog();
|
||||
new PackageModeSupervisor().Do();
|
||||
case Scenario:
|
||||
ScenarioMode();
|
||||
break;
|
||||
case Undefined:
|
||||
break;
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
package Common;
|
||||
public class PackageModeSupervisor {
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package Common;
|
||||
import Common.UI.Menus_2023.StableMenuItem;
|
||||
import Common.Utils.Utils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
@@ -39,7 +38,7 @@ public abstract class Properties {
|
||||
}
|
||||
public void Update() {
|
||||
try {
|
||||
FileUtils.write(getFile(), Utils.jsonToPrettyFormat(Utils.gson.toJson(this)));
|
||||
Utils.jsonToFile(this, getFile());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ public class MainMenuBar extends VisualiserMenuBar {
|
||||
});
|
||||
}
|
||||
});
|
||||
/*
|
||||
add(new MenuBarButton() {
|
||||
{
|
||||
setIcon("/icons/Comparsion.png");
|
||||
@@ -47,6 +48,7 @@ public class MainMenuBar extends VisualiserMenuBar {
|
||||
});
|
||||
}
|
||||
});
|
||||
*/
|
||||
addPasses(PassCode_2021.ShowInstruction);
|
||||
//-
|
||||
setPreferredSize(new Dimension(0, 30));
|
||||
|
||||
@@ -34,7 +34,15 @@ import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
public class Utils {
|
||||
public static Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
||||
public static final Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
||||
public static Object jsonFromFile(File file, Class json_class) throws Exception {
|
||||
String packed = FileUtils.readFileToString(file, Charset.defaultCharset());
|
||||
return Utils.gson.fromJson(packed, json_class);
|
||||
}
|
||||
public static void jsonToFile(Object json_object, File file) throws Exception {
|
||||
FileUtils.writeStringToFile(file, Utils.jsonToPrettyFormat(Utils.gson.toJson(json_object)));
|
||||
}
|
||||
//--->>
|
||||
public static String hideRegularMetasymbols(String word) {
|
||||
String res = word.replace("\\", "\\\\");
|
||||
for (char c : Constants.regular_metasymbols)
|
||||
@@ -896,72 +904,23 @@ public class Utils {
|
||||
}
|
||||
return res;
|
||||
}
|
||||
public static char toStrike = (char) 822;
|
||||
public static String strikeThrough(String s) {
|
||||
StringBuilder res = new StringBuilder();
|
||||
for (char c : s.toCharArray()) {
|
||||
res.append(c);
|
||||
if (c != toStrike)
|
||||
res.append(toStrike);
|
||||
if (c != Constants.toStrike)
|
||||
res.append(Constants.toStrike);
|
||||
}
|
||||
return res.toString();
|
||||
}
|
||||
public static String noStrikeThrough(String s) {
|
||||
StringBuilder res = new StringBuilder();
|
||||
for (char c : s.toCharArray()) {
|
||||
if (c != (toStrike))
|
||||
if (c != (Constants.toStrike))
|
||||
res.append(c);
|
||||
}
|
||||
return res.toString();
|
||||
}
|
||||
public static String splitToolTip(String tip, int length) {
|
||||
int DIALOG_TOOLTIP_MAX_SIZE = 75;
|
||||
int SPACE_BUFFER = 10;
|
||||
if (tip.length() <= length + SPACE_BUFFER) {
|
||||
return tip;
|
||||
}
|
||||
Vector<String> parts = new Vector<>();
|
||||
int maxLength = 0;
|
||||
String overLong = tip.substring(0, length + SPACE_BUFFER);
|
||||
int lastSpace = overLong.lastIndexOf(' ');
|
||||
if (lastSpace >= length) {
|
||||
parts.add(tip.substring(0, lastSpace));
|
||||
maxLength = lastSpace;
|
||||
} else {
|
||||
parts.add(tip.substring(0, length));
|
||||
maxLength = length;
|
||||
}
|
||||
while (maxLength < tip.length()) {
|
||||
if (maxLength + length < tip.length()) {
|
||||
parts.add(tip.substring(maxLength, maxLength + length));
|
||||
maxLength += maxLength + length;
|
||||
} else {
|
||||
parts.add(tip.substring(maxLength));
|
||||
break;
|
||||
}
|
||||
}
|
||||
StringBuilder sb = new StringBuilder("<html>");
|
||||
for (int i = 0; i < parts.size() - 1; i++) {
|
||||
sb.append(parts.get(i) + "<br>");
|
||||
}
|
||||
sb.append(parts.get(parts.size() - 1));
|
||||
sb.append(("</html>"));
|
||||
return sb.toString();
|
||||
}
|
||||
/*
|
||||
public static String appendString(String s, int sizeTo, char symbol) {
|
||||
int delta = sizeTo - s.length();
|
||||
StringBuilder res = new StringBuilder(s);
|
||||
if (delta <= 0) {
|
||||
for (int i = 0; i < sizeTo; ++i)
|
||||
res.append(symbol);
|
||||
}
|
||||
for (int i = 0; i < delta; ++i) {
|
||||
res.append(symbol);
|
||||
}
|
||||
return res.toString();
|
||||
}
|
||||
*/
|
||||
public static void addEmptyLines(Vector<String> lines, int num) {
|
||||
IntStream.range(0, num).mapToObj(i -> "").forEach(lines::add);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package SapforTestingSystem.SapforTestingPlaner;
|
||||
import Common.Global;
|
||||
import Common.Utils.Utils;
|
||||
import SapforTestingSystem.ThreadsPlanner.ThreadsPlanner;
|
||||
public class SapforTestingPlanner extends ThreadsPlanner {
|
||||
public SapforTestingPlanner() {
|
||||
super(2000, 4);
|
||||
//--
|
||||
/*
|
||||
for (int i = 1; i <= 20; ++i) {
|
||||
int thread_number = i;
|
||||
addThread(() -> {
|
||||
@@ -15,5 +14,6 @@ public class SapforTestingPlanner extends ThreadsPlanner {
|
||||
}
|
||||
});
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
package Visual_DVM_2021.Passes.All;
|
||||
import Common.Global;
|
||||
import Common.Utils.Utils;
|
||||
import SapforTestingSystem.SapforTask.SapforTask;
|
||||
import SapforTestingSystem.Json.ScenarioResults_json;
|
||||
import SapforTestingSystem.SapforTask.SapforTask;
|
||||
import Visual_DVM_2021.Passes.Pass_2021;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.Charset;
|
||||
public class AnalyseSapforPackageResults extends Pass_2021<ScenarioResults_json> {
|
||||
File packageWorkspace;
|
||||
File scenarioFile;
|
||||
@@ -23,8 +20,8 @@ public class AnalyseSapforPackageResults extends Pass_2021<ScenarioResults_json>
|
||||
packageWorkspace = new File((String) args[0]);
|
||||
scenarioFile = new File(packageWorkspace, "results.txt");
|
||||
//--
|
||||
String packed = FileUtils.readFileToString(scenarioFile, Charset.defaultCharset());
|
||||
target = Utils.gson.fromJson(packed, ScenarioResults_json.class);
|
||||
// String packed = FileUtils.readFileToString(scenarioFile, Charset.defaultCharset());
|
||||
// target = Utils.gson.fromJson(packed, ScenarioResults_json.class);
|
||||
//---
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class SPF_CreateParallelVariant extends SapforTransformation {
|
||||
@Override
|
||||
protected void performFinish() throws Exception {
|
||||
//в пакетном режиме вариант всегда один. поэтому, сообщения надо распаковать сразу.
|
||||
if (Current.mode.equals(Current.Mode.Package))
|
||||
if (Current.mode.equals(Current.Mode.Scenario))
|
||||
super.performFinish();
|
||||
}
|
||||
@Override
|
||||
|
||||
@@ -224,9 +224,9 @@ public class StartSapforTests extends Pass_2021<SapforScenario> {
|
||||
FileUtils.copyFile(Global.visualiser.getFile(), visualiser);
|
||||
ShowMessage2("Создание настроек");
|
||||
GlobalProperties properties = new GlobalProperties();
|
||||
properties.Mode = Current.Mode.Package;
|
||||
File propertiesFile = new File(target.workspace, "properties");
|
||||
FileUtils.write(propertiesFile, Utils.jsonToPrettyFormat(Utils.gson.toJson(properties)));
|
||||
properties.Mode = Current.Mode.Scenario;
|
||||
//----
|
||||
Utils.jsonToFile(properties, new File(target.workspace, "properties"));
|
||||
//----
|
||||
File scenarioFile = new File(target.workspace, "scenario.txt");
|
||||
SapforScenario_json scenario_json = new SapforScenario_json();
|
||||
@@ -275,7 +275,7 @@ public class StartSapforTests extends Pass_2021<SapforScenario> {
|
||||
scenario_json.packages.add(package_json);
|
||||
}
|
||||
//--
|
||||
FileUtils.write(scenarioFile, Utils.jsonToPrettyFormat(Utils.gson.toJson(scenario_json)));
|
||||
Utils.jsonToFile(scenario_json, scenarioFile);
|
||||
}
|
||||
@Override
|
||||
protected void showFinish() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user