рефакторинг

This commit is contained in:
2023-09-29 21:46:08 +03:00
parent 12898b07bb
commit 760707e6fb
41 changed files with 510 additions and 486 deletions

View File

@@ -1,4 +1,5 @@
package Common.Utils;
import Common.Constants.Constants;
import Common.Global;
import Common.UI.UI;
import ProjectData.Files.DBProjectFile;
@@ -34,367 +35,14 @@ import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Utils {
public static Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
public static final int Nan = -1;
public static final Pattern VALID_EMAIL_ADDRESS_REGEX =
Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
//https://losst.ru/komandy-terminala-linux
public static String[] linux_system_commands = new String[]{
//<editor-fold desc="все линуксовые команды. их МНОГО">
"a2p",
"ac",
"addgroup",
"adduser",
"agrep",
"alias",
"apropos",
"apt",
"aptitude",
"ar",
"arch",
"arp",
"as",
"aspell",
"at",
"awk",
"basename",
"bash",
"bс",
"bdiff",
"bfs",
"bg",
"biff",
"break",
"bs",
"bye",
"cal",
"calendar",
"cancel",
"cat",
"cc",
"cd",
"cfdisk",
"chdir",
"checkeq",
"checknr",
"chfn",
"chgrp",
"chmod",
"chown",
"chroot",
"chsh",
"cksum",
"clear",
"cmp",
"col",
"comm",
"compress",
"continue",
"cp",
"cpio",
"crontab",
"csh",
"csplit",
"ctags",
"cu",
"curl",
"cut",
"date",
"dc",
"dd",
"delgroup",
"deluser",
"depmod",
"deroff",
"df",
"dhclient",
"dig",
"dircmp",
"dirname",
"dmesg",
"dos2unix",
"dpkg",
"dpost",
"du",
"echo",
"ed",
"edit",
"egrep",
"eject",
"elm",
"emacs",
"emerge",
"enable",
"env",
"eqn",
"ex",
"exit",
"expand",
"expr",
"fc",
"fdisk",
"fg",
"fgrep",
"file",
"find",
"findsmb",
"finger",
"fmt",
"fold",
"for",
"foreach",
"free",
"fsck",
"ftp",
"fuser",
"gawk",
"getfacl",
"gpasswd",
"gprof",
"grep",
"groupadd",
"groupdel",
"groupmod",
"gnuzip",
"gview",
"gvim",
"gzip",
"halt",
"head",
"help",
"history",
"host",
"hostid",
"hostname",
"htop",
"id",
"ifconfig",
"ifdown",
"ifquery",
"ifup",
"info",
"insmod",
"iostat",
"ip",
"iwconfig",
"jobs",
"join",
"kill",
"killall",
"ksh",
"last",
"ld",
"ldd",
"less",
"link",
"ln",
"lo",
"locate",
"login",
"logname",
"logout",
"losetup",
"ls",
"lsmod",
"lsof",
"lzcat",
"lzma",
"mach",
"mailx",
"make",
"man",
"merge",
"mesg",
"mkdir",
"mkfs",
"mkswap",
"modinfo",
"modprobe",
"more",
"mount",
"mt",
"mv",
"mysql",
"mysqldump",
"nc",
"netstat",
"newgrp",
"nice",
"niscat",
"nischmod",
"nischown",
"nischttl",
"nisdefaults",
"nistbladm",
"nl",
"nmap",
"nohup",
"nroff",
"nslookup",
"od",
"on",
"onintr",
"pack",
"pacman",
"pagesize",
"parted",
"partprobe",
"passwd",
"paste",
"pax",
"pact",
"perl",
"pg",
"pico",
"pine",
"pkill",
"poweroff",
"pr",
"printenv",
"printf",
"ps",
"pstree",
"pvs",
"pwd",
"quit",
"rcp",
"readlink",
"reboot",
"red",
"rename",
"repeat",
"replace",
"rlogin",
"rm",
"rmdir",
"rmmod",
"route",
"rpcinfo",
"rsh",
"rsync",
"s2p",
"scp",
"screen",
"script",
"sdiff",
"sed",
"sendmail",
"service",
"set",
"setfacl",
"sfdisk",
"sftp",
"sh",
"shred",
"shutdown",
"sleep",
"slogin",
"smbclient",
"sort",
"spell",
"split",
"startx",
"ss",
"ssh",
"stat",
"stop",
"strftime",
"strip",
"stty",
"su",
"sudo",
"swapoff",
"swapon",
"systemctl",
"tabs",
"tac",
"tail",
"talk",
"tar",
"tcopy",
"tcpdump",
"tcsh",
"tee",
"telnet",
"test",
"time",
"timex",
"todos",
"top",
"touch",
"traceroute",
"tree",
"tty",
"umask",
"umount",
"unalias",
"uname",
"uncompress",
"uniq",
"unlink",
"unlzma",
"unpack",
"until",
"unxz",
"unzip",
"uptime",
"useradd",
"userdel",
"usermod",
"vacation",
"vi",
"vim",
"w",
"wait",
"wall",
"wc",
"wget",
"whereis",
"which",
"while",
"who",
"whoami",
"whois",
"Xorg",
"xargs",
"xfd",
"xhost",
"xlsfonts",
"xrdb",
"xset",
"xz",
"xzcat",
"yacc",
"yes",
"yppasswd",
"yum",
"zcat",
"zipcloack",
"zipinfo",
"zipnote",
"zipsplit",
"zypper"
//</editor-fold>
};
public static char[] forbidden_file_name_characters = new char[]{
'#', '%', '&', '{', '}',
'<', '>', '*', '?', '!',
'$', '\'', '\"', '@', '+',
'`', '|', '=', '#', ':', '/', '\\',
'~', '^'
};
public static char[] regular_metasymbols = new char[]{
'<', '>', '(', ')', '[', ']', '{', '}', '^', '-', '=', '$', '!', '|', '?', '*', '+', '.'
};
//все запретные символы через пробел.
public static String all_forbidden_characters_string = "";
public static String hideRegularMetasymbols(String word) {
String res = word.replace("\\", "\\\\");
for (char c : regular_metasymbols)
for (char c : Constants.regular_metasymbols)
res = res.replace(String.valueOf(c), "\\" + c);
return res;
}
public static boolean isLinuxSystemCommand(String text) {
for (String command : linux_system_commands) {
for (String command : Constants.linux_system_commands) {
if (text.equalsIgnoreCase(command)) return true;
}
return false;
@@ -406,13 +54,13 @@ public class Utils {
return false;
}
public static boolean isForbidden(char c) {
for (char f : forbidden_file_name_characters)
for (char f : Constants.forbidden_file_name_characters)
if (c == f) return true;
return false;
}
public static void init() {
for (char f : forbidden_file_name_characters)
all_forbidden_characters_string += f + " ";
for (char f : Constants.forbidden_file_name_characters)
Constants.all_forbidden_characters_string += f + " ";
}
public static String DQuotes(Object o) {
return "\"" + o.toString() + "\"";
@@ -516,7 +164,7 @@ public class Utils {
}
}
}
public static long last_ticks = Utils.Nan;
public static long last_ticks = Constants.Nan;
public static void sleep(long millis) {
try {
Thread.sleep(millis);
@@ -819,7 +467,7 @@ public class Utils {
res = false;
}
if (ContainsForbiddenName(name)) {
Log.Writeln_("Имя файла не может содержать запрещённых символов\n" + all_forbidden_characters_string);
Log.Writeln_("Имя файла не может содержать запрещённых символов\n" + Constants.all_forbidden_characters_string);
res = false;
}
return res;
@@ -851,7 +499,7 @@ public class Utils {
validateProjectFolder_r(dir, files_list);
if (!files_list.isEmpty())
Log.Writeln_("Имена " + filesLines.length + " файлов/подпапок содержат запрещённые символы " +
all_forbidden_characters_string +
Constants.all_forbidden_characters_string +
"или кириллицу");
//нужно проверить корень на наличие хоть одной программы.
return Log.isEmpty();
@@ -996,7 +644,7 @@ public class Utils {
Files.copy(i, dst.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
public static boolean validateEmail(String address, TextLog log) {
Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(address);
Matcher matcher = Constants.VALID_EMAIL_ADDRESS_REGEX.matcher(address);
if (!matcher.find()) {
log.Writeln_("введённый адрес электронной почты некорректен.");
return false;
@@ -1052,7 +700,6 @@ public class Utils {
public static Process startScript(File scriptDirectory, File targetDirectory, String name, String scriptText) throws Exception {
return startScript(scriptDirectory, targetDirectory, name, scriptText, null);
}
public static Process startScript_(File scriptDirectory, File targetDirectory, String name, String scriptText) throws Exception {
//->
File scriptFile = Paths.get(scriptDirectory.getAbsolutePath(), name + (Global.isWindows ? ".bat" : "")).toFile();
@@ -1427,7 +1074,7 @@ public class Utils {
return false;
}
public static void copyDirectory(File src, File dst) throws Exception {
int code = Utils.Nan;
int code = Constants.Nan;
String command = "xcopy " +
Utils.DQuotes(src.getAbsolutePath()) + " " +
Utils.DQuotes(dst.getAbsolutePath()) + " /e";