Skip to content

Commit

Permalink
Cleanup preview param
Browse files Browse the repository at this point in the history
  • Loading branch information
geoff-powell committed Nov 8, 2024
1 parent 9ec12e2 commit f1e65b9
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 54 deletions.
3 changes: 0 additions & 3 deletions paparazzi-gradle-plugin/api/paparazzi-gradle-plugin.api
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
public abstract interface class app/cash/paparazzi/gradle/PaparazziExtension {
}

public final class app/cash/paparazzi/gradle/PaparazziPlugin : org/gradle/api/Plugin {
public fun <init> (Lorg/gradle/api/provider/ProviderFactory;Lorg/gradle/internal/operations/BuildOperationRunner;Lorg/gradle/internal/operations/BuildOperationExecutor;)V
public synthetic fun apply (Ljava/lang/Object;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,14 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
import java.util.Locale
import javax.inject.Inject

public interface PaparazziExtension

@Suppress("unused")
public class PaparazziPlugin @Inject constructor(
private val providerFactory: ProviderFactory,
private val buildOperationRunner: BuildOperationRunner,
private val buildOperationExecutor: BuildOperationExecutor
) : Plugin<Project> {

private lateinit var config: PaparazziExtension
override fun apply(project: Project) {
config = project.createDslConfig()

val supportedPlugins = listOf("com.android.application", "com.android.library", "com.android.dynamic-feature")
project.afterEvaluate {
check(supportedPlugins.any { project.plugins.hasPlugin(it) }) {
Expand Down Expand Up @@ -364,4 +359,3 @@ public class PaparazziPlugin @Inject constructor(
}

private const val DEFAULT_COMPILE_SDK_VERSION = 34
private const val EXTENSION_NAME = "paparazzi"
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ internal object PaparazziPoet {
val visibilityCheck = checkVisibility(func)
val snapshotName = func.snapshotName(env)

when {
visibilityCheck.isPrivate -> addError(
function = func,
snapshotName = snapshotName,
buildErrorMessage = {
"$it is private. Make it internal or public to generate a snapshot."
}
when {
visibilityCheck.isPrivate -> addError(
function = func,
snapshotName = snapshotName,
buildErrorMessage = {
"$it is private. Make it internal or public to generate a snapshot."
}
)
previewParam != null -> addError(
function = func,
snapshotName = snapshotName,
buildErrorMessage = {
"$it preview uses PreviewParameters which aren't currently supported."
function = func,
snapshotName = snapshotName,
buildErrorMessage = {
"$it preview uses PreviewParameters which aren't currently supported."
}
)
else -> addDefault(
Expand Down Expand Up @@ -101,10 +101,7 @@ internal object PaparazziPoet {
addStatement("),")
}

private fun CodeBlock.Builder.addDefault(
function: KSFunctionDeclaration,
snapshotName: String
) {
private fun CodeBlock.Builder.addDefault(function: KSFunctionDeclaration, snapshotName: String) {
addStatement("%L.PaparazziPreviewData.Default(", PACKAGE_NAME)
indent()
addStatement("snapshotName = %S,", snapshotName)
Expand All @@ -123,11 +120,10 @@ internal object PaparazziPoet {
add(simpleName.asString())
}.joinToString("_")

private fun checkVisibility(
function: KSFunctionDeclaration
) = VisibilityCheck(
isFunctionPrivate = function.getVisibility() == Visibility.PRIVATE
)
private fun checkVisibility(function: KSFunctionDeclaration) =
VisibilityCheck(
isFunctionPrivate = function.getVisibility() == Visibility.PRIVATE
)
}

internal data class VisibilityCheck(
Expand Down
18 changes: 2 additions & 16 deletions paparazzi-preview-test-junit/api/paparazzi-preview-test-junit.api
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
public final class app/cash/paparazzi/preview/ComposableSingletons$SnapshotKt {
public static final field INSTANCE Lapp/cash/paparazzi/preview/ComposableSingletons$SnapshotKt;
public static field lambda-1 Lkotlin/jvm/functions/Function3;
public fun <init> ()V
public final fun getLambda-1$paparazzi_preview_test_junit ()Lkotlin/jvm/functions/Function3;
}

public final class app/cash/paparazzi/preview/ComposableSingletons$UtilsKt {
public static final field INSTANCE Lapp/cash/paparazzi/preview/ComposableSingletons$UtilsKt;
public static field lambda-1 Lkotlin/jvm/functions/Function3;
public fun <init> ()V
public final fun getLambda-1$paparazzi_preview_test_junit ()Lkotlin/jvm/functions/Function3;
}

public class app/cash/paparazzi/preview/PaparazziValuesProvider : com/google/testing/junit/testparameterinjector/TestParameter$TestParameterValuesProvider {
public static final field $stable I
public fun <init> (Ljava/util/List;)V
public fun provideValues ()Ljava/util/List;
}

public final class app/cash/paparazzi/preview/SnapshotKt {
public static final fun snapshot (Lapp/cash/paparazzi/Paparazzi;Lapp/cash/paparazzi/annotations/PaparazziPreviewData;Ljava/lang/String;Lkotlin/jvm/functions/Function3;)V
public static synthetic fun snapshot$default (Lapp/cash/paparazzi/Paparazzi;Lapp/cash/paparazzi/annotations/PaparazziPreviewData;Ljava/lang/String;Lkotlin/jvm/functions/Function3;ILjava/lang/Object;)V
public static final fun snapshot (Lapp/cash/paparazzi/Paparazzi;Lapp/cash/paparazzi/annotations/PaparazziPreviewData;Ljava/lang/String;)V
public static synthetic fun snapshot$default (Lapp/cash/paparazzi/Paparazzi;Lapp/cash/paparazzi/annotations/PaparazziPreviewData;Ljava/lang/String;ILjava/lang/Object;)V
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import com.google.testing.junit.testparameterinjector.TestParameter.TestParamete
/**
* Take a snapshot of the given [previewData].
*/
public fun Paparazzi.snapshot(
previewData: PaparazziPreviewData,
name: String? = null
) {
public fun Paparazzi.snapshot(previewData: PaparazziPreviewData, name: String? = null) {
when (previewData) {
is PaparazziPreviewData.Default -> snapshotDefault(previewData, name)
is PaparazziPreviewData.Empty -> Unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ package app.cash.paparazzi.preview
import app.cash.paparazzi.Paparazzi
import app.cash.paparazzi.annotations.PaparazziPreviewData

internal fun Paparazzi.snapshotDefault(
previewData: PaparazziPreviewData.Default,
name: String?
) {
internal fun Paparazzi.snapshotDefault(previewData: PaparazziPreviewData.Default, name: String?) {
snapshot(name) {
previewData.composable()
}
Expand Down
1 change: 0 additions & 1 deletion paparazzi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ dependencies {
implementation libs.moshi.core
implementation libs.moshi.adapters
implementation libs.moshi.kotlinReflect
implementation projects.paparazziAnnotations

def osName = System.getProperty("os.name").toLowerCase(Locale.US)
def osLabel
Expand Down

0 comments on commit f1e65b9

Please sign in to comment.