Skip to content

Commit

Permalink
Remove paparazzi dsl extension for gradle prop
Browse files Browse the repository at this point in the history
  • Loading branch information
geoff-powell committed Sep 3, 2024
1 parent cec6dc6 commit 59f10ef
Show file tree
Hide file tree
Showing 14 changed files with 10 additions and 115 deletions.
2 changes: 1 addition & 1 deletion paparazzi-annotations/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ apply plugin: 'org.jetbrains.kotlin.plugin.compose'
apply plugin: 'com.vanniktech.maven.publish'

dependencies {
implementation libs.compose.runtime
compileOnly libs.compose.runtime
}
4 changes: 0 additions & 4 deletions paparazzi-gradle-plugin/api/paparazzi-gradle-plugin.api
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
public abstract interface class app/cash/paparazzi/gradle/PaparazziExtension {
public abstract fun getGeneratePreviewTestClass ()Lorg/gradle/api/provider/Property;
}

public final class app/cash/paparazzi/gradle/PaparazziPlugin : org/gradle/api/Plugin {
public fun <init> (Lorg/gradle/api/provider/ProviderFactory;)V
public synthetic fun apply (Ljava/lang/Object;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import org.gradle.api.file.Directory
import org.gradle.api.file.FileCollection
import org.gradle.api.internal.artifacts.transform.UnzipTransform
import org.gradle.api.logging.LogLevel.LIFECYCLE
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.provider.ProviderFactory
import org.gradle.api.reporting.ReportingExtension
Expand All @@ -50,19 +49,11 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
import java.util.Locale
import javax.inject.Inject

public interface PaparazziExtension {
public val generatePreviewTestClass: Property<Boolean>
}

@Suppress("unused")
public class PaparazziPlugin @Inject constructor(
private val providerFactory: ProviderFactory
) : 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 @@ -221,7 +212,7 @@ public class PaparazziPlugin @Inject constructor(
test.inputs.dir(
isVerifyRun.flatMap {
project.objects.directoryProperty().apply {
set(if (it) snapshotOutputDir else null)
set(if (it && snapshotOutputDir.asFile.exists()) snapshotOutputDir else null)
}
}
).withPropertyName("paparazzi.snapshot.input.dir")
Expand Down Expand Up @@ -270,7 +261,7 @@ public class PaparazziPlugin @Inject constructor(
project.addAnnotationsDependency()
project.addProcessorDependency()
project.addPreviewTestDependency()
project.registerGeneratePreviewTask(config, extension)
project.registerGeneratePreviewTask(extension)

project.afterEvaluate {
// pass the namespace to the processor
Expand All @@ -290,11 +281,6 @@ public class PaparazziPlugin @Inject constructor(
}
}

private fun Project.createDslConfig() =
extensions.create(EXTENSION_NAME, PaparazziExtension::class.java).apply {
generatePreviewTestClass.convention(true)
}

private fun Project.setupLayoutlibRuntimeDependency(): FileCollection {
val operatingSystem = OperatingSystem.current()
val nativeLibraryArtifactId = when {
Expand Down Expand Up @@ -390,5 +376,4 @@ public class PaparazziPlugin @Inject constructor(
}

private const val DEFAULT_COMPILE_SDK_VERSION = 34
private const val EXTENSION_NAME = "paparazzi"
private const val KSP_ARG_NAMESPACE = "app.cash.paparazzi.preview.namespace"
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app.cash.paparazzi.gradle.utils

import app.cash.paparazzi.gradle.PREVIEW_TEST_SOURCE
import app.cash.paparazzi.gradle.PaparazziExtension
import com.android.build.api.variant.AndroidComponentsExtension
import com.android.build.api.variant.HasUnitTest
import org.gradle.api.Project
Expand All @@ -15,7 +14,6 @@ private const val PREVIEW_DATA_FILE = "PaparazziPreviews.kt"
private const val PREVIEW_TEST_FILE = "PreviewTests.kt"

internal fun Project.registerGeneratePreviewTask(
config: PaparazziExtension,
extension: AndroidComponentsExtension<*, *, *>
) {
extension.onVariants { variant ->
Expand Down Expand Up @@ -58,7 +56,9 @@ internal fun Project.registerGeneratePreviewTask(
.file("$projectDir${File.separator}$KSP_SOURCE_DIR${File.separator}${buildType}${File.separator}kotlin${File.separator}$namespaceDir${File.separator}$PREVIEW_DATA_FILE")
.optional()
.skipWhenEmpty()
task.enabled = config.generatePreviewTestClass.get()

// Defaulted to true unless specified in properties
task.enabled = project.providers.gradleProperty("app.cash.paparazzi.annotation.generateTestClass").orNull?.toBoolean() != false

task.outputs.dir(previewTestDir)
task.outputs.file("$previewTestDir${File.separator}$PREVIEW_TEST_FILE")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1428,19 +1428,6 @@ class PaparazziPluginTest {
assertThat(result.output).contains("IllegalStateException at PreviewTests.kt")
}

@Test
fun previewAnnotationPreviewParameters() {
val fixtureRoot = File("src/test/projects/preview-annotation-preview-parameters")

val result = gradleRunner
.withArguments("verifyPaparazziDebug", "--stacktrace")
.forwardOutput()
.runFixture(fixtureRoot) { buildAndFail() }

assertThat(result.task(":testDebugUnitTest")?.outcome).isEqualTo(TaskOutcome.FAILED)
assertThat(result.output).contains("IllegalStateException at PreviewTests.kt")
}

@Test
fun previewAnnotationDslDisable() {
val fixtureRoot = File("src/test/projects/preview-annotation-dsl-disable")
Expand Down Expand Up @@ -1497,7 +1484,7 @@ class PaparazziPluginTest {
.runFixture(fixtureRoot) { build() }

assertThat(result2.task(":paparazziGeneratePreviewDebugUnitTestKotlin")?.outcome).isEqualTo(FROM_CACHE)
assertThat(result2.task(":testDebugUnitTest")?.outcome).isEqualTo(SUCCESS)
assertThat(result2.task(":testDebugUnitTest")?.outcome).isEqualTo(FROM_CACHE)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ plugins {
id 'org.jetbrains.kotlin.plugin.compose'
}

paparazzi {
generatePreviewTestClass = false
}

android {
namespace 'app.cash.paparazzi.plugin.test'
compileSdk libs.versions.compileSdk.get() as int
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
app.cash.paparazzi.annotation.generateTestClass=false
android.useAndroidX=true
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ plugins {
id 'org.jetbrains.kotlin.plugin.compose'
}

paparazzi {
generatePreviewTestClass = true
}

android {
namespace 'app.cash.paparazzi.plugin.test'
compileSdk libs.versions.compileSdk.get() as int
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ plugins {
id 'org.jetbrains.kotlin.plugin.compose'
}

paparazzi {
generatePreviewTestClass = true
}

android {
namespace 'app.cash.paparazzi.plugin.test'
compileSdk libs.versions.compileSdk.get() as int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ plugins {
id 'org.jetbrains.kotlin.plugin.compose'
}

paparazzi {
generatePreviewTestClass = true
}

android {
namespace 'app.cash.paparazzi.plugin.test'
compileSdk libs.versions.compileSdk.get() as int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ plugins {
id 'org.jetbrains.kotlin.plugin.compose'
}

paparazzi {
generatePreviewTestClass = true
}

android {
namespace 'app.cash.paparazzi.plugin.test'
compileSdk libs.versions.compileSdk.get() as int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class PreviewProcessor(
override fun process(resolver: Resolver): List<KSAnnotated> {
// Due to codgen and multi-round processing of ksp
// https://kotlinlang.org/docs/ksp-multi-round.html
if (resolver.getAllFiles().any { it.fileName.contains("PaparazziPreviews") }) {
if (resolver.getAllFiles().any { it.fileName.contains("PaparazziPreviews") } || resolver.getNewFiles().toList().isEmpty()) {
"Skipping subsequent run due to PaparazziPreviews.kt already created and caused ksp re-run".log()
return emptyList()
}
Expand Down

0 comments on commit 59f10ef

Please sign in to comment.