Skip to content

Commit 465f74e

Browse files
committed
1、修复org.gradle.configuration-cache=true时无法编译的bug
2、新增 includeKotlin 配置
1 parent e2b89e2 commit 465f74e

5 files changed

Lines changed: 26 additions & 35 deletions

File tree

android-aop-plugin/src/main/kotlin/com/flyjingfish/android_aop_plugin/config/AndroidAopConfig.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ open class AndroidAopConfig {
2121
*/
2222
var cutInfoJson = false
2323

24+
/**
25+
* 是否扫描包含 kotlinx、kotlin 下的包,默认 false 不扫描
26+
*/
27+
var includeKotlin = false
28+
2429
/**
2530
* 增量加速,有一定增速效果,默认开启
2631
*/
@@ -79,6 +84,7 @@ open class AndroidAopConfig {
7984
AndroidAopConfig.excludes.add(Utils.extraPackage)
8085
AndroidAopConfig.verifyLeafExtends = verifyLeafExtends
8186
AndroidAopConfig.cutInfoJson = cutInfoJson
87+
AndroidAopConfig.includeKotlin = includeKotlin
8288
// AndroidAopConfig.increment = increment
8389
}
8490

@@ -95,6 +101,7 @@ open class AndroidAopConfig {
95101
var verifyLeafExtends = true
96102
var cutInfoJson = false
97103
var increment = false
104+
var includeKotlin = false
98105
internal fun syncConfig(project: Project){
99106
val androidAopConfig = project.extensions.getByType(AndroidAopConfig::class.java)
100107
androidAopConfig.initConfig()

android-aop-plugin/src/main/kotlin/com/flyjingfish/android_aop_plugin/plugin/CompilePlugin.kt

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import com.flyjingfish.android_aop_plugin.scanner_visitor.SuspendReturnScanner
1313
import com.flyjingfish.android_aop_plugin.scanner_visitor.WovenIntoCode
1414
import com.flyjingfish.android_aop_plugin.tasks.CompileAndroidAopTask
1515
import com.flyjingfish.android_aop_plugin.tasks.DebugModeFileTask
16-
import com.flyjingfish.android_aop_plugin.utils.AppClasses
1716
import com.flyjingfish.android_aop_plugin.utils.ClassFileUtils
1817
import com.flyjingfish.android_aop_plugin.utils.ClassPoolUtils
1918
import com.flyjingfish.android_aop_plugin.utils.FileHashUtils
@@ -25,13 +24,9 @@ import com.flyjingfish.android_aop_plugin.utils.adapterOSPath
2524
import com.flyjingfish.android_aop_plugin.utils.getBuildDirectory
2625
import com.flyjingfish.android_aop_plugin.utils.getRelativePath
2726
import org.codehaus.groovy.runtime.DefaultGroovyMethods
28-
import org.gradle.BuildListener
29-
import org.gradle.BuildResult
3027
import org.gradle.api.Project
3128
import org.gradle.api.execution.TaskExecutionGraph
3229
import org.gradle.api.execution.TaskExecutionGraphListener
33-
import org.gradle.api.initialization.Settings
34-
import org.gradle.api.invocation.Gradle
3530
import org.gradle.api.plugins.JavaPluginExtension
3631
import org.gradle.api.tasks.PathSensitivity
3732
import org.gradle.api.tasks.compile.AbstractCompile
@@ -184,24 +179,13 @@ class CompilePlugin(private val fromRootSet:Boolean): BasePlugin() {
184179
InitConfig.initCutInfo(runtimeProject,true)
185180
}
186181
}
187-
project.rootProject.gradle.taskGraph.removeTaskExecutionGraphListener(this)
188-
}
189-
190-
})
191-
project.rootProject.gradle.addBuildListener(object : BuildListener{
192-
override fun settingsEvaluated(settings: Settings) {
193-
}
194-
195-
override fun projectsLoaded(gradle: Gradle) {
196-
}
197-
198-
override fun projectsEvaluated(gradle: Gradle) {
199-
}
200-
201-
override fun buildFinished(result: BuildResult) {
202-
if (startTask){
203-
endAllTask()
182+
val lastTask = it.allTasks.last()
183+
lastTask.doLast {
184+
if (startTask){
185+
endAllTask()
186+
}
204187
}
188+
project.rootProject.gradle.taskGraph.removeTaskExecutionGraphListener(this)
205189
}
206190

207191
})
@@ -458,9 +442,11 @@ class CompilePlugin(private val fromRootSet:Boolean): BasePlugin() {
458442
}
459443

460444
private fun endAllTask(){
461-
FileHashUtils.clearScanRecord()
462-
WovenInfoUtils.clear()
463-
ClassPoolUtils.clear()
464-
SuspendReturnScanner.hasSuspendReturn = false
445+
synchronized(CompilePlugin::class.java){
446+
FileHashUtils.clearScanRecord()
447+
WovenInfoUtils.clear()
448+
ClassPoolUtils.clear()
449+
SuspendReturnScanner.hasSuspendReturn = false
450+
}
465451
}
466452
}

