From f192f4141a28222b5541c9e747f4a42e26b423d6 Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Wed, 8 Jun 2022 16:15:35 -0400 Subject: [PATCH 1/3] Fixes #40 --- .../internal/DependencyTreeDiffTaskNames.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/DependencyTreeDiffTaskNames.kt b/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/DependencyTreeDiffTaskNames.kt index b8ebd5e..a073adb 100644 --- a/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/DependencyTreeDiffTaskNames.kt +++ b/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/DependencyTreeDiffTaskNames.kt @@ -4,6 +4,25 @@ 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 + */ + private 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()}" } From 57536ace0d23cc3fd08c8eb448efe11044bd479f Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Wed, 8 Jun 2022 16:31:02 -0400 Subject: [PATCH 2/3] Added unit tests for the port of the capitalization extension function. --- .../internal/DependencyTreeDiffTaskNames.kt | 2 +- .../dependencyguard/internal/TaskNamesTest.kt | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 dependency-guard/src/test/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/TaskNamesTest.kt diff --git a/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/DependencyTreeDiffTaskNames.kt b/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/DependencyTreeDiffTaskNames.kt index a073adb..07c379b 100644 --- a/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/DependencyTreeDiffTaskNames.kt +++ b/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/DependencyTreeDiffTaskNames.kt @@ -10,7 +10,7 @@ internal object DependencyTreeDiffTaskNames { * * Fixes: https://github.com/dropbox/dependency-guard/issues/40 */ - private fun String.capitalized(): String { + fun String.capitalized(): String { return if (this.isEmpty()) { "" } else { diff --git a/dependency-guard/src/test/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/TaskNamesTest.kt b/dependency-guard/src/test/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/TaskNamesTest.kt new file mode 100644 index 0000000..4aaa8c6 --- /dev/null +++ b/dependency-guard/src/test/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/TaskNamesTest.kt @@ -0,0 +1,24 @@ +package com.dropbox.gradle.plugins.dependencyguard.internal + +import com.dropbox.gradle.plugins.dependencyguard.internal.DependencyTreeDiffTaskNames.capitalized +import org.gradle.configurationcache.extensions.capitalized +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertTrue +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) + } + } +} From a696eecb7a3235495b44d7138618255e51f5a8ff Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Wed, 8 Jun 2022 16:33:49 -0400 Subject: [PATCH 3/3] Import cleanup. --- .../dependencyguard/internal/DependencyTreeDiffTaskNames.kt | 2 -- .../gradle/plugins/dependencyguard/internal/TaskNamesTest.kt | 2 -- 2 files changed, 4 deletions(-) diff --git a/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/DependencyTreeDiffTaskNames.kt b/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/DependencyTreeDiffTaskNames.kt index 07c379b..b9429b4 100644 --- a/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/DependencyTreeDiffTaskNames.kt +++ b/dependency-guard/src/main/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/DependencyTreeDiffTaskNames.kt @@ -1,7 +1,5 @@ package com.dropbox.gradle.plugins.dependencyguard.internal -import org.gradle.configurationcache.extensions.capitalized - internal object DependencyTreeDiffTaskNames { /** diff --git a/dependency-guard/src/test/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/TaskNamesTest.kt b/dependency-guard/src/test/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/TaskNamesTest.kt index 4aaa8c6..d9ae9b9 100644 --- a/dependency-guard/src/test/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/TaskNamesTest.kt +++ b/dependency-guard/src/test/kotlin/com/dropbox/gradle/plugins/dependencyguard/internal/TaskNamesTest.kt @@ -1,9 +1,7 @@ package com.dropbox.gradle.plugins.dependencyguard.internal import com.dropbox.gradle.plugins.dependencyguard.internal.DependencyTreeDiffTaskNames.capitalized -import org.gradle.configurationcache.extensions.capitalized import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test class TaskNamesTest {