Skip to content

Commit 10bbf33

Browse files
committed
Fix IncludedJarInfo.tryFindInfo returning null in cases where it shouldn't
1 parent d64aa1b commit 10bbf33

2 files changed

Lines changed: 21 additions & 14 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=0.6.4
1+
version=0.6.5

minecraft-codev-includes/src/main/kotlin/net/msrandom/minecraftcodev/includes/IncludedJarInfo.kt

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.gradle.api.artifacts.VersionConstraint
44
import org.gradle.api.artifacts.component.ComponentSelector
55
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
66
import org.gradle.api.artifacts.component.ModuleComponentSelector
7+
import org.gradle.api.artifacts.component.ProjectComponentIdentifier
78
import org.gradle.api.artifacts.result.DependencyResult
89
import org.gradle.api.artifacts.result.ResolvedArtifactResult
910
import org.gradle.api.artifacts.result.ResolvedComponentResult
@@ -42,28 +43,34 @@ interface IncludedJarInfo {
4243
): IncludedJarInfo? {
4344
val componentId = artifact.id.componentIdentifier
4445
val moduleSelector = selector as? ModuleComponentSelector
45-
val moduleIdentifier = componentId as? ModuleComponentIdentifier
4646

47-
val firstCapability = artifact.variant.capabilities.firstOrNull()
48-
49-
val capability = if (moduleIdentifier != null) {
50-
// Try to find first variant that matches identifier, for consistency(matches MDG behavior)
51-
artifact.variant.capabilities.firstOrNull {
52-
it.group == moduleIdentifier.group &&
53-
it.name == moduleIdentifier.module &&
54-
it.version == moduleIdentifier.version
55-
}
56-
} else {
57-
artifact.variant.capabilities.firstOrNull() ?: firstCapability
47+
val mainCapability = when (componentId) {
48+
is ModuleComponentIdentifier ->
49+
// Try to find first variant that matches identifier, for consistency(matches MDG behavior)
50+
artifact.variant.capabilities.firstOrNull {
51+
it.group == componentId.group &&
52+
it.name == componentId.module &&
53+
it.version == componentId.version
54+
}
55+
56+
is ProjectComponentIdentifier ->
57+
// Not in parity with MDG, but gets the capability that matches the project name for consistency with module capability behavior
58+
artifact.variant.capabilities.firstOrNull {
59+
it.name == componentId.projectName
60+
}
61+
62+
else -> null
5863
}
5964

65+
val capability = mainCapability ?: artifact.variant.capabilities.firstOrNull()
66+
6067
if (capability == null) {
6168
return null
6269
}
6370

6471
val group = capability.group
6572
val name = capability.name
66-
val version = capability.version ?: moduleIdentifier?.version ?: moduleSelector?.version ?: "0.0.0"
73+
val version = capability.version ?: (componentId as? ModuleComponentIdentifier)?.version ?: moduleSelector?.version ?: "0.0.0"
6774
val versionRange = versionRange(moduleSelector?.versionConstraint) ?: defaultVersionRange(version)
6875

6976
return objectFactory.newInstance<IncludedJarInfo>().also {

0 commit comments

Comments
 (0)