Skip to content

Commit 81c7ec0

Browse files
committed
fix: detekt
1 parent 99d2ba0 commit 81c7ec0

1 file changed

Lines changed: 30 additions & 15 deletions

File tree

  • gradle-plugins/react/brownfield/src/main/kotlin/com/callstack/react/brownfield/processors

gradle-plugins/react/brownfield/src/main/kotlin/com/callstack/react/brownfield/processors/JNILibsProcessor.kt

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
package com.callstack.react.brownfield.processors
1212

13-
import com.android.build.gradle.LibraryExtension
1413
import com.android.build.gradle.api.LibraryVariant
1514
import com.callstack.react.brownfield.exceptions.TaskNotFound
1615
import com.callstack.react.brownfield.shared.BaseProject
@@ -36,7 +35,6 @@ class JNILibsProcessor : BaseProject() {
3635
throw TaskNotFound("Task $taskName not found")
3736
}
3837

39-
val androidExtension = project.extensions.getByName("android") as LibraryExtension
4038
val copyTask = copySoLibsTask(variant)
4139

4240
mergeJniLibsTask.configure {
@@ -102,22 +100,39 @@ class JNILibsProcessor : BaseProject() {
102100
val (fromDir, intoDir) = getStrippedLibsPath(variant)
103101

104102
existingJNILibs.forEach { (arch, libNames) ->
105-
val sourceArchDir = File(fromDir, arch)
106-
if (!sourceArchDir.exists()) return@forEach
103+
copyLibsForArchitecture(fromDir, intoDir, arch, libNames)
104+
}
105+
}
107106

108-
val destArchDir = File(intoDir, arch).apply { mkdirs() }
107+
private fun copyLibsForArchitecture(
108+
fromDir: File,
109+
intoDir: File,
110+
arch: String,
111+
libNames: List<String>,
112+
) {
113+
val sourceArchDir = File(fromDir, arch)
114+
if (!sourceArchDir.exists()) return
109115

110-
libNames.forEach { libName ->
111-
val sourceFile = File(sourceArchDir, libName)
112-
val destFile = File(destArchDir, libName)
116+
val destArchDir = File(intoDir, arch).apply { mkdirs() }
113117

114-
if (sourceFile.exists()) {
115-
try {
116-
sourceFile.copyTo(destFile, overwrite = true)
117-
} catch (e: Exception) {
118-
Logging.log("Failed to copy $libName: ${e.message}")
119-
}
120-
}
118+
libNames.forEach { libName ->
119+
copyLibFile(sourceArchDir, destArchDir, libName)
120+
}
121+
}
122+
123+
private fun copyLibFile(
124+
sourceArchDir: File,
125+
destArchDir: File,
126+
libName: String,
127+
) {
128+
val sourceFile = File(sourceArchDir, libName)
129+
val destFile = File(destArchDir, libName)
130+
131+
if (sourceFile.exists()) {
132+
try {
133+
sourceFile.copyTo(destFile, overwrite = true)
134+
} catch (e: java.io.IOException) {
135+
Logging.log("Failed to copy $libName: ${e.message}")
121136
}
122137
}
123138
}

0 commit comments

Comments
 (0)