Skip to content

Commit

Permalink
Cleanup from upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
geoff-powell committed Aug 24, 2024
1 parent 023b95f commit 2ae2c2d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 29 deletions.
13 changes: 5 additions & 8 deletions paparazzi-annotations/api/paparazzi-annotations.api
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,26 @@ public abstract interface class app/cash/paparazzi/annotations/PaparazziPreviewD
}

public final class app/cash/paparazzi/annotations/PaparazziPreviewData$Default : app/cash/paparazzi/annotations/PaparazziPreviewData {
public static final field $stable I
public fun <init> (Ljava/lang/String;Lkotlin/jvm/functions/Function2;)V
public fun <init> (Ljava/lang/String;Lkotlin/jvm/functions/Function0;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Lkotlin/jvm/functions/Function2;
public final fun copy (Ljava/lang/String;Lkotlin/jvm/functions/Function2;)Lapp/cash/paparazzi/annotations/PaparazziPreviewData$Default;
public static synthetic fun copy$default (Lapp/cash/paparazzi/annotations/PaparazziPreviewData$Default;Ljava/lang/String;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lapp/cash/paparazzi/annotations/PaparazziPreviewData$Default;
public final fun component2 ()Lkotlin/jvm/functions/Function0;
public final fun copy (Ljava/lang/String;Lkotlin/jvm/functions/Function0;)Lapp/cash/paparazzi/annotations/PaparazziPreviewData$Default;
public static synthetic fun copy$default (Lapp/cash/paparazzi/annotations/PaparazziPreviewData$Default;Ljava/lang/String;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Lapp/cash/paparazzi/annotations/PaparazziPreviewData$Default;
public fun equals (Ljava/lang/Object;)Z
public final fun getComposable ()Lkotlin/jvm/functions/Function2;
public final fun getComposable ()Lkotlin/jvm/functions/Function0;
public final fun getSnapshotName ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class app/cash/paparazzi/annotations/PaparazziPreviewData$Empty : app/cash/paparazzi/annotations/PaparazziPreviewData {
public static final field $stable I
public static final field INSTANCE Lapp/cash/paparazzi/annotations/PaparazziPreviewData$Empty;
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class app/cash/paparazzi/annotations/PaparazziPreviewData$Error : app/cash/paparazzi/annotations/PaparazziPreviewData {
public static final field $stable I
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Ljava/lang/String;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ internal fun Project.registerGeneratePreviewTask(
val testVariant = (variant as? HasUnitTest)?.unitTest ?: return@onVariants
val testVariantSlug = testVariant.name.capitalize()

val buildType = testVariant.buildType
val buildTypeCap = testVariant.buildType?.capitalize()
val buildType = testVariant.buildType
val buildTypeCap = testVariant.buildType?.capitalize()

val taskName = "paparazziGeneratePreview${testVariantSlug}Kotlin"
val taskProvider = tasks.register(taskName) { task ->
val taskName = "paparazziGeneratePreview${testVariantSlug}Kotlin"
val taskProvider = tasks.register(taskName) { task ->
task.group = VERIFICATION_GROUP
task.description = "Generates the preview test class to the test source set for $testVariantSlug"

Expand All @@ -44,31 +44,35 @@ internal fun Project.registerGeneratePreviewTask(
project.tasks.named { it == "ksp${testVariantSlug}Kotlin" }
.configureEach { it.mustRunAfter(taskProvider) }

gradle.taskGraph.whenReady {
gradle.taskGraph.whenReady {
taskProvider.configure { task ->
// Test variant appends .test to the namespace
val namespace = testVariant.namespace.get().replace(".test$".toRegex(), "")
val namespaceDir = namespace.replace(".", File.separator)
val previewTestDir = "$testSourceDir${File.separator}$namespaceDir"

task.enabled = config.generatePreviewTestClass.get()
task.inputs.file(
"$projectDir${File.separator}$KSP_SOURCE_DIR${File.separator}${buildType}${File.separator}kotlin${File.separator}$namespaceDir${File.separator}$PREVIEW_DATA_FILE"
)
task.enabled = config.generatePreviewTestClass.get()

task.outputs.dir(previewTestDir)
task.outputs.file("$previewTestDir${File.separator}$PREVIEW_TEST_FILE")
task.outputs.cacheIf { true }

task.doLast {
File(previewTestDir).mkdirs()
File(previewTestDir, PREVIEW_TEST_FILE).writeText(
buildString {
appendLine("package $namespace")
append(PREVIEW_TEST_SOURCE)
}
task.inputs.file(
"$projectDir${File.separator}$KSP_SOURCE_DIR${File.separator}${buildType}${File.separator}kotlin${File.separator}$namespaceDir${File.separator}$PREVIEW_DATA_FILE"
)
task.enabled = config.generatePreviewTestClass.get()task.outputs.dir(previewTestDir)
task.outputs.file("$previewTestDir${File.separator}$PREVIEW_TEST_FILE")
task.outputs.cacheIf { true }

// test compilation depends on the task
tasks.findByName("compile${typeNameCap}UnitTestKotlin")?.dependsOn(taskName)
// run task before processing symbols
tasks.findByName("ksp${typeNameCap}UnitTestKotlin")?.mustRunAfter(taskName)

task.doLast {
File(previewTestDir).mkdirs()
File(previewTestDir, PREVIEW_TEST_FILE).writeText(
buildString {
appendLine("package $namespace")
append(PREVIEW_TEST_SOURCE)
}
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package app.cash.paparazzi.plugin.test

import android.content.res.Configuration
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.compose.ui.tooling.preview.Wallpapers
import app.cash.paparazzi.annotations.Paparazzi

@Paparazzi
Expand All @@ -11,3 +15,36 @@ import app.cash.paparazzi.annotations.Paparazzi
fun HelloPaparazzi() {
Text("Hello, Paparazzi!")
}

@Paparazzi
@Preview
@Composable
fun HelloPaparazziParameterized(
@PreviewParameter(provider = PreviewData::class) text: String,
) {
Text(text)
}

@Paparazzi
@Preview(
name = "PreviewConfig",
group = "Previews",
device = "id:Nexus 6",
apiLevel = 33,
showSystemUi = true,
uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL,
wallpaper = Wallpapers.RED_DOMINATED_EXAMPLE,
showBackground = true,
fontScale = 1.5f
)
@Composable
fun HelloPaparazziPreviewConfig() {
Text("Hello Paparazzi Preview Config!")
}

object PreviewData : PreviewParameterProvider<String> {
override val values: Sequence<String> = sequenceOf(
"Hello, Paparazzi One!",
"Hello, Paparazzi Two!",
)
}

0 comments on commit 2ae2c2d

Please sign in to comment.