From 17fa5c919b85b094e62b9b0a7a178f5fb27d1ff4 Mon Sep 17 00:00:00 2001 From: Martin Chalupa Date: Tue, 2 Nov 2021 14:02:41 -0700 Subject: [PATCH] Improve descriptions with all the reasons participating in dependency selection, messages for conflict resolution are latered to reduce length if too many versions participate --- .../diff/PathAwareDiffReportGenerator.kt | 37 ++++++------------- .../PathAwareDependencyDiffSpec.groovy | 28 +++++++------- 2 files changed, 25 insertions(+), 40 deletions(-) diff --git a/src/main/kotlin/nebula/plugin/dependencylock/diff/PathAwareDiffReportGenerator.kt b/src/main/kotlin/nebula/plugin/dependencylock/diff/PathAwareDiffReportGenerator.kt index c55dfa2..18f191e 100644 --- a/src/main/kotlin/nebula/plugin/dependencylock/diff/PathAwareDiffReportGenerator.kt +++ b/src/main/kotlin/nebula/plugin/dependencylock/diff/PathAwareDiffReportGenerator.kt @@ -174,34 +174,19 @@ class PathAwareDiffReportGenerator : DiffReportGenerator { fun changeDescription(): String { - return if (selected.selectionReason.isSelectedByRule) { - findDescriptionForCause(ComponentSelectionCause.SELECTED_BY_RULE) - } else if (selected.selectionReason.isExpected) { - if (isSubmodule()) { - "new local submodule" - } else { - findDescriptionForCause(ComponentSelectionCause.REQUESTED) - } - } else if (selected.selectionReason.isForced) { - val forcedDescription = findDescriptionForCause(ComponentSelectionCause.FORCED) - //if it is force and also constrained we add message for constraint, it would be typically alignment - forcedDescription + if (selected.selectionReason.isConstrained) { - ", ${findDescriptionForCause(ComponentSelectionCause.CONSTRAINT)}" - } else { - "" - } - } else if (selected.selectionReason.isConstrained) { - findDescriptionForCause(ComponentSelectionCause.CONSTRAINT) - } else if (isWinnerOfConflictResolution()) { - findDescriptionForCause(ComponentSelectionCause.REQUESTED) - } else { - "" + val causesWithDescription = selected.selectionReason.descriptions.associate { it.cause to it.description }.toSortedMap() + if (causesWithDescription.contains(ComponentSelectionCause.REQUESTED) && isSubmodule()) { + causesWithDescription[ComponentSelectionCause.REQUESTED] = "new local submodule" } - } + if (causesWithDescription.contains(ComponentSelectionCause.CONFLICT_RESOLUTION)) { + val message = if (isWinnerOfConflictResolution()) + "this path brought the winner of conflict resolution" + else + "this path participates in conflict resolution, but the winner is from a different path" + causesWithDescription[ComponentSelectionCause.CONFLICT_RESOLUTION] = message - private fun findDescriptionForCause(cause: ComponentSelectionCause): String { - val gradleDescription = selected.selectionReason.descriptions.find { it.cause == cause} - return gradleDescription!!.description + } + return causesWithDescription.values.joinToString("; ") } fun isSubmodule(): Boolean { diff --git a/src/test/groovy/nebula/plugin/dependencylock/PathAwareDependencyDiffSpec.groovy b/src/test/groovy/nebula/plugin/dependencylock/PathAwareDependencyDiffSpec.groovy index 4167fce..f2e750f 100644 --- a/src/test/groovy/nebula/plugin/dependencylock/PathAwareDependencyDiffSpec.groovy +++ b/src/test/groovy/nebula/plugin/dependencylock/PathAwareDependencyDiffSpec.groovy @@ -173,7 +173,7 @@ class PathAwareDependencyDiffSpec extends IntegrationTestKitSpec { def directDependencies = allConfigurations["differentPaths"] def directTransitive = directDependencies.find { it.dependency == "test.example:direct-dependency-updating-transitive"} directTransitive.version == "2.2.0" - directTransitive.change.description == "requested" + directTransitive.change.description == "requested; this path brought the winner of conflict resolution" directTransitive.change.type == "UPDATED" directTransitive.change.previousVersion == "2.0.0" def ruleUpdateConsumer = directDependencies.find { it.dependency == "test.example:updated-by-rule-dependency-consumer"} @@ -181,7 +181,7 @@ class PathAwareDependencyDiffSpec extends IntegrationTestKitSpec { ruleUpdateConsumer.change == null ruleUpdateConsumer.children[0].dependency == "test.example:updated-by-rule-dependency" ruleUpdateConsumer.children[0].version == "2.0.0" - ruleUpdateConsumer.children[0].change.description == "substitue test.example:updated-by-rule-dependency:1.0.0 with 2.0.0 because JIRA-1039" + ruleUpdateConsumer.children[0].change.description == "requested; substitue test.example:updated-by-rule-dependency:1.0.0 with 2.0.0 because JIRA-1039" ruleUpdateConsumer.children[0].change.type == "UPDATED" ruleUpdateConsumer.children[0].change.previousVersion == "1.0.0" def qux = directDependencies.find { it.dependency == "test.example:qux"} @@ -191,12 +191,12 @@ class PathAwareDependencyDiffSpec extends IntegrationTestKitSpec { qux.change.previousVersion == "1.0.0" def foo = qux.children.find { it.dependency == "test.example:foo" } foo.version == "2.0.1" - foo.change.description == "requested" + foo.change.description == "requested; this path brought the winner of conflict resolution" foo.change.type == "UPDATED" foo.change.previousVersion == "1.0.1" foo.children[0].dependency == "test.example:direct-dependency-updated-transitively" foo.children[0].version == "1.1.0" - foo.children[0].change.description == "requested" + foo.children[0].change.description == "requested; this path brought the winner of conflict resolution" foo.children[0].change.type == "UPDATED" foo.children[0].change.previousVersion == "1.0.0" def newDependency = qux.children.find { it.dependency == "test.example:new-dependency" } @@ -277,7 +277,7 @@ class PathAwareDependencyDiffSpec extends IntegrationTestKitSpec { def directDependencies = allConfigurations["differentPaths"] def qux = directDependencies.find { it.dependency == "test.example:qux"} qux.version == "2.0.0" - qux.change.description == "Recommending version 2.0.0 for dependency test.example:qux via conflict resolution recommendation\n\twith reasons: nebula.dependency-recommender uses mavenBom: test.nebula.bom:testbom:pom:1.0.0" + qux.change.description == "requested; Recommending version 2.0.0 for dependency test.example:qux via conflict resolution recommendation\n\twith reasons: nebula.dependency-recommender uses mavenBom: test.nebula.bom:testbom:pom:1.0.0" qux.change.type == "UPDATED" qux.change.previousVersion == "1.0.0" } @@ -358,22 +358,22 @@ class PathAwareDependencyDiffSpec extends IntegrationTestKitSpec { def directDependencies = allConfigurations["differentPaths"] def consumer1 = directDependencies.find { it.dependency == "test.example.alignment:consumer1-library"} consumer1.version == "1.0.0" - consumer1.change.description == "forced, belongs to platform aligned-platform:diff-lock-with-paths-with-forced-alignment-0-for-test.example.alignment:1.0.0" + consumer1.change.description == "requested; forced; belongs to platform aligned-platform:diff-lock-with-paths-with-forced-alignment-0-for-test.example.alignment:1.0.0" consumer1.change.type == "UPDATED" consumer1.change.previousVersion == "2.0.0" consumer1.children[0].dependency == "test.example.alignment:core-library" consumer1.children[0].version == "1.0.0" - consumer1.children[0].change.description == "forced, belongs to platform aligned-platform:diff-lock-with-paths-with-forced-alignment-0-for-test.example.alignment:1.0.0" + consumer1.children[0].change.description == "requested; forced; belongs to platform aligned-platform:diff-lock-with-paths-with-forced-alignment-0-for-test.example.alignment:1.0.0" consumer1.children[0].change.type == "UPDATED" consumer1.children[0].change.previousVersion == "2.0.0" def consumer2 = directDependencies.find { it.dependency == "test.example.alignment:consumer2-library"} consumer2.version == "1.0.0" - consumer2.change.description == "forced, belongs to platform aligned-platform:diff-lock-with-paths-with-forced-alignment-0-for-test.example.alignment:1.0.0" + consumer2.change.description == "requested; forced; belongs to platform aligned-platform:diff-lock-with-paths-with-forced-alignment-0-for-test.example.alignment:1.0.0" consumer2.change.type == "UPDATED" consumer2.change.previousVersion == "2.0.0" consumer2.children[0].dependency == "test.example.alignment:core2-library" consumer2.children[0].version == "1.0.0" - consumer2.children[0].change.description == "forced, belongs to platform aligned-platform:diff-lock-with-paths-with-forced-alignment-0-for-test.example.alignment:1.0.0" + consumer2.children[0].change.description == "requested; forced; belongs to platform aligned-platform:diff-lock-with-paths-with-forced-alignment-0-for-test.example.alignment:1.0.0" consumer2.children[0].change.type == "UPDATED" consumer2.children[0].change.previousVersion == "2.0.0" } @@ -465,12 +465,12 @@ class PathAwareDependencyDiffSpec extends IntegrationTestKitSpec { alignedConsumer1.change.previousVersion == "1.0.0" def consumer1 = alignedConsumer1.children.find { it.dependency == "test.example.alignment:consumer1-library"} consumer1.version == "2.0.0" - consumer1.change.description == "belongs to platform aligned-platform:diff-lock-with-paths-with-alignment-without-clear-conflict-resolution-winner-0-for-test.example.alignment:2.0.0" + consumer1.change.description == "requested; this path participates in conflict resolution, but the winner is from a different path; belongs to platform aligned-platform:diff-lock-with-paths-with-alignment-without-clear-conflict-resolution-winner-0-for-test.example.alignment:2.0.0" consumer1.change.type == "UPDATED" consumer1.change.previousVersion == "1.0.0" consumer1.children[0].dependency == "test.example.alignment:core-library" consumer1.children[0].version == "2.0.0" - consumer1.children[0].change.description == "belongs to platform aligned-platform:diff-lock-with-paths-with-alignment-without-clear-conflict-resolution-winner-0-for-test.example.alignment:2.0.0" + consumer1.children[0].change.description == "requested; belongs to platform aligned-platform:diff-lock-with-paths-with-alignment-without-clear-conflict-resolution-winner-0-for-test.example.alignment:2.0.0" consumer1.children[0].change.type == "UPDATED" consumer1.children[0].change.previousVersion == "1.0.0" def alignedConsumer2 = directDependencies.find { it.dependency == "test.example:consumer-of-aligned-dependency2"} @@ -480,12 +480,12 @@ class PathAwareDependencyDiffSpec extends IntegrationTestKitSpec { alignedConsumer2.change.previousVersion == "1.0.0" def consumer2 = alignedConsumer2.children.find { it.dependency == "test.example.alignment:consumer2-library"} consumer2.version == "2.0.0" - consumer2.change.description == "belongs to platform aligned-platform:diff-lock-with-paths-with-alignment-without-clear-conflict-resolution-winner-0-for-test.example.alignment:2.0.0" + consumer2.change.description == "requested; belongs to platform aligned-platform:diff-lock-with-paths-with-alignment-without-clear-conflict-resolution-winner-0-for-test.example.alignment:2.0.0" consumer2.change.type == "UPDATED" consumer2.change.previousVersion == "1.0.0" consumer2.children[0].dependency == "test.example.alignment:core2-library" consumer2.children[0].version == "2.0.0" - consumer2.children[0].change.description == "belongs to platform aligned-platform:diff-lock-with-paths-with-alignment-without-clear-conflict-resolution-winner-0-for-test.example.alignment:2.0.0" + consumer2.children[0].change.description == "requested; belongs to platform aligned-platform:diff-lock-with-paths-with-alignment-without-clear-conflict-resolution-winner-0-for-test.example.alignment:2.0.0" consumer2.children[0].change.type == "UPDATED" consumer2.children[0].change.previousVersion == "1.0.0" } @@ -545,7 +545,7 @@ class PathAwareDependencyDiffSpec extends IntegrationTestKitSpec { consumer.children[0].version == "1.0.0" consumer.children[0].change.type == "UPDATED" consumer.children[0].change.previousVersion == "2.0.0" - consumer.children[0].change.description == "constraint" + consumer.children[0].change.description == "constraint; by ancestor" } def 'diff lock with paths with repeated dependencies'() {