Skip to content

Commit

Permalink
Do not use textual 'null' for dependencies without group (#725) (#731)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire authored Feb 20, 2023
1 parent c07dab4 commit 91a63f2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class PlainTextReporter(
companion object {
/** Returns the dependency key as a stringified label. */
private fun label(dependency: Dependency): String {
return "${dependency.group}:${dependency.name}"
return "${dependency.group.orEmpty()}:${dependency.name}"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,8 @@ class Resolver(
val resolvedCoordinate = Coordinate.from(dependency.module.id)
val originalCoordinate = coordinates[resolvedCoordinate.key]
val coord = originalCoordinate ?: resolvedCoordinate
if (originalCoordinate == null && resolvedCoordinate.groupId != "null") {
project.logger.info("Skipping hidden dependency: $resolvedCoordinate")
} else {
val projectUrl = getProjectUrl(dependency.module.id)
result.add(DependencyStatus(coord, resolvedCoordinate.version, projectUrl))
}
val projectUrl = getProjectUrl(dependency.module.id)
result.add(DependencyStatus(coord, resolvedCoordinate.version, projectUrl))
}

for (dependency in unresolved) {
Expand Down Expand Up @@ -167,7 +163,7 @@ class Resolver(
}

// Format the query with an optional classifier and extension
var query = "${dependency.group}:${dependency.name}:$version"
var query = "${dependency.group.orEmpty()}:${dependency.name}:$version"
if (dependency.artifacts.isNotEmpty()) {
dependency.artifacts.firstOrNull()?.classifier?.let { classifier ->
query += ":$classifier"
Expand All @@ -191,7 +187,7 @@ class Resolver(
// If no version was specified then use "none" to pass it through.
val version = if (dependency.version == null) "none" else "+"
val nonTransitiveDependency =
project.dependencies.create("${dependency.group}:${dependency.name}:$version") as ModuleDependency
project.dependencies.create("${dependency.group.orEmpty()}:${dependency.name}:$version") as ModuleDependency
nonTransitiveDependency.isTransitive = false
return nonTransitiveDependency
}
Expand Down Expand Up @@ -249,7 +245,7 @@ class Resolver(
/** Returns the coordinates for the current (declared) dependency versions. */
private fun getCurrentCoordinates(configuration: Configuration): Map<Coordinate.Key, Coordinate> {
val declared = getResolvableDependencies(configuration)
.associateBy({ it.key }, { it })
.associateBy { it.key }
if (declared.isEmpty()) {
return emptyMap()
}
Expand Down Expand Up @@ -378,7 +374,7 @@ class Resolver(
} else {
val parent = getParentFromPom(file)
if (parent != null &&
"${parent.group}:${parent.name}" != "org.sonatype.oss:oss-parent"
"${parent.group.orEmpty()}:${parent.name}" != "org.sonatype.oss:oss-parent"
) {
url = getProjectUrl(parent)
if (!url.isNullOrEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ComponentSelectionWithCurrent(
override fun toString(): String {
return """\
ComponentSelectionWithCurrent{
group="${candidate.group}",
group="${candidate.group.orEmpty()}",
module="${candidate.module}",
version="${candidate.version}",
currentVersion="$currentVersion",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,11 @@ final class DependencyUpdatesSpec extends Specification {
with(reporter) {
unresolved.collect { it.selector }.collectEntries { dependency ->
[['group': dependency.group, 'name': dependency.name]: dependency.version]
} == [['group': 'null', 'name': 'guava-18.0']: NONE_VERSION]
} == [['group': '', 'name': 'guava-18.0']: NONE_VERSION]
upgradeVersions.isEmpty()
upToDateVersions.isEmpty()
downgradeVersions.isEmpty()
undeclared.contains(new Coordinate('null', 'guice-4.0', NONE_VERSION, null))
undeclared.contains(new Coordinate('', 'guice-4.0', NONE_VERSION, null))
}
}

Expand Down

0 comments on commit 91a63f2

Please sign in to comment.