Skip to content

Commit

Permalink
Small corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
tabere-ubique committed Sep 6, 2024
1 parent 0a93444 commit c3faac5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package ch.ubique.linth

import ch.ubique.linth.common.GitUtils
import ch.ubique.linth.common.capitalize
import ch.ubique.linth.common.getMergedManifestFile
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskAction
import java.io.File

Expand All @@ -15,20 +14,17 @@ abstract class InjectMetaIntoManifestTask : DefaultTask() {
private val METADATA_KEY_BRANCH = "ch.ubique.linth.branch"
private val METADATA_KEY_FLAVOR = "ch.ubique.linth.flavor"


private var buildId: String = "0"
private var buildNumber: String = "0"
private var buildBranch: String = "master"
private var buildFlavor: String = "default"


init {
description = "Inject Metadata into Manifest"
group = "linth"
buildId = project.findProperty("buildid")?.toString() ?: project.findProperty("ubappid")?.toString() ?: "localbuild"
buildNumber = project.findProperty("buildnumber")?.toString() ?: "0"
buildBranch = project.findProperty("branch")?.toString() ?: GitUtils.obtainBranch()

}

@get:Input
Expand All @@ -37,18 +33,12 @@ abstract class InjectMetaIntoManifestTask : DefaultTask() {
@TaskAction
fun injectMetadataIntoManifest() {
flavorAndBuildType.forEach { (flavor, buildType) ->
println("Injecting metadata into manifest for flavor: $flavor and buildType: $buildType")
val variantName = flavor + buildType.capitalize()
val manifestFile = File(
project.layout.buildDirectory.asFile.get(),
"intermediates/merged_manifests/${variantName}/process${variantName}Manifest/AndroidManifest.xml"
)
val manifestFile = project.getMergedManifestFile(flavor, buildType)
if (manifestFile.exists()) {
manipulateManifestFile(manifestFile)
} else {
println("Manifest file not found for flavor: $flavor and buildType: $buildType")
}

}
}

Expand Down Expand Up @@ -82,7 +72,7 @@ abstract class InjectMetaIntoManifestTask : DefaultTask() {
private fun addMetaData(manifest: String, metaName: String, metaValue: String): String {
val xmlAppClosingTag = "</application>"
val metaTag = "<meta-data android:name=\"$metaName\" android:value=\"$metaValue\" />"
return manifest.replace("${xmlAppClosingTag}", " $metaTag\n $xmlAppClosingTag")
return manifest.replace(xmlAppClosingTag, " $metaTag\n $xmlAppClosingTag")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class LinthPlugin : Plugin<Project> {
manifestTask.flavorAndBuildType = flavorAndBuildType
}

//hook Manifest into android build process
//hook injectMetaTask into android build process
project.afterEvaluate {
androidExtension.applicationVariants.forEach { variant ->
variant.outputs.forEach { output ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ object GitUtils {
if (branchName.isEmpty()) {
branchName = "develop"
}
println("Branch name: $branchName")
return branchName
}

Expand Down

0 comments on commit c3faac5

Please sign in to comment.