Browse Source

readme => 支持构建时并发安全

JustryDeng 1 year ago
parent
commit
ead7ab444f

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

@@ -65,12 +65,12 @@ public class EncryptExecutor {
     /**
      * 调用EncryptExecutor进行加密的“人”是否是maven插件
      */
-    public static boolean invokerIsPlugin = false;
+    public boolean invokerIsPlugin = false;
     
     /** 本项目(class-winter)需要打包的代码 */
-    public static final Set<String> CLASS_WINTER_FILES = new HashSet<>();
+    public final Set<String> CLASS_WINTER_FILES = new HashSet<>();
     
-    static {
+    {
         CLASS_WINTER_FILES.add(Cache.class.getName().replace(".", "/") + Constant.CLASS_SUFFIX);
         CLASS_WINTER_FILES.add(JustryDeng.class.getName().replace(".", "/") + Constant.CLASS_SUFFIX);
         CLASS_WINTER_FILES.add(ClassWinterException.class.getName().replace(".", "/") + Constant.CLASS_SUFFIX);
@@ -404,7 +404,7 @@ public class EncryptExecutor {
      *            步骤描述
      */
     private void showProcess(String completedStep, String lastStep, String stepDesc) {
-        if (EncryptExecutor.invokerIsPlugin) {
+        if (invokerIsPlugin) {
             Logger.simpleInfo(completedStep + "/" + lastStep + "\t" + stepDesc  + " completed.");
         } else {
             Logger.info(completedStep + "/" + lastStep + "\t" + stepDesc  + " completed.");

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

@@ -30,10 +30,10 @@ public final class Cache {
      *     <li>value-密码</li>
      * </ul>
      */
-    public static volatile Map<String, char[]> passwordCacheForEncrypt = new ConcurrentHashMap<>(8);
+    public static Map<String, char[]> passwordCacheForEncrypt = new ConcurrentHashMap<>(8);
     
     /** 本项目加密时的印章 (key-projectPath; value-印章) */
-    public static volatile Map<String, String>  sealCache =  new ConcurrentHashMap<>(8);
+    public static Map<String, String>  sealCache =  new ConcurrentHashMap<>(8);
     
     /** 本项目获取到的第一个印章 */
     public static volatile String  firstSealCache;

+ 2 - 2
class-winter-maven-plugin/src/main/java/winter/com/ideaaedi/classwinter/plugin/ClassWinterPlugin.java

@@ -21,7 +21,7 @@ import java.io.File;
  * @author JustryDeng
  */
 @SuppressWarnings("unused")
-@Mojo(name = "class-winter", defaultPhase = LifecyclePhase.PACKAGE)
+@Mojo(name = "class-winter", defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true)
 public class ClassWinterPlugin extends AbstractMojo {
 
     @Parameter(defaultValue = "${project}", readonly = true, required = true)
@@ -122,7 +122,7 @@ public class ClassWinterPlugin extends AbstractMojo {
         Logger.debug("The encrypted executor generated based on your configuration is -> " + encryptExecutor);
         String encryptedJarOrWar;
         try {
-            EncryptExecutor.invokerIsPlugin = true;
+            encryptExecutor.invokerIsPlugin = true;
             encryptedJarOrWar = encryptExecutor.process();
             Logger.simpleInfo("The absolute path of the obfuscated jar is [" + encryptedJarOrWar + "]");
         } catch (Exception e) {