From 912a1e5f0b4537902b97ff81594611a8b6b3a853 Mon Sep 17 00:00:00 2001
From: dengzedong <dengzedong@email>
Date: 星期一, 30 九月 2024 17:33:31 +0800
Subject: [PATCH] 动态加载、卸载 jar、dll 模型测试运行 替换临时文件夹

---
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/impl/MpkFileServiceImpl.java |   29 +++++++++++++++++++----------
 1 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/impl/MpkFileServiceImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/impl/MpkFileServiceImpl.java
index cdeb74e..b3c7725 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/impl/MpkFileServiceImpl.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/impl/MpkFileServiceImpl.java
@@ -36,6 +36,7 @@
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.*;
+import java.nio.file.Files;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -189,9 +190,13 @@
         VelocityContext dataContext = new VelocityContext(map);
 
         //临时文件夹
-        File dirPath = new File("D:/DLUT/tmp/");
-        dirPath.deleteOnExit();
-        dirPath.mkdirs();
+        File dirPath = null;
+        try {
+            dirPath = Files.createTempDirectory("generatorCodeTmp").toFile();
+            log.info("生成临时文件夹," + dirPath.getAbsolutePath());
+        } catch (IOException e) {
+            throw new RuntimeException("创建临时文件夹异常",e);
+        }
 
         List<String> javaFilePaths = new ArrayList<>();
         List<String> cppFilePaths = new ArrayList<>();
@@ -273,7 +278,7 @@
         try {
             FileUtils.deleteDirectory(dirPath);
         } catch (IOException e) {
-            throw new RuntimeException("删除临时文件异常");
+            throw new RuntimeException("删除临时文件异常",e);
         }
         return bytes;
     }
@@ -289,9 +294,13 @@
 //        VelocityContext context = new VelocityContext(map);
 
         //临时文件夹
-        File dirPath = new File("D:/DLUT/tmp/");
-        dirPath.deleteOnExit();
-        dirPath.mkdirs();
+        File dirPath = null;
+        try {
+            dirPath = Files.createTempDirectory("packageModelTmp").toFile();
+            log.info("生成临时文件夹," + dirPath.getAbsolutePath());
+        } catch (IOException e) {
+            throw new RuntimeException("创建临时文件夹异常",e);
+        }
 
         //设置velocity资源加载器
         Properties prop = new Properties();
@@ -434,7 +443,7 @@
             // 等待命令执行完成
             process.waitFor();
         } catch (Exception e) {
-            throw new RuntimeException("执行cmd命令生成dll异常");
+            throw new RuntimeException("执行cmd命令生成dll异常",e);
         }
     }
 
@@ -492,7 +501,7 @@
             process.waitFor();
             return jarSavePath;
         } catch (InterruptedException e) {
-            throw new RuntimeException("执行cmd命令打jar包异常");
+            throw new RuntimeException("执行cmd命令打jar包异常",e);
         }
     }
 
@@ -513,7 +522,7 @@
             Process process = RuntimeUtil.exec(sb.toString());
             process.waitFor();
         } catch (InterruptedException e) {
-            throw new RuntimeException("执行cmd命令生成class异常");
+            throw new RuntimeException("执行cmd命令生成class异常",e);
         }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3