Skip to content

Commit

Permalink
修改生成代码部分
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyJingFish committed Apr 24, 2024
1 parent 9fdb28c commit 324f4c2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ class AndroidAopPlugin : Plugin<Project> {
}
if (localInput.isNotEmpty()){
val output = File(javaCompile.destinationDirectory.asFile.orNull.toString())
val task = CompileAndroidAopTask(jarInput,localInput,output,project,isApp)
val task = CompileAndroidAopTask(jarInput,localInput,output,project,isApp,
File(project.buildDir.path + "/tmp/android-aop/" + fullName)
)
task.taskAction()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.flyjingfish.android_aop_plugin
import com.flyjingfish.android_aop_plugin.beans.ClassMethodRecord
import com.flyjingfish.android_aop_plugin.beans.MethodRecord
import com.flyjingfish.android_aop_plugin.beans.ReplaceMethodInfo
import com.flyjingfish.android_aop_plugin.beans.TmpFile
import com.flyjingfish.android_aop_plugin.config.AndroidAopConfig
import com.flyjingfish.android_aop_plugin.scanner_visitor.SearchAopMethodVisitor
import com.flyjingfish.android_aop_plugin.scanner_visitor.SearchAOPConfigVisitor
Expand Down Expand Up @@ -45,7 +46,8 @@ class CompileAndroidAopTask(val allJars: MutableList<File>,
val allDirectories: MutableList<File>,
val output: File,
val project: Project,
val outPutInitClass:Boolean
val outPutInitClass:Boolean,
val tmpFile:File
) {


Expand Down Expand Up @@ -326,15 +328,14 @@ class CompileAndroidAopTask(val allJars: MutableList<File>,
WovenInfoUtils.removeDeletedClassMethodRecord()
WovenInfoUtils.verifyModifyExtendsClassInfo()
}

private fun wovenIntoCode(){
val includes = AndroidAopConfig.includes
val excludes = AndroidAopConfig.excludes
WovenInfoUtils.makeReplaceMethodInfoUse()
// logger.error("getClassMethodRecord="+WovenInfoUtils.classMethodRecords)
val hasReplace = WovenInfoUtils.hasReplace()
val hasReplaceExtendsClass = WovenInfoUtils.hasModifyExtendsClass()

val tempFiles = mutableListOf<TmpFile>()
fun processFile(file : File,directory:File,directoryPath:String){
if (file.isFile) {
val entryName = file.absolutePath.replace("$directoryPath/","")
Expand All @@ -343,7 +344,15 @@ class CompileAndroidAopTask(val allJars: MutableList<File>,
}
val relativePath = directory.toURI().relativize(file.toURI()).path

val outFile = file
val outFile = File(tmpFile.absolutePath+"/"+relativePath)
if (!outFile.parentFile.exists()){
outFile.parentFile.mkdirs()
}
if (!outFile.exists()){
outFile.createNewFile()
}
val tmpFile = TmpFile(file,outFile)
tempFiles.add(tmpFile)
val methodsRecord: HashMap<String, MethodRecord>? = WovenInfoUtils.getClassMethodRecord(file.absolutePath)
if (methodsRecord != null){
FileInputStream(file).use { inputs ->
Expand Down Expand Up @@ -428,6 +437,13 @@ class CompileAndroidAopTask(val allJars: MutableList<File>,
WovenIntoCode.createInitClass(output)
}

for (tempFile in tempFiles) {
tempFile.tmp.inputStream().use { inputStream ->
inputStream.copyTo(FileOutputStream(tempFile.target))
}
// tempFile.tmp.copyTo(tempFile.target,true)
}

exportCutInfo()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.flyjingfish.android_aop_plugin.beans

import java.io.File

class TmpFile(val target: File, val tmp :File)

0 comments on commit 324f4c2

Please sign in to comment.