Skip to content

Commit

Permalink
fix: handle project declaration without named arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
autonomousapps committed Dec 4, 2024
1 parent 2c32cc5 commit b9eba00
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ public class DependencyExtractor(
configuration = configuration,
identifier = identifier
?: error("Could not determine dependency identifier. Failed to parse expression:\n `$fullText`"),
producerConfiguration = identifier.configuration,
capability = capability,
type = type.or(identifier),
fullText = fullText,
Expand Down Expand Up @@ -422,10 +423,6 @@ public class DependencyExtractor(
val explicitPath = firstKey == "path" || secondKey == "path"

if (firstKey == "path" || firstKey == null) {
require(secondKey == "configuration") {
"Expected 'configuration', was '$secondKey'."
}

path = firstValue
configuration = secondValue
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cash.grammar.kotlindsl.utils

import cash.grammar.kotlindsl.model.DependencyDeclaration
import cash.grammar.kotlindsl.model.DependencyDeclaration.Capability
import cash.grammar.kotlindsl.model.DependencyDeclaration.Identifier
import cash.grammar.kotlindsl.model.DependencyDeclaration.Identifier.Companion.asSimpleIdentifier
import cash.grammar.kotlindsl.model.DependencyDeclaration.Type
import cash.grammar.kotlindsl.parse.Parser
Expand Down Expand Up @@ -209,6 +210,15 @@ internal class DependencyExtractorTest {
capability = Capability.DEFAULT,
type = Type.PROJECT,
),
TestCase(
displayName = "project dependency on configuration",
fullText = """api(project(":foo", "shadow"))""",
configuration = "api",
identifier = Identifier(path = "\":foo\"", configuration = "\"shadow\""),
capability = Capability.DEFAULT,
type = Type.PROJECT,
producerConfiguration = "\"shadow\"",
),
TestCase(
displayName = "testFixtures capability for project dependency",
fullText = "testImplementation(testFixtures(project(\":has-test-fixtures\")))",
Expand Down Expand Up @@ -248,20 +258,45 @@ internal class DependencyExtractorTest {
val displayName: String,
val fullText: String,
val configuration: String,
val identifier: String,
val identifier: Identifier,
val capability: Capability,
val type: Type,
val producerConfiguration: String? = null,
val precedingComment: String? = null
) {
override fun toString(): String = displayName

fun toDependencyDeclaration() = DependencyDeclaration(
constructor(
displayName: String,
fullText: String,
configuration: String,
identifier: String,
capability: Capability,
type: Type,
producerConfiguration: String? = null,
precedingComment: String? = null
) : this(
displayName = displayName,
fullText = fullText,
configuration = configuration,
identifier = identifier.asSimpleIdentifier()!!,
capability = capability,
type = type,
fullText = fullText,
producerConfiguration = producerConfiguration,
precedingComment = precedingComment,
)

override fun toString(): String = displayName

fun toDependencyDeclaration(): DependencyDeclaration {
return DependencyDeclaration(
configuration = configuration,
identifier = identifier,
capability = capability,
type = type,
fullText = fullText,
producerConfiguration = producerConfiguration,
precedingComment = precedingComment,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,14 @@ internal class DependenciesSimplifierTest {
""".trimIndent()
)
}

@Test fun `the project function doesn't require named arguments`() {
DependenciesSimplifier.of(
"""
dependencies {
api(project(":imported-protos", "shadow"))
}
""".trimIndent()
)
}
}

0 comments on commit b9eba00

Please sign in to comment.