From e2b408b43f764bb07dd7477ee9897bf3d052c322 Mon Sep 17 00:00:00 2001 From: "jiashuaizhang@126.com" Date: Sun, 19 Dec 2021 18:53:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=AF=E5=8A=A8=E5=89=8D=E5=90=8E=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E6=B7=BB=E5=8A=A0=E5=85=B3=E9=97=AD=E5=BC=80=E5=85=B3?= =?UTF-8?q?=EF=BC=9B=E4=BF=AE=E6=AD=A3=E4=BA=86=E5=87=A0=E4=B8=AA=E5=B0=8F?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 18 +- yyets-history/pom.xml | 2 +- .../yyetshistory/YyetsHistoryApplication.java | 4 + .../yyetshistory/config/AppRunner.java | 16 -- .../config/YyetsHistoryProperties.java | 28 ++- .../yyetshistory/entity/Resource.java | 6 +- .../yyetshistory/service/ResourceService.java | 6 +- .../service/impl/ResourceServiceImpl.java | 13 +- .../yyetshistory/util/NativeConfigUtil.java | 218 ++++++++++++++++++ .../util/NativeOperationUtils.java | 34 ++- .../yyetshistory/util/NativeYamlUtil.java | 147 ------------ .../src/main/resources/application.yml | 4 +- .../yyetshistory/SimpleTest.java | 24 +- .../YyetsHistoryApplicationTests.java | 33 +++ 14 files changed, 341 insertions(+), 212 deletions(-) delete mode 100644 yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/config/AppRunner.java create mode 100644 yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/util/NativeConfigUtil.java delete mode 100644 yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/util/NativeYamlUtil.java diff --git a/README.md b/README.md index 7fc8332..3342466 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # yyets-snapshot -> 人人影视历史镜像,致敬曾经的辉煌。 +> 人人影视历史镜像 ##### 几点说明 @@ -9,10 +9,20 @@ ##### 效果展示 1. 剧目检索 - ![yyets-1](./static/yyets-1.png) + ![yyets-1](./static/yyets-1.png) 2. 复制链接 - ![yyets-2](./static/yyets-2.png) + ![yyets-2](./static/yyets-2.png) 3. 查看链接 - ![yyets-3](./static/yyets-3.png) + ![yyets-3](./static/yyets-3.png) + +##### 配置说明 + +| 配置项 | 类型 | 作用 | 缺省值 | 说明 | +| ----------------------------------- | -------- | -------------------- | --------- | ------------------------------------------------------------ | +| `yyets-history.link-way-filter` | string[] | 保留的链接类型 | 电驴,磁力 | 所有支持的链接类型:[电驴, 腾讯, 百度云, 磁力, Bilibili, 优酷, 诚通网盘, 微云, 网盘, 搜狐, 乐视, Acfun] | +| `yyets-history.host` | string | 域名 | localhost | 启动前后事件中使用 | +| `yyets-history.start-prepare-event` | boolean | 是否开启启动前置事件 | true | 前置事件: 检查程序是否已在另一进程启动。支持命令行--参数、jvm -D参数、系统环境变量,不支持yml配置 | +| `yyets-history.start-finish-event` | boolean | 是否开启启动后置事件 | true | 后置事件: 自动弹出浏览器,失败则弹框给出访问地址 | + diff --git a/yyets-history/pom.xml b/yyets-history/pom.xml index 3cb7839..59cba98 100644 --- a/yyets-history/pom.xml +++ b/yyets-history/pom.xml @@ -10,7 +10,7 @@ com.zhangjiashuai yyets-history - 2.2 + 2.3 yyets-history a yyets history snapshot diff --git a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/YyetsHistoryApplication.java b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/YyetsHistoryApplication.java index 908a505..1f83c47 100644 --- a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/YyetsHistoryApplication.java +++ b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/YyetsHistoryApplication.java @@ -3,6 +3,9 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import java.util.concurrent.atomic.AtomicBoolean; + +import static com.zhangjiashuai.yyetshistory.util.NativeOperationUtils.onStartFinish; import static com.zhangjiashuai.yyetshistory.util.NativeOperationUtils.onStartPrepare; @SpringBootApplication @@ -11,6 +14,7 @@ public class YyetsHistoryApplication { public static void main(String[] args) { onStartPrepare(args); SpringApplication.run(YyetsHistoryApplication.class, args); + onStartFinish(args); } } diff --git a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/config/AppRunner.java b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/config/AppRunner.java deleted file mode 100644 index 2bc5b62..0000000 --- a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/config/AppRunner.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.zhangjiashuai.yyetshistory.config; - -import com.zhangjiashuai.yyetshistory.util.NativeOperationUtils; -import org.springframework.boot.ApplicationArguments; -import org.springframework.boot.ApplicationRunner; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class AppRunner implements ApplicationRunner { - - @Override - public void run(ApplicationArguments args) { - NativeOperationUtils.onStartFinish(); - } - -} diff --git a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/config/YyetsHistoryProperties.java b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/config/YyetsHistoryProperties.java index 7eb98e2..b34d506 100644 --- a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/config/YyetsHistoryProperties.java +++ b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/config/YyetsHistoryProperties.java @@ -1,8 +1,10 @@ package com.zhangjiashuai.yyetshistory.config; +import cn.hutool.core.collection.CollectionUtil; import lombok.Data; -import java.util.LinkedHashSet; +import java.util.Collections; +import java.util.Set; @Data public class YyetsHistoryProperties { @@ -15,20 +17,28 @@ public class YyetsHistoryProperties { public static final String PID_KEY = "pid"; public static final long UNKNOWN_PID = -1L; + public static final String DEFAULT_HOST = "localhost"; + public static final Set DEFAULT_LINK_WAY_FILTER = + Collections.unmodifiableSet(CollectionUtil.newHashSet("电驴", "磁力")); + /** * 保留的链接类型 */ - private LinkedHashSet linkWayFilter; + private Set linkWayFilter = DEFAULT_LINK_WAY_FILTER; + + /** + * 域名 + */ + private String host = DEFAULT_HOST; + /** - * 默认每页大小 + * 是否触发启动前置事件 */ - private int defaultPageSize; + private boolean startPrepareEvent = true; + /** - * 域名 + * 是否触发启动成功事件 */ - private String host; + private boolean startFinishEvent = true; - public int getDefaultPageSize() { - return defaultPageSize < 1 ? DEFAULT_PAGE_SIZE : defaultPageSize; - } } diff --git a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/entity/Resource.java b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/entity/Resource.java index 088abaf..3898910 100644 --- a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/entity/Resource.java +++ b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/entity/Resource.java @@ -1,7 +1,7 @@ package com.zhangjiashuai.yyetshistory.entity; +import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.util.ReflectUtil; -import cn.hutool.core.util.StrUtil; import lombok.Data; import java.util.Collections; @@ -48,7 +48,7 @@ public static class Group implements Comparable { @Override public int compareTo(Group that) { - return StrUtil.compareIgnoreCase(this.name, that.name,false); + return CharSequenceUtil.compareIgnoreCase(this.name, that.name, false); } } @@ -72,7 +72,7 @@ public static class Link implements Comparable { @Override public int compareTo(Link that) { - return StrUtil.compareIgnoreCase(this.way, that.way,false); + return CharSequenceUtil.compareIgnoreCase(this.way, that.way, false); } } diff --git a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/service/ResourceService.java b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/service/ResourceService.java index 337fbdd..0784b34 100644 --- a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/service/ResourceService.java +++ b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/service/ResourceService.java @@ -6,6 +6,8 @@ import java.util.List; +import static com.zhangjiashuai.yyetshistory.config.YyetsHistoryProperties.DEFAULT_PAGE_SIZE; + public interface ResourceService { List findByNameLike(String name); @@ -16,6 +18,8 @@ public interface ResourceService { PageInfo selectPage(String name, int pageNo, int pageSize); - PageInfo selectPage(String name, int pageNo); + default PageInfo selectPage(String name, int pageNo) { + return selectPage(name, pageNo, DEFAULT_PAGE_SIZE); + } } diff --git a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/service/impl/ResourceServiceImpl.java b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/service/impl/ResourceServiceImpl.java index 11d2a0c..f29defd 100644 --- a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/service/impl/ResourceServiceImpl.java +++ b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/service/impl/ResourceServiceImpl.java @@ -110,10 +110,10 @@ public Resource parseResource(ResourceDO resourceDO) { for (int k = 0; k < filesArray.size(); k++) { JSONObject fileJson = filesArray.getJSONObject(k); String way = fileJson.getString("way_cn"); - LinkedHashSet linkWayFilter = config.getLinkWayFilter(); - if(!linkWayFilter.contains(way)) { - continue; - } + Set linkWayFilter = config.getLinkWayFilter(); +// if(!linkWayFilter.contains(way)) { +// continue; +// } String address = fileJson.getString("address"); if(StrUtil.isEmpty(address)) { continue; @@ -141,9 +141,4 @@ public PageInfo selectPage(String name, int pageNo, int pageSize) { return page.toPageInfo(this::parseResource); } - @Override - public PageInfo selectPage(String name, int pageNo) { - return selectPage(name, pageNo, config.getDefaultPageSize()); - } - } diff --git a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/util/NativeConfigUtil.java b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/util/NativeConfigUtil.java new file mode 100644 index 0000000..4cd0b60 --- /dev/null +++ b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/util/NativeConfigUtil.java @@ -0,0 +1,218 @@ +package com.zhangjiashuai.yyetshistory.util; + +import cn.hutool.core.lang.Dict; +import cn.hutool.core.lang.Pair; +import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.extra.spring.SpringUtil; +import cn.hutool.setting.yaml.YamlUtil; +import lombok.extern.slf4j.Slf4j; + +import java.util.*; +import java.util.stream.Collectors; + +import static cn.hutool.core.text.StrPool.*; +import static com.zhangjiashuai.yyetshistory.config.YyetsHistoryProperties.DEFAULT_HOST; + +@Slf4j +class NativeConfigUtil { + + private static final Map PROPERTIES = new HashMap<>(); + private static final int DEFAULT_PORT = 8080; + private static final String COMMAND_LINE_ARG_PREFIX = "--"; + private static final String COMMAND_LINE_ARG_SEPARATOR = "="; + + /** + * 获取配置属性 + * @param key + * @return + */ + static Object getProperty(String key) { + if(SpringUtil.getApplicationContext() != null) { + return SpringUtil.getProperty(key); + } + return PROPERTIES.get(key); + } + + /** + * 获取环境变量 + * @param key + * @return + */ + static String getSystemEnv(String key) { + String envKey = Arrays.stream(key.split("\\.")).map(str -> str.replaceAll(DASHED, UNDERLINE).toUpperCase()) + .collect(Collectors.joining(UNDERLINE)); + String value = null; + if((value = System.getenv(envKey)) == null) { + value = System.getenv(key); + } + return StrUtil.trim(value); + } + + /** + * 获取jvm参数 + * @param key + * @return + */ + static String getJvmPropertity(String key) { + String value = System.getProperty(key); + return StrUtil.trim(value); + } + + /** + * 获取命令行参数 + * @param str + * @return + */ + static Pair getCommandLineArg(String str) { + if(StrUtil.isBlank(str) || !str.startsWith(COMMAND_LINE_ARG_PREFIX)) { + return null; + } + String subs = str.substring(COMMAND_LINE_ARG_PREFIX.length()); + String[] array = subs.split(COMMAND_LINE_ARG_SEPARATOR); + if(array.length != 2 || StrUtil.isBlank(array[0])) { + return null; + } + return Pair.of(array[0].trim(), StrUtil.trim(array[1])); + } + + static void loadYamlConfig() { + PROPERTIES.clear(); + try { + loadConfigYaml(null); + Object configValue = PROPERTIES.get("spring.profiles.active"); + if(configValue == null) { + return; + } + Collection activeProfiles; + if (configValue instanceof Collection) { + activeProfiles = (Collection) configValue; + } else { + activeProfiles = Arrays.stream(configValue.toString().split(COMMA)).collect(Collectors.toList()); + } + for (String profile : activeProfiles) { + if(StrUtil.isBlank(profile)) { + continue; + } + try { + loadConfigYaml(profile); + } catch (Exception e) { + log.debug("yaml加载异常, profile: {}", profile, e); + } + } + } finally { + loadSystemProperties(); + } + } + + static void loadCommandLineArgs(String[] args) { + if(ArrayUtil.isEmpty(args)) { + return; + } + for (String arg : args) { + Pair pair = getCommandLineArg(arg); + if(pair != null) { + PROPERTIES.put(pair.getKey(), pair.getValue()); + } + } + } + + static String getHost() { + String host = StrUtil.toStringOrNull(getProperty("yyets-history.host")); + return StrUtil.isNotBlank(host) ? StrUtil.trim(host) : DEFAULT_HOST; + } + + static int getPort() { + Object value = getProperty("server.port"); + if(value == null) { + return DEFAULT_PORT; + } + if(value instanceof Number) { + return ((Number) value).intValue(); + } + try { + return Integer.parseInt(value.toString()); + } catch (NumberFormatException e) { + return DEFAULT_PORT; + } + } + + static boolean isStartPrepareEvent(String[] args) { + String key = "yyets-history.start-prepare-event"; + return eventCheck(key, args); + } + + static boolean isStartFinishEvent(String[] args) { + String key = "yyets-history.start-finish-event"; + Object configValue = getProperty(key); + if(configValue != null) { + return Boolean.parseBoolean(configValue.toString()); + } + return eventCheck(key, args); + } + + private static boolean eventCheck(String key, String[] args) { + String strValue = null; + if(ArrayUtil.isNotEmpty(args)) { + for (String arg : args) { + if(StrUtil.startWith(arg, COMMAND_LINE_ARG_PREFIX + key)) { + Pair pair = getCommandLineArg(arg); + strValue = pair.getValue(); + break; + } + } + } + if(strValue == null) { + strValue = getJvmPropertity(key); + } + if(strValue == null) { + strValue = getSystemEnv(key); + } + if (strValue == null) { + // 默认开启事件 + return true; + } + return Boolean.parseBoolean(strValue); + } + + /** + * 尝试获取系统变量与jvm参数 + */ + private static void loadSystemProperties() { + for (Map.Entry entry : PROPERTIES.entrySet()) { + String key = entry.getKey(); + String newValue; + if((newValue = getJvmPropertity(key)) == null) { + newValue = getSystemEnv(key); + } + if(newValue != null) { + entry.setValue(newValue); + } + } + } + + private static void loadConfigYaml(String profile) { + String filename; + if(StrUtil.isBlank(profile)) { + filename = "application.yml"; + } else { + filename = String.format("application-%s.yml", profile.trim()); + } + Dict dict = YamlUtil.loadByPath(filename); + readYaml(PROPERTIES, null, dict); + } + + private static void readYaml(Map properties, String key, Object value) { + if(value instanceof LinkedHashMap) { + LinkedHashMap map = (LinkedHashMap) value; + for (Map.Entry entry : map.entrySet()) { + String childKey = StrUtil.trim(entry.getKey()); + Object childValue = entry.getValue(); + String keyPart = Optional.ofNullable(key).map(s -> (s + DOT + childKey)).orElse(childKey); + readYaml(properties, keyPart, childValue); + } + } else { + properties.put(key, value instanceof String ? ((String) value).trim() : value); + } + } +} diff --git a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/util/NativeOperationUtils.java b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/util/NativeOperationUtils.java index b189a3b..d74ef1f 100644 --- a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/util/NativeOperationUtils.java +++ b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/util/NativeOperationUtils.java @@ -27,20 +27,18 @@ public class NativeOperationUtils { static { System.setProperty("java.awt.headless", "false"); - NativeYamlUtil.loadYamlConfig(); } /** - * 项目范文路径 + * 项目访问路径 */ private static volatile String uri; private NativeOperationUtils() {} - private static String buildUri(String host, int port) { + private static void buildUri(String host, int port) { uri = String.format("http://%s:%d/", host, port); log.info("项目访问路径初始化完成: {}", uri); - return uri; } /** @@ -48,11 +46,19 @@ private static String buildUri(String host, int port) { * @param args 命令行参数 */ public static void onStartPrepare(String[] args) { - NativeYamlUtil.loadCommandLineArgs(args); - String host = NativeYamlUtil.getHost(); - int port = NativeYamlUtil.getPort(); - String uri = buildUri(host, port); - log.info("检查项目是否已经启动"); + String classLoader = NativeOperationUtils.class.getClassLoader().getClass().getSimpleName(); + log.debug("onStartPrepare, classloader {}", classLoader); + if(classLoader.endsWith("RestartClassLoader")) { + return; + } + if(!NativeConfigUtil.isStartPrepareEvent(args)) { + return; + } + NativeConfigUtil.loadYamlConfig(); + NativeConfigUtil.loadCommandLineArgs(args); + String host = NativeConfigUtil.getHost(); + int port = NativeConfigUtil.getPort(); + buildUri(host, port); if(!telnet(host, port)) { return; } @@ -60,7 +66,7 @@ public static void onStartPrepare(String[] args) { Pair processInfo = getRunningProcessInfo(); if (APPLICATION_INFO.equals(processInfo.getKey())) { log.info("服务已在另一进程运行,pid: {}", processInfo.getValue()); - onStartFinish(); + onStartFinish(args); } else { openErrorDialog ("端口冲突","当前地址: " + uri + " 已被占用"); } @@ -71,7 +77,13 @@ public static void onStartPrepare(String[] args) { * 启动成功触发事件 * @param uri 项目访问地址 */ - public static void onStartFinish() { + public static void onStartFinish(String[] args) { + if(!NativeConfigUtil.isStartFinishEvent(args)) { + return; + } + if(uri == null) { + buildUri(NativeConfigUtil.getHost(), NativeConfigUtil.getPort()); + } log.info("程序启动完成,访问地址: {}", uri); try { webBrowse(uri); diff --git a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/util/NativeYamlUtil.java b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/util/NativeYamlUtil.java deleted file mode 100644 index 30e949d..0000000 --- a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/util/NativeYamlUtil.java +++ /dev/null @@ -1,147 +0,0 @@ -package com.zhangjiashuai.yyetshistory.util; - -import cn.hutool.core.lang.Dict; -import cn.hutool.core.util.ArrayUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.extra.spring.SpringUtil; -import cn.hutool.setting.yaml.YamlUtil; -import lombok.extern.slf4j.Slf4j; - -import java.util.*; -import java.util.stream.Collectors; - -import static cn.hutool.core.text.StrPool.*; - -@Slf4j -class NativeYamlUtil { - - private static final Map PROPERTIES = new HashMap<>(); - private static final int DEFAULT_PORT = 8080; - - - static Object getProperty(String key) { - if(SpringUtil.getApplicationContext() != null) { - return SpringUtil.getProperty(key); - } - return PROPERTIES.get(key); - } - - static Object getPropertyOrDefault(String key, Object defaultValue) { - Object v; - return (((v = getProperty(key)) != null) || PROPERTIES.containsKey(key)) - ? v : defaultValue; - } - - static void loadYamlConfig() { - PROPERTIES.clear(); - loadConfigYaml(null); - Object configValue = PROPERTIES.get("spring.profiles.active"); - if(configValue == null) { - loadSystemProperties(); - return; - } - Collection activeProfiles; - if (configValue instanceof Collection) { - activeProfiles = (Collection) configValue; - } else { - activeProfiles = Arrays.stream(configValue.toString().split(COMMA)).collect(Collectors.toList()); - } - for (String profile : activeProfiles) { - if(StrUtil.isBlank(profile)) { - continue; - } - try { - loadConfigYaml(profile); - } catch (Exception e) { - log.debug("yaml加载异常, profile: {}", profile, e); - } - } - loadSystemProperties(); - } - - static void loadCommandLineArgs(String[] args) { - if(ArrayUtil.isEmpty(args)) { - return; - } - String prefix = "--"; - String separator = "="; - for (String arg : args) { - if(StrUtil.isBlank(arg) || !arg.startsWith(prefix)) { - continue; - } - String subs = arg.substring(prefix.length()); - String[] array = subs.split(separator); - if(array.length != 2 || StrUtil.isBlank(array[0])) { - continue; - } - PROPERTIES.put(array[0].trim(), StrUtil.trim(array[1])); - } - } - - static String getHost() { - return getPropertyOrDefault("yyets-history.host", "localhost").toString(); - } - - static int getPort() { - Object value = getProperty("server.port"); - if(value == null) { - return DEFAULT_PORT; - } - if(value instanceof Number) { - return ((Number) value).intValue(); - } - try { - return Integer.parseInt(value.toString()); - } catch (NumberFormatException e) { - return DEFAULT_PORT; - } - } - - /** - * 尝试获取系统变量与jvm参数 - */ - private static void loadSystemProperties() { - for (Map.Entry entry : PROPERTIES.entrySet()) { - String key = entry.getKey(); - String newValue; - if((newValue = System.getenv(key)) != null) { - if(newValue.contains(UNDERLINE)) { - newValue = Arrays.stream(newValue.split(UNDERLINE)).map(String::toLowerCase) - .collect(Collectors.joining(DOT)); - } else { - newValue = newValue.toLowerCase(); - } - } else { - newValue = System.getProperty(key); - } - if(newValue != null) { - entry.setValue(newValue.trim()); - } - } - } - - private static void loadConfigYaml(String profile) { - String filename; - if(StrUtil.isBlank(profile)) { - filename = "application.yml"; - } else { - filename = String.format("application-%s.yml", profile.trim()); - } - Dict dict = YamlUtil.loadByPath(filename); - readYaml(PROPERTIES, null, dict); - } - - private static void readYaml(Map properties, String key, Object value) { - if(value instanceof LinkedHashMap) { - LinkedHashMap map = (LinkedHashMap) value; - for (Map.Entry entry : map.entrySet()) { - String childKey = entry.getKey(); - Object childValue = entry.getValue(); - String keyPart = Optional.ofNullable(key).map(s -> (s + DOT + childKey)).orElse(childKey); - readYaml(properties, keyPart, childValue); - } - } else { - properties.put(key, value instanceof String ? ((String) value).trim() : value); - } - } -} diff --git a/yyets-history/src/main/resources/application.yml b/yyets-history/src/main/resources/application.yml index 12f8546..d62e33e 100644 --- a/yyets-history/src/main/resources/application.yml +++ b/yyets-history/src/main/resources/application.yml @@ -24,5 +24,5 @@ yyets-history: link-way-filter: #保留的链接类型 - 电驴 - 磁力 - default-page-size: 10 #默认的查询数量 - host: localhost # 域名 \ No newline at end of file + host: localhost # 域名 + start-finish-event: true # 是否触发启动成功事件 \ No newline at end of file diff --git a/yyets-history/src/test/java/com/zhangjiashuai/yyetshistory/SimpleTest.java b/yyets-history/src/test/java/com/zhangjiashuai/yyetshistory/SimpleTest.java index 33acd00..b8e1d5a 100644 --- a/yyets-history/src/test/java/com/zhangjiashuai/yyetshistory/SimpleTest.java +++ b/yyets-history/src/test/java/com/zhangjiashuai/yyetshistory/SimpleTest.java @@ -1,7 +1,6 @@ package com.zhangjiashuai.yyetshistory; import cn.hutool.core.lang.Assert; -import cn.hutool.core.net.NetUtil; import cn.hutool.core.net.URLDecoder; import cn.hutool.core.swing.DesktopUtil; import cn.hutool.core.swing.clipboard.ClipboardUtil; @@ -13,10 +12,14 @@ import java.io.File; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.util.Arrays; import java.util.LinkedHashSet; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.stream.Collectors; +import static cn.hutool.core.text.StrPool.DASHED; +import static cn.hutool.core.text.StrPool.UNDERLINE; import static javax.swing.JOptionPane.INFORMATION_MESSAGE; public class SimpleTest { @@ -86,14 +89,6 @@ public void testMsg() { Assert.isTrue(url.equals(ClipboardUtil.getStr())); } - @Test - public void testTelnet() { - boolean open = NetUtil.isOpen(NetUtil.buildInetSocketAddress("localhost", 9000), 1000); - Assert.isTrue(open); - open = NetUtil.isOpen(NetUtil.buildInetSocketAddress("localhost", 9001), 10); - Assert.isFalse(open); - } - @Test public void testMsgError() { String uri = "http://localhost:9000/"; @@ -101,4 +96,15 @@ public void testMsgError() { System.exit(0); } + @Test + public void testSystemEnv() { + String key = "yyets-history.start-prepare-event"; + String envKey = Arrays.stream(key.split("\\.")).map(str -> str.replaceAll(DASHED, UNDERLINE).toUpperCase()) + .collect(Collectors.joining(UNDERLINE)); + System.out.println(envKey); + String value = System.getenv(envKey); + System.out.println(value); + Assert.notNull(value); + } + } diff --git a/yyets-history/src/test/java/com/zhangjiashuai/yyetshistory/YyetsHistoryApplicationTests.java b/yyets-history/src/test/java/com/zhangjiashuai/yyetshistory/YyetsHistoryApplicationTests.java index 71f57a7..917c8c9 100644 --- a/yyets-history/src/test/java/com/zhangjiashuai/yyetshistory/YyetsHistoryApplicationTests.java +++ b/yyets-history/src/test/java/com/zhangjiashuai/yyetshistory/YyetsHistoryApplicationTests.java @@ -13,7 +13,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import java.util.HashSet; import java.util.List; +import java.util.Set; @Slf4j @SpringBootTest @@ -55,4 +57,35 @@ public void servicePageTest() { log.info("==========第2页==============="); Assert.isFalse(page1.equals(page2)); } + + @Test + public void allWaysTest() { + PageInfo page1 = resourceService.selectPage(null, 1, 100); + Set allWays = new HashSet<>(); + for (Resource resource : page1.getList()) { + List seasons = resource.getSeasons(); + if(seasons == null) + continue; + for (Resource.Season season : seasons) { + List groups = season.getGroups(); + if(groups == null) + continue; + for (Resource.Group group : groups) { + List items = group.getItems(); + if(items == null) + continue; + for (Resource.Item item : items) { + List links = item.getLinks(); + if(links == null) + continue; + for (Resource.Link link : links) { + allWays.add(link.getWay()); + } + } + } + } + } + System.out.println(allWays); + Assert.isTrue(allWays.size() > 2); + } }