From a717d0342071c9dc5d83b91d2caeacfe8476bb98 Mon Sep 17 00:00:00 2001 From: Looly Date: Fri, 3 Mar 2023 20:51:46 +0800 Subject: [PATCH] =?UTF-8?q?JavaSourceCompiler#compile=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89options=E9=87=8D=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + .../hutool/core/compiler/JavaSourceCompiler.java | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce7131d4e..cb5b5e6bd 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ * 【core 】 build(pom): 添加 Automatic-Module-Name属性(pr#2926@Github) * 【core 】 根据JDK-8080225修改了部分新建文件输入流和文件输出流的创建方式(pr#2930@Github) * 【http 】 HttpRequest#body增加支持Resource重载(issue#2901@Github) +* 【core 】 JavaSourceCompiler#compile增加自定义options重载(issue#I6IVZK@Gitee) ### 🐞Bug修复 * 【db 】 修复识别JDBC驱动时重复问题(pr#940@Gitee) diff --git a/hutool-core/src/main/java/cn/hutool/core/compiler/JavaSourceCompiler.java b/hutool-core/src/main/java/cn/hutool/core/compiler/JavaSourceCompiler.java index 39e08d28f..b14907160 100644 --- a/hutool-core/src/main/java/cn/hutool/core/compiler/JavaSourceCompiler.java +++ b/hutool-core/src/main/java/cn/hutool/core/compiler/JavaSourceCompiler.java @@ -168,6 +168,16 @@ public class JavaSourceCompiler { * @return 类加载器 */ public ClassLoader compile() { + return compile(null); + } + + /** + * 编译所有文件并返回类加载器 + * + * @param options 编译参数 + * @return 类加载器 + */ + public ClassLoader compile(List options) { // 获得classPath final List classPath = getClassPath(); final URL[] urLs = URLUtil.getURLs(classPath.toArray(new File[0])); @@ -181,7 +191,9 @@ public class JavaSourceCompiler { final JavaClassFileManager javaFileManager = new JavaClassFileManager(ucl, CompilerUtil.getFileManager()); // classpath - final List options = new ArrayList<>(); + if (null == options) { + options = new ArrayList<>(); + } if (false == classPath.isEmpty()) { final List cp = CollUtil.map(classPath, File::getAbsolutePath, true); options.add("-cp");