weiguo 7 éve
szülő
commit
50d64bb155

+ 1 - 1
app/src/main/java/com/uddream/plugin/MainActivity.java

@@ -10,7 +10,7 @@ import android.widget.Toast;
 import com.bumptech.glide.Glide;
 
 public class MainActivity extends AppCompatActivity {
-
+    
     private View.OnClickListener listener = new View.OnClickListener() {
         @Override
         public void onClick(View v) {

+ 1 - 2
buildSrc/src/main/groovy/com/gradle/AresPlugin.groovy

@@ -11,7 +11,6 @@ public class AresPlugin implements Plugin<Project> {
 
     @Override
     void apply(Project project) {
-        project.logger.error("start and gradle plugin")
-        project.android.registerTransform(new ModifyClassTransform(project))
+        project.android.registerTransform(new AresTransform(project))
     }
 }

+ 53 - 0
buildSrc/src/main/groovy/com/gradle/AresTransform.groovy

@@ -0,0 +1,53 @@
+package com.gradle
+
+import org.gradle.api.Project
+
+/**
+ * Created by Glen on 2017/2/7.
+ */
+
+public class AresTransform extends ModifyClassTransform {
+    public AresTransform(Project project) {
+        super(project);
+    }
+
+    @Override
+    protected void handleChangedFile(File input) {
+        String path = input.absolutePath.replace("/", "\\")
+        if (input.isFile()) {
+            debug("changed:" + input.absolutePath)
+            if (path.endsWith(".class")) {
+                modifyClass(input)
+            } else if (path.endsWith(".jar")) {
+                if (path.contains("exploded-aar")) {
+                    if (!path.contains("com.android.support")) {
+//                        //需要处理的jar包
+//                        File tmp = new File(input.getParent() + File.separator + "tmp")
+//                        tmp.deleteOnExit()
+
+//                        boolean modify = false
+//                        if (!modify) JarZipUtil.unzipJar(input, tmp.absolutePath)
+//                        tmp.eachFileRecurse { File file ->
+//                            if (file.isFile()) {
+//                                if (modifyClass(file)) {
+//                                    modify = true
+//                                }
+//                            }
+//                        }
+//                        if (modify) JarZipUtil.zipJar(tmp.absolutePath, input)
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * 修改类文件
+     * @param clazz
+     * @return
+     */
+    private boolean modifyClass(File clazz) {
+        debug("modify:" + clazz.absolutePath)
+        return false
+    }
+}

+ 16 - 51
buildSrc/src/main/groovy/com/gradle/ModifyClassTransform.groovy

@@ -12,9 +12,9 @@ import org.gradle.api.logging.Logging
  * Created by Glen on 2017/2/7.
  */
 
-public class ModifyClassTransform extends Transform {
-    Project project;
-    Logger logger;
+public abstract class ModifyClassTransform extends Transform {
+    protected Project project;
+    protected Logger logger;
 
     public ModifyClassTransform(Project project) {
         this.project = project;
@@ -79,63 +79,18 @@ public class ModifyClassTransform extends Transform {
                 }
 
                 //output modify jar file
-                File file = transformInvocation.outputProvider.getContentLocation(getUniqueHashName(jarInput.file), jarInput.contentTypes, jarInput.scopes, Format.JAR)
+                File file = transformInvocation.outputProvider.getContentLocation(getUniqueFileName(jarInput.file), jarInput.contentTypes, jarInput.scopes, Format.JAR)
                 FileUtils.copyFile(jarInput.file, file)
             }
         }
     }
 
     /**
-     * 增量文件
-     * @param input
-     */
-    private void handleChangedFile(File input) {
-        String path = input.absolutePath.replace("/", "\\")
-        if (input.isFile()) {
-            debug("changed:" + input.absolutePath)
-            if (path.endsWith(".class")) {
-                modifyClass(input)
-            } else if (path.endsWith(".jar")) {
-                if (path.contains("exploded-aar")) {
-                    if (!path.contains("com.android.support")) {
-                        //需要处理的jar包
-                        File tmp = new File(input.getParent() + File.separator + "tmp")
-                        tmp.deleteOnExit()
-
-                        boolean modify = false
-                        if (!modify) JarZipUtil.unzipJar(input, tmp.absolutePath)
-                        tmp.eachFileRecurse { File file ->
-                            if (file.isFile()) {
-                                if (modifyClass(file)) {
-                                    modify = true
-                                }
-                            }
-                        }
-                        if (modify) JarZipUtil.zipJar(tmp.absolutePath, input)
-                    }
-                }
-            }
-        }
-    }
-
-    /**
-     * 修改类文件
-     * @param clazz
-     * @return
-     */
-    private boolean modifyClass(File clazz) {
-        debug("modify:" + clazz.absolutePath)
-
-
-        return false
-    }
-
-    /**
      * 生成唯一文件名
      * @param fileInput
      * @return
      */
-    private String getUniqueHashName(File fileInput) {
+    protected String getUniqueFileName(File fileInput) {
         final String fileInputName = fileInput.getName()
         if (fileInput.isDirectory()) {
             return fileInputName
@@ -148,7 +103,17 @@ public class ModifyClassTransform extends Transform {
         return fileInputNamePrefix + '_' + pathMD5
     }
 
-    private void debug(def msg) {
+    /**
+     * logger
+     * @param msg
+     */
+    protected void debug(def msg) {
         this.logger.lifecycle(":" + this.project.name + ":" + msg)
     }
+
+    /**
+     * 增量文件
+     * @param input
+     */
+    protected abstract void handleChangedFile(File input)
 }