|
@@ -12,9 +12,9 @@ import org.gradle.api.logging.Logging
|
|
* Created by Glen on 2017/2/7.
|
|
* 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) {
|
|
public ModifyClassTransform(Project project) {
|
|
this.project = project;
|
|
this.project = project;
|
|
@@ -79,63 +79,18 @@ public class ModifyClassTransform extends Transform {
|
|
}
|
|
}
|
|
|
|
|
|
//output modify jar file
|
|
//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)
|
|
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
|
|
* @param fileInput
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- private String getUniqueHashName(File fileInput) {
|
|
|
|
|
|
+ protected String getUniqueFileName(File fileInput) {
|
|
final String fileInputName = fileInput.getName()
|
|
final String fileInputName = fileInput.getName()
|
|
if (fileInput.isDirectory()) {
|
|
if (fileInput.isDirectory()) {
|
|
return fileInputName
|
|
return fileInputName
|
|
@@ -148,7 +103,17 @@ public class ModifyClassTransform extends Transform {
|
|
return fileInputNamePrefix + '_' + pathMD5
|
|
return fileInputNamePrefix + '_' + pathMD5
|
|
}
|
|
}
|
|
|
|
|
|
- private void debug(def msg) {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * logger
|
|
|
|
+ * @param msg
|
|
|
|
+ */
|
|
|
|
+ protected void debug(def msg) {
|
|
this.logger.lifecycle(":" + this.project.name + ":" + msg)
|
|
this.logger.lifecycle(":" + this.project.name + ":" + msg)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 增量文件
|
|
|
|
+ * @param input
|
|
|
|
+ */
|
|
|
|
+ protected abstract void handleChangedFile(File input)
|
|
}
|
|
}
|