-
-
Notifications
You must be signed in to change notification settings - Fork 136
#1124 Reason explanation id ambiguity #1125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -216,8 +216,8 @@ abstract class ReasonTask @Inject constructor( | |
}?.gav() | ||
|
||
// Guaranteed to find full GAV or throw | ||
val gavKey = dependencyUsages.entries.find(requestedId::matchesKey)?.key | ||
?: annotationProcessorUsages.entries.find(requestedId::matchesKey)?.key | ||
val gavKey = findFilteredDependencyKey(dependencyUsages.entries, requestedId) | ||
?: findFilteredDependencyKey(annotationProcessorUsages.entries, requestedId) | ||
?: findInGraph() | ||
?: throw InvalidUserDataException("There is no dependency with coordinates '$requestedId' in this project.") | ||
|
||
|
@@ -253,6 +253,29 @@ abstract class ReasonTask @Inject constructor( | |
} | ||
|
||
private fun wasFiltered(): Boolean = finalAdvice == null && unfilteredAdvice != null | ||
|
||
internal companion object { | ||
internal fun findFilteredDependencyKey(dependencies: Set<Map.Entry<String, Any>>, requestedId: String): String? { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this need to be internal instead of private? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because of accessing from the unit test |
||
val filteredKeys = LinkedHashSet<String>() | ||
for (entry in dependencies) { | ||
if (requestedId.equalsKey(entry)) { | ||
// for exact equal - return immediately | ||
return entry.key | ||
} | ||
if (requestedId.matchesKey(entry)) { | ||
filteredKeys.add(entry.key) | ||
} | ||
} | ||
return if (filteredKeys.isEmpty()) { | ||
null | ||
} else if (filteredKeys.size == 1) { | ||
filteredKeys.iterator().next() | ||
} else { | ||
throw InvalidUserDataException("Coordinates '$requestedId' matches more than 1 dependency " + | ||
"${filteredKeys.map { it.secondCoordinatesKeySegment() ?: it }}") | ||
} | ||
} | ||
} | ||
} | ||
|
||
interface ExplainModuleAdviceParams : WorkParameters { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.autonomousapps.tasks | ||
|
||
import com.autonomousapps.model.declaration.Bucket | ||
import com.autonomousapps.model.declaration.Variant | ||
import com.autonomousapps.model.intermediates.Usage | ||
import com.autonomousapps.tasks.ReasonTask.ExplainDependencyAdviceAction.Companion.findFilteredDependencyKey | ||
import org.gradle.api.InvalidUserDataException | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Assertions.assertThrows | ||
import org.junit.jupiter.api.Test | ||
|
||
class ReasonTaskTest { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for this great unit test |
||
|
||
private val usage = Usage(null, null, Variant.MAIN, Bucket.NONE, emptySet()) | ||
|
||
private val entries = mapOf( | ||
"demo-gradle-multi-module:list|:list" to usage, | ||
"demo-gradle-multi-module:list:sublist|:list:sublist" to usage, | ||
"demo-gradle-multi-module:list-default|:list-default" to usage, | ||
"demo-gradle-multi-module:list-impl|:list-impl" to usage, | ||
"com.squareup.okio:okio-jvm:3.0.0" to usage, | ||
"com.squareup.okio:okio:3.0.0" to usage | ||
).entries | ||
|
||
@Test | ||
fun shouldThrowOnProjectModuleAmbiguity() { | ||
val ex = assertThrows(InvalidUserDataException::class.java) { findFilteredDependencyKey(entries, ":li") } | ||
assertEquals("Coordinates ':li' matches more than 1 dependency " + | ||
"[:list, :list:sublist, :list-default, :list-impl]", ex.message) | ||
} | ||
|
||
@Test | ||
fun shouldMatchEqualProjectModule() { | ||
val key = findFilteredDependencyKey(entries, ":list") | ||
assertEquals("demo-gradle-multi-module:list|:list", key) | ||
} | ||
|
||
@Test | ||
fun shouldMatchPrefixProjectModuleColon() { | ||
val key = findFilteredDependencyKey(entries, ":list:") | ||
assertEquals("demo-gradle-multi-module:list:sublist|:list:sublist", key) | ||
} | ||
|
||
@Test | ||
fun shouldMatchPrefixProjectModule() { | ||
val key = findFilteredDependencyKey(entries, ":list-d") | ||
assertEquals("demo-gradle-multi-module:list-default|:list-default", key) | ||
} | ||
|
||
@Test | ||
fun shouldThrowOnLibraryAmbiguity() { | ||
val ex = assertThrows(InvalidUserDataException::class.java) { | ||
findFilteredDependencyKey(entries, "com.squareup.okio:oki") | ||
} | ||
assertEquals("Coordinates 'com.squareup.okio:oki' matches more than 1 dependency " + | ||
"[com.squareup.okio:okio-jvm:3.0.0, com.squareup.okio:okio:3.0.0]", ex.message) | ||
} | ||
|
||
@Test | ||
fun shouldMatchEqualLibrary() { | ||
val key = findFilteredDependencyKey(entries, "com.squareup.okio:okio") | ||
assertEquals("com.squareup.okio:okio:3.0.0", key) | ||
} | ||
|
||
@Test | ||
fun shouldMatchPrefixLibraryColon() { | ||
val key = findFilteredDependencyKey(entries, "com.squareup.okio:okio:") | ||
assertEquals("com.squareup.okio:okio:3.0.0", key) | ||
} | ||
|
||
@Test | ||
fun shouldMatchLibraryVersion() { | ||
val key = findFilteredDependencyKey(entries, "com.squareup.okio:okio:3.0.0") | ||
assertEquals("com.squareup.okio:okio:3.0.0", key) | ||
} | ||
|
||
@Test | ||
fun shouldMatchPrefixLibrary() { | ||
val key = findFilteredDependencyKey(entries, "com.squareup.okio:okio-") | ||
assertEquals("com.squareup.okio:okio-jvm:3.0.0", key) | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.