Skip to content

Commit

Permalink
Remove compiler args for custom previews
Browse files Browse the repository at this point in the history
  • Loading branch information
oas004 committed Feb 20, 2023
1 parent d40c9d5 commit 312680c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 33 deletions.
2 changes: 0 additions & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,11 @@ android {
if (project.hasProperty("useKsp")) {
ksp {
arg("skipPrivatePreviews", "true")
arg("multiPreviewTypes", "com.airbnb.android.submodule.showkasesample.FontPreview")
}
} else {
kapt {
arguments {
arg("skipPrivatePreviews", "true")
arg("multiPreviewTypes", "com.airbnb.android.submodule.showkasesample.FontPreview")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,30 +585,25 @@ class ShowkaseProcessorTest : BaseProcessorTest() {

@Test
fun `composable function with custom preview annotation generates output`() {
compileInputsAndVerifyOutputs(modes = listOf(Mode.KAPT, Mode.KSP), options = mutableMapOf("multiPreviewTypes" to "com.airbnb.android.showkase_processor_testing.ThemePreview"))
compileInputsAndVerifyOutputs(modes = listOf(Mode.KAPT, Mode.KSP))
}

@Test
fun `composable function with custom preview annotation with preview param generates output`() {
compileInputsAndVerifyOutputs(modes = listOf(Mode.KAPT, Mode.KSP), options = mutableMapOf("multiPreviewTypes" to "com.airbnb.android.showkase_processor_testing.ThemePreview"))
compileInputsAndVerifyOutputs(modes = listOf(Mode.KAPT, Mode.KSP))
}

@Test
fun `composable function with repeatable custom preview annotation generates output`() {
// This is only supported by KSP for now
compileInputsAndVerifyOutputs(modes = listOf(Mode.KSP), options = mutableMapOf("multiPreviewTypes" to "com.airbnb.android.showkase_processor_testing.ThemePreview"))
compileInputsAndVerifyOutputs(modes = listOf(Mode.KSP))
}

@Test
fun `composable function with multiple repeatable custom preview annotation generates output`() {
// This is only supported by KSP for now
compileInputsAndVerifyOutputs(
modes = listOf(Mode.KSP),
options = mutableMapOf(
"multiPreviewTypes" to
"com.airbnb.android.showkase_processor_testing.ThemePreview, " +
"com.airbnb.android.showkase_processor_testing.FontPreview"
)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,9 @@ class ShowkaseProcessor @JvmOverloads constructor(
ShowkaseScreenshot::class.java.name,
)
supportedAnnotationTypes.addAll(supportedAnnotationTypes)
supportedAnnotationTypes.addAll(supportedCustomAnnotationTypes())
return supportedAnnotationTypes
}
override fun getSupportedOptions() = mutableSetOf("skipPrivatePreviews", "multiPreviewTypes")

// Getting the custom annotations that are supported as an compiler argument.
// It is expected to get the compiler argument as follows:
// arg("multiPreviewTypes", "com.airbnb.android.submodule.showkasesample.FontPreview")
private fun supportedCustomAnnotationTypes(): MutableSet<String> {
val set = mutableSetOf<String>()
environment
.options["multiPreviewTypes"]
?.split(",")?.map { it.replace(" ", "") }
?.toSet()?.let { set.addAll(it) }
return set
}
override fun getSupportedOptions() = mutableSetOf("skipPrivatePreviews")

override fun process(environment: XProcessingEnv, round: XRoundEnv) {
val componentMetadata = processComponentAnnotation(round)
Expand All @@ -98,7 +85,7 @@ class ShowkaseProcessor @JvmOverloads constructor(
private fun processComponentAnnotation(roundEnvironment: XRoundEnv): Set<ShowkaseMetadata.Component> {
val showkaseComposablesMetadata = processShowkaseAnnotation(roundEnvironment)
val previewComposablesMetadata = processPreviewAnnotation(roundEnvironment)
val customPreviewFromClassPathMetadata = processCustomAnnotation(roundEnvironment)
val customPreviewFromClassPathMetadata = processCustomAnnotationFromClasspath(roundEnvironment)
return (showkaseComposablesMetadata + previewComposablesMetadata + customPreviewFromClassPathMetadata)
.dedupeAndSort()
.toSet()
Expand Down Expand Up @@ -157,7 +144,6 @@ class ShowkaseProcessor @JvmOverloads constructor(
): Set<ShowkaseMetadata.Component> {
val supportedTypes = mutableListOf<String>()
if (annotation != null) supportedTypes.add(annotation.qualifiedName)
supportedTypes.addAll(supportedCustomAnnotationTypes())
val components = mutableSetOf<ShowkaseMetadata.Component>()

supportedTypes.map { supportedType ->
Expand Down Expand Up @@ -190,7 +176,7 @@ class ShowkaseProcessor @JvmOverloads constructor(
// In this function we are checking generated classpath for MultiPreview codegen annotations.
// We also check the current module if there is any composables that are annotated with the qualified name
// from the annotation from classpath. We use the fields from the classpath annotation to build
// common data for the ShowkasMetadata.
// common data for the ShowkaseMetadata.

// Supported annotations from classpath
val supportedCustomPreview = environment.getTypeElementsFromPackage(CODEGEN_PACKAGE_NAME)
Expand Down
6 changes: 0 additions & 6 deletions showkase-screenshot-testing-paparazzi-sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,10 @@ plugins {

if (project.hasProperty('useKsp')) {
apply plugin: 'com.google.devtools.ksp'
ksp {
arg("multiPreviewTypes", "com.airbnb.android.showkase.screenshot.testing.paparazzi.sample.HighFont")
}
} else {
apply plugin: 'kotlin-kapt'
kapt {
correctErrorTypes = true
arguments {
arg("multiPreviewTypes", "com.airbnb.android.showkase.screenshot.testing.paparazzi.sample.HighFont")
}
}
}

Expand Down

0 comments on commit 312680c

Please sign in to comment.