com.autonomousapps.kit.gradle.VersionCatalogFile.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-testkit-support Show documentation
Show all versions of gradle-testkit-support Show documentation
A DSL for building test fixtures with Gradle TestKit
package com.autonomousapps.kit.gradle
import org.intellij.lang.annotations.Language
/**
* Represents a
* [version catalog file](https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format).
*/
public class VersionCatalogFile(
@Language("toml") public var content: String,
) {
public companion object {
public const val DEFAULT_PATH: String = "gradle/libs.versions.toml"
}
override fun toString(): String = content
public class Builder {
public var versions: MutableList = mutableListOf()
public var libraries: MutableList = mutableListOf()
public var bundles: MutableList = mutableListOf()
public var plugins: MutableList = mutableListOf()
public fun build(): VersionCatalogFile {
val content = buildString {
var didWrite = maybeWriteBlock("versions", versions, false)
didWrite = maybeWriteBlock("libraries", libraries, didWrite)
didWrite = maybeWriteBlock("bundles", bundles, didWrite)
maybeWriteBlock("plugins", plugins, didWrite)
}
return VersionCatalogFile(content)
}
private fun StringBuilder.maybeWriteBlock(
name: String,
section: List,
prependLine: Boolean,
): Boolean {
if (section.isNotEmpty()) {
if (prependLine) appendLine()
appendLine("[$name]")
section.forEach { appendLine(it) }
return true
}
return false
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy