JustryDeng 3 лет назад
Родитель
Сommit
1ef4e35310

+ 20 - 21
class-winter-core/src/main/java/winter/com/ideaaedi/classwinter/Reverses.java

@@ -293,29 +293,28 @@ public class Reverses {
         }
         try {
             byte[] sealByte = IOUtil.readFileFromWorkbenchRoot(new File(projectPath), Constant.SEAL_FILE);
-            // 如果指定了解密路径,但是没有获取到印章的话,直接报错
-            if (settingDecryptProjectPath) {
-                if (sealByte == null) {
-                    Logger.error(Reverses.class, "Obtain project seal fail. "
-                            + "Cannot found seal at " + new File(projectPath, Constant.SEAL_FILE).getAbsolutePath());
-                    // 结束程序
-                    exit(projectPath);
+            String sealContent = null;
+            if (sealByte == null) {
+                // 在没有指定解密路径的情况下,没有获取到印章的话,那么获取第一个印章作为本projectPath的印章
+                if (!settingDecryptProjectPath && Cache.firstSealCache != null) {
+                    sealContent = Cache.firstSealCache;
+                    Logger.debug(Reverses.class, "Use first-seal as curr project seal.");
                 }
-                String sealContent = new String(sealByte, StandardCharsets.UTF_8);
-                Logger.debug(Reverses.class, "seal of the project is -> " + sealContent);
-                Cache.sealCache.put(projectPath, sealContent);
-            } else if (Cache.firstSealCache != null) {
-                // 如果在没有指定解密路径的情况下,没有获取到印章的话,那么获取第一个印章作为本projectPath的印章
-                Logger.debug(Reverses.class, "direct-seal of the project obtain fail. use firstSealCache as this project seal. "
-                        + "firstSealProjectPath -> '" + Cache.firstSealProjectPath + "'. firstSealCache -> '" + Cache.firstSealCache + "'.");
-                Cache.sealCache.put(projectPath, Cache.firstSealCache);
             } else {
-                if (sealByte == null) {
-                    Logger.error(Reverses.class, "Obtain project seal fail. "
-                            + "Cannot found seal at " + new File(projectPath, Constant.SEAL_FILE).getAbsolutePath());
-                    // 结束程序
-                    exit(projectPath);
-                }
+                sealContent = new String(sealByte, StandardCharsets.UTF_8);
+                Logger.debug(Reverses.class, "direct-seal of the project is -> " + sealContent);
+            }
+            if (sealContent == null) {
+                Logger.error(Reverses.class, "Obtain project seal fail.");
+                // 结束程序
+                exit(projectPath);
+            }
+            Cache.sealCache.put(projectPath, sealContent);
+            if (Cache.firstSealCache == null) {
+                Cache.firstSealCache = sealContent;
+                Cache.firstSealProjectPath = projectPath;
+                Logger.error(Reverses.class, "first-seal found. projectPath -> " + Cache.firstSealProjectPath);
+                Logger.error(Reverses.class, "first-seal found. sealContent -> " + Cache.firstSealCache);
             }
         } catch (Exception e) {
             Logger.error(Reverses.class, "Obtain project seal fail.");

BIN
class-winter-core/src/test/resources/class-winter-core-2.8.0.jar