feat #I6BDLN 解析器自定义解析器场景报错
This commit is contained in:
parent
e0b08a714f
commit
32e24769b0
|
@ -5,6 +5,7 @@ import cn.hutool.core.io.FileUtil;
|
|||
import cn.hutool.core.io.resource.ClassPathResource;
|
||||
import cn.hutool.core.io.resource.FileResource;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.util.ClassLoaderUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.exception.ConfigErrorException;
|
||||
import com.yomahub.liteflow.spi.PathContentParser;
|
||||
|
@ -52,13 +53,17 @@ public class LocalPathContentParser implements PathContentParser {
|
|||
List<String> result = new ArrayList<>();
|
||||
|
||||
for (String path : pathList) {
|
||||
if (FileUtil.isAbsolutePath(path) && FileUtil.isFile(path)) {
|
||||
if (FileUtil.isAbsolutePath(path) && FileUtil.isFile(path)) {
|
||||
path = FILE_URL_PREFIX + path;
|
||||
result.add(new FileResource(path).getFile().getAbsolutePath());
|
||||
} else {
|
||||
if (!path.startsWith(CLASSPATH_URL_PREFIX)) {
|
||||
path = CLASSPATH_URL_PREFIX + path;
|
||||
result.add(new ClassPathResource(path).getAbsolutePath());
|
||||
|
||||
// 这里会有自定义解析器
|
||||
if(ClassLoaderUtil.isPresent(path)){
|
||||
result.add(new ClassPathResource(path).getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,10 @@ public class SolonPathContentParser implements PathContentParser {
|
|||
@Override
|
||||
public List<String> getFileAbsolutePath(List<String> pathList) throws Exception {
|
||||
List<URL> allResource = getUrls(pathList);
|
||||
return StreamUtil.of(allResource).map(URL::getPath).collect(Collectors.toList());
|
||||
return StreamUtil.of(allResource)
|
||||
.map(URL::getPath)
|
||||
.filter(FileUtil::isFile)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static List<URL> getUrls(List<String> pathList) throws MalformedURLException {
|
||||
|
@ -57,14 +60,16 @@ public class SolonPathContentParser implements PathContentParser {
|
|||
path = path.substring(ResourceUtils.CLASSPATH_URL_PREFIX.length());
|
||||
}
|
||||
|
||||
allResource.add(Utils.getResource(path));
|
||||
if (Utils.getResource(path) != null) {
|
||||
allResource.add(Utils.getResource(path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//如果有多个资源,检查资源都是同一个类型,如果出现不同类型的配置,则抛出错误提示
|
||||
Set<String> fileTypeSet = new HashSet<>();
|
||||
allResource.forEach(resource -> fileTypeSet.add(FileUtil.extName(resource.getPath())));
|
||||
if (fileTypeSet.size() != 1) {
|
||||
if (fileTypeSet.size() > 1) {
|
||||
throw new ConfigErrorException("config error,please use the same type of configuration");
|
||||
}
|
||||
return allResource;
|
||||
|
|
Loading…
Reference in New Issue