Skip to content

Commit 461af11

Browse files
committed
Refactor: Simplify package name and plugin source folder retrieval
- Use `orElse` with namespace provider to lazily get the package name - Simplify setting the `pluginSourceFolder` path.
1 parent c03aa93 commit 461af11

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

secretsvaultplugin/src/main/kotlin/com/commencis/secretsvaultplugin/SecretsVaultPlugin.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.commencis.secretsvaultplugin
33
import com.android.build.api.dsl.CommonExtension
44
import com.commencis.secretsvaultplugin.extensions.CMakeExtension
55
import com.commencis.secretsvaultplugin.extensions.SecretsVaultExtension
6-
import com.commencis.secretsvaultplugin.utils.EMPTY_STRING
76
import com.commencis.secretsvaultplugin.utils.Utils
87
import org.gradle.api.Plugin
98
import org.gradle.api.Project
@@ -67,22 +66,24 @@ internal class SecretsVaultPlugin : Plugin<Project> {
6766
group = TASK_GROUP
6867
description = "Re-generate and obfuscate keys from the json file and add it to your Android project"
6968
pluginSourceFolder.set(
70-
unzipTaskProvider.map { copyTask ->
71-
project.layout.projectDirectory.dir(copyTask.destinationDir.path)
72-
}
69+
project.layout.projectDirectory.dir(
70+
unzipTaskProvider.map { task -> task.destinationDir.absolutePath }
71+
)
7372
)
7473
secretsFile.set(secretsVaultExtension.secretsFile)
7574
sourceSetSecretsMappingFile.set(secretsVaultExtension.sourceSetSecretsMappingFile)
7675
obfuscationKey.set(secretsVaultExtension.obfuscationKey)
7776
appSignatures.set(secretsVaultExtension.appSignatures)
7877
makeInjectable.set(secretsVaultExtension.makeInjectable)
7978

80-
// Provide the package name in the extension unless it is not specified or empty,
79+
// Provide the package name in the extension unless it is not specified,
8180
// in which case the namespace is used.
8281
packageName.set(
83-
secretsVaultExtension.packageName.getOrElse(EMPTY_STRING).ifEmpty {
84-
project.extensions.getByType(CommonExtension::class.java).namespace.orEmpty()
85-
}
82+
secretsVaultExtension.packageName.orElse(
83+
project.provider {
84+
project.extensions.findByType(CommonExtension::class.java)?.namespace.orEmpty()
85+
}
86+
)
8687
)
8788

8889
cmakeProjectName.set(secretsVaultExtension.cmake.flatMap { cMakeExtension -> cMakeExtension.projectName })

0 commit comments

Comments
 (0)