diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/ConfigurePluginEnvironment.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/ConfigurePluginEnvironment.java index 536b4e34b97681207e6645a6d5aa3d79eb9aa555..272d6a14bcd531b7add4885067b777a08e849d32 100644 --- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/ConfigurePluginEnvironment.java +++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/ConfigurePluginEnvironment.java @@ -39,7 +39,8 @@ import java.util.Map; /** * 插件环境配置 * @author starBlues - * @version 3.0.0 + * @since 3.0.0 + * @version 3.1.0 */ public class ConfigurePluginEnvironment { private final Logger logger = LoggerFactory.getLogger(ConfigurePluginEnvironment.class); @@ -100,11 +101,12 @@ public class ConfigurePluginEnvironment { } private String getConfigFileLocation(String configFileLocation){ - String s = FilesUtils.resolveRelativePath(new File("").getAbsolutePath(), configFileLocation); - if(s.endsWith("/") || s.endsWith(File.separator)){ - return s; + String path = FilesUtils.resolveRelativePath(new File("").getAbsolutePath(), configFileLocation); + // 拼接最后字符斜杠 + if(path.endsWith(FilesUtils.SLASH) || path.endsWith(File.separator)){ + return path; } else { - return s + File.separator; + return path + File.separator; } } diff --git a/spring-brick-common/src/main/java/com/gitee/starblues/utils/FilesUtils.java b/spring-brick-common/src/main/java/com/gitee/starblues/utils/FilesUtils.java index a057e15315fe473cfbe229a9506dab30de48e5c1..7235739fb6ac43e60909e17ac40bcbafd0faf50f 100644 --- a/spring-brick-common/src/main/java/com/gitee/starblues/utils/FilesUtils.java +++ b/spring-brick-common/src/main/java/com/gitee/starblues/utils/FilesUtils.java @@ -31,6 +31,22 @@ import java.io.IOException; */ public class FilesUtils { + /** + * 正斜杠 + */ + public static final String SLASH = "/"; + + /** + * 双正斜杠 + */ + public static final String DOUBLE_SLASH = "//"; + + /** + * 反斜杠 + */ + public static final String BACKSLASH = "\\"; + + /** * 获取存在的文件 * @@ -77,17 +93,17 @@ public class FilesUtils { continue; } if (i < length - 1) { - if (path.endsWith("/")) { - path = path.replace("/", ""); - } else if (path.endsWith("\\")) { - path = path.replace("\\", ""); - } else if (path.endsWith("//")) { - path = path.replace("//", ""); + if (path.endsWith(SLASH)) { + path = path.replace(SLASH, ""); + } else if (path.endsWith(BACKSLASH)) { + path = path.replace(BACKSLASH, ""); + } else if (path.endsWith(DOUBLE_SLASH)) { + path = path.replace(DOUBLE_SLASH, ""); } } if (i > 0) { - if (path.startsWith(File.separator) || path.startsWith("/") || - path.startsWith("\\") || path.startsWith("//")) { + if (path.startsWith(File.separator) || path.startsWith(SLASH) || + path.startsWith(DOUBLE_SLASH) || path.startsWith(BACKSLASH)) { stringBuilder.append(path); } else { stringBuilder.append(File.separator).append(path); @@ -119,12 +135,12 @@ public class FilesUtils { continue; } if(i < length - 1){ - if(path.endsWith("/")){ - path = path.replace("/", ""); - } else if(path.endsWith("\\")){ - path = path.replace("\\", ""); - } else if(path.endsWith("//")){ - path = path.replace("//", ""); + if(path.endsWith(SLASH)){ + path = path.replace(SLASH, ""); + } else if(path.endsWith(BACKSLASH)){ + path = path.replace(BACKSLASH, ""); + } else if(path.endsWith(DOUBLE_SLASH)){ + path = path.replace(DOUBLE_SLASH, ""); } } if(i > 0){ @@ -162,7 +178,6 @@ public class FilesUtils { } } - /** * 解决相对路径 * @param rootPath 根路径 @@ -174,12 +189,37 @@ public class FilesUtils { return relativePath; } if(isRelativePath(relativePath)){ - return joiningFilePath(rootPath, relativePath.replaceFirst(Constants.RELATIVE_SIGN, "")); + String resolveRelativePath = relativePath.replaceFirst(Constants.RELATIVE_SIGN, ""); + return joiningFilePath(rootPath, resolveRelativePath); } else { return relativePath; } } + /** + * 解决存在的相对路径 + * @param rootPath 根路径 + * @param path 以 ~ 开头的相对路径或者完整路径 + * @return File 或者 null(不存在) + */ + public static File resolveExistRelativePathFile(String rootPath, String path){ + if(ObjectUtils.isEmpty(path)){ + return null; + } + if(isRelativePath(path)){ + String resolveRelativePath = path.replaceFirst(Constants.RELATIVE_SIGN, ""); + String joiningFilePath = joiningFilePath(rootPath, resolveRelativePath); + return getExistFile(joiningFilePath); + } else { + File existFile = getExistFile(path); + if(existFile != null){ + return existFile; + } + String joiningFilePath = joiningFilePath(rootPath, path); + return getExistFile(joiningFilePath); + } + } + /** * 是否是相对路径 * @param path 路径 @@ -192,4 +232,5 @@ public class FilesUtils { return path.startsWith(Constants.RELATIVE_SIGN); } + } diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/SpringMainProdBootstrap.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/SpringMainProdBootstrap.java index 85582244b1b637d6615fede9bf10a3f62ceb7218..6e34e2b22e009dfad541618915ab527b406c31b2 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/SpringMainProdBootstrap.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/SpringMainProdBootstrap.java @@ -17,21 +17,7 @@ package com.gitee.starblues.loader.launcher; import com.gitee.starblues.loader.jar.JarFile; -import com.gitee.starblues.loader.launcher.isolation.IsolationJarOuterLauncher; -import com.gitee.starblues.loader.launcher.isolation.IsolationFastJarLauncher; -import com.gitee.starblues.loader.launcher.runner.MethodRunner; -import com.gitee.starblues.loader.utils.ObjectUtils; -import java.io.File; -import java.net.URI; -import java.net.URISyntaxException; -import java.security.CodeSource; -import java.security.ProtectionDomain; -import java.util.Objects; -import java.util.jar.Attributes; -import java.util.jar.Manifest; - -import static com.gitee.starblues.loader.LoaderConstant.*; /** * 主程序生成环境启动引导器 * @author starBlues diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/descriptor/AbstractPluginDescriptorLoader.java b/spring-brick/src/main/java/com/gitee/starblues/core/descriptor/AbstractPluginDescriptorLoader.java index efeb3a0e72e4c0a36526012821e08a7e1f38194d..49e3cda9867c72f8ebda429d623d7d91ee17f5cb 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/core/descriptor/AbstractPluginDescriptorLoader.java +++ b/spring-brick/src/main/java/com/gitee/starblues/core/descriptor/AbstractPluginDescriptorLoader.java @@ -191,25 +191,21 @@ public abstract class AbstractPluginDescriptorLoader implements PluginDescriptor return configPluginLibDir; } // 先检查插件相对目录 - String resolveRelativePath = null; - if(FilesUtils.isRelativePath(configPluginLibDir)){ - // 先相对当前插件目录 - resolveRelativePath = FilesUtils.resolveRelativePath(descriptor.getPluginPath(), configPluginLibDir); - } else { - resolveRelativePath = FilesUtils.joiningFilePath(descriptor.getPluginPath(), configPluginLibDir); - } - if(FilesUtils.existFile(resolveRelativePath)){ - return resolveRelativePath; + File libDirFile = FilesUtils.resolveExistRelativePathFile(descriptor.getPluginPath(), configPluginLibDir); + if(libDirFile != null){ + return libDirFile.getPath(); } // 再相对插件存放目录 - resolveRelativePath = FilesUtils.joiningFilePath(new File(descriptor.getPluginPath()).getParent(), configPluginLibDir); - if(FilesUtils.existFile(resolveRelativePath)){ - return resolveRelativePath; + libDirFile = FilesUtils.resolveExistRelativePathFile( + new File(descriptor.getPluginPath()).getParent(), configPluginLibDir); + if(libDirFile != null){ + return libDirFile.getPath(); } // 最后相对主程序目录 - resolveRelativePath = FilesUtils.joiningFilePath(new File("").getAbsolutePath(), configPluginLibDir); - if(FilesUtils.existFile(resolveRelativePath)){ - return resolveRelativePath; + libDirFile = FilesUtils.resolveExistRelativePathFile(new File("").getAbsolutePath(), + configPluginLibDir); + if(libDirFile != null){ + return libDirFile.getPath(); } return null; } diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/descriptor/ProdPackagePluginDescriptorLoader.java b/spring-brick/src/main/java/com/gitee/starblues/core/descriptor/ProdPackagePluginDescriptorLoader.java index a52b8a6cd3aa7f853c052011f50315f358ec16b7..7a4d0b98177c13bc6bc2ae38b3b5dab7fb896af0 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/core/descriptor/ProdPackagePluginDescriptorLoader.java +++ b/spring-brick/src/main/java/com/gitee/starblues/core/descriptor/ProdPackagePluginDescriptorLoader.java @@ -85,6 +85,16 @@ public class ProdPackagePluginDescriptorLoader extends AbstractPluginDescriptorL protected String getLibDir(DefaultInsidePluginDescriptor descriptor, String configPluginLibDir) { if(PluginType.isNestedPackage(descriptor.getType())){ return descriptor.getPluginLibDir(); + } else if(PluginType.isOuterPackage(descriptor.getType())){ + String pluginLibDir = descriptor.getPluginLibDir(); + if(ObjectUtils.isEmpty(pluginLibDir)){ + return super.getLibDir(descriptor, configPluginLibDir); + } + if(FilesUtils.isRelativePath(pluginLibDir)){ + return super.getLibDir(descriptor, configPluginLibDir); + } else { + return descriptor.getPluginLibDir(); + } } else { return super.getLibDir(descriptor, configPluginLibDir); }