Skip to content

Commit 2a878f1

Browse files
committed
bumped to kotlin 2.0.0-Beta5, included the compiler plugin with tests as separate module
1 parent 4f8d874 commit 2a878f1

File tree

32 files changed

+1338
-61
lines changed

32 files changed

+1338
-61
lines changed

build.gradle.kts

+38
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
@file:Suppress("UnstableApiUsage")
22

3+
import Projects.compilerPlugin
4+
import Projects.gradlePlugin
5+
import com.github.gmazzo.buildconfig.BuildConfigExtension
6+
7+
38
buildscript {
49
repositories {
510
mavenCentral()
@@ -15,6 +20,7 @@ plugins {
1520
dokka version Versions.dokka
1621
idea
1722
kotlin version Versions.kotlin apply false
23+
buildconfig version Versions.buildconfig apply false
1824
}
1925

2026
group = Versions.groupID
@@ -113,4 +119,36 @@ allprojects {
113119
}
114120
}
115121
}
122+
}
123+
124+
subprojects {
125+
afterEvaluate {
126+
extensions.findByType<BuildConfigExtension>()?.apply {
127+
val projectVersion = Versions.project
128+
val groupId = Versions.groupID
129+
130+
val compilerPluginId = "$groupId.compilerPlugin"
131+
132+
val compilerPluginArtifactId = compilerPlugin.name
133+
val gradlePluginArtifactId = gradlePlugin.name
134+
135+
val defaultSparkifyFqName = "$groupId.plugin.annotations.Sparkify"
136+
val defaultColumnNameFqName = "$groupId.plugin.annotations.ColumnName"
137+
138+
val projectRoot = project.rootDir.absolutePath
139+
140+
packageName(groupId)
141+
className("Artifacts")
142+
143+
buildConfigField("compilerPluginId", compilerPluginId)
144+
buildConfigField("groupId", groupId)
145+
buildConfigField("gradlePluginArtifactId", gradlePluginArtifactId)
146+
buildConfigField("projectVersion", projectVersion)
147+
buildConfigField("compilerPluginArtifactId", compilerPluginArtifactId)
148+
149+
buildConfigField("defaultSparkifyFqName", defaultSparkifyFqName)
150+
buildConfigField("defaultColumnNameFqName", defaultColumnNameFqName)
151+
buildConfigField("projectRoot", projectRoot)
152+
}
153+
}
116154
}

buildSrc/src/main/kotlin/Dependencies.kt

+14-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@ object Dependencies {
99
inline val hadoopClient get() = "org.apache.hadoop:hadoop-client:${Versions.hadoop}"
1010
inline val sparkRepl get() = "org.apache.spark:spark-repl_${Versions.scalaCompat}:${Versions.spark}"
1111
inline val jupyter get() = "org.jetbrains.kotlinx:kotlin-jupyter-api:${Versions.jupyter}"
12-
inline val junit get() = "org.junit.jupiter:junit-jupiter-engine:5.8.1"
12+
inline val junitJupiterEngine get() = "org.junit.jupiter:junit-jupiter-engine:${Versions.junitJupiterEngine}"
13+
// must be platform()
14+
inline val junitBom get() = "org.junit:junit-bom:${Versions.junitJupiterEngine}"
15+
inline val junitJupiter get() = "org.junit.jupiter:junit-jupiter"
16+
inline val junitPlatformCommons get() = "org.junit.platform:junit-platform-commons"
17+
inline val junitPlatformLauncher get() = "org.junit.platform:junit-platform-launcher"
18+
inline val junitPlatformRunner get() = "org.junit.platform:junit-platform-runner"
19+
inline val junitPlatformSuiteApi get() = "org.junit.platform:junit-platform-suite-api"
20+
21+
inline val junit get() = "junit:junit:${Versions.junit}"
1322
inline val sparkStreamingKafka get() = "org.apache.spark:spark-streaming-kafka-0-10_${Versions.scalaCompat}:${Versions.spark}"
1423
inline val kotest get() = "io.kotest:kotest-runner-junit5:${Versions.kotest}"
1524
inline val kotestTestcontainers get() = "io.kotest.extensions:kotest-extensions-testcontainers:${Versions.kotestTestContainers}"
@@ -22,6 +31,10 @@ object Dependencies {
2231
inline val kotlinScriptingJvm get() = "org.jetbrains.kotlin:kotlin-scripting-jvm"
2332
inline val jacksonDatabind get() = "com.fasterxml.jackson.core:jackson-databind:${Versions.jacksonDatabind}"
2433
inline val kotlinDateTime get() = "org.jetbrains.kotlinx:kotlinx-datetime:${Versions.kotlinxDateTime}"
34+
inline val kotlinCompiler get() = "org.jetbrains.kotlin:kotlin-compiler:${Versions.kotlin}"
35+
inline val kotlinScriptRuntime get() = "org.jetbrains.kotlin:kotlin-script-runtime:${Versions.kotlin}"
36+
inline val kotlinAnnotationsJvm get() = "org.jetbrains.kotlin:kotlin-annotations-jvm:${Versions.kotlin}"
37+
inline val kotlinCompilerInternalTestFramework get() = "org.jetbrains.kotlin:kotlin-compiler-internal-test-framework:${Versions.kotlin}"
2538
}
2639

2740

buildSrc/src/main/kotlin/Helpers.kt

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ fun DependencyHandler.testImplementation(vararg dependencyNotations: Any): List<
1818
add("testImplementation", it)
1919
}
2020

