@@ -218,9 +218,6 @@ private object PaparazziPreviewRule {
218218 false -> previewInfo.apiLevel
219219 }
220220 val tolerance = 0.0
221- val sentryOutputDir = File(
222- System.getProperty("sentry.snapshot.output", "build/sentry-snapshots")
223- )
224221 return Paparazzi(
225222 environment = detectEnvironment().copy(compileSdkVersion = previewApiLevel),
226223 deviceConfig = DeviceConfigBuilder.build(preview.previewInfo),
@@ -234,10 +231,7 @@ private object PaparazziPreviewRule {
234231 snapshotHandler = TestNameOverrideHandler(
235232 when (System.getProperty("paparazzi.test.verify")?.toBoolean() == true) {
236233 true -> SnapshotVerifier(maxPercentDifference = tolerance)
237- false -> HtmlReportWriter(
238- maxPercentDifference = tolerance,
239- snapshotRootDirectory = sentryOutputDir,
240- )
234+ false -> HtmlReportWriter(maxPercentDifference = tolerance)
241235 }
242236 ),
243237 maxPercentDifference = tolerance,
@@ -310,8 +304,6 @@ class $CLASS_NAME(
310304 .encodeUnsafeCharacters()
311305 .build()
312306
313- writeSidecarMetadata(screenshotId, preview)
314-
315307 paparazzi.snapshot(name = screenshotId) {
316308 val previewInfo = preview.previewInfo
317309 when (previewInfo.showSystemUi) {
@@ -338,57 +330,40 @@ class $CLASS_NAME(
338330 }
339331 }
340332 }
333+
334+ writeSidecarMetadata(screenshotId, preview)
341335 }
342336
343337 private fun writeSidecarMetadata(
344338 screenshotId: String,
345339 preview: ComposablePreview<AndroidPreviewInfo>,
346340 ) {
347- val sentryRoot = File(
348- System.getProperty("sentry.snapshot.output", "build/sentry-snapshots")
349- )
350- val imagesDir = File(sentryRoot, "images")
341+ val snapshotDir = File(System.getProperty("paparazzi.snapshot.dir"))
342+ val imagesDir = File(snapshotDir, "images")
351343 imagesDir.mkdirs()
352344 val info = preview.previewInfo
353- val q = '"'
354- val parts = mutableListOf<String>()
355- parts.add(q + "display_name" + q + ": " + q + escapeJson(screenshotId) + q)
356- parts.add(q + "image_file_name" + q + ": " + q + escapeJson(screenshotId) + q)
357- parts.add(q + "className" + q + ": " + q + escapeJson(preview.declaringClass) + q)
358- parts.add(q + "methodName" + q + ": " + q + escapeJson(preview.methodName) + q)
359- if (info.group.isNotBlank()) {
360- parts.add(q + "group" + q + ": " + q + escapeJson(info.group) + q)
361- }
362- if (info.name.isNotBlank()) {
363- parts.add(q + "previewName" + q + ": " + q + escapeJson(info.name) + q)
364- }
365- if (info.locale.isNotBlank()) {
366- parts.add(q + "locale" + q + ": " + q + escapeJson(info.locale) + q)
367- }
368- if (info.device.isNotBlank()) {
369- parts.add(q + "device" + q + ": " + q + escapeJson(info.device) + q)
370- }
371- val nightMode = info.uiMode and 0x30 == 0x20
372- parts.add(q + "nightMode" + q + ": " + if (nightMode) "true" else "false")
373- if (info.fontScale != 1f) {
374- parts.add(q + "fontScale" + q + ": " + info.fontScale)
375- }
376- if (info.apiLevel != -1) {
377- parts.add(q + "apiLevel" + q + ": " + info.apiLevel)
378- }
379- if (info.widthDp > 0) {
380- parts.add(q + "widthDp" + q + ": " + info.widthDp)
381- }
382- if (info.heightDp > 0) {
383- parts.add(q + "heightDp" + q + ": " + info.heightDp)
384- }
385- if (info.showSystemUi) {
386- parts.add(q + "showSystemUi" + q + ": true")
387- }
388- if (info.showBackground) {
389- parts.add(q + "showBackground" + q + ": true")
345+ val metadata = linkedMapOf<String, Any>(
346+ "display_name" to screenshotId,
347+ "image_file_name" to screenshotId,
348+ "className" to preview.declaringClass,
349+ "methodName" to preview.methodName,
350+ )
351+ if (info.group.isNotBlank()) metadata["group"] = info.group
352+ if (info.name.isNotBlank()) metadata["previewName"] = info.name
353+ if (info.locale.isNotBlank()) metadata["locale"] = info.locale
354+ if (info.device.isNotBlank()) metadata["device"] = info.device
355+ metadata["nightMode"] = (info.uiMode and 0x30 == 0x20)
356+ if (info.fontScale != 1f) metadata["fontScale"] = info.fontScale
357+ if (info.apiLevel != -1) metadata["apiLevel"] = info.apiLevel
358+ if (info.widthDp > 0) metadata["widthDp"] = info.widthDp
359+ if (info.heightDp > 0) metadata["heightDp"] = info.heightDp
360+ if (info.showSystemUi) metadata["showSystemUi"] = true
361+ if (info.showBackground) metadata["showBackground"] = true
362+
363+ val json = metadata.entries.joinToString(",\n ", prefix = "{\n ", postfix = "\n}") { (k, v) ->
364+ if (v is String) "\"" + k + "\": \"" + escapeJson(v) + "\""
365+ else "\"" + k + "\": " + v
390366 }
391- val json = parts.joinToString(",\n ", prefix = "{\n ", postfix = "\n}")
392367 val sidecarName = "Paparazzi_Preview_Test_" +
393368 screenshotId.lowercase(Locale.US).replace("\\s".toRegex(), "_")
394369 File(imagesDir, "${' $' } {sidecarName}.json").writeText(json)
0 commit comments