-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the plugin work with Kotlin multiplatform for multiple targets: * Rename tasks to include the target (except for the JVM - for backwards compatibility) * Rather than having separate tasks where some use the original name, just have two collector tasks "apiDump" and "apiCheck" that depend on the platform-specific versions. It improves consistency, compatibility, and usability. * Store and build .api files in subdirectories named after the target Author: Paul de Vrieze <paul.devrieze@gmail.com> Co-authored-by: Vsevolod Tolstopyatov <qwwdfsad@gmail.com>
- Loading branch information
Showing
8 changed files
with
557 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/functionalTest/kotlin/kotlinx/validation/api/pluginTestRuntimeClasspath.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2016-2021 JetBrains s.r.o. | ||
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. | ||
*/ | ||
|
||
package kotlinx.validation.api | ||
|
||
import org.gradle.testkit.runner.GradleRunner | ||
import java.io.File | ||
import java.io.InputStreamReader | ||
|
||
|
||
fun GradleRunner.addPluginTestRuntimeClasspath() = apply { | ||
|
||
val cpResource = javaClass.classLoader.getResourceAsStream("plugin-classpath.txt") | ||
?.let { InputStreamReader(it) } | ||
?: throw IllegalStateException("Could not find classpath resource") | ||
|
||
val pluginClasspath = pluginClasspath + cpResource.readLines().map { File(it) } | ||
withPluginClasspath(pluginClasspath) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
src/functionalTest/kotlin/kotlinx/validation/test/MultiPlatformSingleJvmTargetTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* Copyright 2016-2021 JetBrains s.r.o. | ||
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. | ||
*/ | ||
|
||
package kotlinx.validation.test | ||
|
||
import kotlinx.validation.api.* | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.Test | ||
import java.io.File | ||
|
||
internal class MultiPlatformSingleJvmTargetTest : BaseKotlinGradleTest() { | ||
private fun BaseKotlinScope.createProjectHierarchyWithPluginOnRoot() { | ||
settingsGradleKts { | ||
resolve("examples/gradle/settings/settings-name-testproject.gradle.kts") | ||
} | ||
buildGradleKts { | ||
resolve("examples/gradle/base/multiplatformWithSingleJvmTarget.gradle.kts") | ||
} | ||
} | ||
|
||
@Test | ||
fun testApiCheckPasses() { | ||
val runner = test { | ||
createProjectHierarchyWithPluginOnRoot() | ||
runner { | ||
arguments.add(":apiCheck") | ||
arguments.add("--stacktrace") | ||
} | ||
|
||
dir("api/") { | ||
file("testproject.api") { | ||
resolve("examples/classes/Subsub1Class.dump") | ||
resolve("examples/classes/Subsub2Class.dump") | ||
} | ||
} | ||
|
||
dir("src/jvmMain/kotlin") {} | ||
kotlin("Subsub1Class.kt", "commonMain") { | ||
resolve("examples/classes/Subsub1Class.kt") | ||
} | ||
kotlin("Subsub2Class.kt", "jvmMain") { | ||
resolve("examples/classes/Subsub2Class.kt") | ||
} | ||
|
||
}.addPluginTestRuntimeClasspath() | ||
|
||
runner.build().apply { | ||
assertTaskSuccess(":apiCheck") | ||
} | ||
} | ||
|
||
@Test | ||
fun testApiCheckFails() { | ||
val runner = test { | ||
createProjectHierarchyWithPluginOnRoot() | ||
runner { | ||
arguments.add("--continue") | ||
arguments.add(":check") | ||
arguments.add("--stacktrace") | ||
} | ||
|
||
dir("api/") { | ||
file("testproject.api") { | ||
resolve("examples/classes/Subsub2Class.dump") | ||
resolve("examples/classes/Subsub1Class.dump") | ||
} | ||
} | ||
|
||
dir("src/jvmMain/kotlin") {} | ||
kotlin("Subsub1Class.kt", "commonMain") { | ||
resolve("examples/classes/Subsub1Class.kt") | ||
} | ||
kotlin("Subsub2Class.kt", "jvmMain") { | ||
resolve("examples/classes/Subsub2Class.kt") | ||
} | ||
|
||
}.addPluginTestRuntimeClasspath() | ||
|
||
runner.buildAndFail().apply { | ||
assertTaskFailure(":jvmApiCheck") | ||
assertTaskNotRun(":apiCheck") | ||
assertThat(output).contains("API check failed for project testproject") | ||
assertTaskNotRun(":check") | ||
} | ||
} | ||
|
||
@Test | ||
fun testApiDumpPasses() { | ||
val runner = test { | ||
createProjectHierarchyWithPluginOnRoot() | ||
|
||
runner { | ||
arguments.add(":apiDump") | ||
arguments.add("--stacktrace") | ||
} | ||
|
||
dir("src/jvmMain/kotlin") {} | ||
kotlin("Subsub1Class.kt", "commonMain") { | ||
resolve("examples/classes/Subsub1Class.kt") | ||
} | ||
kotlin("Subsub2Class.kt", "jvmMain") { | ||
resolve("examples/classes/Subsub2Class.kt") | ||
} | ||
|
||
}.addPluginTestRuntimeClasspath() | ||
|
||
runner.build().apply { | ||
assertTaskSuccess(":apiDump") | ||
|
||
val commonExpectedApi = readFileList("examples/classes/Subsub1Class.dump") | ||
|
||
val mainExpectedApi = commonExpectedApi + "\n" + readFileList("examples/classes/Subsub2Class.dump") | ||
assertThat(jvmApiDump.readText()).isEqualToIgnoringNewLines(mainExpectedApi) | ||
} | ||
} | ||
|
||
private val jvmApiDump: File get() = rootProjectDir.resolve("api/testproject.api") | ||
|
||
} |
140 changes: 140 additions & 0 deletions
140
src/functionalTest/kotlin/kotlinx/validation/test/MultipleJvmTargetsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/* | ||
* Copyright 2016-2021 JetBrains s.r.o. | ||
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. | ||
*/ | ||
|
||
package kotlinx.validation.test | ||
|
||
import kotlinx.validation.api.* | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.gradle.testkit.runner.GradleRunner | ||
import org.junit.Test | ||
import java.io.File | ||
import java.io.InputStreamReader | ||
|
||
internal class MultipleJvmTargetsTest : BaseKotlinGradleTest() { | ||
private fun BaseKotlinScope.createProjectHierarchyWithPluginOnRoot() { | ||
settingsGradleKts { | ||
resolve("examples/gradle/settings/settings-name-testproject.gradle.kts") | ||
} | ||
buildGradleKts { | ||
resolve("examples/gradle/base/multiplatformWithJvmTargets.gradle.kts") | ||
} | ||
} | ||
|
||
@Test | ||
fun testApiCheckPasses() { | ||
val runner = test { | ||
createProjectHierarchyWithPluginOnRoot() | ||
runner { | ||
arguments.add(":apiCheck") | ||
} | ||
|
||
dir("api/jvm/") { | ||
file("testproject.api") { | ||
resolve("examples/classes/Subsub1Class.dump") | ||
resolve("examples/classes/Subsub2Class.dump") | ||
} | ||
} | ||
|
||
dir("api/anotherJvm/") { | ||
file("testproject.api") { | ||
resolve("examples/classes/Subsub1Class.dump") | ||
} | ||
} | ||
|
||
dir("src/jvmMain/kotlin") {} | ||
kotlin("Subsub1Class.kt", "commonMain") { | ||
resolve("examples/classes/Subsub1Class.kt") | ||
} | ||
kotlin("Subsub2Class.kt", "jvmMain") { | ||
resolve("examples/classes/Subsub2Class.kt") | ||
} | ||
|
||
}.addPluginTestRuntimeClasspath() | ||
|
||
runner.build().apply { | ||
assertTaskSuccess(":apiCheck") | ||
assertTaskSuccess(":jvmApiCheck") | ||
assertTaskSuccess(":anotherJvmApiCheck") | ||
} | ||
} | ||
|
||
@Test | ||
fun testApiCheckFails() { | ||
val runner = test { | ||
createProjectHierarchyWithPluginOnRoot() | ||
runner { | ||
arguments.add("--continue") | ||
arguments.add(":check") | ||
} | ||
|
||
dir("api/jvm/") { | ||
file("testproject.api") { | ||
resolve("examples/classes/Subsub2Class.dump") | ||
resolve("examples/classes/Subsub1Class.dump") | ||
} | ||
} | ||
|
||
dir("api/anotherJvm/") { | ||
file("testproject.api") { | ||
resolve("examples/classes/Subsub2Class.dump") | ||
} | ||
} | ||
|
||
dir("src/jvmMain/kotlin") {} | ||
kotlin("Subsub1Class.kt", "commonMain") { | ||
resolve("examples/classes/Subsub1Class.kt") | ||
} | ||
kotlin("Subsub2Class.kt", "jvmMain") { | ||
resolve("examples/classes/Subsub2Class.kt") | ||
} | ||
|
||
}.addPluginTestRuntimeClasspath() | ||
|
||
runner.buildAndFail().apply { | ||
assertTaskNotRun(":apiCheck") | ||
assertTaskFailure(":jvmApiCheck") | ||
assertTaskFailure(":anotherJvmApiCheck") | ||
assertThat(output).contains("API check failed for project testproject") | ||
assertTaskNotRun(":check") | ||
} | ||
} | ||
|
||
@Test | ||
fun testApiDumpPasses() { | ||
val runner = test { | ||
createProjectHierarchyWithPluginOnRoot() | ||
|
||
runner { | ||
arguments.add(":apiDump") | ||
} | ||
|
||
dir("src/jvmMain/kotlin") {} | ||
kotlin("Subsub1Class.kt", "commonMain") { | ||
resolve("examples/classes/Subsub1Class.kt") | ||
} | ||
kotlin("Subsub2Class.kt", "jvmMain") { | ||
resolve("examples/classes/Subsub2Class.kt") | ||
} | ||
|
||
}.addPluginTestRuntimeClasspath() | ||
runner.build().apply { | ||
assertTaskSuccess(":apiDump") | ||
assertTaskSuccess(":jvmApiDump") | ||
assertTaskSuccess(":anotherJvmApiDump") | ||
|
||
System.err.println(output) | ||
|
||
val anotherExpectedApi = readFileList("examples/classes/Subsub1Class.dump") | ||
assertThat(anotherApiDump.readText()).isEqualToIgnoringNewLines(anotherExpectedApi) | ||
|
||
val mainExpectedApi = anotherExpectedApi + "\n" + readFileList("examples/classes/Subsub2Class.dump") | ||
assertThat(jvmApiDump.readText()).isEqualToIgnoringNewLines(mainExpectedApi) | ||
} | ||
} | ||
|
||
private val jvmApiDump: File get() = rootProjectDir.resolve("api/jvm/testproject.api") | ||
private val anotherApiDump: File get() = rootProjectDir.resolve("api/anotherJvm/testproject.api") | ||
|
||
} |
Oops, something went wrong.