From 895e9c58bed8d9ab7cf0b1858b4800c98ed32443 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 30 Jan 2025 18:07:30 +0000 Subject: [PATCH 1/2] Update dependency com.pinterest.ktlint:ktlint-cli to v1.5.0 --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d961dab1..6c78ddd9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -16,7 +16,7 @@ maven-modelBuilder = "org.apache.maven:maven-model-builder:3.9.9" androidx-gradlePluginLints = "androidx.lint:lint-gradle:1.0.0-alpha03" # Dummy to get renovate updates, the version is used in rootProject build.gradle with spotless. -ktlint = "com.pinterest.ktlint:ktlint-cli:1.3.1" +ktlint = "com.pinterest.ktlint:ktlint-cli:1.5.0" kotlinpoet = "com.squareup:kotlinpoet:2.0.0" From b0e3735a5654d964e6611f60bdcae10e74231628 Mon Sep 17 00:00:00 2001 From: Jake Wharton Date: Mon, 10 Mar 2025 17:15:29 -0400 Subject: [PATCH 2/2] Format --- .editorconfig | 1 + build.gradle | 1 + .../app/cash/licensee/SpdxLicenseJson.kt | 4 +- .../kotlin/app/cash/licensee/SpdxLicenses.kt | 16 ++-- .../licensee/SpdxLicensesGeneratorTest.kt | 73 ++++++++++++++++--- .../app/cash/licensee/dependencyGraph.kt | 31 ++++---- .../app/cash/licensee/licenseValidation.kt | 8 +- .../kotlin/app/cash/licensee/outputModel.kt | 15 +--- src/main/kotlin/app/cash/licensee/plugin.kt | 47 ++++++------ .../app/cash/licensee/pluginExtension.kt | 37 ++++++---- src/main/kotlin/app/cash/licensee/task.kt | 58 +++++++++------ .../licensee/LicenseePluginFixtureTest.kt | 19 +++-- .../app/cash/licensee/SpdxLicensesTest.kt | 18 ++++- 13 files changed, 212 insertions(+), 116 deletions(-) diff --git a/.editorconfig b/.editorconfig index 16a2af5c..a73e54d2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,6 +6,7 @@ end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true +max_line_length=100 [*.{kt,kts}] ij_kotlin_allow_trailing_comma = true diff --git a/build.gradle b/build.gradle index 20911558..a10eef4d 100644 --- a/build.gradle +++ b/build.gradle @@ -155,6 +155,7 @@ spotless { targetExclude("**/src/test/test-build-logic/build/**", "**/generated-sources/**") ktlint(libs.ktlint.get().version).editorConfigOverride([ 'ktlint_standard_filename': 'disabled', + 'ktlint_standard_max-lint-length': 'enabled', // Making something an expression body should be a choice around readability. 'ktlint_standard_function-expression-body': 'disabled', ]) diff --git a/gradle/build-logic/src/main/kotlin/app/cash/licensee/SpdxLicenseJson.kt b/gradle/build-logic/src/main/kotlin/app/cash/licensee/SpdxLicenseJson.kt index 1eda05b9..f520e2c3 100644 --- a/gradle/build-logic/src/main/kotlin/app/cash/licensee/SpdxLicenseJson.kt +++ b/gradle/build-logic/src/main/kotlin/app/cash/licensee/SpdxLicenseJson.kt @@ -19,9 +19,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -internal data class SpdxLicensesJson( - val licenses: List, -) +internal data class SpdxLicensesJson(val licenses: List) @Serializable internal data class SpdxLicenseJson( diff --git a/gradle/build-logic/src/main/kotlin/app/cash/licensee/SpdxLicenses.kt b/gradle/build-logic/src/main/kotlin/app/cash/licensee/SpdxLicenses.kt index c4a20274..3aa77f39 100644 --- a/gradle/build-logic/src/main/kotlin/app/cash/licensee/SpdxLicenses.kt +++ b/gradle/build-logic/src/main/kotlin/app/cash/licensee/SpdxLicenses.kt @@ -115,6 +115,7 @@ internal class FallbackBuilder( } } +@Suppress("ktlint:standard:max-line-length") internal fun Map>.simplify(): List, List>> = entries.groupBy({ it.value }, { it.key }).toList().map { it.second.sorted() to it.first @@ -122,11 +123,12 @@ internal fun Map>.simplify(): List - if (firstUrl.startsWith("http://")) { - // Assume an 'https' variant is reachable. - "https" + firstUrl.substring(4) - } else { - firstUrl +internal val SpdxLicenseJson.targetUrl + get() = (otherUrls.firstOrNull() ?: spdxUrl).let { firstUrl -> + if (firstUrl.startsWith("http://")) { + // Assume an 'https' variant is reachable. + "https" + firstUrl.substring(4) + } else { + firstUrl + } } -} diff --git a/gradle/build-logic/src/test/kotlin/app/cash/licensee/SpdxLicensesGeneratorTest.kt b/gradle/build-logic/src/test/kotlin/app/cash/licensee/SpdxLicensesGeneratorTest.kt index f1051d2a..3b0882f8 100644 --- a/gradle/build-logic/src/test/kotlin/app/cash/licensee/SpdxLicensesGeneratorTest.kt +++ b/gradle/build-logic/src/test/kotlin/app/cash/licensee/SpdxLicensesGeneratorTest.kt @@ -58,18 +58,33 @@ class SpdxLicensesGeneratorTest { assertThat( spdxLicenses.findByUrl("http://example.com/foo"), ).isNotNull().containsExactly( - SpdxLicenseJson("FOO-1.0", "Foo License", "https://spdx.org/licenses/FOO-1.0.html", listOf("http://example.com/foo")), + SpdxLicenseJson( + "FOO-1.0", + "Foo License", + "https://spdx.org/licenses/FOO-1.0.html", + listOf("http://example.com/foo"), + ), ) assertThat( spdxLicenses.findByUrl("https://example.com/foo"), ).isNotNull().containsExactly( - SpdxLicenseJson("FOO-1.0", "Foo License", "https://spdx.org/licenses/FOO-1.0.html", listOf("http://example.com/foo")), + SpdxLicenseJson( + "FOO-1.0", + "Foo License", + "https://spdx.org/licenses/FOO-1.0.html", + listOf("http://example.com/foo"), + ), ) assertThat(spdxLicenses.findByUrl("http://example.com/bar")).isNull() assertThat( spdxLicenses.findByUrl("https://example.com/bar"), ).isNotNull().containsExactly( - SpdxLicenseJson("BAR-1.0", "Bar License", "https://spdx.org/licenses/BAR-1.0.html", listOf("https://example.com/bar")), + SpdxLicenseJson( + "BAR-1.0", + "Bar License", + "https://spdx.org/licenses/BAR-1.0.html", + listOf("https://example.com/bar"), + ), ) } @@ -96,12 +111,22 @@ class SpdxLicensesGeneratorTest { assertThat( spdxLicenses.findByUrl("http://example.com/foo"), ).isNotNull().containsExactly( - SpdxLicenseJson("FOO-1.0", "Foo License", "https://spdx.org/licenses/FOO-1.0.html", listOf("http://example.com/foo")), + SpdxLicenseJson( + "FOO-1.0", + "Foo License", + "https://spdx.org/licenses/FOO-1.0.html", + listOf("http://example.com/foo"), + ), ) assertThat( spdxLicenses.findByUrl("https://spdx.org/licenses/FOO-1.0.html"), ).isNotNull().containsExactly( - SpdxLicenseJson("FOO-1.0", "Foo License", "https://spdx.org/licenses/FOO-1.0.html", listOf("http://example.com/foo")), + SpdxLicenseJson( + "FOO-1.0", + "Foo License", + "https://spdx.org/licenses/FOO-1.0.html", + listOf("http://example.com/foo"), + ), ) } @@ -136,12 +161,22 @@ class SpdxLicensesGeneratorTest { assertThat( spdxLicenses.findByIdentifier("FOO-1.0"), ).isEqualTo( - SpdxLicenseJson("FOO-1.0", "Foo License", "https://spdx.org/licenses/FOO-1.0.html", emptyList()), + SpdxLicenseJson( + "FOO-1.0", + "Foo License", + "https://spdx.org/licenses/FOO-1.0.html", + emptyList(), + ), ) assertThat( spdxLicenses.findByIdentifier("BAR-1.0"), ).isEqualTo( - SpdxLicenseJson("BAR-1.0", "Bar License", "https://spdx.org/licenses/BAR-1.0.html", emptyList()), + SpdxLicenseJson( + "BAR-1.0", + "Bar License", + "https://spdx.org/licenses/BAR-1.0.html", + emptyList(), + ), ) } @@ -175,9 +210,27 @@ class SpdxLicensesGeneratorTest { add("https://example.com/bar") } } - val foo = SpdxLicenseJson("FOO-1.0", "Foo License", "https://spdx.org/licenses/FOO-1.0.html", emptyList()) - val bar1 = SpdxLicenseJson("BAR-1.0", "Bar License", "https://spdx.org/licenses/BAR-1.0.html", emptyList()) - val bar2 = SpdxLicenseJson("BAR-2.0", "Bar 2 License", "https://spdx.org/licenses/BAR-2.0.html", emptyList()) + val foo = + SpdxLicenseJson( + "FOO-1.0", + "Foo License", + "https://spdx.org/licenses/FOO-1.0.html", + emptyList(), + ) + val bar1 = + SpdxLicenseJson( + "BAR-1.0", + "Bar License", + "https://spdx.org/licenses/BAR-1.0.html", + emptyList(), + ) + val bar2 = + SpdxLicenseJson( + "BAR-2.0", + "Bar 2 License", + "https://spdx.org/licenses/BAR-2.0.html", + emptyList(), + ) assertThat( spdxLicenses.findByUrl("https://spdx.org/licenses/FOO-1.0.html"), ).isNotNull().containsExactly( diff --git a/src/main/kotlin/app/cash/licensee/dependencyGraph.kt b/src/main/kotlin/app/cash/licensee/dependencyGraph.kt index 52adeb9f..a1195248 100644 --- a/src/main/kotlin/app/cash/licensee/dependencyGraph.kt +++ b/src/main/kotlin/app/cash/licensee/dependencyGraph.kt @@ -34,10 +34,7 @@ internal data class DependencyConfig( val ignoredCoordinates: Map>, ) : Serializable -internal data class IgnoredData( - val reason: String?, - val transitive: Boolean, -) : Serializable +internal data class IgnoredData(val reason: String?, val transitive: Boolean) : Serializable internal fun loadDependencyCoordinates( logger: Logger, @@ -60,7 +57,16 @@ internal fun loadDependencyCoordinates( } val coordinates = mutableSetOf() - loadDependencyCoordinates(logger, root, config, unusedGroupIds, unusedCoordinates, coordinates, mutableSetOf(), depth = 1) + loadDependencyCoordinates( + logger, + root, + config, + unusedGroupIds, + unusedCoordinates, + coordinates, + mutableSetOf(), + depth = 1, + ) for (unusedGroupId in unusedGroupIds) { warnings += "Dependency ignore for $unusedGroupId is unused" @@ -77,7 +83,8 @@ internal data class DependencyResolutionResult( val configWarnings: List, ) -internal fun ModuleComponentIdentifier.toDependencyCoordinates() = DependencyCoordinates(group, module, version) +internal fun ModuleComponentIdentifier.toDependencyCoordinates() = + DependencyCoordinates(group, module, version) private fun loadDependencyCoordinates( logger: Logger, @@ -181,10 +188,7 @@ private fun ResolvedComponentResult.isPlatform(): Boolean { } } -internal fun loadPomInfo( - pom: Model, - getRawModel: (String) -> Model?, -): PomInfo { +internal fun loadPomInfo(pom: Model, getRawModel: (String) -> Model?): PomInfo { val parentRawModel = pom.parent?.let { getRawModel("${it.groupId}:${it.artifactId}:${it.version}") } @@ -208,11 +212,12 @@ internal fun loadPomInfo( pomScm?.url } + val rawLicenses = pom.licenses.takeUnless { it.isEmpty() } + ?: parentRawModel?.licenses + ?: emptyList() return PomInfo( name = pom.name ?: parentRawModel?.name, - licenses = (pom.licenses.takeUnless { it.isEmpty() } ?: parentRawModel?.licenses)?.mapTo(mutableSetOf()) { - PomLicense(it.name, it.url) - } ?: emptySet(), + licenses = rawLicenses.mapTo(mutableSetOf()) { PomLicense(it.name, it.url) }, scm = PomScm(url), ) } diff --git a/src/main/kotlin/app/cash/licensee/licenseValidation.kt b/src/main/kotlin/app/cash/licensee/licenseValidation.kt index a1d09e7a..52b288df 100644 --- a/src/main/kotlin/app/cash/licensee/licenseValidation.kt +++ b/src/main/kotlin/app/cash/licensee/licenseValidation.kt @@ -142,13 +142,17 @@ internal fun validateArtifacts( } for (unusedAllowedIdentifier in unusedAllowedIdentifiers) { - configResults += ValidationResult.Warning("Allowed SPDX identifier '$unusedAllowedIdentifier' is unused") + configResults += + ValidationResult.Warning("Allowed SPDX identifier '$unusedAllowedIdentifier' is unused") } for (unusedAllowedUrl in unusedAllowedUrls.keys) { configResults += ValidationResult.Warning("Allowed license URL '$unusedAllowedUrl' is unused") } for (unusedAllowedCoordinate in unusedAllowedCoordinates) { - configResults += ValidationResult.Warning("Allowed dependency '${unusedAllowedCoordinate.group}:${unusedAllowedCoordinate.artifact}:${unusedAllowedCoordinate.version}' is unused") + configResults += + ValidationResult.Warning( + "Allowed dependency '${unusedAllowedCoordinate.group}:${unusedAllowedCoordinate.artifact}:${unusedAllowedCoordinate.version}' is unused", + ) } return ValidationResults(configResults, artifactResultMap) diff --git a/src/main/kotlin/app/cash/licensee/outputModel.kt b/src/main/kotlin/app/cash/licensee/outputModel.kt index ea17b8af..58504428 100644 --- a/src/main/kotlin/app/cash/licensee/outputModel.kt +++ b/src/main/kotlin/app/cash/licensee/outputModel.kt @@ -30,19 +30,10 @@ data class ArtifactDetail( ) @Serializable -data class SpdxLicense( - val identifier: String, - val name: String, - val url: String, -) +data class SpdxLicense(val identifier: String, val name: String, val url: String) @Serializable -data class UnknownLicense( - val name: String?, - val url: String?, -) +data class UnknownLicense(val name: String?, val url: String?) @Serializable -data class ArtifactScm( - val url: String, -) +data class ArtifactScm(val url: String) diff --git a/src/main/kotlin/app/cash/licensee/plugin.kt b/src/main/kotlin/app/cash/licensee/plugin.kt index f572afae..54a8242e 100644 --- a/src/main/kotlin/app/cash/licensee/plugin.kt +++ b/src/main/kotlin/app/cash/licensee/plugin.kt @@ -99,18 +99,13 @@ class LicenseePlugin : Plugin { } } -private fun configureAndroidPlugin( - project: Project, -) { +private fun configureAndroidPlugin(project: Project) { val rootTask = registerRootTask(project, "all Android variants") configureAndroidVariants(project, rootTask) withKotlinMultiPlatformPlugin(project, withAndroid = true) } -private fun withKotlinMultiPlatformPlugin( - project: Project, - withAndroid: Boolean, -) { +private fun withKotlinMultiPlatformPlugin(project: Project, withAndroid: Boolean) { project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { val rootTask = registerRootTask(project, "all Kotlin targets") configureKotlinMultiplatformTargets(project, rootTask) @@ -120,10 +115,7 @@ private fun withKotlinMultiPlatformPlugin( } } -private fun registerRootTask( - project: Project, - target: String, -): TaskProvider { +private fun registerRootTask(project: Project, target: String): TaskProvider { val rootTask = if (BASE_TASK_NAME in project.tasks.names) { project.tasks.named(BASE_TASK_NAME) } else { @@ -140,10 +132,7 @@ private fun registerRootTask( return rootTask } -private fun configureAndroidVariants( - project: Project, - rootTask: TaskProvider, -) { +private fun configureAndroidVariants(project: Project, rootTask: TaskProvider) { val androidComponents = project.extensions.getByType(AndroidComponentsExtension::class.java) androidComponents.onVariants { variant -> val suffix = variant.name.replaceFirstChar { it.titlecase(ROOT) } @@ -155,7 +144,9 @@ private fun configureAndroidVariants( it.configurationToCheck(variant.runtimeConfiguration) - val reportBase = project.extensions.getByType(ReportingExtension::class.java).baseDirectory.dir(REPORT_FOLDER) + val reportBase = project.extensions.getByType( + ReportingExtension::class.java, + ).baseDirectory.dir(REPORT_FOLDER) it.outputDir.set(reportBase.map { it.dir("android$suffix") }) } @@ -165,10 +156,7 @@ private fun configureAndroidVariants( } } -private fun configureKotlinMultiplatformTargets( - project: Project, - rootTask: TaskProvider, -) { +private fun configureKotlinMultiplatformTargets(project: Project, rootTask: TaskProvider) { val kotlin = project.extensions.getByType(KotlinMultiplatformExtension::class.java) val targets = kotlin.targets targets.configureEach { target -> @@ -186,12 +174,16 @@ private fun configureKotlinMultiplatformTargets( val compilation = target.compilations.getByName(KotlinCompilation.MAIN_COMPILATION_NAME) // Fallback to compile dependencies when runtime isn't supported, e.g. Kotlin/Native. - val runtimeConfigurationName = compilation.runtimeDependencyConfigurationName ?: compilation.compileDependencyConfigurationName + val runtimeConfigurationName = + compilation.runtimeDependencyConfigurationName + ?: compilation.compileDependencyConfigurationName val runtimeConfiguration = project.configurations.named(runtimeConfigurationName) it.configurationToCheck(runtimeConfiguration) - val reportBase = project.extensions.getByType(ReportingExtension::class.java).baseDirectory.dir(REPORT_FOLDER) + val reportBase = project.extensions.getByType( + ReportingExtension::class.java, + ).baseDirectory.dir(REPORT_FOLDER) it.outputDir.set(reportBase.map { it.dir(target.name) }) } @@ -201,9 +193,7 @@ private fun configureKotlinMultiplatformTargets( } } -private fun configureJavaPlugin( - project: Project, -) { +private fun configureJavaPlugin(project: Project) { val task = project.tasks.configure(BASE_TASK_NAME) { it.group = VERIFICATION_GROUP it.description = taskDescription() @@ -216,7 +206,12 @@ private fun configureJavaPlugin( } } -private fun TaskContainer.configure(name: String, config: (LicenseeTask) -> Unit): TaskProvider = if (name in names) { +private fun TaskContainer.configure( + name: String, + config: (LicenseeTask) -> Unit, +): TaskProvider = if (name in + names +) { named(name, LicenseeTask::class.java, config) } else { register(name, LicenseeTask::class.java, config) diff --git a/src/main/kotlin/app/cash/licensee/pluginExtension.kt b/src/main/kotlin/app/cash/licensee/pluginExtension.kt index d46e968b..15752b68 100644 --- a/src/main/kotlin/app/cash/licensee/pluginExtension.kt +++ b/src/main/kotlin/app/cash/licensee/pluginExtension.kt @@ -95,19 +95,13 @@ interface LicenseeExtension { /** @suppress */ @JvmSynthetic // For Groovy build scripts, hide from normal callers. - fun allowDependency( - groupId: String, - artifactId: String, - version: String, - ) { + fun allowDependency(groupId: String, artifactId: String, version: String) { allowDependency(groupId, artifactId, version, {}) } /** @suppress */ @JvmSynthetic // For Groovy build scripts, hide from normal callers. - fun allowDependency( - dependencyProvider: Provider, - ) { + fun allowDependency(dependencyProvider: Provider) { allowDependency(dependencyProvider, {}) } @@ -273,7 +267,11 @@ internal abstract class MutableLicenseeExtension : LicenseeExtension { } fun toLicenseValidationConfig(): Provider { - return allowedIdentifiers.zip(allowedUrls, allowedDependencies) { allowedIdentifiers, allowedUrls, allowedDependencies -> + return allowedIdentifiers.zip(allowedUrls, allowedDependencies) { + allowedIdentifiers, + allowedUrls, + allowedDependencies, + -> ValidationConfig( allowedIdentifiers, allowedUrls.mapValues { @@ -312,7 +310,10 @@ internal abstract class MutableLicenseeExtension : LicenseeExtension { ) { val optionsImpl = AllowDependencyOptionsImpl() options.execute(optionsImpl) - allowedDependencies.put(DependencyCoordinates(group = groupId, artifact = artifactId, version = version), Optional.ofNullable(optionsImpl.setReason)) + allowedDependencies.put( + DependencyCoordinates(group = groupId, artifact = artifactId, version = version), + Optional.ofNullable(optionsImpl.setReason), + ) } private class AllowDependencyOptionsImpl : AllowDependencyOptions { @@ -335,14 +336,20 @@ internal abstract class MutableLicenseeExtension : LicenseeExtension { DependencyCoordinates( group = requireNotNull(it.group) { "group was null in allowDependency for ${it.name}" }, artifact = it.name, - version = requireNotNull(it.version) { "version was null in allowDependency for ${it.name}" }, + version = requireNotNull(it.version) { + "version was null in allowDependency for ${it.name}" + }, ) to Optional.ofNullable(optionsImpl.setReason), ) }, ) } - override fun ignoreDependencies(groupId: String, artifactId: String?, options: Action) { + override fun ignoreDependencies( + groupId: String, + artifactId: String?, + options: Action, + ) { val option = object : IgnoreDependencyOptions { var setReason: String? = null override fun because(reason: String) { @@ -385,7 +392,11 @@ internal abstract class MutableLicenseeExtension : LicenseeExtension { } } -private fun Provider.zip(left: Provider, right: Provider, merge: (T, L, R) -> V): Provider { +private fun Provider.zip( + left: Provider, + right: Provider, + merge: (T, L, R) -> V, +): Provider { return zip(left) { t, l -> t to l }.zip(right) { (t, l), r -> diff --git a/src/main/kotlin/app/cash/licensee/task.kt b/src/main/kotlin/app/cash/licensee/task.kt index c4e07208..9723c3ea 100644 --- a/src/main/kotlin/app/cash/licensee/task.kt +++ b/src/main/kotlin/app/cash/licensee/task.kt @@ -76,13 +76,20 @@ abstract class LicenseeTask : DefaultTask() { } fun configurationToCheck(configuration: Provider) { - loadDependenciesFromConfiguration(configuration.flatMap { it.incoming.resolutionResult.rootComponent }) + loadDependenciesFromConfiguration( + configuration.flatMap { + it.incoming.resolutionResult.rootComponent + }, + ) } private fun loadDependenciesFromConfiguration(root: Provider) { val dependencies = project.dependencies val configurations = project.configurations - val pomInfos: Provider> = root.zip(dependencyConfig) { root, depConfig -> + val pomInfos: Provider> = root.zip(dependencyConfig) { + root, + depConfig, + -> val directDependencies = loadDependencyCoordinates( logger, root, @@ -120,14 +127,18 @@ abstract class LicenseeTask : DefaultTask() { return FileModelSource(pomFile) } - override fun resolveModel(groupId: String, artifactId: String, version: String): ModelSource2 = - resolve(DependencyCoordinates(groupId, artifactId, version)) + override fun resolveModel( + groupId: String, + artifactId: String, + version: String, + ): ModelSource2 = resolve(DependencyCoordinates(groupId, artifactId, version)) override fun resolveModel(parent: Parent): ModelSource2 = resolve(DependencyCoordinates(parent.groupId, parent.artifactId, parent.version)) - override fun resolveModel(dependency: Dependency): ModelSource2 = - resolve(DependencyCoordinates(dependency.groupId, dependency.artifactId, dependency.version)) + override fun resolveModel(dependency: Dependency): ModelSource2 = resolve( + DependencyCoordinates(dependency.groupId, dependency.artifactId, dependency.version), + ) override fun addRepository(repository: Repository) { } override fun addRepository(repository: Repository, replace: Boolean) { } @@ -174,12 +185,16 @@ abstract class LicenseeTask : DefaultTask() { return (withVariants + withoutVariants).map { // Cast is safe because all resolved artifacts are pom files. - val coordinates = (it.id.componentIdentifier as ModuleComponentIdentifier).toDependencyCoordinates() + val coordinates = (it.id.componentIdentifier as ModuleComponentIdentifier) + .toDependencyCoordinates() DependencyCoordinatesWithPomFile(coordinates, it.file) }.distinctBy { it.dependencyCoordinates } } - private fun Configuration.artifacts() = resolvedConfiguration.lenientConfiguration.allModuleDependencies.flatMap { it.allModuleArtifacts } + private fun Configuration.artifacts() = resolvedConfiguration + .lenientConfiguration + .allModuleDependencies + .flatMap { it.allModuleArtifacts } @get:OutputDirectory abstract val outputDir: DirectoryProperty @@ -286,7 +301,12 @@ abstract class LicenseeTask : DefaultTask() { val lifecycleLevel = if (violationAction == ViolationAction.IGNORE) INFO else LIFECYCLE - fun logResult(configResult: ValidationResult, error: LogLevel, warning: LogLevel, prefix: String = "") { + fun logResult( + configResult: ValidationResult, + error: LogLevel, + warning: LogLevel, + prefix: String = "", + ) { when (configResult) { is ValidationResult.Error -> { val message = prefix + "ERROR: " + configResult.message @@ -310,7 +330,9 @@ abstract class LicenseeTask : DefaultTask() { for (configResult in validationResult.configResults) { logResult(configResult, unusedErrorLevel, unusedWarningLevel) } - if (validationResult.configResults.isNotEmpty() && validationResult.artifactResults.isNotEmpty()) { + if (validationResult.configResults.isNotEmpty() && + validationResult.artifactResults.isNotEmpty() + ) { validationReport.appendLine() // We know these are always at warning or error level, so use lifecycle for space. if (unusedWarningLevel > INFO || unusedErrorLevel > INFO || logger.isInfoEnabled) { @@ -352,20 +374,12 @@ private data class DependencyCoordinatesWithPomFile( val pomFile: File, ) -internal data class PomInfo( - val name: String?, - val licenses: Set, - val scm: PomScm?, -) : Serializable +internal data class PomInfo(val name: String?, val licenses: Set, val scm: PomScm?) : + Serializable -internal data class PomLicense( - val name: String?, - val url: String?, -) : Serializable +internal data class PomLicense(val name: String?, val url: String?) : Serializable -internal data class PomScm( - val url: String?, -) : Serializable +internal data class PomScm(val url: String?) : Serializable private val outputFormat = Json { prettyPrint = true } private val listOfArtifactDetail = ListSerializer(ArtifactDetail.serializer()) diff --git a/src/test/kotlin/app/cash/licensee/LicenseePluginFixtureTest.kt b/src/test/kotlin/app/cash/licensee/LicenseePluginFixtureTest.kt index abdca42e..7bf302d7 100644 --- a/src/test/kotlin/app/cash/licensee/LicenseePluginFixtureTest.kt +++ b/src/test/kotlin/app/cash/licensee/LicenseePluginFixtureTest.kt @@ -201,13 +201,14 @@ class LicenseePluginFixtureTest { val fixtureDir = File(fixturesDir, fixtureName) val result = createRunner(fixtureDir).buildAndFail() assertThat(result.output).containsMatch( - "Transitive dependency ignore on 'com\\.example(:example)?' is dangerous and requires a reason string".toRegex(), + Regex( + "Transitive dependency ignore on 'com\\.example(:example)?' " + + "is dangerous and requires a reason string", + ), ) } - @Test fun invalidSpdxFails( - @TestParameter("allow-with-invalid-spdx") fixtureName: String, - ) { + @Test fun invalidSpdxFails(@TestParameter("allow-with-invalid-spdx") fixtureName: String) { val fixtureDir = File(fixturesDir, fixtureName) val result = createRunner(fixtureDir).buildAndFail() assertThat(result.output).contains( @@ -343,7 +344,15 @@ class LicenseePluginFixtureTest { return GradleRunner.create() .withProjectDir(fixtureDir) .withDebug(true) // Run in-process - .withArguments("clean", "assemble", "licensee", "--stacktrace", "--continue", "--configuration-cache", versionProperty) + .withArguments( + "clean", + "assemble", + "licensee", + "--stacktrace", + "--continue", + "--configuration-cache", + versionProperty, + ) .forwardOutput() } diff --git a/src/test/kotlin/app/cash/licensee/SpdxLicensesTest.kt b/src/test/kotlin/app/cash/licensee/SpdxLicensesTest.kt index 032c48d2..2dc8c021 100644 --- a/src/test/kotlin/app/cash/licensee/SpdxLicensesTest.kt +++ b/src/test/kotlin/app/cash/licensee/SpdxLicensesTest.kt @@ -35,13 +35,25 @@ class SpdxLicensesTest { assertThat( SpdxId.findByUrl("https://api.github.com/licenses/bsd-2-clause").map { it.toSpdxLicense() }, ).containsExactly( - SpdxLicense("BSD-2-Clause", "BSD 2-Clause \"Simplified\" License", "https://opensource.org/licenses/BSD-2-Clause"), + SpdxLicense( + "BSD-2-Clause", + "BSD 2-Clause \"Simplified\" License", + "https://opensource.org/licenses/BSD-2-Clause", + ), ) assertThat( SpdxId.findByUrl("https://api.github.com/licenses/gpl-2.0").map { it.toSpdxLicense() }, ).containsExactly( - SpdxLicense("GPL-2.0", "GNU General Public License v2.0 only", "https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html"), - SpdxLicense("GPL-2.0-or-later", "GNU General Public License v2.0 or later", "https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html"), + SpdxLicense( + "GPL-2.0", + "GNU General Public License v2.0 only", + "https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html", + ), + SpdxLicense( + "GPL-2.0-or-later", + "GNU General Public License v2.0 or later", + "https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html", + ), ) }