Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,43 @@ class WriteKotlinWarningBaselineTaskTest {
assertThat(baselineFile.readText()).doesNotContain("w: file:///")
}

@Test
fun `if all files are cleaned up in baseline, baseline is deleted`() {
val project = BasicAndroidProject.getComposeProject()

val generateTask = ":android:releaseWriteKotlinWarningBaseline"
val generateResult = project.execute(generateTask)

assertThat(generateResult).task(generateTask).succeeded()
val baselineFile = project.projectDir(":android").resolve("warning-baseline-release-android.txt")
assertThat(baselineFile.toFile()).exists()
assertThat(baselineFile.readText())
.contains("TestComposable.kt:6:20 Condition 'test != null' is always 'true")

project
.projectDir("android")
.resolve("src/main/kotlin/com/example/myapplication/TestComposable.kt")
.toFile()
.writeText(
"""
package com.example.myapplication

class AndroidApp {
init {
val test = "hello"
println(test)
}
}
"""
.trimIndent(),
)

val newGenerateResult = project.execute(generateTask)

assertThat(newGenerateResult).task(generateTask).succeeded()
assertThat(baselineFile).doesNotExist()
}

@Test
fun `write generates no baseline if no warnings exist`() {
val project = BasicAndroidProject.getComposeProject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,29 @@ public abstract class KotlinWarningBaselineGeneratorService :
projectName,
) ?: emptySet()

if (content.isNotEmpty()) {
val warningFileCollector = warningFileCollectors[projectName]
val filePathToWriteTo = if (isWriteTask) {
baselineFilePaths[projectName]
} else if (isCheckTask) {
warningFilePaths[projectName]
val warningFileCollector = warningFileCollectors[projectName]
val filePathToWriteTo = if (isWriteTask) {
baselineFilePaths[projectName]
} else if (isCheckTask) {
warningFilePaths[projectName]
} else {
null
}
if (filePathToWriteTo != null) {
val baselineFile = File(filePathToWriteTo)
if (content.isNotEmpty()) {
if (warningFileCollector != null) {
println("joerDebug - writing warnings to file, $filePathToWriteTo")
warningFileCollector.writeWarningsToFile(
content,
baselineFile,
)
}
} else {
null
}

if (warningFileCollector != null && filePathToWriteTo != null) {
warningFileCollector.writeWarningsToFile(
content,
File(filePathToWriteTo),
)
if (baselineFile.exists()) {
// had a baseline file previously, but no warnings, delete the file
baselineFile.delete()
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion kotlin-warning-baseline-generator/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kotlin.code.style=official

GROUP=com.joetr.kotlin.warning.baseline.generator
VERSION_NAME=1.0.2
VERSION_NAME=1.0.3
YEAR=2024
DISPLAY_NAME=Kotlin Warning Baseline Generator
DESCRIPTION=A Gradle plugin for creating baselines from Kotlin warnings
Expand Down
6 changes: 3 additions & 3 deletions sandbox-android-app/app/warning-baseline-release-android.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file was automatically generated by the Kotlin Warning Baseline Generator Plugin
# and should not be edited manually.

ExampleInstrumentedTest.kt:10:12 Condition is always 'true'.
ExampleUnitTest.kt:16:12 Condition is always 'true'.
MainActivity.kt:25:12 Condition is always 'true'.
.../src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.kt:10:12 Condition is always 'true'.
.../src/main/java/com/example/myapplication/MainActivity.kt:25:12 Condition is always 'true'.
.../src/test/java/com/example/myapplication/ExampleUnitTest.kt:16:12 Condition is always 'true'.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file was automatically generated by the Kotlin Warning Baseline Generator Plugin
# and should not be edited manually.

w: file:///Users/joeroskopf/Code/KotlinWarningBaselineGeneratorGithub/KotlinWarningBaselineGenerator/sandbox-android-app/feature/src/main/kotlin/com/example/myapplication/feature/MyComposable.kt:13:8 Condition is always 'true'.
w: file:///Users/joeroskopf/Code/KotlinWarningBaselineGeneratorGithub/KotlinWarningBaselineGenerator/sandbox-android-app/feature/src/test/java/com/example/myapplication/ExampleUnitTest.kt:31:12 Condition is always 'true'.
.../src/main/kotlin/com/example/myapplication/feature/MyComposable.kt:13:8 Condition is always 'true'.
.../src/test/java/com/example/myapplication/ExampleUnitTest.kt:31:12 Condition is always 'true'.
Loading