Skip to content
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

fix: handle more kinds of dependency declarations on properties. #15

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,7 @@ public class DependencyExtractor(
val maybeProjectType = newLeaf.primaryExpression().text
if (maybeProjectType == "project") {
type = DependencyDeclaration.Type.PROJECT
identifier = quoted(
newLeaf.postfixUnarySuffix().single()
.callSuffix()
.valueArguments().valueArgument().single()
).asSimpleIdentifier()
identifier = newLeaf.findIdentifier()
} else {
// e.g., `libs.kotlinGradleBom` ("libs" is the primaryExpression)
identifier = newLeaf.text.asSimpleIdentifier()
Expand All @@ -188,6 +184,10 @@ public class DependencyExtractor(
identifier = leaf.text.asSimpleIdentifier()
}

if (identifier == null && leaf is PostfixUnaryExpressionContext) {
identifier = leaf.findIdentifier()
}

val precedingComment = comments.getCommentsToLeft(declaration)
val fullText = declaration.fullText(input)
?: error("Could not determine 'full text' of dependency declaration. Failed to parse expression:\n ${declaration.text}")
Expand Down Expand Up @@ -248,6 +248,10 @@ public class DependencyExtractor(
return Identifier(path = identifier, explicitPath = true)
}
}

(singleArg.leafRule() as? SimpleIdentifierContext)?.Identifier()?.text.asSimpleIdentifier()?.let {
return it
}
}

// Unclear what this would be, bail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,40 @@ internal class DependencyExtractorTest {
capability = Capability.DEFAULT,
type = Type.MODULE,
),
/*
* This case might look like this in a build script:
* ```
* val gav = "g:a:v"
* dependencies {
* api(platform(gav))
* }
* ```
*/
TestCase(
displayName = "extracted string coordinates for a platform",
fullText = "api(platform(gav))",
configuration = "api",
identifier = "gav",
capability = Capability.PLATFORM,
type = Type.MODULE,
),
/*
* This case might look like this in a build script:
* ```
* val proj = ":project"
* dependencies {
* api(platform(project(proj)))
* }
* ```
*/
TestCase(
displayName = "extracted string coordinates for a platform on a project",
fullText = "api(platform(project(proj)))",
configuration = "api",
identifier = "proj",
capability = Capability.PLATFORM,
type = Type.PROJECT,
),
TestCase(
displayName = "version catalog accessor",
fullText = "implementation(libs.gAV)",
Expand Down