com.autonomousapps.internal.utils.utils.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dependency-analysis-gradle-plugin Show documentation
Show all versions of dependency-analysis-gradle-plugin Show documentation
Analyzes dependency usage in Android and JVM projects
@file:Suppress("UnstableApiUsage")
package com.autonomousapps.internal.utils
import org.gradle.api.artifacts.result.DependencyResult
import org.gradle.api.artifacts.result.ResolvedDependencyResult
import org.gradle.api.file.RegularFile
import org.gradle.api.file.RegularFileProperty
import java.io.File
import java.util.*
/**
* Resolves the file from the property and deletes its constants, then returns the file.
*/
internal fun RegularFileProperty.getAndDelete(): File {
val file = get().asFile
file.delete()
return file
}
internal inline fun RegularFileProperty.fromJsonSet(): Set = get().fromJsonSet()
internal inline fun RegularFile.fromJsonSet(): Set = asFile.readText().fromJsonSet()
internal inline fun RegularFileProperty.fromJsonList(): List {
return get().asFile.readText().fromJsonList()
}
internal inline fun RegularFileProperty.fromJson(): T = get().fromJson()
internal inline fun RegularFile.fromJson(): T = asFile.readText().fromJson()
internal inline fun RegularFileProperty.fromNullableJsonSet(): Set? {
return orNull?.asFile?.readText()?.fromJsonSet()
}
internal fun RegularFileProperty.readLines(): List {
return get().asFile.readLines()
}
// Print dependency tree (like running the `dependencies` task).
@Suppress("unused")
internal fun printDependencyTree(dependencies: Set, level: Int = 0) {
dependencies.filterIsInstance().forEach { result ->
val resolvedComponentResult = result.selected
println("${" ".repeat(level)}- ${resolvedComponentResult.id}")
printDependencyTree(resolvedComponentResult.dependencies, level + 1)
}
}
// copied from StringsJVM.kt
fun String.capitalizeSafely(locale: Locale = Locale.ROOT): String {
if (isNotEmpty()) {
val firstChar = this[0]
if (firstChar.isLowerCase()) {
return buildString {
val titleChar = firstChar.toTitleCase()
if (titleChar != firstChar.toUpperCase()) {
append(titleChar)
} else {
append([email protected](0, 1).toUpperCase(locale))
}
append([email protected](1))
}
}
}
return this
}