Skip to content

Commit

Permalink
Backport of the String.capitalized() extension for Pre Gradle 7.4. F…
Browse files Browse the repository at this point in the history
…ixes #40 (#41)

* Fixes #40

* Added unit tests for the port of the capitalization extension function.

* Import cleanup.
  • Loading branch information
handstandsam committed Jun 8, 2022
1 parent ba514c4 commit 1497fe4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
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)
}
}
}

0 comments on commit 1497fe4

Please sign in to comment.