Skip to content

Commit

Permalink
Added gradle plugin and fixed package naming errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Jolanrensen committed Mar 22, 2024
1 parent 2a878f1 commit c0a3140
Show file tree
Hide file tree
Showing 30 changed files with 251 additions and 57 deletions.
13 changes: 8 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ plugins {
idea
kotlin version Versions.kotlin apply false
buildconfig version Versions.buildconfig apply false

// Needs to be installed in the local maven repository
id("org.jetbrains.kotlinx.spark.api") version Versions.project apply false
}

group = Versions.groupID
Expand Down Expand Up @@ -127,17 +130,17 @@ subprojects {
val projectVersion = Versions.project
val groupId = Versions.groupID

val compilerPluginId = "$groupId.compilerPlugin"

val compilerPluginArtifactId = compilerPlugin.name
val gradlePluginArtifactId = gradlePlugin.name

val defaultSparkifyFqName = "$groupId.plugin.annotations.Sparkify"
val defaultColumnNameFqName = "$groupId.plugin.annotations.ColumnName"
val compilerPluginId = "$groupId.api"

val defaultSparkifyFqName = "$groupId.api.plugin.annotations.Sparkify"
val defaultColumnNameFqName = "$groupId.api.plugin.annotations.ColumnName"

val projectRoot = project.rootDir.absolutePath

packageName(groupId)
packageName("$groupId.api")
className("Artifacts")

buildConfigField("compilerPluginId", compilerPluginId)
Expand Down
4 changes: 1 addition & 3 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import org.gradle.kotlin.dsl.`kotlin-dsl`
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`kotlin-dsl`
}

