|
@@ -2,11 +2,10 @@ package com.gradle
|
|
|
|
|
|
import com.android.build.api.transform.*
|
|
import com.android.build.api.transform.*
|
|
import com.google.common.collect.ImmutableSet
|
|
import com.google.common.collect.ImmutableSet
|
|
|
|
+import com.google.common.io.Files
|
|
import org.apache.commons.codec.digest.DigestUtils
|
|
import org.apache.commons.codec.digest.DigestUtils
|
|
import org.apache.commons.io.FileUtils
|
|
import org.apache.commons.io.FileUtils
|
|
import org.gradle.api.Project
|
|
import org.gradle.api.Project
|
|
-import org.gradle.api.logging.Logger
|
|
|
|
-import org.gradle.api.logging.Logging
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* Created by Glen on 2017/2/7.
|
|
* Created by Glen on 2017/2/7.
|
|
@@ -14,11 +13,10 @@ import org.gradle.api.logging.Logging
|
|
|
|
|
|
public abstract class ModifyClassTransform extends Transform {
|
|
public abstract class ModifyClassTransform extends Transform {
|
|
protected Project project;
|
|
protected Project project;
|
|
- protected Logger logger;
|
|
|
|
|
|
|
|
public ModifyClassTransform(Project project) {
|
|
public ModifyClassTransform(Project project) {
|
|
this.project = project
|
|
this.project = project
|
|
- this.logger = Logging.getLogger(ModifyClassTransform.class)
|
|
|
|
|
|
+ MyLogger.init(project.name)
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -50,42 +48,70 @@ public abstract class ModifyClassTransform extends Transform {
|
|
@Override
|
|
@Override
|
|
void transform(TransformInvocation transformInvocation) throws TransformException, InterruptedException, IOException {
|
|
void transform(TransformInvocation transformInvocation) throws TransformException, InterruptedException, IOException {
|
|
long time = System.currentTimeMillis()
|
|
long time = System.currentTimeMillis()
|
|
- //delete all
|
|
|
|
- transformInvocation.outputProvider.deleteAll()
|
|
|
|
|
|
|
|
// Collecting inputs.
|
|
// Collecting inputs.
|
|
transformInvocation.inputs.each { input ->
|
|
transformInvocation.inputs.each { input ->
|
|
input.directoryInputs.each { dirInput ->
|
|
input.directoryInputs.each { dirInput ->
|
|
if (transformInvocation.incremental) {
|
|
if (transformInvocation.incremental) {
|
|
-// 待修复bug
|
|
|
|
-// dirInput.changedFiles.each { changedFile ->
|
|
|
|
-// handleChangedFile(changedFile.key)
|
|
|
|
-// }
|
|
|
|
- dirInput.file.eachFileRecurse { File file ->
|
|
|
|
- handleChangedFile(file)
|
|
|
|
|
|
+ File dirOutput = transformInvocation.outputProvider.getContentLocation(dirInput.file.name, dirInput.contentTypes, dirInput.scopes, Format.DIRECTORY)
|
|
|
|
+ if (!dirOutput.exists()) {
|
|
|
|
+ dirOutput.mkdirs()
|
|
|
|
+ }
|
|
|
|
+ dirInput.changedFiles.each { changedFile ->
|
|
|
|
+ File fileInput = changedFile.getKey()
|
|
|
|
+ File fileOutput = new File(fileInput.getAbsolutePath().replace(
|
|
|
|
+ dirInput.file.getAbsolutePath(), dirOutput.getAbsolutePath()))
|
|
|
|
+ if (!fileOutput.exists()) {
|
|
|
|
+ fileOutput.getParentFile().mkdirs()
|
|
|
|
+ }
|
|
|
|
+ switch (changedFile.value) {
|
|
|
|
+ case Status.ADDED:
|
|
|
|
+ case Status.CHANGED:
|
|
|
|
+ if (fileInput.isDirectory()) {
|
|
|
|
+ return // continue.
|
|
|
|
+ }
|
|
|
|
+ handleChangedFile(fileInput)
|
|
|
|
+ if (fileInput.getName().endsWith('.class')) {
|
|
|
|
+ Files.copy(fileInput, fileOutput)
|
|
|
|
+ }
|
|
|
|
+ break
|
|
|
|
+ case Status.REMOVED:
|
|
|
|
+ if (fileOutput.exists()) {
|
|
|
|
+ if (fileOutput.isDirectory()) {
|
|
|
|
+ fileOutput.deleteDir()
|
|
|
|
+ } else {
|
|
|
|
+ fileOutput.delete()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ break
|
|
|
|
+ }
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
dirInput.file.eachFileRecurse { File file ->
|
|
dirInput.file.eachFileRecurse { File file ->
|
|
handleChangedFile(file)
|
|
handleChangedFile(file)
|
|
}
|
|
}
|
|
|
|
+ //output modify class file
|
|
|
|
+ File file = transformInvocation.outputProvider.getContentLocation(dirInput.file.name, dirInput.contentTypes, dirInput.scopes, Format.DIRECTORY)
|
|
|
|
+ if (file.exists()) file.deleteDir()
|
|
|
|
+ FileUtils.copyDirectory(dirInput.file, file)
|
|
}
|
|
}
|
|
-
|
|
|
|
- //output modify class file
|
|
|
|
- File file = transformInvocation.outputProvider.getContentLocation(dirInput.file.name, dirInput.contentTypes, dirInput.scopes, Format.DIRECTORY)
|
|
|
|
- FileUtils.copyDirectory(dirInput.file, file)
|
|
|
|
}
|
|
}
|
|
input.jarInputs.each { jarInput ->
|
|
input.jarInputs.each { jarInput ->
|
|
|
|
+ File file = transformInvocation.outputProvider.getContentLocation(getUniqueFileName(jarInput.file), jarInput.contentTypes, jarInput.scopes, Format.JAR)
|
|
switch (jarInput.status) {
|
|
switch (jarInput.status) {
|
|
case Status.NOTCHANGED:
|
|
case Status.NOTCHANGED:
|
|
if (transformInvocation.incremental) break
|
|
if (transformInvocation.incremental) break
|
|
case Status.ADDED:
|
|
case Status.ADDED:
|
|
case Status.CHANGED:
|
|
case Status.CHANGED:
|
|
|
|
+ file.deleteOnExit()
|
|
handleChangedFile(jarInput.file)
|
|
handleChangedFile(jarInput.file)
|
|
|
|
+ //output modify jar file
|
|
|
|
+ FileUtils.copyFile(jarInput.file, file)
|
|
|
|
+ break
|
|
|
|
+ case Status.REMOVED:
|
|
|
|
+ file.deleteOnExit()
|
|
|
|
+ break
|
|
}
|
|
}
|
|
-
|
|
|
|
- //output modify jar file
|
|
|
|
- File file = transformInvocation.outputProvider.getContentLocation(getUniqueFileName(jarInput.file), jarInput.contentTypes, jarInput.scopes, Format.JAR)
|
|
|
|
- FileUtils.copyFile(jarInput.file, file)
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -111,14 +137,6 @@ public abstract class ModifyClassTransform extends Transform {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * logger
|
|
|
|
- * @param msg
|
|
|
|
- */
|
|
|
|
- protected void debug(def msg) {
|
|
|
|
- //this.logger.lifecycle(":" + this.project.name + ":" + msg)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
* 增量文件
|
|
* 增量文件
|
|
* @param input
|
|
* @param input
|
|
*/
|
|
*/
|