android-aop-plugin/src/main/kotlin/com/flyjingfish/android_aop_plugin/tasks/AssembleAndroidAopTask.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ abstract class AssembleAndroidAopTask : DefaultTransformTask() {
333333
val isClassFile = file.name.endsWith(_CLASS)
334334
val isWovenInfoCode = isClassFile
335335
&& AndroidAopConfig.inRules(thisClassName)
336-
&& !entryClazzName.startsWith("kotlinx/") && !entryClazzName.startsWith("kotlin/")
336+
&& (AndroidAopConfig.includeKotlin || (!entryClazzName.startsWith("kotlinx/") && !entryClazzName.startsWith("kotlin/")))
337337

338338
val methodsRecord: HashMap<String, MethodRecord>? = WovenInfoUtils.getClassMethodRecord(file.absolutePath)
339339
val isSuspend:Boolean
@@ -578,7 +578,7 @@ abstract class AssembleAndroidAopTask : DefaultTransformTask() {
578578
val isClassFile = entryName.endsWith(_CLASS)
579579
val isWovenInfoCode = isClassFile
580580
&& AndroidAopConfig.inRules(thisClassName)
581-
&& !entryName.startsWith("kotlinx/") && !entryName.startsWith("kotlin/")
581+
&& (AndroidAopConfig.includeKotlin || (!entryName.startsWith("kotlinx/") && !entryName.startsWith("kotlin/")))
582582
val methodsRecord: HashMap<String, MethodRecord>? = WovenInfoUtils.getClassMethodRecord(entryName)
583583
val isSuspend:Boolean
584584
val realMethodsRecord: HashMap<String, MethodRecord>? = if (methodsRecord == null && SuspendReturnScanner.hasSuspendReturn && isWovenInfoCode){

android-aop-plugin/src/main/kotlin/com/flyjingfish/android_aop_plugin/tasks/CompileAndroidAopTask.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class CompileAndroidAopTask(
181181
val isClassFile = file.name.endsWith(_CLASS)
182182
val isWovenInfoCode = isClassFile
183183
&& AndroidAopConfig.inRules(thisClassName)
184-
&& !entryClazzName.startsWith("kotlinx/") && !entryClazzName.startsWith("kotlin/")
184+
&& (AndroidAopConfig.includeKotlin || (!entryClazzName.startsWith("kotlinx/") && !entryClazzName.startsWith("kotlin/")))
185185

186186
val methodsRecord: HashMap<String, MethodRecord>? = WovenInfoUtils.getClassMethodRecord(file.absolutePath)
187187
val isSuspend:Boolean

android-aop-plugin/src/main/kotlin/com/flyjingfish/android_aop_plugin/utils/AopTaskUtils.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ class AopTaskUtils(
6363
searchJobs.add(job)
6464
// processJar()
6565
} else if (file.absolutePath.endsWith(_CLASS)) {
66-
if (AndroidAopConfig.verifyLeafExtends && !className.startsWith("kotlinx/") && !className.startsWith(
67-
"kotlin/"
68-
)
66+
if (AndroidAopConfig.verifyLeafExtends &&
67+
(AndroidAopConfig.includeKotlin || (!className.startsWith("kotlinx/") && !className.startsWith("kotlin/")))
6968
) {
7069

7170
fun processJar(){
@@ -126,9 +125,8 @@ class AopTaskUtils(
126125
searchJobs.add(job)
127126
// processJar()
128127
} else if (entryName.endsWith(_CLASS)) {
129-
if (AndroidAopConfig.verifyLeafExtends && !entryName.startsWith("kotlinx/") && !entryName.startsWith(
130-
"kotlin/"
131-
)
128+
if (AndroidAopConfig.verifyLeafExtends &&
129+
(AndroidAopConfig.includeKotlin || (!entryName.startsWith("kotlinx/") && !entryName.startsWith("kotlin/")))
132130
) {
133131
fun processJar(){
134132
jarFile.getInputStream(jarEntry).use { inputs ->

0 commit comments

Comments
 (0)