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 options handling #43

Merged
merged 1 commit into from
Aug 8, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
--------------

- **Fix:** Don't cache symbols between processing rounds. This better supports KSP2.
- **Fix:** Workaround Kotlin plugin option parsing limitations. Contributing annotations should now be colon-delimited, and the underlying KSP argument is changed to a more consistent `anvil-ksp-extraContributingAnnotations`.

0.2.0
-----
Expand Down
8 changes: 4 additions & 4 deletions FORK.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ too.

For simple cases where a custom annotation is processed by a custom generator, you can simply indicate these annotations to Anvil KSP. These can be provided in three different ways, whichever is most convenient.

1. A comma-separated Gradle property whose values are the canonical class names of your custom annotations.
1. A colon-delimited Gradle property whose values are the canonical class names of your custom annotations.
```properties
com.squareup.anvil.kspContributingAnnotations=com.example.CustomAnnotation,com.example.InjectWith
com.squareup.anvil.kspContributingAnnotations=com.example.CustomAnnotation:com.example.InjectWith
```
2. Setting via the `AnvilExtension` in Gradle. Note this property defaults to the above Gradle property.
```kotlin
Expand All @@ -164,8 +164,8 @@ For simple cases where a custom annotation is processed by a custom generator, y
```kotlin
ksp {
arg(
"anvil.ksp.extraContributingAnnotations",
"com.example.CustomAnnotation,com.example.InjectWith"
"anvil-ksp-extraContributingAnnotations",
"com.example.CustomAnnotation:com.example.InjectWith"
)
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ internal class KspContributionMerger(
add(contributesMultibindingFqName.asString())
env.options[OPTION_EXTRA_CONTRIBUTING_ANNOTATIONS]?.let {
if (it.isNotBlank()) {
addAll(it.splitToSequence(',').filterNot { it.isBlank() })
addAll(it.splitToSequence(':').filterNot(String::isBlank))
}
}
// contributesSubcomponentFqName is handled uniquely
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/main/java/com/squareup/anvil/compiler/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ public const val OPTION_GENERATE_SHIMS: String = "anvil.ksp.generateShims"
* KSP option to specify custom extra contributing annotations. Useful for situations where you
* can't or don't want to implement an `AnvilKspExtension` implementation to provide them.
*
* Value should be a comma-separated list of fully qualified canonical class names.
* Value should be a colon-delimited list of fully qualified canonical class names.
*/
public const val OPTION_EXTRA_CONTRIBUTING_ANNOTATIONS: String = "anvil.ksp.extraContributingAnnotations"
public const val OPTION_EXTRA_CONTRIBUTING_ANNOTATIONS: String = "anvil-ksp-extraContributingAnnotations"

/**
* Returns the single element matching the given [predicate], or `null` if element was not found.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ public abstract class AnvilExtension @Inject constructor(
* merging. Values should be the canonical class name of extra contributing annotations.
*
* Can be set via `com.squareup.anvil.kspContributingAnnotations` gradle property with
* comma-separated values.
* colon-delimited values.
*/
public val kspContributingAnnotations: SetProperty<String> = objects.setProperty(
String::class.java,
)
.convention(
providers.gradleProperty("com.squareup.anvil.kspContributingAnnotations")
.map { it.splitToSequence(",").filterNot { it.isBlank() }.toSet() }
.map { it.splitToSequence(":").filterNot { it.isBlank() }.toSet() }
.orElse(emptySet()),
)

Expand Down Expand Up @@ -238,8 +238,8 @@ public abstract class AnvilExtension @Inject constructor(
"generate-dagger-factories" to generateDaggerFactories,
"generate-dagger-factories-only" to generateDaggerFactoriesOnly,
"disable-component-merging" to disableComponentMerging,
"anvil.ksp.extraContributingAnnotations" to kspContributingAnnotations.map {
it.sorted().joinToString(",")
"anvil-ksp-extraContributingAnnotations" to kspContributingAnnotations.map {
it.sorted().joinToString(":")
},
"will-have-dagger-factories" to willHaveDaggerFactories,
"merging-backend" to useKspComponentMergingBackend
Expand Down
Loading