21+
fun DependencyHandler.testRuntimeOnly(vararg dependencyNotations: Any): List<Dependency?> =
22+
dependencyNotations.map {
23+
add("testRuntimeOnly", it)
24+
}
25+
2126
fun DependencyHandler.implementation(vararg dependencyNotations: Any): List<Dependency?> =
2227
dependencyNotations.map {
2328
add("implementation", it)

buildSrc/src/main/kotlin/Plugins.kt

+3
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ inline val Project.mavenPublishBase
3333
inline val PluginDependenciesSpec.jupyter
3434
get() = kotlin("jupyter.api") version Versions.jupyter
3535

36+
inline val PluginDependenciesSpec.buildconfig
37+
get() = id("com.github.gmazzo.buildconfig")
38+

buildSrc/src/main/kotlin/Projects.kt

+6
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,10 @@ object Projects {
2626

2727
inline val Project.scalaTuplesInKotlin
2828
get() = searchProject("scala-tuples-in-kotlin")
29+
30+
inline val Project.compilerPlugin
31+
get() = searchProject("compiler-plugin")
32+
33+
inline val Project.gradlePlugin
34+
get() = searchProject("gradle-plugin")
2935
}

buildSrc/src/main/kotlin/Versions.kt

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
object Versions {
22
const val project = "1.2.5-SNAPSHOT"
33
const val groupID = "org.jetbrains.kotlinx.spark"
4-
const val kotlin = "1.9.22"
4+
const val kotlin = "2.0.0-Beta5"
55
const val jvmTarget = "8"
66
const val jupyterJvmTarget = "8"
77
inline val spark get() = System.getProperty("spark") as String
8-
98
inline val scala get() = System.getProperty("scala") as String
109
inline val sparkMinor get() = spark.substringBeforeLast('.')
11-
inline val scalaCompat get() = scala.substringBeforeLast('.')
1210

11+
inline val scalaCompat get() = scala.substringBeforeLast('.')
1312
// TODO
1413
inline val sparkConnect get() = System.getProperty("sparkConnect", "false").toBoolean()
15-
1614
const val jupyter = "0.12.0-32-1"
1715

1816
const val kotest = "5.5.4"
17+
18+
const val buildconfig = "5.3.5"
19+
20+
const val junitJupiterEngine = "5.8.1"
21+
const val junit = "4.13.2"
1922
const val kotestTestContainers = "1.3.3"
2023
const val dokka = "1.8.20"
2124
const val jcp = "7.0.5"

compiler-plugin/build.gradle.kts

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2+
3+
plugins {
4+
java
5+
kotlin
6+
mavenPublishBase
7+
buildconfig
8+
}
9+
10+
group = Versions.groupID
11+
version = Versions.project
12+
13+
repositories {
14+
mavenCentral()
15+
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap")
16+
}
17+
18+
sourceSets {
19+
test {
20+
val srcDirs = listOf("src/test-gen/kotlin")
21+
kotlin.srcDirs(srcDirs)
22+
java.srcDirs(srcDirs)
23+
}
24+
}
25+
26+
dependencies {
27+
with(Dependencies) {
28+
compileOnly(kotlinCompiler)
29+
30+
testRuntimeOnly(
31+
kotlinTest,
32+
kotlinScriptRuntime,
33+
kotlinAnnotationsJvm,
34+
)
35+
36+
testImplementation(
37+
kotlinCompiler,
38+
reflect,
39+
kotlinCompilerInternalTestFramework,
40+
junit,
41+
42+
platform(junitBom),
43+
junitJupiter,
44+
junitPlatformCommons,
45+
junitPlatformLauncher,
46+
junitPlatformRunner,
47+
junitPlatformSuiteApi,
48+
)
49+
}
50+
}
51+
52+
tasks.test {
53+
useJUnitPlatform()
54+
doFirst {
55+
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-stdlib", "kotlin-stdlib")
56+
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-stdlib-jdk8", "kotlin-stdlib-jdk8")
57+
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-reflect", "kotlin-reflect")
58+
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-test", "kotlin-test")
59+
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-script-runtime", "kotlin-script-runtime")
60+
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-annotations-jvm", "kotlin-annotations-jvm")
61+
}
62+
}
63+
64+
tasks.withType<KotlinCompile>().configureEach {
65+
kotlinOptions {
66+
languageVersion = "2.0"
67+
freeCompilerArgs = freeCompilerArgs +
68+
"-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi" +
69+
"-Xcontext-receivers"
70+
}
71+
}
72+
73+
val generateTests by tasks.creating(JavaExec::class) {
74+
classpath = sourceSets.test.get().runtimeClasspath
75+
mainClass.set("org.jetbrains.kotlinx.spark.compilerPlugin.GenerateTestsKt")
76+
}
77+
78+
val compileTestKotlin by tasks.getting {
79+
doLast {
80+
generateTests.exec()
81+
}
82+
}
83+
84+
fun Test.setLibraryProperty(propName: String, jarName: String) {
85+
val path = project.configurations
86+
.testRuntimeClasspath.get()
87+
.files
88+
.find { """$jarName-\d.*jar""".toRegex().matches(it.name) }
89+
?.absolutePath
90+
?: return
91+
systemProperty(propName, path)
92+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.jetbrains.kotlinx.spark.compilerPlugin
2+
3+
import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrar
4+
5+
// Potential future K2 FIR hook
6+
class SimplePluginRegistrar(private val sparkifyAnnotationFqNames: List<String>) : FirExtensionRegistrar() {
7+
override fun ExtensionRegistrarContext.configurePlugin() {}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package org.jetbrains.kotlinx.spark.compilerPlugin
2+
3+
import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption
4+
import org.jetbrains.kotlin.compiler.plugin.CliOption
5+
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
6+
import org.jetbrains.kotlin.config.CompilerConfiguration
7+
import org.jetbrains.kotlin.config.CompilerConfigurationKey
8+
import org.jetbrains.kotlinx.spark.Artifacts
9+
10+
open class SparkifyCommandLineProcessor : CommandLineProcessor {
11+
12+
init {
13+
println("SparkifyCommandLineProcessor loaded")
14+
}
15+
16+
override val pluginId: String = Artifacts.compilerPluginId
17+
18+
override val pluginOptions: Collection<AbstractCliOption> = listOf(
19+
OPTION_ENABLED,
20+
OPTION_SPARKIFY_ANNOTATION_FQ_NAMES,
21+
OPTION_COLUMN_NAME_ANNOTATION_FQ_NAMES,
22+
)
23+
24+
override fun processOption(option: AbstractCliOption, value: String, configuration: CompilerConfiguration) {
25+
when (val optionName = option.optionName) {
26+
OPTION_ENABLED.optionName ->
27+
configuration.put(KEY_ENABLED, value.toBoolean())
28+
29+
OPTION_SPARKIFY_ANNOTATION_FQ_NAMES.optionName ->
30+
configuration.put(KEY_SPARKIFY_ANNOTATION_FQ_NAMES, value.split(",").map { it.trim() })
31+
32+
OPTION_COLUMN_NAME_ANNOTATION_FQ_NAMES.optionName ->
33+
configuration.put(KEY_COLUMN_NAME_ANNOTATION_FQ_NAMES, value.split(",").map { it.trim() })
34+
35+
else -> error("Unexpected option: $optionName")
36+
}
37+
}
38+
}
39+
40+
internal val KEY_ENABLED = CompilerConfigurationKey<Boolean>("Whether to enable Sparkify")
41+
42+
internal val OPTION_ENABLED = CliOption(
43+
optionName = "enabled",
44+
valueDescription = "<true|false>",
45+
description = "Whether to enable Sparkify",
46+
required = false,
47+
allowMultipleOccurrences = false,
48+
)
49+
50+
internal val KEY_SPARKIFY_ANNOTATION_FQ_NAMES = CompilerConfigurationKey<List<String>>(
51+
"Fully qualified names of annotations for Sparkify"
52+
)
53+
54+
internal val OPTION_SPARKIFY_ANNOTATION_FQ_NAMES = CliOption(
55+
optionName = "sparkifyAnnotationFqNames",
56+
valueDescription = "<fqName1,fqName2,...>",
57+
description = "Fully qualified names of annotations to sparkify",
58+
required = false,
59+
allowMultipleOccurrences = false,
60+
)
61+
62+
internal val KEY_COLUMN_NAME_ANNOTATION_FQ_NAMES = CompilerConfigurationKey<List<String>>(
63+
"Fully qualified names of annotations for ColumnName"
64+
)
65+
66+
internal val OPTION_COLUMN_NAME_ANNOTATION_FQ_NAMES = CliOption(
67+
optionName = "columnNameAnnotationFqNames",
68+
valueDescription = "<fqName1,fqName2,...>",
69+
description = "Fully qualified names of annotations for ColumnName",
70+
required = false,
71+
allowMultipleOccurrences = false,
72+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.jetbrains.kotlinx.spark.compilerPlugin
2+
3+
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
4+
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
5+
import org.jetbrains.kotlin.config.CompilerConfiguration
6+
import org.jetbrains.kotlinx.spark.Artifacts
7+
import org.jetbrains.kotlinx.spark.compilerPlugin.ir.SparkifyIrGenerationExtension
8+
9+
open class SparkifyCompilerPluginRegistrar: CompilerPluginRegistrar() {
10+
init {
11+
println("SparkifyCompilerPluginRegistrar loaded")
12+
}
13+
14+
override val supportsK2: Boolean
15+
get() = true
16+
17+
override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
18+
if (configuration.get(KEY_ENABLED) != true) return
19+
20+
val sparkifyAnnotationFqNames = configuration.get(KEY_SPARKIFY_ANNOTATION_FQ_NAMES)
21+
?: listOf(Artifacts.defaultSparkifyFqName)
22+
23+
val columnNameAnnotationFqNames = configuration.get(KEY_COLUMN_NAME_ANNOTATION_FQ_NAMES)
24+
?: listOf(Artifacts.defaultColumnNameFqName)
25+
26+
IrGenerationExtension.registerExtension(
27+
SparkifyIrGenerationExtension(
28+
sparkifyAnnotationFqNames = sparkifyAnnotationFqNames,
29+
columnNameAnnotationFqNames = columnNameAnnotationFqNames,
30+
)
31+
)
32+
}
33+
}

0 commit comments

Comments
 (0)