feat #I6BDLN 自定义文件解析器报错问题

This commit is contained in:
gaibu 2023-02-03 10:54:33 +08:00
parent dd22f0e0f5
commit e0b08a714f
6 changed files with 34 additions and 30 deletions

View File

@ -28,6 +28,7 @@ import com.yomahub.liteflow.slot.DataBus;
import com.yomahub.liteflow.slot.DefaultContext;
import com.yomahub.liteflow.slot.Slot;
import com.yomahub.liteflow.spi.holder.ContextCmpInitHolder;
import com.yomahub.liteflow.spi.holder.PathContentParserHolder;
import com.yomahub.liteflow.thread.ExecutorHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -125,6 +126,9 @@ public class FlowExecutor {
//支持多类型的配置文件分别解析
if (BooleanUtil.isTrue(liteflowConfig.isSupportMultipleType())) {
// 添加监听文件路径
addMonitorFilePaths(ListUtil.toList(path));
// 解析文件
parser.parseMain(ListUtil.toList(path));
}
} catch (CyclicDependencyException e) {
@ -149,6 +153,9 @@ public class FlowExecutor {
//进行多个配置文件的一起解析
try {
if (parser != null) {
// 添加监听文件路径
addMonitorFilePaths(rulePathList);
// 解析文件
parser.parseMain(rulePathList);
} else {
throw new ConfigErrorException("parse error, please check liteflow config property");
@ -181,7 +188,7 @@ public class FlowExecutor {
}
// 文件监听
if (liteflowConfig.getEnableMonitorFile()){
if (liteflowConfig.getEnableMonitorFile()) {
MonitorFile.getInstance().create();
}
}
@ -397,4 +404,15 @@ public class FlowExecutor {
//把liteFlowConfig设到LiteFlowGetter中去
LiteflowConfigGetter.setLiteflowConfig(liteflowConfig);
}
/**
* 添加监听文件路径
*
* @param pathList 文件路径
*/
private void addMonitorFilePaths(List<String> pathList) throws Exception {
// 添加规则文件监听
List<String> fileAbsolutePath = PathContentParserHolder.loadContextAware().getFileAbsolutePath(pathList);
MonitorFile.getInstance().addMonitorFilePaths(fileAbsolutePath);
}
}

View File

@ -1,6 +1,5 @@
package com.yomahub.liteflow.parser.el;
import com.yomahub.liteflow.monitor.MonitorFile;
import com.yomahub.liteflow.spi.holder.PathContentParserHolder;
import java.util.List;
@ -16,11 +15,6 @@ public class LocalJsonFlowELParser extends JsonFlowELParser {
@Override
public void parseMain(List<String> pathList) throws Exception {
List<String> contentList = PathContentParserHolder.loadContextAware().parseContent(pathList);
// 添加规则文件监听
List<String> fileAbsolutePath = PathContentParserHolder.loadContextAware().getFileAbsolutePath(pathList);
MonitorFile.getInstance().addMonitorFilePaths(fileAbsolutePath);
parse(contentList);
}
}

View File

@ -1,6 +1,5 @@
package com.yomahub.liteflow.parser.el;
import com.yomahub.liteflow.monitor.MonitorFile;
import com.yomahub.liteflow.spi.holder.PathContentParserHolder;
import java.util.List;
@ -14,11 +13,6 @@ public class LocalXmlFlowELParser extends XmlFlowELParser{
@Override
public void parseMain(List<String> pathList) throws Exception {
List<String> contentList = PathContentParserHolder.loadContextAware().parseContent(pathList);
// 添加规则文件监听
List<String> fileAbsolutePath = PathContentParserHolder.loadContextAware().getFileAbsolutePath(pathList);
MonitorFile.getInstance().addMonitorFilePaths(fileAbsolutePath);
parse(contentList);
}
}

View File

@ -1,6 +1,5 @@
package com.yomahub.liteflow.parser.el;
import com.yomahub.liteflow.monitor.MonitorFile;
import com.yomahub.liteflow.spi.holder.PathContentParserHolder;
import java.util.List;
@ -15,11 +14,6 @@ public class LocalYmlFlowELParser extends YmlFlowELParser {
@Override
public void parseMain(List<String> pathList) throws Exception {
List<String> contentList = PathContentParserHolder.loadContextAware().parseContent(pathList);
// 添加规则文件监听
List<String> fileAbsolutePath = PathContentParserHolder.loadContextAware().getFileAbsolutePath(pathList);
MonitorFile.getInstance().addMonitorFilePaths(fileAbsolutePath);
parse(contentList);
}

View File

@ -3,6 +3,7 @@ package com.yomahub.liteflow.spi.solon;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.stream.StreamUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.exception.ConfigErrorException;
@ -16,6 +17,7 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class SolonPathContentParser implements PathContentParser {
@Override
@ -37,11 +39,7 @@ public class SolonPathContentParser implements PathContentParser {
@Override
public List<String> getFileAbsolutePath(List<String> pathList) throws Exception {
List<URL> allResource = getUrls(pathList);
List<String> result = new ArrayList<>();
for (URL url : allResource) {
result.add(url.getPath());
}
return result;
return StreamUtil.of(allResource).map(URL::getPath).collect(Collectors.toList());
}
private static List<URL> getUrls(List<String> pathList) throws MalformedURLException {

View File

@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.stream.StreamUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
@ -19,6 +20,7 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class SpringPathContentParser implements PathContentParser {
@Override
@ -41,12 +43,16 @@ public class SpringPathContentParser implements PathContentParser {
public List<String> getFileAbsolutePath(List<String> pathList) throws Exception {
List<Resource> allResource = getResources(pathList);
//转换成内容List
List<String> result = new ArrayList<>();
for (Resource resource : allResource) {
result.add(resource.getFile().getAbsolutePath());
}
return result;
return StreamUtil.of(allResource)
// 过滤非 file 类型 Resource
.filter(Resource::isFile)
.map(r -> {
try {
return r.getFile().getAbsolutePath();
} catch (IOException e) {
throw new RuntimeException(e);
}
}).collect(Collectors.toList());
}
private List<Resource> getResources(List<String> pathList) throws IOException {