Sfoglia il codice sorgente

bug fix, 修复多模块项目打包时,后加密的项目密钥丢失问题

JustryDeng 5 anni fa
parent
commit
902b2de302

+ 1 - 1
class-winter-core/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <groupId>com.idea-aedi</groupId>
         <artifactId>class-winter</artifactId>
-        <version>1.1.0</version>
+        <version>1.2.0</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 3 - 3
class-winter-core/src/main/java/winter/com/ideaaedi/classwinter/executor/DecryptExecutor.java

@@ -248,9 +248,9 @@ public class DecryptExecutor {
     private static char[] obtainAutoGeneratedPwdWhileEncrypt(String projectPath, String classWinterInfoDir) {
         // 项目本身
         if (classWinterInfoDir.equals(Constant.DEFAULT_ENCRYPTED_CLASSES_SAVE_DIR)) {
-            if (Cache.passwordCache != null) {
+            if (Cache.passwordCacheForDecrypt != null) {
                 // 从缓存读取
-                return Cache.passwordCache;
+                return Cache.passwordCacheForDecrypt;
             }
             // 读取文件
             byte[] passwordByte = IOUtil.readFileFromWorkbenchRoot(new File(projectPath), Constant.PWD_WINTER);
@@ -265,7 +265,7 @@ public class DecryptExecutor {
             String password = new String(passwordByte, StandardCharsets.UTF_8);
             char[] passwordCharArr = password.toCharArray();
             // 放入缓存
-            Cache.passwordCache = passwordCharArr;
+            Cache.passwordCacheForDecrypt = passwordCharArr;
             return passwordCharArr;
         } else {
             // lib包

+ 5 - 6
class-winter-core/src/main/java/winter/com/ideaaedi/classwinter/executor/EncryptExecutor.java

@@ -644,9 +644,8 @@ public class EncryptExecutor {
      * @return  密码
      */
     private char[] obtainPassword() {
-        if (Cache.passwordCache != null) {
-            // 从缓存读取
-            return Cache.passwordCache;
+        if (Cache.passwordCacheForEncrypt.containsKey(this.originJarOrWar)) {
+            return Cache.passwordCacheForEncrypt.get(this.originJarOrWar);
         }
         boolean passwordIsBlank = StrUtil.isBlank(this.password);
         if (passwordIsBlank) {
@@ -656,13 +655,13 @@ public class EncryptExecutor {
             String encryptedGeneratedPwd = EncryptUtil.encrypt(new String(generatedPwd), Constant.SEAL.toCharArray());
             IOUtil.writeContentToFile(encryptedGeneratedPwd, new File(targetRootDir, Constant.PWD_WINTER));
             // 放入缓存
-            Cache.passwordCache = generatedPwd;
+            Cache.passwordCacheForEncrypt.put(this.originJarOrWar, generatedPwd);
         } else {
-            Cache.passwordCache = this.password.toCharArray();
+            Cache.passwordCacheForEncrypt.put(this.originJarOrWar, this.password.toCharArray());
         }
         // 记录加密时,用户是否输入了密码
         IOUtil.writeContentToFile(passwordIsBlank ? "false" : "true", new File(targetRootDir, Constant.USER_IF_INPUT_PWD));
-        return Cache.passwordCache;
+        return Cache.passwordCacheForEncrypt.get(this.originJarOrWar);
     }
     
     /**

+ 13 - 1
class-winter-core/src/main/java/winter/com/ideaaedi/classwinter/util/Cache.java

@@ -1,7 +1,9 @@
 package winter.com.ideaaedi.classwinter.util;
 
 import winter.com.ideaaedi.classwinter.author.JustryDeng;
+import winter.com.ideaaedi.classwinter.executor.EncryptExecutor;
 
+import java.util.HashMap;
 import java.util.Map;
 
 /**
@@ -12,7 +14,17 @@ import java.util.Map;
  */
 public final class Cache {
     
-    public static char[] passwordCache = null;
+    /** 解密时的密码缓存 */
+    public static char[] passwordCacheForDecrypt = null;
+    
+    /**
+     * 加密时的密码缓存
+     * <ul>
+     *     <li>key-{@link EncryptExecutor#originJarOrWar}</li>
+     *     <li>value-密码</li>
+     * </ul>
+     */
+    public static Map<String, char[]> passwordCacheForEncrypt = new HashMap<>(8);
     
     /** 本项目加密时的印章 */
     public static String sealCache = null;

+ 1 - 0
class-winter-core/src/main/java/winter/com/ideaaedi/classwinter/util/IOUtil.java

@@ -130,6 +130,7 @@ public final class IOUtil {
             close(output, inputStream);
         }
     }
+    
     /**
      * 只罗列文件(即:只返回文件)
      * <p>

+ 1 - 1
class-winter-maven-plugin/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <groupId>com.idea-aedi</groupId>
         <artifactId>class-winter</artifactId>
-        <version>1.1.0</version>
+        <version>1.2.0</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 1 - 1
pom.xml

@@ -9,7 +9,7 @@
     </modules>
     <groupId>com.idea-aedi</groupId>
     <artifactId>class-winter</artifactId>
-    <version>1.1.0</version>
+    <version>1.2.0</version>
 
     <!-- 配置项目的基础信息 -->
     <name>class-winter</name>