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

View File

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

View File

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

View File

@ -3,6 +3,7 @@ package com.yomahub.liteflow.spi.solon;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil; import cn.hutool.core.io.IoUtil;
import cn.hutool.core.stream.StreamUtil;
import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.exception.ConfigErrorException; import com.yomahub.liteflow.exception.ConfigErrorException;
@ -16,6 +17,7 @@ import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
public class SolonPathContentParser implements PathContentParser { public class SolonPathContentParser implements PathContentParser {
@Override @Override
@ -37,11 +39,7 @@ public class SolonPathContentParser implements PathContentParser {
@Override @Override
public List<String> getFileAbsolutePath(List<String> pathList) throws Exception { public List<String> getFileAbsolutePath(List<String> pathList) throws Exception {
List<URL> allResource = getUrls(pathList); List<URL> allResource = getUrls(pathList);
List<String> result = new ArrayList<>(); return StreamUtil.of(allResource).map(URL::getPath).collect(Collectors.toList());
for (URL url : allResource) {
result.add(url.getPath());
}
return result;
} }
private static List<URL> getUrls(List<String> pathList) throws MalformedURLException { 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.collection.ListUtil;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil; import cn.hutool.core.io.IoUtil;
import cn.hutool.core.stream.StreamUtil;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
@ -19,6 +20,7 @@ import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
public class SpringPathContentParser implements PathContentParser { public class SpringPathContentParser implements PathContentParser {
@Override @Override
@ -41,12 +43,16 @@ public class SpringPathContentParser implements PathContentParser {
public List<String> getFileAbsolutePath(List<String> pathList) throws Exception { public List<String> getFileAbsolutePath(List<String> pathList) throws Exception {
List<Resource> allResource = getResources(pathList); List<Resource> allResource = getResources(pathList);
//转换成内容List return StreamUtil.of(allResource)
List<String> result = new ArrayList<>(); // 过滤非 file 类型 Resource
for (Resource resource : allResource) { .filter(Resource::isFile)
result.add(resource.getFile().getAbsolutePath()); .map(r -> {
} try {
return result; return r.getFile().getAbsolutePath();
} catch (IOException e) {
throw new RuntimeException(e);
}
}).collect(Collectors.toList());
} }
private List<Resource> getResources(List<String> pathList) throws IOException { private List<Resource> getResources(List<String> pathList) throws IOException {