|
1 | 1 | package com.callstack.react.brownfield.processors |
2 | 2 |
|
3 | | -import com.callstack.react.brownfield.shared.BaseProject |
4 | | -import com.callstack.react.brownfield.utils.AndroidArchiveLibrary |
5 | | -import com.callstack.react.brownfield.utils.DirectoryManager |
6 | 3 | import com.callstack.react.brownfield.utils.capitalized |
7 | | -import org.gradle.api.file.ConfigurableFileCollection |
8 | | -import java.io.File |
9 | | -import java.nio.file.Files |
10 | | -import java.nio.file.Path |
11 | | -import java.nio.file.Paths |
12 | | - |
13 | | -class VariantHelper : BaseProject() { |
14 | | - private fun getClassPathDirFiles(variantName: String): ConfigurableFileCollection { |
15 | | - return project.files( |
16 | | - "$buildDir/intermediates/javac/$variantName/compile${variantName.capitalized()}JavaWithJavac/classes", |
17 | | - ) |
| 4 | + |
| 5 | +object VariantHelper { |
| 6 | + fun getAsmTransformTaskName(capitalizedVariantName: String): String { |
| 7 | + return "transform${capitalizedVariantName}ClassesWithAsm" |
18 | 8 | } |
19 | 9 |
|
20 | | - fun classesMergeTaskDoFirst( |
21 | | - outputDir: File, |
22 | | - variantName: String, |
23 | | - ) { |
24 | | - val pathsToDelete = mutableListOf<Path>() |
25 | | - val javacDir = getClassPathDirFiles(variantName).first() |
26 | | - project.fileTree(outputDir).forEach { path -> |
27 | | - pathsToDelete.add( |
28 | | - Paths.get(outputDir.absolutePath).relativize(Paths.get(path.absolutePath)), |
29 | | - ) |
| 10 | + fun getBundledAssetsVariantName( |
| 11 | + variantName: String?, |
| 12 | + buildTypeName: String?, |
| 13 | + isDebuggable: Boolean, |
| 14 | + ): String { |
| 15 | + require(!variantName.isNullOrEmpty()) { |
| 16 | + "getBundledAssetsVariantName: Variant name cannot be empty" |
30 | 17 | } |
31 | | - outputDir.deleteRecursively() |
32 | | - pathsToDelete.forEach { path -> |
33 | | - Files.deleteIfExists(Paths.get("$javacDir.absolutePath/$path")) |
| 18 | + |
| 19 | + require(!buildTypeName.isNullOrEmpty()) { |
| 20 | + "getBundledAssetsVariantName: Build Type cannot be empty" |
34 | 21 | } |
35 | | - } |
36 | 22 |
|
37 | | - fun classesMergeTaskDoLast( |
38 | | - outputDir: File, |
39 | | - aarLibraries: Collection<AndroidArchiveLibrary>, |
40 | | - jarFiles: MutableList<File>, |
41 | | - variantName: String, |
42 | | - isMinifyEnabled: Boolean, |
43 | | - ) { |
44 | | - MergeProcessor.mergeClassesJarIntoClasses(project, aarLibraries, outputDir) |
45 | | - if (isMinifyEnabled) { |
46 | | - MergeProcessor.mergeLibsIntoClasses(project, aarLibraries, jarFiles, outputDir) |
| 23 | + if (!isDebuggable) { |
| 24 | + return variantName |
47 | 25 | } |
48 | | - val javacDir = getClassPathDirFiles(variantName).first() |
49 | | - project.copy { copyTask -> |
50 | | - copyTask.from(outputDir) |
51 | | - copyTask.into(javacDir) |
52 | | - copyTask.exclude("META-INF/") |
| 26 | + |
| 27 | + if (variantName == buildTypeName) { |
| 28 | + return "release" |
53 | 29 | } |
54 | 30 |
|
55 | | - project.copy { copyTask -> |
56 | | - copyTask.from("${outputDir.absolutePath}/META-INF") |
57 | | - copyTask.into(DirectoryManager.getKotlinMetaDirectory(variantName)) |
58 | | - copyTask.include("*.kotlin_module") |
| 31 | + val capitalizedBuildTypeName = buildTypeName.capitalized() |
| 32 | + return if (variantName.endsWith(capitalizedBuildTypeName)) { |
| 33 | + "${variantName.removeSuffix(capitalizedBuildTypeName)}Release" |
| 34 | + } else { |
| 35 | + "release" |
59 | 36 | } |
60 | 37 | } |
| 38 | + |
| 39 | + fun getExpoUpdatesResourcesTaskName(variantName: String): String { |
| 40 | + return "create${variantName.capitalized()}UpdatesResources" |
| 41 | + } |
61 | 42 | } |
0 commit comments