-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
250 additions
and
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,4 +44,4 @@ tasks.check { | |
rootProject.allprojects { | ||
dependsOn(tasks.withType<CodeOwnersReportTask>()) | ||
} | ||
} | ||
} |
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
3 changes: 3 additions & 0 deletions
3
...in/src/compatibilityTest/kotlin/io/github/gmazzo/codeowners/CodeOwnersPluginCompatTest.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,3 @@ | ||
package io.github.gmazzo.codeowners | ||
|
||
class CodeOwnersPluginCompatTest : CodeOwnersBaseCompatTest("io.github.gmazzo.codeowners") |
37 changes: 0 additions & 37 deletions
37
...ins/base-plugin/src/test/kotlin/io/github/gmazzo/codeowners/CodeOwnersPluginCompatTest.kt
This file was deleted.
Oops, something went wrong.
119 changes: 119 additions & 0 deletions
119
...se-plugin/src/testFixtures/kotlin/io/github/gmazzo/codeowners/CodeOwnersBaseCompatTest.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,119 @@ | ||
package io.github.gmazzo.codeowners | ||
|
||
import org.gradle.testkit.runner.GradleRunner | ||
import org.gradle.testkit.runner.TaskOutcome | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.params.ParameterizedTest | ||
import org.junit.jupiter.params.provider.EnumSource | ||
import java.io.File | ||
|
||
abstract class CodeOwnersBaseCompatTest( | ||
private val pluginId: String, | ||
) { | ||
|
||
@Suppress("EnumEntryName") | ||
enum class Kind(val kotlin: Boolean, val android: Boolean) { | ||
alone(false, false), | ||
withKotlin(true, false), | ||
withAndroid(false, true), | ||
withBoth(true, true) | ||
} | ||
|
||
@ParameterizedTest(name = "{0}") | ||
@EnumSource(Kind::class) | ||
open fun `plugin can be applied with given classpath`(kind: Kind) { | ||
val rootDir = File(kind.name) | ||
rootDir.deleteRecursively() | ||
rootDir.mkdirs() | ||
|
||
val plugins = when (kind) { | ||
Kind.alone -> "java" | ||
Kind.withKotlin -> "id(\"org.jetbrains.kotlin.jvm\")" | ||
Kind.withAndroid -> "id(\"com.android.application\")" | ||
Kind.withBoth -> """ | ||
id("com.android.application") | ||
id("org.jetbrains.kotlin.android") | ||
""".trimIndent() | ||
} | ||
|
||
val buildFile = File(rootDir, "build.gradle.kts") | ||
buildFile.writeText( | ||
""" | ||
plugins { | ||
$plugins | ||
id("$pluginId") | ||
} | ||
configurations.all { | ||
exclude("io.github.gmazzo.codeowners", "jvm-core") | ||
exclude("io.github.gmazzo.codeowners", "kotlin-core") | ||
} | ||
""".trimIndent() | ||
) | ||
|
||
if (kind.android) { | ||
buildFile.appendText( | ||
""" | ||
android { | ||
namespace = "org.test" | ||
compileSdk = 30 | ||
defaultConfig { | ||
minSdk = 21 | ||
targetSdk = 30 | ||
} | ||
} | ||
""".trimIndent() | ||
) | ||
|
||
File(rootDir, "src/main/AndroidManifest.xml") | ||
.apply { parentFile.mkdirs() } | ||
.writeText("<manifest/>") | ||
} | ||
|
||
File(rootDir, "settings.gradle.kts").writeText( | ||
""" | ||
pluginManagement { | ||
repositories { | ||
gradlePluginPortal() | ||
mavenCentral() | ||
google() | ||
} | ||
} | ||
dependencyResolutionManagement { | ||
repositories { | ||
mavenCentral() | ||
google() | ||
} | ||
} | ||
rootProject.name = "test" | ||
include(":app") | ||
""".trimIndent() | ||
) | ||
|
||
File(rootDir, "CODEOWNERS").createNewFile() | ||
|
||
val build = GradleRunner.create() | ||
.withProjectDir(rootDir) | ||
.withPluginClasspath("/$kind.classpath") | ||
.withArguments("codeOwnersReport", "-s") | ||
.build() | ||
|
||
assertEquals( | ||
if (kind.android) TaskOutcome.SUCCESS else TaskOutcome.NO_SOURCE, | ||
build.task(":codeOwnersReport")?.outcome | ||
) | ||
} | ||
|
||
fun GradleRunner.withPluginClasspath(fromResource: String) = apply { | ||
withPluginClasspath( | ||
javaClass.getResource(fromResource)!!.readText() | ||
.splitToSequence(File.pathSeparatorChar) | ||
.map(::File) | ||
.toList() | ||
) | ||
} | ||
|
||
} |
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
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 |
---|---|---|
@@ -1,16 +1,22 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
alias(libs.plugins.buildConfig) | ||
} | ||
|
||
repositories { | ||
gradlePluginPortal() | ||
} | ||
|
||
dependencies { | ||
fun plugin(dep: Provider<PluginDependency>) = with(dep.get()) { | ||
create("$pluginId:$pluginId.gradle.plugin:$version") | ||
} | ||
fun plugin(dep: Provider<PluginDependency>) = dep.map { | ||
"${it.pluginId}:${it.pluginId}.gradle.plugin:${it.version}" | ||
} | ||
|
||
dependencies { | ||
implementation(plugin(libs.plugins.buildConfig)) | ||
implementation(plugin(libs.plugins.dokka)) | ||
} | ||
|
||
buildConfig { | ||
buildConfigField("KOTLIN_PLUGIN", plugin(libs.plugins.kotlin.jvm)) | ||
buildConfigField("ANDROID_PLUGIN", plugin(libs.plugins.android.application)) | ||
} |
75 changes: 75 additions & 0 deletions
75
plugins/buildSrc/src/main/kotlin/plugin-compatibility-test.gradle.kts
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,75 @@ | ||
import buildSrc.BuildConfig | ||
|
||
plugins { | ||
`java-gradle-plugin` | ||
} | ||
|
||
val compatibilityTest by testing.suites.registering(JvmTestSuite::class) { | ||
dependencies { | ||
implementation(testFixtures(project(":base-plugin"))) | ||
} | ||
targets.configureEach { | ||
testTask.configure { | ||
javaLauncher = javaToolchains.launcherFor { languageVersion = JavaLanguageVersion.of(17) } | ||
workingDir(temporaryDir) | ||
} | ||
} | ||
} | ||
|
||
val compatibilityTestSelfPlugin by configurations.creating | ||
val compatibilityTestKotlinPlugin by configurations.creating | ||
val compatibilityTestAndroidPlugin by configurations.creating | ||
|
||
dependencies { | ||
compatibilityTestSelfPlugin(project) | ||
compatibilityTestKotlinPlugin(BuildConfig.KOTLIN_PLUGIN) | ||
compatibilityTestAndroidPlugin(BuildConfig.ANDROID_PLUGIN) | ||
} | ||
|
||
val collectPluginMetadata by tasks.registering(CollectDependencies::class) { | ||
aloneClasspath.from(compatibilityTestSelfPlugin) | ||
kotlinClasspath.from(compatibilityTestSelfPlugin, compatibilityTestKotlinPlugin) | ||
androidClasspath.from(compatibilityTestSelfPlugin, compatibilityTestAndroidPlugin) | ||
bothClasspath.from(compatibilityTestSelfPlugin, compatibilityTestKotlinPlugin, compatibilityTestAndroidPlugin) | ||
outputDirectory.set(temporaryDir) | ||
} | ||
|
||
sourceSets.named(::compatibilityTest.name) { | ||
resources.srcDirs(collectPluginMetadata) | ||
} | ||
|
||
tasks.check { | ||
dependsOn(compatibilityTest) | ||
} | ||
|
||
@CacheableTask | ||
abstract class CollectDependencies : DefaultTask() { | ||
|
||
@get:Classpath | ||
abstract val aloneClasspath: ConfigurableFileCollection | ||
|
||
@get:Classpath | ||
abstract val kotlinClasspath: ConfigurableFileCollection | ||
|
||
@get:Classpath | ||
abstract val androidClasspath: ConfigurableFileCollection | ||
|
||
@get:Classpath | ||
abstract val bothClasspath: ConfigurableFileCollection | ||
|
||
@get:OutputDirectory | ||
abstract val outputDirectory: DirectoryProperty | ||
|
||
@TaskAction | ||
fun generateResources() { | ||
val outDir = outputDirectory.get().asFile | ||
outDir.deleteRecursively() | ||
outDir.mkdirs() | ||
|
||
File(outDir, "alone.classpath").writeText(aloneClasspath.asPath) | ||
File(outDir, "withKotlin.classpath").writeText(kotlinClasspath.asPath) | ||
File(outDir, "withAndroid.classpath").writeText(androidClasspath.asPath) | ||
File(outDir, "withBoth.classpath").writeText(bothClasspath.asPath) | ||
} | ||
|
||
} |
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
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
3 changes: 3 additions & 0 deletions
3
...src/compatibilityTest/kotlin/io/github/gmazzo/codeowners/CodeOwnersJVMPluginCompatTest.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,3 @@ | ||
package io.github.gmazzo.codeowners | ||
|
||
class CodeOwnersJVMPluginCompatTest : CodeOwnersBaseCompatTest("io.github.gmazzo.codeowners.jvm") |
Oops, something went wrong.