fix(cli): 修复argument和environment为空时报错

This commit is contained in:
2024-02-29 18:42:50 +08:00
parent e9aa11a15d
commit 9c6615c33c
2 changed files with 7 additions and 15 deletions

View File

@@ -68,19 +68,4 @@ public class ServiceInfoWrapper {
", name='" + name + '\'' +
'}';
}
private Map<String, Object> escape(Map<String, Object> map) {
// https://github.com/spring-projects/spring-framework/issues/9628
// spring boot 的配置文件没有办法转义 $,使用 $\{ -> ${ 来绕过一下
return map.entrySet()
.stream()
.peek(entry -> {
if (entry.getValue() instanceof String) {
String key = entry.getKey();
String value = (String) entry.getValue();
entry.setValue(value.replace("$\\{", "${"));
}
})
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
}

View File

@@ -1,5 +1,6 @@
package com.lanyuanxiaoyao.service.cli.runner;
import cn.hutool.core.util.ObjectUtil;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
@@ -18,6 +19,9 @@ public class SpringPropertiesEscapeHelper {
* 使用 _ 代替 map key 的 .
*/
public static <T> Map<String, T> escapeMapKey(Map<String, T> map) {
if (ObjectUtil.isEmpty(map)) {
return map;
}
Map<String, T> result = new HashMap<>();
for (Map.Entry<String, T> entry : map.entrySet()) {
result.put(entry.getKey().replaceAll("_", "."), entry.getValue());
@@ -28,6 +32,9 @@ public class SpringPropertiesEscapeHelper {
public static <T> Map<String, T> escapeMapValue(Map<String, T> map) {
// https://github.com/spring-projects/spring-framework/issues/9628
// spring boot 的配置文件没有办法转义 $,使用 $\{ -> ${ 来绕过一下
if (ObjectUtil.isEmpty(map)) {
return map;
}
return map.entrySet()
.stream()
.peek(entry -> {