Skip to content

Commit

Permalink
feat: Adding support for providing a default properties file. (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
arriolac authored Jan 27, 2021
1 parent 7a93ebf commit 6982e8b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,18 @@ class SecretsPlugin : Plugin<Project> {
SecretsPluginExtension::class.java
)
project.afterEvaluate {
val defaultProperties = extension.defaultPropertiesFileName?.let {
project.rootProject.loadPropertiesFile(it)
}
val properties = project.rootProject.loadPropertiesFile(
extension.propertiesFileName
)
project.androidProject()?.applicationVariants?.all { variant ->
// Inject defaults first
defaultProperties?.let {
variant.inject(it, extension.ignoreList)
}

variant.inject(properties, extension.ignoreList)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ open class SecretsPluginExtension {
*/
var ignoreList: MutableList<String> = defaultIgnoreList

/**
* The name of the properties file containing secrets' default values.
*/
var defaultPropertiesFileName: String? = null

companion object {
const val defaultPropertiesFile = "local.properties"
val defaultIgnoreList = mutableListOf("sdk.dir")
Expand Down
1 change: 1 addition & 0 deletions sample-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ secrets {
// Optionally specify a different file name containing your secrets.
// The plugin defaults to "local.properties"
propertiesFileName = "secrets.properties"
// defaultPropertiesFileName = "secrets.defaults.properties"

// Add keys that the plugin should ignore from the properties file
ignoreList.add("keyToIgnore")
Expand Down
2 changes: 1 addition & 1 deletion sample-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
android:theme="@style/Theme.MyApplication">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="gmpApiKey" />
android:value="${gmpApiKey}" />
<activity
android:name="com.google.secrets_gradle_plugin.sample.MainActivity"
android:label="@string/app_name"
Expand Down
7 changes: 7 additions & 0 deletions secrets.defaults.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Sample properties file containing application secrets.
# This file is checked into version control for the sake of demonstrating sample contents.
# In practice, your properties file that contains secrets *should not* be under version control.
gmpApiKey=""
keyToIgnore=""
ignoreKey1=""
ignoreKey2=""
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ include(":plugin", ":sample-app")

pluginManagement {
repositories {
gradlePluginPortal()
maven(url = "./plugin/build/repository")
gradlePluginPortal()
}
}

0 comments on commit 6982e8b

Please sign in to comment.