Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of the String.capitalized() extension for Pre Gradle 7.4. Fixes #40 #41

Merged
merged 3 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
package com.dropbox.gradle.plugins.dependencyguard.internal

import org.gradle.configurationcache.extensions.capitalized

internal object DependencyTreeDiffTaskNames {

/**
* This extension [org.gradle.configurationcache.extensions.capitalized]
* is not available until 7.4.x, so this is a backport.
*
* Fixes: https://github.com/dropbox/dependency-guard/issues/40
*/
fun String.capitalized(): String {
return if (this.isEmpty()) {
""
} else {
val firstChar = get(0)
if (firstChar.isUpperCase()) {
return this
} else {
firstChar.toUpperCase() + substring(1)
}
}
}

fun createDependencyTreeTaskNameForConfiguration(configurationName: String): String {
return "dependencyTreeDiff${configurationName.capitalized()}"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.dropbox.gradle.plugins.dependencyguard.internal

import com.dropbox.gradle.plugins.dependencyguard.internal.DependencyTreeDiffTaskNames.capitalized
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class TaskNamesTest {
@Test
fun `new library is added`() {
listOf(
"" to "",
"a" to "A",
"A" to "A",
"aa" to "Aa",
"aaa" to "Aaa",
"aA" to "AA",
"Aa" to "Aa",
).forEach {
assertEquals(it.first.capitalized(), it.second)
}
}
}