Skip to content

Commit d9c6126

Browse files
committed
1、修改支持单个通信module
1 parent 13fa927 commit d9c6126

File tree

5 files changed

+54
-10
lines changed

5 files changed

+54
-10
lines changed

lib-login/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ plugins {
55
id("communication.export")
66
}
77

8-
communicationConfig{
9-
exportModuleName = "communication2"
10-
}
8+
//communicationConfig{
9+
// exportModuleName = "communication2"
10+
//}
1111

1212
android {
1313
namespace = "com.flyjingfish.login"

lib-user/build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ plugins {
44
// id("com.google.devtools.ksp")
55
id("communication.export")
66
}
7-
communicationConfig{
8-
exportModuleName = "communication"
9-
}
7+
//communicationConfig{
8+
// exportModuleName = "communication"
9+
//}
1010
android {
1111
namespace = "com.flyjingfish.user"
1212
compileSdk = 34
@@ -34,7 +34,7 @@ dependencies {
3434
androidTestImplementation(libs.androidx.test.ext.junit)
3535
androidTestImplementation(libs.espresso.core)
3636
implementation(project(":base-lib"))
37-
compileOnly(project(":communication2"))
37+
compileOnly(project(":communication"))
3838
// implementation(project(":module-communication-annotation"))
3939
// ksp(project(":module-communication-ksp"))
4040
}

module-communication-plugin/src/main/kotlin/com/flyjingfish/module_communication_plugin/CommunicationModulePlugin.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.flyjingfish.module_communication_plugin
33
import com.android.build.api.variant.AndroidComponentsExtension
44
import org.gradle.api.Plugin
55
import org.gradle.api.Project
6+
import org.gradle.configurationcache.extensions.capitalized
67
import java.io.File
78

89
class CommunicationModulePlugin : Plugin<Project> {
@@ -19,5 +20,12 @@ class CommunicationModulePlugin : Plugin<Project> {
1920
java.addStaticSourceDirectory("build/${LibVersion.pathName}/${variant.name}")
2021
}
2122
}
23+
// project.afterEvaluate {
24+
// for (variant in variantList) {
25+
// val variantName = variant.name
26+
// val variantNameCapitalized = variantName.capitalized()
27+
// project.tasks.findByName("ksp${variantNameCapitalized}Kotlin")?.finalizedBy("generateCommunication$variantNameCapitalized")
28+
// }
29+
// }
2230
}
2331
}

module-communication-plugin/src/main/kotlin/com/flyjingfish/module_communication_plugin/ExportTask.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ abstract class ExportTask : DefaultTask() {
1919
abstract var variant: Variant
2020
@get:Input
2121
abstract var exportModuleName: String
22+
2223
@TaskAction
2324
fun taskAction() {
2425
val variantName = variant.name
@@ -30,12 +31,16 @@ abstract class ExportTask : DefaultTask() {
3031

3132
val dir = project.project(":${exportModuleName}".replace("\"","")).projectDir
3233
val path = "build/${LibVersion.pathName}/${variantName}"
33-
val packageFile = File(dir, path)
34-
packageFile.deleteRecursively()
34+
val buildFile = File(dir, path)
35+
36+
val moduleKey = curProject.buildDir.absolutePath
37+
PackageRecordUtils.clear(moduleKey,buildFile)
38+
3539
for (file in collection.files) {
3640
val packageName = getPackageName(file)
3741
packageName?.let {
38-
val packagePath = packageFile.absolutePath +"/"+ it.replace(".","/")
42+
PackageRecordUtils.record(moduleKey,it)
43+
val packagePath = buildFile.absolutePath +"/"+ it.replace(".","/")
3944
val targetFile = File(packagePath,file.name.replace(".api",""))
4045
file.copyTo(targetFile,true)
4146
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.flyjingfish.module_communication_plugin
2+
3+
import java.io.File
4+
5+
object PackageRecordUtils {
6+
private val lastRecordPackageMap = mutableMapOf<String,MutableSet<String>>()
7+
8+
fun record(moduleKey :String,packageName :String){
9+
var lastRecordPackageSet = lastRecordPackageMap[moduleKey]
10+
if (lastRecordPackageSet == null){
11+
lastRecordPackageSet = mutableSetOf()
12+
lastRecordPackageMap[moduleKey] = lastRecordPackageSet
13+
}
14+
lastRecordPackageSet.add(packageName)
15+
}
16+
17+
fun clear(moduleKey :String,buildFile : File){
18+
val lastRecordPackageSet = lastRecordPackageMap[moduleKey]
19+
lastRecordPackageSet?.let {
20+
println("lastRecordPackageSet-size="+it.size);
21+
22+
for (packageName in it) {
23+
val packageFile = File(buildFile.absolutePath +"/"+ packageName.replace(".","/"))
24+
packageFile.deleteRecursively()
25+
}
26+
27+
it.clear()
28+
}
29+
}
30+
31+
}

0 commit comments

Comments
 (0)