Jelajahi Sumber

优化projectPath推断逻辑

JustryDeng 3 tahun lalu
induk
melakukan
688cb24bc7

+ 13 - 39
class-winter-core/src/main/java/winter/com/ideaaedi/classwinter/Reverses.java

@@ -116,22 +116,18 @@ public class Reverses {
                     } catch (UnsupportedEncodingException ex) {
                         // ignore
                     }
-                    
-                    // 如果不是强制指定解密该projectPath,那么解析其projectPath
-                    if (!ifPointToDecrypt(decryptProjectPathPrefixSet, projectPath)) {
-                        try {
-                            projectPath = JarUtil.getRootPath(projectPath);
-                        } catch (ClassWinterException e) {
-                            if (!projectPathSet.contains(projectPath)) {
-                                Logger.debug(Reverses.class, "Exist projectPath -> " +  projectPath);
-                                projectPathSet.add(projectPath);
-                            }
-                            return classfileBuffer;
-                        } catch (Exception e) {
-                            Logger.warn(Reverses.class, "JarUtil.getRootPath occur exception."
-                                    + " projectPath -> " + projectPath + ", e.getMessage() -> " + e.getMessage());
+    
+                    try {
+                        projectPath = JarUtil.getRootPath(projectPath);
+                    } catch (ClassWinterException e) {
+                        // 如果没有指定解密该projectPath,那么返回
+                        if (!ifPointToDecrypt(decryptProjectPathPrefixSet, projectPath)) {
                             return classfileBuffer;
                         }
+                    } catch (Exception e) {
+                        Logger.warn(Reverses.class, "JarUtil.getRootPath occur exception."
+                                + " projectPath -> " + projectPath + ", e.getMessage() -> " + e.getMessage());
+                        return classfileBuffer;
                     }
                     if (!projectPathSet.contains(projectPath)) {
                         Logger.debug(Reverses.class, "Exist projectPath -> " +  projectPath);
@@ -156,35 +152,13 @@ public class Reverses {
                         try {
                             byte[] sealByte = IOUtil.readFileFromWorkbenchRoot(new File(projectPath), Constant.SEAL_FILE);
                             if (sealByte == null) {
-                                try {
-                                    // 试着修正projectPath
-                                    String correctionProjectPath = JarUtil.getRootPath(projectPath);
-                                    sealByte = IOUtil.readFileFromWorkbenchRoot(new File(correctionProjectPath),
-                                            Constant.SEAL_FILE);
-                                    if (sealByte != null) {
-                                        Logger.debug(Reverses.class, "Fix projectPath from '" + projectPath
-                                                + "' to '" + correctionProjectPath + "'.");
-                                        projectPath = correctionProjectPath;
-                                        if (!projectPathSet.contains(projectPath)) {
-                                            Logger.debug(Reverses.class, "Exist projectPath -> " +  projectPath);
-                                            projectPathSet.add(projectPath);
-                                        }
-                                    }
-                                } catch (Exception e) {
-                                    // ignore
-                                }
-                            }
-                            if (sealByte == null) {
-                                Logger.error(Reverses.class, "Obtain project seal fail. projectPath -> " + projectPath);
+                                Logger.error(Reverses.class, "Obtain project seal fail. "
+                                        + "Maybe you need to try it with decrypt params 'decryptProjectPathPrefix' or 'skipProjectPathPrefix'. "
+                                        + "@see https://gitee.com/JustryDeng/class-winter#%E8%A7%A3%E5%AF%86%E5%8F%82%E6%95%B0 ");
                                 // 结束程序
                                 exit(projectPath);
                             }
                             String sealContent = new String(sealByte, StandardCharsets.UTF_8);
-                            if (StrUtil.isBlank(sealContent)) {
-                                Logger.error(Reverses.class, "Obtain project seal fail. projectPath -> " + projectPath);
-                                // 结束程序
-                                exit(projectPath);
-                            }
                             Logger.debug(Reverses.class, "seal of the project is -> " + sealContent);
                             Cache.sealCache = sealContent;
                         } catch (Exception e) {