Bladeren bron

支持加密参数includeLibSet正则匹配

(cherry picked from commit 3803f65ad43ea60eb4c5e510ca433b0e4c93de34)
wang 2 jaren geleden
bovenliggende
commit
47a095632f

+ 16 - 7
class-winter-core/src/main/java/winter/com/ideaaedi/classwinter/executor/EncryptExecutor.java

@@ -155,6 +155,11 @@ public class EncryptExecutor {
      * </pre>
      */
     private final Set<String> includeLibSet;
+
+    /**
+     * 如果这次需要加密的lib本身就已经是被加密了的,那么这次不再对其进行加密
+     */
+    private final Set<String> protectedLibSet;
     
     /**
      * 不需要加密的类的全类名前缀(也可以精确匹配)
@@ -223,7 +228,7 @@ public class EncryptExecutor {
     private EncryptExecutor(String originJarOrWar, boolean originIsJar, String finalName, String targetRootDir,
                             String targetLibDir, String targetClassesDir, String password,
                             Set<String> includeXmlPrefixSet, Set<String> excludeXmlPrefixSet, Set<String> toCleanXmlChildElementNameSet,
-                            LinkedHashSet<String> includePrefixSet, Set<String> excludePrefixSet, Set<String> includeLibSet,
+                            LinkedHashSet<String> includePrefixSet, Set<String> excludePrefixSet, Set<String> includeLibSet, Set<String> protectedLibSet,
                             String alreadyProtectedRootDir, Set<Pair<String, String>> alreadyProtectedLibSet,
                             String supportFile, Set<String> jvmArgCheckSet) {
         this.originJarOrWar = originJarOrWar;
@@ -239,6 +244,7 @@ public class EncryptExecutor {
         this.includePrefixSet = includePrefixSet;
         this.excludePrefixSet = excludePrefixSet;
         this.includeLibSet = includeLibSet;
+        this.protectedLibSet = protectedLibSet;
         this.alreadyProtectedRootDir = alreadyProtectedRootDir;
         this.alreadyProtectedLibSet = alreadyProtectedLibSet;
         this.supportFile = supportFile;
@@ -628,8 +634,8 @@ public class EncryptExecutor {
         // 罗列出targetRootDir下的所有.jar文件
         List<File> allJarFiles = IOUtil.listFileOnly(new File(targetRootDir), Constant.JAR_SUFFIX);
         // 筛选出需要加密的lib包
-        List<File> neededEncryptedLibs =  allJarFiles.stream().filter(jarFile -> includeLibSet.contains(jarFile.getName())).collect(Collectors.toList());
-    
+        List<File> neededEncryptedLibs = allJarFiles.stream().filter(jarFile -> !protectedLibSet.contains(jarFile.getName()) &&
+                includeLibSet.stream().anyMatch(s -> StrUtil.regMatched(s, jarFile.getName()))).collect(Collectors.toList());
         // 依次解密
         neededEncryptedLibs.forEach(jar -> {
             // 假设: jarAbsolutePath为  /xyz/abc.jar
@@ -1091,6 +1097,7 @@ public class EncryptExecutor {
                 ", excludeXmlPrefixSet=" + excludeXmlPrefixSet +
                 ", toCleanChildElementNameSet=" + toCleanXmlChildElementNameSet +
                 ", includeLibSet=" + includeLibSet +
+                ", protectedLibSet=" + protectedLibSet +
                 ", alreadyProtectedLibSet=" + alreadyProtectedLibSet +
                 '}';
     }
@@ -1281,12 +1288,14 @@ public class EncryptExecutor {
             Set<String> excludePrefixSet = StrUtil.strToSet(excludePrefix);
             Set<String> includeLibSet = StrUtil.strToSet(includeLibs);
             Set<Pair<String, String>> alreadyProtectedLibSet = parseAlreadyProtectedLibs();
-            
+
+            Set<String> matchAlreadyProtectedLibSet = new HashSet<>();
+
             // 如果这次需要加密的lib本身就已经是被加密了的,那么这次不再对其进行加密
             alreadyProtectedLibSet.stream().map(Pair::getLeft).forEach(lib -> {
-                if (includeLibSet.contains(lib)) {
+                if (includeLibSet.stream().anyMatch(s -> StrUtil.regMatched(s, lib))) {
                     Logger.warn(EncryptExecutor.class, "Ignore includeLibs item [" + lib + "], because this item already be protected by class-winter.");
-                    includeLibSet.remove(lib);
+                    matchAlreadyProtectedLibSet.add(lib);
                 }
             });
             
@@ -1307,7 +1316,7 @@ public class EncryptExecutor {
             
             return new EncryptExecutor(this.originJarOrWar, originIsJar, this.finalName, targetRootDir, targetLibDir, targetClassesDir,
                     password, includeXmlPrefixSet, excludeXmlPrefixSet, toCleanXmlChildElementNameSet, includePrefixSortSet,
-                    excludePrefixSet, includeLibSet, alreadyProtectedRootDir, alreadyProtectedLibSet, this.supportFile, jvmArgCheckSet);
+                    excludePrefixSet, includeLibSet,matchAlreadyProtectedLibSet, alreadyProtectedRootDir, alreadyProtectedLibSet, this.supportFile, jvmArgCheckSet);
         }
     
         /**