Skip to content

Commit

Permalink
Multiple user properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Krystian Panek committed Nov 5, 2020
1 parent 36e85be commit b52d262
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/main/kotlin/com/neva/gradle/fork/ForkExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ open class ForkExtension(val project: Project, val props: PropsExtension) {
}
}

fun loadProperties(path: String) = loadProperties(project.file(path))
fun loadProperties(filePath: String) = loadProperties(project.file(filePath))

fun loadPropertiesFrom(dirPath: String) = project.fileTree(dirPath)
.matching { it.include("**/*.properties") }
.sorted()
.forEach { loadProperties(it) }

// Defining config and task at same time

Expand All @@ -92,9 +97,10 @@ open class ForkExtension(val project: Project, val props: PropsExtension) {
options()
}

fun useProperties(configName: String, filePath: String) = inPlaceConfig(configName).apply {
fun useProperties(configName: String, filePath: String, dirPath: String? = null) = inPlaceConfig(configName).apply {
copyTemplateFile(filePath)
loadProperties(filePath)
dirPath?.let { loadPropertiesFrom(dirPath) }

project.tasks.register(name, PropertiesTask::class.java, this)
project.tasks.register("require${name.capitalize()}", RequirePropertiesTask::class.java, this, filePath)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/neva/gradle/fork/ForkPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ open class ForkPlugin : Plugin<Project> {
// Predefine configurations
extension.apply {
useForking(Config.NAME_FORK)
useProperties(Config.NAME_PROPERTIES, "gradle.user.properties")
useProperties(Config.NAME_PROPERTIES, "gradle.user.properties", "gradle/user")
}
}
}
Expand Down

0 comments on commit b52d262

Please sign in to comment.