Skip to content

Commit 4de530a

Browse files
authored
Revert JVM tasks configuration changes introduced in #200 (#212)
* Rollback task skipping logic based on srcset emptyness check for JVM tasks
1 parent f3b53bb commit 4de530a

File tree

6 files changed

+130
-5
lines changed

6 files changed

+130
-5
lines changed

src/functionalTest/kotlin/kotlinx/validation/api/Assert.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ internal fun BuildResult.assertTaskSkipped(task: String) {
3131
assertTaskOutcome(TaskOutcome.SKIPPED, task)
3232
}
3333

34+
/**
35+
* Helper `fun` for asserting a [TaskOutcome] to be equal to [TaskOutcome.UP_TO_DATE]
36+
*/
37+
internal fun BuildResult.assertTaskUpToDate(task: String) {
38+
assertTaskOutcome(TaskOutcome.UP_TO_DATE, task)
39+
}
40+
3441
private fun BuildResult.assertTaskOutcome(taskOutcome: TaskOutcome, taskName: String) {
3542
assertEquals(taskOutcome, task(taskName)?.outcome)
3643
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2016-2024 JetBrains s.r.o.
3+
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
4+
*/
5+
6+
package kotlinx.validation.test
7+
8+
import kotlinx.validation.api.*
9+
import kotlinx.validation.api.resolve
10+
import kotlinx.validation.api.test
11+
import org.assertj.core.api.Assertions
12+
import org.junit.Test
13+
14+
class JvmProjectTests : BaseKotlinGradleTest() {
15+
@Test
16+
fun `apiDump for a project with generated sources only`() {
17+
val runner = test {
18+
buildGradleKts {
19+
resolve("/examples/gradle/base/withPlugin.gradle.kts")
20+
resolve("/examples/gradle/configuration/generatedSources/generatedJvmSources.gradle.kts")
21+
}
22+
// TODO: enable configuration cache back when we start skipping tasks correctly
23+
runner(withConfigurationCache = false) {
24+
arguments.add(":apiDump")
25+
}
26+
}
27+
runner.build().apply {
28+
assertTaskSuccess(":apiDump")
29+
30+
val expectedApi = readFileList("/examples/classes/GeneratedSources.dump")
31+
Assertions.assertThat(rootProjectApiDump.readText()).isEqualToIgnoringNewLines(expectedApi)
32+
}
33+
}
34+
35+
@Test
36+
fun `apiCheck for a project with generated sources only`() {
37+
val runner = test {
38+
buildGradleKts {
39+
resolve("/examples/gradle/base/withPlugin.gradle.kts")
40+
resolve("/examples/gradle/configuration/generatedSources/generatedJvmSources.gradle.kts")
41+
}
42+
apiFile(projectName = rootProjectDir.name) {
43+
resolve("/examples/classes/GeneratedSources.dump")
44+
}
45+
// TODO: enable configuration cache back when we start skipping tasks correctly
46+
runner(withConfigurationCache = false) {
47+
arguments.add(":apiCheck")
48+
}
49+
}
50+
runner.build().apply {
51+
assertTaskSuccess(":apiCheck")
52+
}
53+
}
54+
}

src/functionalTest/kotlin/kotlinx/validation/test/MultiPlatformSingleJvmKlibTargetTest.kt renamed to src/functionalTest/kotlin/kotlinx/validation/test/MultiPlatformSingleJvmTargetTest.kt

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
/*
2-
* Copyright 2016-2021 JetBrains s.r.o.
2+
* Copyright 2016-2024 JetBrains s.r.o.
33
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
44
*/
55

66
package kotlinx.validation.test
77

88
import kotlinx.validation.api.*
99
import org.assertj.core.api.Assertions.assertThat
10+
import org.gradle.testkit.runner.TaskOutcome
1011
import org.junit.Test
1112
import java.io.File
1213

13-
internal class MultiPlatformSingleJvmKlibTargetTest : BaseKotlinGradleTest() {
14+
internal class MultiPlatformSingleJvmTargetTest : BaseKotlinGradleTest() {
1415
private fun BaseKotlinScope.createProjectHierarchyWithPluginOnRoot() {
1516
settingsGradleKts {
1617
resolve("/examples/gradle/settings/settings-name-testproject.gradle.kts")
@@ -116,6 +117,45 @@ internal class MultiPlatformSingleJvmKlibTargetTest : BaseKotlinGradleTest() {
116117
}
117118
}
118119

120+
@Test
121+
fun testApiDumpPassesForEmptyProject() {
122+
val runner = test {
123+
buildGradleKts {
124+
resolve("/examples/gradle/base/multiplatformWithSingleJvmTarget.gradle.kts")
125+
}
126+
127+
runner {
128+
arguments.add(":apiDump")
129+
}
130+
}
131+
132+
runner.build().apply {
133+
assertTaskSkipped(":jvmApiDump")
134+
assertTaskUpToDate(":apiDump")
135+
}
136+
}
137+
138+
@Test
139+
fun testApiCheckPassesForEmptyProject() {
140+
val runner = test {
141+
buildGradleKts {
142+
resolve("/examples/gradle/base/multiplatformWithSingleJvmTarget.gradle.kts")
143+
}
144+
145+
emptyApiFile(projectName = rootProjectDir.name)
146+
147+
runner {
148+
arguments.add(":apiCheck")
149+
}
150+
}
151+
152+
runner.build().apply {
153+
assertTaskSkipped(":jvmApiCheck")
154+
assertTaskUpToDate(":apiCheck")
155+
156+
}
157+
}
158+
119159
private val jvmApiDump: File get() = rootProjectDir.resolve("$API_DIR/testproject.api")
120160

121161
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public final class Generated {
2+
public fun <init> ()V
3+
public final fun helloCreator ()I
4+
}
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
abstract class GenerateSourcesTask : org.gradle.api.DefaultTask() {
2+
@get:org.gradle.api.tasks.OutputDirectory
3+
abstract val outputDirectory: org.gradle.api.file.DirectoryProperty
4+
5+
@org.gradle.api.tasks.TaskAction
6+
fun generate() {
7+
outputDirectory.asFile.get().mkdirs()
8+
outputDirectory.file("Generated.kt").get().asFile.writeText("""
9+
public class Generated { public fun helloCreator(): Int = 42 }
10+
""".trimIndent())
11+
}
12+
}
13+
14+
val srcgen = project.tasks.register("generateSources", GenerateSourcesTask::class.java)
15+
srcgen.configure {
16+
outputDirectory.set(project.layout.buildDirectory.get().dir("generated").dir("kotlin"))
17+
}
18+
19+
project.sourceSets.getByName("main") {
20+
kotlin.srcDir(srcgen)
21+
}

src/main/kotlin/BinaryCompatibilityValidatorPlugin.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,7 @@ private fun Project.configureKotlinCompilation(
219219

220220
val apiBuild = task<KotlinApiBuildTask>(targetConfig.apiTaskName("Build")) {
221221
// Do not enable task for empty umbrella modules
222-
isEnabled = apiCheckEnabled(projectName, extension)
223-
val hasSourcesPredicate = compilation.hasAnySourcesPredicate()
224-
onlyIf { hasSourcesPredicate.get() }
222+
isEnabled = apiCheckEnabled(projectName, extension) && compilation.hasAnySources()
225223
// 'group' is not specified deliberately, so it will be hidden from ./gradlew tasks
226224
description =
227225
"Builds Kotlin API for 'main' compilations of $projectName. Complementary task and shouldn't be called manually"

0 commit comments

Comments
 (0)