repositories {
mavenCentral()
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap")
}
3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
object Dependencies {
object Dependencies : Dsl<Dependencies> {
inline val kotlinStdLib get() = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${Versions.kotlin}"
inline val reflect get() = "org.jetbrains.kotlin:kotlin-reflect:${Versions.kotlin}"
inline val scalaLibrary get() = "org.scala-lang:scala-library:${Versions.scala}"
Expand Down Expand Up @@ -35,6 +35,7 @@ object Dependencies {
inline val kotlinScriptRuntime get() = "org.jetbrains.kotlin:kotlin-script-runtime:${Versions.kotlin}"
inline val kotlinAnnotationsJvm get() = "org.jetbrains.kotlin:kotlin-annotations-jvm:${Versions.kotlin}"
inline val kotlinCompilerInternalTestFramework get() = "org.jetbrains.kotlin:kotlin-compiler-internal-test-framework:${Versions.kotlin}"
inline val kotlinGradlePlugin get() = "org.jetbrains.kotlin:kotlin-gradle-plugin"
}


Expand Down
11 changes: 10 additions & 1 deletion buildSrc/src/main/kotlin/Helpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.dsl.DependencyHandler

interface Dsl<T> {
operator fun invoke(block: T.() -> Unit) = block(this as T)
}

fun DependencyHandler.testApi(vararg dependencyNotations: Any): List<Dependency?> =
dependencyNotations.map {
add("testApi", it)
Expand Down Expand Up @@ -33,10 +37,15 @@ fun DependencyHandler.runtimeOnly(vararg dependencyNotations: Any): List<Depende
add("runtimeOnly", it)
}

fun DependencyHandler.compileOnly(vararg dependencyNotations: Any): List<Dependency?> =
dependencyNotations.map {
add("compileOnly", it)
}

fun DependencyHandler.project(
path: String,
configuration: String? = null
): ProjectDependency = project(
if (configuration != null) mapOf("path" to path, "configuration" to configuration)
else mapOf("path" to path)
) as ProjectDependency
) as ProjectDependency
5 changes: 5 additions & 0 deletions buildSrc/src/main/kotlin/Plugins.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ inline val PluginDependenciesSpec.jupyter
inline val PluginDependenciesSpec.buildconfig
get() = id("com.github.gmazzo.buildconfig")

inline val PluginDependenciesSpec.gradlePublishPlugin
get() = id("com.gradle.plugin-publish") version Versions.gradlePublishPlugin

inline val PluginDependenciesSpec.shadow
get() = id("com.github.johnrengelman.shadow") version Versions.shadow
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Projects.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.gradle.api.Project

object Projects {
object Projects : Dsl<Projects> {

inline fun Project.searchProject(name: String): Project =
rootProject
Expand Down
6 changes: 4 additions & 2 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
object Versions {
const val project = "1.2.5-SNAPSHOT"
object Versions : Dsl<Versions> {
const val project = "2.0.0-SNAPSHOT"
const val groupID = "org.jetbrains.kotlinx.spark"
const val kotlin = "2.0.0-Beta5"
const val jvmTarget = "8"
Expand All @@ -13,7 +13,9 @@ object Versions {
inline val sparkConnect get() = System.getProperty("sparkConnect", "false").toBoolean()
const val jupyter = "0.12.0-32-1"

const val gradlePublishPlugin = "1.1.0"
const val kotest = "5.5.4"
const val shadow = "8.1.1"

const val buildconfig = "5.3.5"

Expand Down
29 changes: 21 additions & 8 deletions compiler-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
java
kotlin
mavenPublishBase
mavenPublish
buildconfig
}

Expand All @@ -24,7 +25,7 @@ sourceSets {
}

dependencies {
with(Dependencies) {
Dependencies {
compileOnly(kotlinCompiler)

testRuntimeOnly(
Expand Down Expand Up @@ -62,17 +63,29 @@ tasks.test {
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
languageVersion = "2.0"
freeCompilerArgs = freeCompilerArgs +
"-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi" +
"-Xcontext-receivers"
compilerOptions {
freeCompilerArgs.addAll(
"-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi",
"-Xcontext-receivers"
)
languageVersion = KotlinVersion.KOTLIN_2_0
}
}

kotlin {
jvmToolchain {
languageVersion = JavaLanguageVersion.of(8)
}
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
}

val generateTests by tasks.creating(JavaExec::class) {
classpath = sourceSets.test.get().runtimeClasspath
mainClass.set("org.jetbrains.kotlinx.spark.compilerPlugin.GenerateTestsKt")
mainClass.set("org.jetbrains.kotlinx.spark.api.compilerPlugin.GenerateTestsKt")
}

val compileTestKotlin by tasks.getting {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jetbrains.kotlinx.spark.compilerPlugin
package org.jetbrains.kotlinx.spark.api.compilerPlugin

import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrar

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.jetbrains.kotlinx.spark.compilerPlugin
package org.jetbrains.kotlinx.spark.api.compilerPlugin

import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption
import org.jetbrains.kotlin.compiler.plugin.CliOption
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.CompilerConfigurationKey
import org.jetbrains.kotlinx.spark.Artifacts
import org.jetbrains.kotlinx.spark.api.Artifacts

open class SparkifyCommandLineProcessor : CommandLineProcessor {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.jetbrains.kotlinx.spark.compilerPlugin
package org.jetbrains.kotlinx.spark.api.compilerPlugin

import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlinx.spark.Artifacts
import org.jetbrains.kotlinx.spark.compilerPlugin.ir.SparkifyIrGenerationExtension
import org.jetbrains.kotlinx.spark.api.Artifacts
import org.jetbrains.kotlinx.spark.api.compilerPlugin.ir.SparkifyIrGenerationExtension

open class SparkifyCompilerPluginRegistrar: CompilerPluginRegistrar() {
init {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jetbrains.kotlinx.spark.compilerPlugin.ir
package org.jetbrains.kotlinx.spark.api.compilerPlugin.ir

import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.ir.IrElement
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.jetbrains.kotlinx.spark.compilerPlugin.ir
package org.jetbrains.kotlinx.spark.api.compilerPlugin.ir

import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
import org.jetbrains.kotlinx.spark.api.compilerPlugin.ir.DataClassPropertyAnnotationGenerator

class SparkifyIrGenerationExtension(
private val sparkifyAnnotationFqNames: List<String>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
org.jetbrains.kotlinx.spark.compilerPlugin.SparkifyCommandLineProcessor
org.jetbrains.kotlinx.spark.api.compilerPlugin.SparkifyCommandLineProcessor
Original file line number Diff line number Diff line change
@@ -1 +1 @@
org.jetbrains.kotlinx.spark.compilerPlugin.SparkifyCompilerPluginRegistrar
org.jetbrains.kotlinx.spark.api.compilerPlugin.SparkifyCompilerPluginRegistrar
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


package org.jetbrains.kotlinx.spark.compilerPlugin.runners;
package org.jetbrains.kotlinx.spark.api.compilerPlugin.runners;

import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.util.KtTestUtil;
Expand All @@ -11,7 +11,7 @@
import java.io.File;
import java.util.regex.Pattern;

/** This class is generated by {@link org.jetbrains.kotlinx.spark.compilerPlugin.GenerateTestsKt}. DO NOT MODIFY MANUALLY */
/** This class is generated by {@link org.jetbrains.kotlinx.spark.api.compilerPlugin.GenerateTestsKt}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("/mnt/data/Projects/kotlin-spark-api/compiler-plugin/src/test/resources/testData/box")
@TestDataPath("$PROJECT_ROOT")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.jetbrains.kotlinx.spark.compilerPlugin
package org.jetbrains.kotlinx.spark.api.compilerPlugin

import org.jetbrains.kotlin.generators.generateTestGroupSuiteWithJUnit5
import org.jetbrains.kotlinx.spark.Artifacts
import org.jetbrains.kotlinx.spark.compilerPlugin.runners.AbstractBoxTest
import org.jetbrains.kotlinx.spark.api.Artifacts
import org.jetbrains.kotlinx.spark.api.compilerPlugin.runners.AbstractBoxTest

fun main() {
generateTestGroupSuiteWithJUnit5 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jetbrains.kotlinx.spark.compilerPlugin.runners
package org.jetbrains.kotlinx.spark.api.compilerPlugin.runners

import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
import org.jetbrains.kotlin.test.FirParser
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package org.jetbrains.kotlinx.spark.compilerPlugin.runners
package org.jetbrains.kotlinx.spark.api.compilerPlugin.runners

import org.jetbrains.kotlin.test.FirParser
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
import org.jetbrains.kotlin.test.directives.ConfigurationDirectives.WITH_STDLIB
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives.FIR_DUMP
import org.jetbrains.kotlin.test.directives.configureFirParser
import org.jetbrains.kotlin.test.runners.baseFirDiagnosticTestConfiguration
import org.jetbrains.kotlin.test.services.EnvironmentBasedStandardLibrariesPathProvider
import org.jetbrains.kotlin.test.services.KotlinStandardLibrariesPathProvider

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jetbrains.kotlinx.spark.compilerPlugin.runners
package org.jetbrains.kotlinx.spark.api.compilerPlugin.runners

import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives
Expand All @@ -8,7 +8,7 @@ import org.jetbrains.kotlin.test.runners.AbstractKotlinCompilerTest
import org.jetbrains.kotlin.test.runners.baseFirDiagnosticTestConfiguration
import org.jetbrains.kotlin.test.services.EnvironmentBasedStandardLibrariesPathProvider
import org.jetbrains.kotlin.test.services.KotlinStandardLibrariesPathProvider
import org.jetbrains.kotlinx.spark.compilerPlugin.services.ExtensionRegistrarConfigurator
import org.jetbrains.kotlinx.spark.api.compilerPlugin.services.ExtensionRegistrarConfigurator
import org.junit.jupiter.api.BeforeAll

abstract class BaseTestRunner : AbstractKotlinCompilerTest() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.jetbrains.kotlinx.spark.compilerPlugin.services
package org.jetbrains.kotlinx.spark.api.compilerPlugin.services

import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.test.model.TestModule
import org.jetbrains.kotlin.test.services.EnvironmentConfigurator
import org.jetbrains.kotlin.test.services.TestServices
import org.jetbrains.kotlinx.spark.compilerPlugin.ir.SparkifyIrGenerationExtension
import org.jetbrains.kotlinx.spark.api.compilerPlugin.ir.SparkifyIrGenerationExtension

class ExtensionRegistrarConfigurator(testServices: TestServices) : EnvironmentConfigurator(testServices) {
override fun CompilerPluginRegistrar.ExtensionStorage.registerCompilerExtensions(
Expand Down
20 changes: 14 additions & 6 deletions examples/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Needs to be installed in the local maven repository
id("org.jetbrains.kotlinx.spark.api")
kotlin
idea
}

//kotlinSparkApi {
// enabled = true
// sparkifyAnnotationFqNames = listOf(
// "org.jetbrains.kotlinx.spark.api.plugin.annotations.Sparkify",
// )
//}

group = Versions.groupID
version = Versions.project

repositories {
mavenLocal()
mavenCentral()
}

dependencies {

with(Projects) {
Projects {
implementation(
kotlinSparkApi,
)
}

with(Dependencies) {
Dependencies {

// https://github.com/FasterXML/jackson-bom/issues/52
if (Versions.spark == "3.3.1") implementation(jacksonDatabind)
Expand All @@ -31,12 +39,12 @@ dependencies {
sparkStreaming,
sparkStreamingKafka,
)

}
}

kotlin {
jvmToolchain(8)
jvmToolchain {
languageVersion = JavaLanguageVersion.of(Versions.jvmTarget)
}
}
}
Loading

0 comments on commit c0a3140

Please sign in to comment.