Skip to content

Commit

Permalink
fix #704 can't modify unresolved.dependencies (#708)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanlermitage authored Nov 12, 2022
1 parent a4d20b7 commit fd9f07b
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ package com.github.benmanes.gradle.versions.reporter.result
*/
data class DependenciesGroup<T : Dependency>(
val count: Int,
val dependencies: Set<T> = sortedSetOf(),
val dependencies: MutableSet<T> = mutableSetOf(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -176,38 +176,38 @@ class DependencyUpdatesReporter(
)
}

private fun buildCurrentGroup(): Set<Dependency> {
private fun buildCurrentGroup(): MutableSet<Dependency> {
return sortByGroupAndName(upToDateVersions)
.map { dep ->
updateKey(dep.key as HashMap)
buildDependency(dep.value, dep.key)
}.toSortedSet() as TreeSet<Dependency>
}.toSortedSet()
}

private fun buildOutdatedGroup(): Set<DependencyOutdated> {
private fun buildOutdatedGroup(): MutableSet<DependencyOutdated> {
return sortByGroupAndName(upgradeVersions)
.map { dep ->
updateKey(dep.key as HashMap)
buildOutdatedDependency(dep.value, dep.key)
}.toSortedSet() as TreeSet<DependencyOutdated>
}.toSortedSet()
}

private fun buildExceededGroup(): Set<DependencyLatest> {
private fun buildExceededGroup(): MutableSet<DependencyLatest> {
return sortByGroupAndName(downgradeVersions)
.map { dep ->
updateKey(dep.key as HashMap)
buildExceededDependency(dep.value, dep.key)
}.toSortedSet() as TreeSet<DependencyLatest>
}.toSortedSet()
}

private fun buildUndeclaredGroup(): Set<Dependency> {
private fun buildUndeclaredGroup(): MutableSet<Dependency> {
return undeclared
.map { coordinate ->
Dependency(coordinate.groupId, coordinate.artifactId)
}.toSortedSet() as TreeSet<Dependency>
}.toSortedSet()
}

private fun buildUnresolvedGroup(): Set<DependencyUnresolved> {
private fun buildUnresolvedGroup(): MutableSet<DependencyUnresolved> {
return unresolved
.sortedWith { a, b ->
compareKeys(keyOf(a.selector), keyOf(b.selector))
Expand Down Expand Up @@ -311,7 +311,7 @@ class DependencyUpdatesReporter(
)
}

private fun <T : Dependency> buildDependenciesGroup(dependencies: Set<T>): DependenciesGroup<T> {
private fun <T : Dependency> buildDependenciesGroup(dependencies: MutableSet<T>): DependenciesGroup<T> {
return DependenciesGroup<T>(dependencies.size, dependencies)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,4 +534,92 @@ Failed to determine the latest version for the following dependencies (use --inf
expected == actual
result.task(':dependencyUpdates').outcome == SUCCESS
}

def 'outputFormatter custom - modify unresolvable dependencies then outputs text output'() {
given:
buildFile = testProjectDir.newFile('build.gradle')
buildFile <<
"""
import com.github.benmanes.gradle.versions.reporter.PlainTextReporter
buildscript {
dependencies {
classpath files($classpathString)
}
}
apply plugin: 'java'
apply plugin: 'com.github.ben-manes.versions'
repositories {
maven {
url '${mavenRepoUrl}'
}
}
dependencies {
implementation('backport-util-concurrent:backport-util-concurrent:3.1') { because 'I said so' }
implementation('backport-util-concurrent:backport-util-concurrent-java12:3.1')
implementation('com.google.guava:guava:99.0-SNAPSHOT') { because 'I know the future' }
implementation('com.google.guava:guava-tests:99.0-SNAPSHOT')
implementation('com.google.inject:guice:2.0') { because 'That\\'s just the way it is' }
implementation('com.google.inject.extensions:guice-multibindings:2.0')
implementation('com.github.ben-manes:unresolvable:1.0') { because 'Life is hard' }
implementation('com.github.ben-manes:unresolvable2:1.0')
implementation('com.github.ben-manes:unresolvable20:1.0')
implementation('com.github.ben-manes:unresolvable21:1.0')
implementation('com.github.ben-manes:unresolvable3:1.0')
}
dependencyUpdates {
outputFormatter = { result ->
result.unresolved.dependencies.removeIf {
it.name == 'unresolvable20' || it.name == 'unresolvable21'
}
def plainTextReporter = new PlainTextReporter(project, revision, gradleReleaseChannel)
plainTextReporter.write(System.out, result)
}
checkForGradleUpdate = false // future proof tests from breaking
}
""".stripIndent()

when:
def result = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments('dependencyUpdates')
.withPluginClasspath()
.build()
def expected = """
------------------------------------------------------------
: Project Dependency Updates (report to plain text file)
------------------------------------------------------------
The following dependencies are using the latest milestone version:
- backport-util-concurrent:backport-util-concurrent:3.1
I said so
- backport-util-concurrent:backport-util-concurrent-java12:3.1
The following dependencies exceed the version found at the milestone revision level:
- com.google.guava:guava [99.0-SNAPSHOT <- 16.0-rc1]
I know the future
- com.google.guava:guava-tests [99.0-SNAPSHOT <- 16.0-rc1]
The following dependencies have later milestone versions:
- com.google.inject:guice [2.0 -> 3.1]
That's just the way it is
https://code.google.com/p/google-guice/
- com.google.inject.extensions:guice-multibindings [2.0 -> 3.0]
https://code.google.com/p/google-guice/
Failed to determine the latest version for the following dependencies (use --info for details):
- com.github.ben-manes:unresolvable
Life is hard
- com.github.ben-manes:unresolvable2
- com.github.ben-manes:unresolvable3
""".replace('\r', '').replace('\n', System.lineSeparator())

then:
assert result.output.toString().contains(expected)
result.task(':dependencyUpdates').outcome == SUCCESS
}
}

0 comments on commit fd9f07b

Please sign in to comment.