Skip to content

Commit 2febe17

Browse files
committed
适配windows电脑
1 parent df89466 commit 2febe17

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.google.devtools.ksp.gradle.KspExtension
88
import org.gradle.api.Plugin
99
import org.gradle.api.Project
1010
import org.gradle.configurationcache.extensions.capitalized
11+
import java.io.File
1112

1213
class ApplyExportPlugin: Plugin<Project> {
1314
companion object{
@@ -55,8 +56,9 @@ class ApplyExportPlugin: Plugin<Project> {
5556
if (moduleName.isNotEmpty()){
5657
variantList.add(variant)
5758
for ((index,exposeAsset) in communicationConfig.exposeAssets.withIndex()) {
58-
if (exposeAsset.substring(0,1) == "/"){
59-
communicationConfig.exposeAssets[index] = exposeAsset.substring(1)
59+
if (exposeAsset.substring(0,1) == "/"||exposeAsset.substring(0,1) == "\\"){
60+
communicationConfig.exposeAssets[index] = exposeAsset.substring(1).replace('/',
61+
File.separatorChar)
6062
}
6163
}
6264
val variantName = variant.name

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class CommunicationModulePlugin : Plugin<Project> {
1919
androidComponents.onVariants { variant ->
2020
variantList.add(variant)
2121
variant.sources.java?.let { java ->
22-
val path = "/${LibVersion.buildDir}/${variant.name}/${LibVersion.pathName}"
22+
val path = "/${LibVersion.buildDir}/${variant.name}/${LibVersion.pathName}".replace('/',File.separatorChar)
2323
val file = File("${project.buildDir}$path")
2424
if (!file.exists()){
2525
file.mkdirs()
@@ -28,15 +28,15 @@ class CommunicationModulePlugin : Plugin<Project> {
2828
}
2929

3030
variant.sources.assets?.let { assets ->
31-
val path = "/${LibVersion.buildDir}/${variant.name}/${LibVersion.assetsName}"
31+
val path = "/${LibVersion.buildDir}/${variant.name}/${LibVersion.assetsName}".replace('/',File.separatorChar)
3232
val file = File("${project.buildDir}$path")
3333
if (!file.exists()){
3434
file.mkdirs()
3535
}
3636
assets.addStaticSourceDirectory("build$path")
3737
}
3838

39-
val path = "/${LibVersion.buildDir}/${variant.name}/${LibVersion.resName}"
39+
val path = "/${LibVersion.buildDir}/${variant.name}/${LibVersion.resName}".replace('/',File.separatorChar)
4040
val file = File("${project.buildDir}$path")
4141
if (!file.exists()){
4242
file.mkdirs()

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ abstract class ExportTask : DefaultTask() {
5353
}
5454

5555
private fun searchAssetsFileAndCopy(curProject: Project){
56-
val codePath = "/${LibVersion.buildDir}/${variant.name}/${LibVersion.assetsName}"
56+
val codePath = "/${LibVersion.buildDir}/${variant.name}/${LibVersion.assetsName}".replace('/', File.separatorChar)
5757
val libraryExtension = project.extensions.getByName("android") as LibraryExtension
5858
val variantNames = libraryExtension.sourceSets.names
5959

@@ -72,7 +72,7 @@ abstract class ExportTask : DefaultTask() {
7272
for (srcDir in assets.srcDirs) {
7373
if (srcDir.exists()){
7474
for (resValue in resValuesDel) {
75-
val targetFile = File("${buildFile.absolutePath}/$resValue")
75+
val targetFile = File("${buildFile.absolutePath}${File.separator}$resValue")
7676
if (targetFile.exists()){
7777
targetFile.deleteRecursively()
7878
}
@@ -94,8 +94,8 @@ abstract class ExportTask : DefaultTask() {
9494
for (srcDir in res.srcDirs) {
9595
if (srcDir.exists()){
9696
for (resValue in resValues) {
97-
val targetFile = File("${buildFile.absolutePath}/$resValue")
98-
val file = File("${srcDir.absolutePath}/$resValue")
97+
val targetFile = File("${buildFile.absolutePath}${File.separator}$resValue")
98+
val file = File("${srcDir.absolutePath}${File.separator}$resValue")
9999
if (file.exists()){
100100
file.copyRecursively(targetFile,true)
101101
}
@@ -109,7 +109,7 @@ abstract class ExportTask : DefaultTask() {
109109
}
110110

111111
private fun searchResFileAndCopy(curProject: Project){
112-
val codePath = "/${LibVersion.buildDir}/${variant.name}/${LibVersion.resName}"
112+
val codePath = "/${LibVersion.buildDir}/${variant.name}/${LibVersion.resName}".replace('/',File.separatorChar)
113113
val libraryExtension = project.extensions.getByName("android") as LibraryExtension
114114
val variantNames = libraryExtension.sourceSets.names
115115

@@ -146,8 +146,8 @@ abstract class ExportTask : DefaultTask() {
146146
val collection = curProject.files(dirs).asFileTree.filter { it.name.startsWith(resValue.fileName) }
147147

148148
for (file in collection.files) {
149-
val copyPath = "${file.parentFile.name}/${file.name}"
150-
val targetFile = File("${buildFile.absolutePath}/$copyPath")
149+
val copyPath = "${file.parentFile.name}${File.separator}${file.name}"
150+
val targetFile = File("${buildFile.absolutePath}${File.separator}$copyPath")
151151
file.copyTo(targetFile,true)
152152
IncrementalRecordUtils.recordResFile(moduleKey,copyPath)
153153
if (resValue.dir == "color"){
@@ -167,7 +167,7 @@ abstract class ExportTask : DefaultTask() {
167167
val nodeName: String = element.name
168168
val name: String = element.attribute("name").value
169169
if (name == resValue.fileName && nodeName != "item"){
170-
val targetFile = File("${buildFile.absolutePath}/${file.parentFile.name}",file.name)
170+
val targetFile = File("${buildFile.absolutePath}${File.separator}${file.parentFile.name}",file.name)
171171
if (!targetFile.exists()){
172172
targetFile.parentFile?.mkdirs()
173173
targetFile.createNewFile()
@@ -199,8 +199,8 @@ abstract class ExportTask : DefaultTask() {
199199

200200
private fun searchApiFileAndCopy(curProject: Project){
201201
val variantName = variant.name
202-
val codePath = "/${LibVersion.buildDir}/${variant.name}/${LibVersion.pathName}"
203-
val genFile = curProject.file("${curProject.buildDir}/generated/ksp/${variantName}").listFiles()
202+
val codePath = "/${LibVersion.buildDir}/${variant.name}/${LibVersion.pathName}".replace('/',File.separatorChar)
203+
val genFile = curProject.file("${curProject.buildDir}${File.separator}generated${File.separator}ksp${File.separator}${variantName}").listFiles()
204204
val collection = curProject.files(genFile).asFileTree.filter { it.name.endsWith(".api") }
205205

206206
val dir = project.project(":${exportModuleName}".replace("\"","")).projectDir
@@ -219,7 +219,7 @@ abstract class ExportTask : DefaultTask() {
219219
}
220220

221221
for (packageName in recordPackageSet) {
222-
val packageFile = File(buildFile.absolutePath +"/"+ packageName.replace(".","/"))
222+
val packageFile = File(buildFile.absolutePath + File.separator + packageName.replace(".",File.separator))
223223
packageFile.deleteRecursively()
224224
}
225225
}
@@ -228,7 +228,9 @@ abstract class ExportTask : DefaultTask() {
228228
val packageName = getPackageName(file)
229229
packageName?.let {
230230
IncrementalRecordUtils.recordCodeFile(moduleKey,it)
231-
val packagePath = buildFile.absolutePath +"/"+ it.replace(".","/")
231+
val packagePath = buildFile.absolutePath + File.separator + it.replace(".",
232+
File.separator
233+
)
232234
val targetFile = File(packagePath,file.name.replace(".api",""))
233235
file.copyTo(targetFile,true)
234236
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ object TmpUtils {
5656

5757
fun initTmp(project: Project, variant: Variant){
5858
val dir = project.projectDir
59-
val codePath = "build/${LibVersion.buildDir}/${variant.name}"
59+
val codePath = "build/${LibVersion.buildDir}/${variant.name}".replace("/", File.separator)
6060
val buildFile = File(dir, codePath)
6161
buildConfigCacheFile = File(buildFile.absolutePath, "tmp.json")
6262
if (temporaryDirMkdirs()){

0 commit comments

Comments
 (0)