diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 0000000..8b7d3ce
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,16 @@
+# Documentation for all configuration options:
+# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
+
+version: 2
+updates:
+ # Updates for Github Actions used in the repo
+ - package-ecosystem: "github-actions"
+ directory: "/"
+ schedule:
+ interval: "weekly"
+ # Updates for Gradle dependencies used in the app
+ - package-ecosystem: gradle
+ directory: "/"
+ schedule:
+ interval: "weekly"
+ open-pull-requests-limit: 2
diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml
index 0e12312..65136a1 100644
--- a/.github/workflows/gradle.yml
+++ b/.github/workflows/gradle.yml
@@ -8,10 +8,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v1
+ - uses: actions/checkout@v4
- name: Set up JDK 1.8
- uses: actions/setup-java@v1
+ uses: actions/setup-java@v4
with:
- java-version: 1.8
+ java-version: '11'
+ distribution: 'zulu'
- name: Build with Gradle
- run: ./gradlew build
+ run: ./gradlew clean build
diff --git a/.github/workflows/update-gradle-wrapper.yml b/.github/workflows/update-gradle-wrapper.yml
new file mode 100644
index 0000000..df63bf4
--- /dev/null
+++ b/.github/workflows/update-gradle-wrapper.yml
@@ -0,0 +1,23 @@
+name: Update Gradle Wrapper
+
+on:
+ workflow_dispatch:
+ schedule:
+ - cron: "0 0 * * *"
+
+jobs:
+ update-gradle-wrapper:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Install JDK 21
+ uses: actions/setup-java@v4
+ with:
+ distribution: 'temurin'
+ java-version: 21
+ - uses: actions/checkout@v4
+ - name: Update Gradle Wrapper
+ uses: gradle-update/update-gradle-wrapper-action@v2
+ with:
+ merge-method: SQUASH
diff --git a/.gitignore b/.gitignore
index 1c94608..75829d2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,12 +1,4 @@
/build
-/example/app/build
-/plugin/build
-/plugin/idea
-/example/.gradle
-/plugin/kotlin-compiler-plugin/build
-/plugin/compiler-plugin-shared/build
-/plugin/kotlin-compiler-native-plugin/build
-/plugin/gradle-plugin/build
-/plugin/.idea
/.gradle
-.idea
\ No newline at end of file
+.idea
+/lib/build/
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
deleted file mode 100644
index a9ea262..0000000
--- a/.idea/codeStyles/Project.xml
+++ /dev/null
@@ -1,38 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
deleted file mode 100644
index 79ee123..0000000
--- a/.idea/codeStyles/codeStyleConfig.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
deleted file mode 100644
index 15a15b2..0000000
--- a/.idea/encodings.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/.idea/markdown-navigator.xml b/.idea/markdown-navigator.xml
deleted file mode 100644
index d030f38..0000000
--- a/.idea/markdown-navigator.xml
+++ /dev/null
@@ -1,85 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/markdown-navigator/profiles_settings.xml b/.idea/markdown-navigator/profiles_settings.xml
deleted file mode 100644
index 57927c5..0000000
--- a/.idea/markdown-navigator/profiles_settings.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index 31a4e77..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules/app/KotlinCompilerPluginHelloWorld.app.jvmMain.iml b/.idea/modules/app/KotlinCompilerPluginHelloWorld.app.jvmMain.iml
deleted file mode 100644
index 2ae5e12..0000000
--- a/.idea/modules/app/KotlinCompilerPluginHelloWorld.app.jvmMain.iml
+++ /dev/null
@@ -1,104 +0,0 @@
-
-
-
-
-
-
- KotlinCompilerPluginHelloWorld.app.commonMain
-
- COMPILATION_AND_SOURCE_SET_HOLDER
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules/app/KotlinCompilerPluginHelloWorld.app.jvmTest.iml b/.idea/modules/app/KotlinCompilerPluginHelloWorld.app.jvmTest.iml
deleted file mode 100644
index 4c959a8..0000000
--- a/.idea/modules/app/KotlinCompilerPluginHelloWorld.app.jvmTest.iml
+++ /dev/null
@@ -1,120 +0,0 @@
-
-
-
-
-
-
- KotlinCompilerPluginHelloWorld.app.commonMain
- KotlinCompilerPluginHelloWorld.app.commonTest
- KotlinCompilerPluginHelloWorld.app.jvmMain
-
- COMPILATION_AND_SOURCE_SET_HOLDER
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules/gradle-plugin/de.jensklingenberg.gradle-plugin.main.iml b/.idea/modules/gradle-plugin/de.jensklingenberg.gradle-plugin.main.iml
deleted file mode 100644
index d1ecdad..0000000
--- a/.idea/modules/gradle-plugin/de.jensklingenberg.gradle-plugin.main.iml
+++ /dev/null
@@ -1,193 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules/gradle-plugin/de.jensklingenberg.gradle-plugin.test.iml b/.idea/modules/gradle-plugin/de.jensklingenberg.gradle-plugin.test.iml
deleted file mode 100644
index e2aceeb..0000000
--- a/.idea/modules/gradle-plugin/de.jensklingenberg.gradle-plugin.test.iml
+++ /dev/null
@@ -1,209 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules/kotlin-compiler-plugin/de.jensklingenberg.kotlin-compiler-plugin.main.iml b/.idea/modules/kotlin-compiler-plugin/de.jensklingenberg.kotlin-compiler-plugin.main.iml
deleted file mode 100644
index 2d4e8fd..0000000
--- a/.idea/modules/kotlin-compiler-plugin/de.jensklingenberg.kotlin-compiler-plugin.main.iml
+++ /dev/null
@@ -1,193 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules/kotlin-compiler-plugin/de.jensklingenberg.kotlin-compiler-plugin.test.iml b/.idea/modules/kotlin-compiler-plugin/de.jensklingenberg.kotlin-compiler-plugin.test.iml
deleted file mode 100644
index 324c394..0000000
--- a/.idea/modules/kotlin-compiler-plugin/de.jensklingenberg.kotlin-compiler-plugin.test.iml
+++ /dev/null
@@ -1,191 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 35eb1dd..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Readme.md b/Readme.md
index 525e574..f0a20bf 100644
--- a/Readme.md
+++ b/Readme.md
@@ -4,7 +4,7 @@
[](https://github.com/Foso/KotlinReactNativeMpp/blob/master/LICENSE)
[](http://makeapullrequest.com)
-[](https://github.com/Foso/Sheasy/blob/master/LICENSE)
@@ -14,35 +14,43 @@
This is an example project that shows how to create a Kotlin Compiler Plugin. At compile time a gradle plugin will trigger the compiler plugin. The plugin will print "Hello from" and the name of the file that is being compiled, as a compiler warning to the terminal log.
-
+
### Show some :heart: and star the repo to support the project
-[](https://github.com/Foso/JK_KotlinCompilerPluginHelloWorld) [](https://github.com/Foso/JK_KotlinCompilerPluginHelloWorld/fork) [](https://github.com/Foso/JK_KotlinCompilerPluginHelloWorld) [](https://twitter.com/jklingenberg_)
+[](https://github.com/Foso/KotlinCompilerPluginExample) [](https://github.com/Foso/KotlinCompilerPluginExample/fork) [](https://github.com/Foso/KotlinCompilerPluginExample) [](https://twitter.com/jklingenberg_)
## Usage
-> :information_source: Please be aware that the Kotlin Compiler still doesn’t have any stable API and there is no backwards compatibility guaranteed. Kotlin versions above 1.6.21 can have a totally different API.
+> :information_source: Please be aware that the Kotlin Compiler still doesn't have any stable API and there is no
+> backwards compatibility guaranteed. Kotlin versions above 1.9.23 can have a totally different API.
-* Inside the project folder run ` ./gradlew clean build`
+* Inside the project folder run `./gradlew clean build`
The plugin is only active when the build cache is changed. This is why you need to run "clean" before building, when you want to see the log output again.
### 👷 Project Structure
-#### src
-* src - A Kotlin Multiplatform project which applies a gradle plugin(compiler.plugin.helloworld) whichs triggers the compiler plugin.
+* lib - A Kotlin Multiplatform project which applies a gradle plugin(compiler.plugin.helloworld) which triggers the compiler plugin.
+* compiler-plugin - This module contains the Kotlin Compiler Plugin
+* gradle-plugin - This module contains the gradle plugin which trigger the compiler plugin
-#### buildSrc/compiler-plugin
- * kotlin-compiler-native-plugin - This module contains the Kotlin Compiler Plugin for native targets
- * kotlin-compiler-plugin - This module contains the Kotlin Compiler Plugin for JVM/JS targets
- * gradle-plugin - This module contains the gradle plugin which trigger the two compiler plugins
+## Useful resources
+[The Road to the New Kotlin Compiler](https://www.youtube.com/watch?v=iTdJJq_LyoY)
+
+[https://github.com/bnorm/kotlin-ir-plugin-template](https://github.com/bnorm/kotlin-ir-plugin-template)
+
+[Writing Your Second Kotlin Compiler Plugin, Part 1 — Project Setup](https://blog.bnorm.dev/writing-your-second-compiler-plugin-part-1)
+
+[Experimenting with the Kotlin Compiler by Jossi Wolf, Snapp Mobile EN](https://www.youtube.com/watch?v=Y6gEA-nS2uQ)
+
+[Crash course on the Kotlin compiler | 1. Frontend: Parsing phase](https://medium.com/google-developer-experts/crash-course-on-the-kotlin-compiler-1-frontend-parsing-phase-9898490d922b)
## ✍️ Feedback
-Feel free to send feedback on [Twitter](https://twitter.com/jklingenberg_) or [file an issue](https://github.com/foso/JK_KotlinCompilerPluginHelloWorld/issues/new). Feature requests are always welcome.
+Feel free to send feedback on [Twitter](https://twitter.com/jklingenberg_) or [file an issue](https://github.com/foso/KotlinCompilerPluginExample/issues/new). Feature requests are always welcome.
### Find this project useful ? :heart:
diff --git a/build.gradle b/build.gradle
deleted file mode 100644
index f49cca1..0000000
--- a/build.gradle
+++ /dev/null
@@ -1,97 +0,0 @@
-buildscript {
-
- ext.buildMaven = { p -> repositories { maven { url p } } }
-
- repositories {
- mavenLocal()
- google()
- mavenCentral()
- }
-
- dependencies {
- classpath "de.jensklingenberg:compiler.gradleplugin.helloworld:1.0.0"
- }
-}
-plugins {
- id 'org.jetbrains.kotlin.multiplatform' version '1.6.21'
-}
-apply plugin: 'compiler.gradleplugin.helloworld'
-
-System.setProperty("kotlin.compiler.execution.strategy", "in-process") // For debugging
-
-allprojects {
- repositories {
- mavenLocal()
- mavenCentral()
- maven { url "https://maven.google.com" }
- maven { url "https://plugins.gradle.org/m2/" }
- }
-}
-
-helloWorld {
- enabled = true
-}
-
-allprojects {
- ext.buildMaven = { p -> repositories { maven { url p } } }
-
- repositories {
- mavenLocal()
- mavenCentral()
- maven { url "https://maven.google.com" }
- maven { url "https://plugins.gradle.org/m2/" }
- google()
- }
-}
-
-
-kotlin {
- jvm()
- linuxX64("linux")
- js()
- sourceSets {
- commonMain {
- dependencies {
- implementation kotlin('stdlib-common')
- }
- }
- commonTest {
- dependencies {
- implementation kotlin('test-common')
- implementation kotlin('test-annotations-common')
- }
- }
-
- jsMain {
- dependencies {
- implementation kotlin('stdlib-js')
- }
- }
- jsTest {
- dependencies {
- implementation kotlin('test-js')
- }
- }
-
- jvmMain {
- dependencies {
- implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
- }
- }
- jsTest {
- dependencies {
- implementation kotlin('test-js')
- }
- }
- linuxMain {
-
- }
- linuxTest {
- }
- }
-}
-
-// workaround for https://youtrack.jetbrains.com/issue/KT-27170
-configurations {
- compileClasspath
-}
diff --git a/build.gradle.kts b/build.gradle.kts
new file mode 100644
index 0000000..7456bbc
--- /dev/null
+++ b/build.gradle.kts
@@ -0,0 +1,33 @@
+import org.gradle.kotlin.dsl.libs
+
+buildscript {
+
+ repositories {
+ mavenLocal()
+ google()
+ mavenCentral()
+ }
+
+ dependencies {
+ classpath("com.vanniktech:gradle-maven-publish-plugin:0.25.3")
+ classpath("de.jensklingenberg:gradle-plugin:1.0.0")
+ }
+}
+plugins {
+ id("org.jetbrains.kotlin.multiplatform") version libs.versions.kotlin apply false
+}
+apply(plugin = "compiler.gradleplugin.helloworld")
+
+System.setProperty("kotlin.compiler.execution.strategy", "in-process") // For debugging
+
+
+allprojects {
+ repositories {
+ mavenLocal()
+ mavenCentral()
+ maven("https://maven.google.com")
+ maven("https://plugins.gradle.org/m2/")
+ google()
+ }
+}
+
diff --git a/buildSrc/.gitignore b/buildSrc/.gitignore
deleted file mode 100644
index 1571bfe..0000000
--- a/buildSrc/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/build
-/.gradle/
diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle
deleted file mode 100644
index de0b05f..0000000
--- a/buildSrc/build.gradle
+++ /dev/null
@@ -1,26 +0,0 @@
-plugins {
- id 'org.jetbrains.kotlin.jvm' version '1.6.21'
-}
-
-allprojects {
- repositories {
- mavenLocal()
- mavenCentral()
- maven { url "https://maven.google.com" }
- maven { url "https://plugins.gradle.org/m2/" }
- }
-}
-
-compileKotlin {
- kotlinOptions.jvmTarget = "1.8"
-}
-compileTestKotlin {
- kotlinOptions.jvmTarget = "1.8"
-}
-
-build {
- dependsOn ':compiler-plugin:kotlin-plugin:publishToMavenLocal'
- dependsOn ':compiler-plugin:kotlin-native-plugin:publishToMavenLocal'
-
- dependsOn ':compiler-plugin:gradle-plugin:publishToMavenLocal'
-}
diff --git a/buildSrc/compiler-plugin/gradle-plugin/.gitignore b/buildSrc/compiler-plugin/gradle-plugin/.gitignore
deleted file mode 100644
index c8c70f2..0000000
--- a/buildSrc/compiler-plugin/gradle-plugin/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/build
-/.gradle
diff --git a/buildSrc/compiler-plugin/gradle-plugin/build.gradle b/buildSrc/compiler-plugin/gradle-plugin/build.gradle
deleted file mode 100644
index 4f85798..0000000
--- a/buildSrc/compiler-plugin/gradle-plugin/build.gradle
+++ /dev/null
@@ -1,43 +0,0 @@
-plugins {
- id "org.jetbrains.kotlin.jvm"
- id "org.jetbrains.kotlin.kapt"
- id 'java-gradle-plugin'
- id("maven-publish")
-
-}
-
-
-group = "de.jensklingenberg"
-archivesBaseName = "compiler.gradleplugin.helloworld"
-version = "1.0.0"
-
-
-
-gradlePlugin {
- plugins {
- simplePlugin {
- id = "compiler.gradleplugin.helloworld" // users will do `apply plugin: "compiler.plugin.helloworld"`
- implementationClass = "de.jensklingenberg.gradle.HelloWorldGradleSubPlugin" // entry-point class
- }
- }
-}
-
-dependencies {
- implementation "org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.6.21"
-}
-
-
-publishing {
- publications {
- maven(MavenPublication) {
- groupId = 'de.jensklingenberg'
- artifactId = 'compiler.gradleplugin.helloworld'
- version = '1.0.0'
-
- from components.java
- }
- }
- repositories {
-
- }
-}
\ No newline at end of file
diff --git a/buildSrc/compiler-plugin/kotlin-native-plugin/build.gradle b/buildSrc/compiler-plugin/kotlin-native-plugin/build.gradle
deleted file mode 100644
index 74c32f3..0000000
--- a/buildSrc/compiler-plugin/kotlin-native-plugin/build.gradle
+++ /dev/null
@@ -1,44 +0,0 @@
-plugins {
- id("maven-publish")
-
- id "org.jetbrains.kotlin.jvm"
- id "org.jetbrains.kotlin.kapt"
-
-}
-
-group = "de.jensklingenberg"
-archivesBaseName = "helloworld-compiler-plugin-native"
-version = "0.0.1"
-
-
-repositories {
- mavenLocal()
-}
-
-dependencies {
- compileOnly "org.jetbrains.kotlin:kotlin-compiler"
- compileOnly "com.google.auto.service:auto-service:1.0"
- kapt "com.google.auto.service:auto-service:1.0"
-}
-
-compileKotlin {
- kotlinOptions.jvmTarget = "1.8"
-}
-compileTestKotlin {
- kotlinOptions.jvmTarget = "1.8"
-}
-
-publishing {
- publications {
- maven(MavenPublication) {
- groupId = 'de.jensklingenberg'
- artifactId = 'helloworld-compiler-plugin-native'
- version = '0.0.1'
-
- from components.java
- }
- }
- repositories {
-
- }
-}
\ No newline at end of file
diff --git a/buildSrc/compiler-plugin/kotlin-native-plugin/src/main/java/de/jensklingenberg/common/NativeCommandLineProcessor.kt b/buildSrc/compiler-plugin/kotlin-native-plugin/src/main/java/de/jensklingenberg/common/NativeCommandLineProcessor.kt
deleted file mode 100644
index c75f0be..0000000
--- a/buildSrc/compiler-plugin/kotlin-native-plugin/src/main/java/de/jensklingenberg/common/NativeCommandLineProcessor.kt
+++ /dev/null
@@ -1,35 +0,0 @@
-package de.jensklingenberg.common
-
-import com.google.auto.service.AutoService
-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
-
-@AutoService(CommandLineProcessor::class) // don't forget!
-class NativeCommandLineProcessor : CommandLineProcessor {
-
- override val pluginId: String = "helloWorldPlugin"
-
- override val pluginOptions: Collection = listOf(
- CliOption(
- optionName = "enabled", valueDescription = "",
- description = "whether to enable the plugin or not"
- )
- )
-
- override fun processOption(
- option: AbstractCliOption,
- value: String,
- configuration: CompilerConfiguration
- ) {
-
- return when (option.optionName) {
- "enabled" -> configuration.put(KEY_ENABLED, value.toBoolean())
- else -> configuration.put(KEY_ENABLED, true)
- }
- }
-}
-
-val KEY_ENABLED = CompilerConfigurationKey("whether the plugin is enabled")
diff --git a/buildSrc/compiler-plugin/kotlin-plugin/.gitignore b/buildSrc/compiler-plugin/kotlin-plugin/.gitignore
deleted file mode 100644
index 796b96d..0000000
--- a/buildSrc/compiler-plugin/kotlin-plugin/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/build
diff --git a/buildSrc/compiler-plugin/kotlin-plugin/build.gradle b/buildSrc/compiler-plugin/kotlin-plugin/build.gradle
deleted file mode 100644
index b0bf8dd..0000000
--- a/buildSrc/compiler-plugin/kotlin-plugin/build.gradle
+++ /dev/null
@@ -1,46 +0,0 @@
-plugins {
-
- id 'org.jetbrains.kotlin.jvm'
- id "org.jetbrains.kotlin.kapt"
- id("maven-publish")
-
-}
-
-group = "de.jensklingenberg"
-archivesBaseName = "helloworld-compiler-plugin"
-version = "0.0.1"
-
-
-repositories {
- mavenLocal()
-}
-
-dependencies {
- implementation "org.jetbrains.kotlin:kotlin-stdlib"
- compileOnly "org.jetbrains.kotlin:kotlin-compiler-embeddable"
- compileOnly "com.google.auto.service:auto-service:1.0"
- kapt "com.google.auto.service:auto-service:1.0"
-}
-
-compileKotlin {
- kotlinOptions.jvmTarget = "1.8"
-}
-compileTestKotlin {
- kotlinOptions.jvmTarget = "1.8"
-}
-
-
-publishing {
- publications {
- maven(MavenPublication) {
- groupId = 'de.jensklingenberg'
- artifactId = 'helloworld-compiler-plugin'
- version = '0.0.1'
-
- from components.java
- }
- }
- repositories {
-
- }
-}
\ No newline at end of file
diff --git a/buildSrc/compiler-plugin/kotlin-plugin/src/main/java/de/jensklingenberg/CommonComponentRegistrar.kt b/buildSrc/compiler-plugin/kotlin-plugin/src/main/java/de/jensklingenberg/CommonComponentRegistrar.kt
deleted file mode 100644
index b48d076..0000000
--- a/buildSrc/compiler-plugin/kotlin-plugin/src/main/java/de/jensklingenberg/CommonComponentRegistrar.kt
+++ /dev/null
@@ -1,32 +0,0 @@
-package de.jensklingenberg
-
-import com.google.auto.service.AutoService
-import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
-import org.jetbrains.kotlin.cli.common.config.kotlinSourceRoots
-import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
-import org.jetbrains.kotlin.cli.common.messages.MessageCollector
-import org.jetbrains.kotlin.com.intellij.mock.MockProject
-import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
-import org.jetbrains.kotlin.config.CompilerConfiguration
-
-@AutoService(ComponentRegistrar::class)
-class CommonComponentRegistrar : ComponentRegistrar {
- override fun registerProjectComponents(
- project: MockProject,
- configuration: CompilerConfiguration
- ) {
-
- if (configuration[KEY_ENABLED] == false) {
- return
- }
-
- val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
- configuration.kotlinSourceRoots.forEach {
- messageCollector.report(
- CompilerMessageSeverity.WARNING,
- "*** Hello from ***" + it.path
- )
- }
-
- }
-}
diff --git a/buildSrc/gradlew b/buildSrc/gradlew
deleted file mode 100755
index cccdd3d..0000000
--- a/buildSrc/gradlew
+++ /dev/null
@@ -1,172 +0,0 @@
-#!/usr/bin/env sh
-
-##############################################################################
-##
-## Gradle start up script for UN*X
-##
-##############################################################################
-
-# Attempt to set APP_HOME
-# Resolve links: $0 may be a link
-PRG="$0"
-# Need this for relative symlinks.
-while [ -h "$PRG" ] ; do
- ls=`ls -ld "$PRG"`
- link=`expr "$ls" : '.*-> \(.*\)$'`
- if expr "$link" : '/.*' > /dev/null; then
- PRG="$link"
- else
- PRG=`dirname "$PRG"`"/$link"
- fi
-done
-SAVED="`pwd`"
-cd "`dirname \"$PRG\"`/" >/dev/null
-APP_HOME="`pwd -P`"
-cd "$SAVED" >/dev/null
-
-APP_NAME="Gradle"
-APP_BASE_NAME=`basename "$0"`
-
-# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-DEFAULT_JVM_OPTS=""
-
-# Use the maximum available, or set MAX_FD != -1 to use that value.
-MAX_FD="maximum"
-
-warn () {
- echo "$*"
-}
-
-die () {
- echo
- echo "$*"
- echo
- exit 1
-}
-
-# OS specific support (must be 'true' or 'false').
-cygwin=false
-msys=false
-darwin=false
-nonstop=false
-case "`uname`" in
- CYGWIN* )
- cygwin=true
- ;;
- Darwin* )
- darwin=true
- ;;
- MINGW* )
- msys=true
- ;;
- NONSTOP* )
- nonstop=true
- ;;
-esac
-
-CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
-
-# Determine the Java command to use to start the JVM.
-if [ -n "$JAVA_HOME" ] ; then
- if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
- # IBM's JDK on AIX uses strange locations for the executables
- JAVACMD="$JAVA_HOME/jre/sh/java"
- else
- JAVACMD="$JAVA_HOME/bin/java"
- fi
- if [ ! -x "$JAVACMD" ] ; then
- die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
-
-Please set the JAVA_HOME variable in your environment to match the
-location of your Java installation."
- fi
-else
- JAVACMD="java"
- which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-
-Please set the JAVA_HOME variable in your environment to match the
-location of your Java installation."
-fi
-
-# Increase the maximum file descriptors if we can.
-if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
- MAX_FD_LIMIT=`ulimit -H -n`
- if [ $? -eq 0 ] ; then
- if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
- MAX_FD="$MAX_FD_LIMIT"
- fi
- ulimit -n $MAX_FD
- if [ $? -ne 0 ] ; then
- warn "Could not set maximum file descriptor limit: $MAX_FD"
- fi
- else
- warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
- fi
-fi
-
-# For Darwin, add options to specify how the application appears in the dock
-if $darwin; then
- GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
-fi
-
-# For Cygwin, switch paths to Windows format before running java
-if $cygwin ; then
- APP_HOME=`cygpath --path --mixed "$APP_HOME"`
- CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
- JAVACMD=`cygpath --unix "$JAVACMD"`
-
- # We build the pattern for arguments to be converted via cygpath
- ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
- SEP=""
- for dir in $ROOTDIRSRAW ; do
- ROOTDIRS="$ROOTDIRS$SEP$dir"
- SEP="|"
- done
- OURCYGPATTERN="(^($ROOTDIRS))"
- # Add a user-defined pattern to the cygpath arguments
- if [ "$GRADLE_CYGPATTERN" != "" ] ; then
- OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
- fi
- # Now convert the arguments - kludge to limit ourselves to /bin/sh
- i=0
- for arg in "$@" ; do
- CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
- CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
-
- if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
- eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
- else
- eval `echo args$i`="\"$arg\""
- fi
- i=$((i+1))
- done
- case $i in
- (0) set -- ;;
- (1) set -- "$args0" ;;
- (2) set -- "$args0" "$args1" ;;
- (3) set -- "$args0" "$args1" "$args2" ;;
- (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
- (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
- (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
- (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
- (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
- (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
- esac
-fi
-
-# Escape application args
-save () {
- for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
- echo " "
-}
-APP_ARGS=$(save "$@")
-
-# Collect all arguments for the java command, following the shell quoting and substitution rules
-eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
-
-# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
-if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
- cd "$(dirname "$0")"
-fi
-
-exec "$JAVACMD" "$@"
diff --git a/buildSrc/gradlew.bat b/buildSrc/gradlew.bat
deleted file mode 100644
index f955316..0000000
--- a/buildSrc/gradlew.bat
+++ /dev/null
@@ -1,84 +0,0 @@
-@if "%DEBUG%" == "" @echo off
-@rem ##########################################################################
-@rem
-@rem Gradle startup script for Windows
-@rem
-@rem ##########################################################################
-
-@rem Set local scope for the variables with windows NT shell
-if "%OS%"=="Windows_NT" setlocal
-
-set DIRNAME=%~dp0
-if "%DIRNAME%" == "" set DIRNAME=.
-set APP_BASE_NAME=%~n0
-set APP_HOME=%DIRNAME%
-
-@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-set DEFAULT_JVM_OPTS=
-
-@rem Find java.exe
-if defined JAVA_HOME goto findJavaFromJavaHome
-
-set JAVA_EXE=java.exe
-%JAVA_EXE% -version >NUL 2>&1
-if "%ERRORLEVEL%" == "0" goto init
-
-echo.
-echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:findJavaFromJavaHome
-set JAVA_HOME=%JAVA_HOME:"=%
-set JAVA_EXE=%JAVA_HOME%/bin/java.exe
-
-if exist "%JAVA_EXE%" goto init
-
-echo.
-echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:init
-@rem Get command-line arguments, handling Windows variants
-
-if not "%OS%" == "Windows_NT" goto win9xME_args
-
-:win9xME_args
-@rem Slurp the command line arguments.
-set CMD_LINE_ARGS=
-set _SKIP=2
-
-:win9xME_args_slurp
-if "x%~1" == "x" goto execute
-
-set CMD_LINE_ARGS=%*
-
-:execute
-@rem Setup the command line
-
-set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
-
-@rem Execute Gradle
-"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
-
-:end
-@rem End local scope for the variables with windows NT shell
-if "%ERRORLEVEL%"=="0" goto mainEnd
-
-:fail
-rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
-rem the _cmd.exe /c_ return code!
-if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
-exit /b 1
-
-:mainEnd
-if "%OS%"=="Windows_NT" endlocal
-
-:omega
diff --git a/buildSrc/settings.gradle b/buildSrc/settings.gradle
deleted file mode 100644
index 45cb0f1..0000000
--- a/buildSrc/settings.gradle
+++ /dev/null
@@ -1,4 +0,0 @@
-include ':compiler-plugin:kotlin-plugin'
-include ':compiler-plugin:kotlin-native-plugin'
-
-include ':compiler-plugin:gradle-plugin'
diff --git a/buildSrc/compiler-plugin/kotlin-native-plugin/.gitignore b/compiler-plugin/.gitignore
similarity index 100%
rename from buildSrc/compiler-plugin/kotlin-native-plugin/.gitignore
rename to compiler-plugin/.gitignore
diff --git a/compiler-plugin/build.gradle.kts b/compiler-plugin/build.gradle.kts
new file mode 100644
index 0000000..6cf4e39
--- /dev/null
+++ b/compiler-plugin/build.gradle.kts
@@ -0,0 +1,107 @@
+import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
+import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
+
+plugins {
+ kotlin("jvm") version("2.0.0")
+ kotlin("kapt") version("2.0.0")
+ id("com.vanniktech.maven.publish") version("0.23.1")
+ `maven-publish`
+ signing
+
+}
+
+allprojects {
+ repositories {
+ mavenLocal()
+ mavenCentral()
+ maven("https://maven.google.com")
+ maven("https://plugins.gradle.org/m2/")
+ google()
+ }
+}
+
+mavenPublishing {
+ publishToMavenCentral()
+
+}
+
+group = "de.jensklingenberg"
+version = "0.0.1"
+val autoService = "1.1.1"
+dependencies {
+ compileOnly("com.google.auto.service:auto-service:$autoService")
+ kapt("com.google.auto.service:auto-service:$autoService")
+ compileOnly("org.jetbrains.kotlin:kotlin-compiler-embeddable:2.0.0")
+ testImplementation("dev.zacsweers.kctfork:core:0.4.1")
+ testImplementation("junit:junit:4.13.2")
+ testImplementation("com.google.truth:truth:1.4.2")
+ testImplementation(kotlin("reflect"))
+
+}
+
+publishing {
+ publications {
+ create("default") {
+ from(components["java"])
+
+ pom {
+ name.set("compiler-plugin")
+ description.set("Hello World Compiler Plugin")
+ url.set("https://github.com/Foso/KotlinCompilerPluginExample")
+
+ licenses {
+ license {
+ name.set("Apache License 2.0")
+ url.set("https://github.com/Foso/KotlinCompilerPluginExample/blob/master/LICENSE.txt")
+ }
+ }
+ scm {
+ url.set("https://github.com/Foso/KotlinCompilerPluginExample")
+ connection.set("scm:git:git://github.com/Foso/KotlinCompilerPluginExample.git")
+ }
+ developers {
+ developer {
+ name.set("Developer Name")
+ url.set("Developer URL")
+ }
+ }
+ }
+ }
+ }
+
+ repositories {
+ if (
+ hasProperty("sonatypeUsername") &&
+ hasProperty("sonatypePassword") &&
+ hasProperty("sonatypeSnapshotUrl") &&
+ hasProperty("sonatypeReleaseUrl")
+ ) {
+ maven {
+ val url = when {
+ "SNAPSHOT" in version.toString() -> property("sonatypeSnapshotUrl")
+ else -> property("sonatypeReleaseUrl")
+ } as String
+ setUrl(url)
+ credentials {
+ username = property("sonatypeUsername") as String
+ password = property("sonatypePassword") as String
+ }
+ }
+ }
+ }
+}
+
+java {
+ toolchain {
+ languageVersion.set(JavaLanguageVersion.of(8))
+ }
+}
+
+tasks.withType {
+ kotlinOptions.jvmTarget = "1.8"
+}
+tasks.withType>().configureEach {
+ compilerOptions.freeCompilerArgs.add("-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi")
+}
+
+//./gradlew clean :lib:compileKotlinJvm --no-daemon -Dorg.gradle.debug=true -Dkotlin.compiler.execution.strategy="in-process" -Dkotlin.daemon.jvm.options="-Xdebug,-Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n"
diff --git a/buildSrc/compiler-plugin/kotlin-native-plugin/src/main/java/de/jensklingenberg/NativeTestComponentRegistrar.kt b/compiler-plugin/src/main/java/de/jensklingenberg/CommonComponentRegistrar.kt
similarity index 56%
rename from buildSrc/compiler-plugin/kotlin-native-plugin/src/main/java/de/jensklingenberg/NativeTestComponentRegistrar.kt
rename to compiler-plugin/src/main/java/de/jensklingenberg/CommonComponentRegistrar.kt
index 2228126..8731151 100644
--- a/buildSrc/compiler-plugin/kotlin-native-plugin/src/main/java/de/jensklingenberg/NativeTestComponentRegistrar.kt
+++ b/compiler-plugin/src/main/java/de/jensklingenberg/CommonComponentRegistrar.kt
@@ -1,32 +1,37 @@
package de.jensklingenberg
import com.google.auto.service.AutoService
-import com.intellij.mock.MockProject
-import de.jensklingenberg.common.KEY_ENABLED
+import de.jensklingenberg.transform.ExampleIrGenerationExtension
+import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.config.kotlinSourceRoots
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
-import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
+import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
import org.jetbrains.kotlin.config.CompilerConfiguration
-@AutoService(ComponentRegistrar::class)
-class NativeTestComponentRegistrar : ComponentRegistrar {
+@AutoService(CompilerPluginRegistrar::class)
+class CommonComponentRegistrar : CompilerPluginRegistrar() {
+ override val supportsK2: Boolean
+ get() = true
- override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) {
-
+ override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
if (configuration[KEY_ENABLED] == false) {
return
}
val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
-
configuration.kotlinSourceRoots.forEach {
messageCollector.report(
CompilerMessageSeverity.WARNING,
"*** Hello from ***" + it.path
)
}
+
+ val logging = true
+ IrGenerationExtension.registerExtension(
+ ExampleIrGenerationExtension(DebugLogger(logging, messageCollector))
+ )
}
}
diff --git a/compiler-plugin/src/main/java/de/jensklingenberg/DebugLogger.kt b/compiler-plugin/src/main/java/de/jensklingenberg/DebugLogger.kt
new file mode 100644
index 0000000..ec3d478
--- /dev/null
+++ b/compiler-plugin/src/main/java/de/jensklingenberg/DebugLogger.kt
@@ -0,0 +1,12 @@
+package de.jensklingenberg
+
+import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
+import org.jetbrains.kotlin.cli.common.messages.MessageCollector
+
+internal data class DebugLogger(val debug: Boolean, val messageCollector: MessageCollector) {
+ fun log(message: String) {
+ if (debug) {
+ messageCollector.report(CompilerMessageSeverity.INFO, message)
+ }
+ }
+}
\ No newline at end of file
diff --git a/buildSrc/compiler-plugin/kotlin-plugin/src/main/java/de/jensklingenberg/NativeCommandLineProcessor.kt b/compiler-plugin/src/main/java/de/jensklingenberg/ExampleCommandLineProcessor.kt
similarity index 94%
rename from buildSrc/compiler-plugin/kotlin-plugin/src/main/java/de/jensklingenberg/NativeCommandLineProcessor.kt
rename to compiler-plugin/src/main/java/de/jensklingenberg/ExampleCommandLineProcessor.kt
index 027e9ab..3ff4850 100644
--- a/buildSrc/compiler-plugin/kotlin-plugin/src/main/java/de/jensklingenberg/NativeCommandLineProcessor.kt
+++ b/compiler-plugin/src/main/java/de/jensklingenberg/ExampleCommandLineProcessor.kt
@@ -8,7 +8,7 @@ import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.CompilerConfigurationKey
@AutoService(CommandLineProcessor::class) // don't forget!
-class NativeCommandLineProcessor : CommandLineProcessor {
+class ExampleCommandLineProcessor : CommandLineProcessor {
override val pluginId: String = "helloWorldPlugin"
diff --git a/compiler-plugin/src/main/java/de/jensklingenberg/transform/CreateFuncTransformer.kt b/compiler-plugin/src/main/java/de/jensklingenberg/transform/CreateFuncTransformer.kt
new file mode 100644
index 0000000..92e6851
--- /dev/null
+++ b/compiler-plugin/src/main/java/de/jensklingenberg/transform/CreateFuncTransformer.kt
@@ -0,0 +1,105 @@
+package de.jensklingenberg.transform
+
+import de.jensklingenberg.DebugLogger
+import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext
+import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
+import org.jetbrains.kotlin.ir.expressions.IrCall
+import org.jetbrains.kotlin.ir.expressions.IrExpression
+import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl
+import org.jetbrains.kotlin.ir.types.classFqName
+import org.jetbrains.kotlin.ir.types.defaultType
+import org.jetbrains.kotlin.ir.types.impl.originalKotlinType
+import org.jetbrains.kotlin.ir.util.constructors
+import org.jetbrains.kotlin.name.ClassId
+import org.jetbrains.kotlin.name.FqName
+import org.jetbrains.kotlin.name.Name
+
+/**
+ * Transform create() to create(_TestApiIProvider())
+ */
+internal class CreateFuncTransformer(
+ private val pluginContext: IrPluginContext,
+ private val debugLogger: DebugLogger
+) : IrElementTransformerVoidWithContext() {
+
+ companion object {
+
+ fun ERROR_IMPL_NOT_FOUND(implName: String) =
+ "${implName} not found"
+
+ private const val EXAMPLE_PACKAGE = "sample"
+ private const val EXAMPLE_CREATE = "create"
+
+ }
+
+ override fun visitExpression(expression: IrExpression): IrExpression {
+
+ //Find exampleKtorfit.create()
+ (expression as? IrCall)?.let { irCall ->
+ if (irCall.typeArgumentsCount > 0) {
+
+ if (!expression.symbol.owner.symbol.toString().contains(EXAMPLE_PACKAGE)) {
+ return expression
+ }
+ if (expression.symbol.owner.name.asString() != EXAMPLE_CREATE) {
+ return expression
+ }
+
+ if (expression.getValueArgument(0) != null) {
+ return expression
+ }
+
+ //Get T from create()
+ val argumentType = irCall.getTypeArgument(0) ?: return expression
+ val classFqName = argumentType.classFqName
+
+ //if (!argumentType.isInterface()) throw IllegalStateException(ERROR_TYPE_ARGUMENT_NOT_INTERFACE(argumentType.originalKotlinType.toString()))
+
+ if (classFqName == null) {
+ throw IllegalStateException(ERROR_IMPL_NOT_FOUND(argumentType.originalKotlinType.toString()))
+ }
+
+ val packageName = classFqName.packageName
+ val className = classFqName.shortName().toString()
+ val providerClassName = "_$className" + "Provider"
+
+ //Find the class _TestApiProvider
+ val implClassSymbol = pluginContext.referenceClass(
+ ClassId(
+ FqName(packageName),
+ Name.identifier(providerClassName)
+ )
+ ) ?: throw IllegalStateException(ERROR_IMPL_NOT_FOUND(providerClassName))
+
+ val newConstructor = implClassSymbol.constructors.first()
+
+ //Create the constructor call for _ExampleApiImpl()
+ val newCall = IrConstructorCallImpl(
+ 0,
+ 0,
+ type = implClassSymbol.defaultType,
+ symbol = newConstructor,
+ 0,
+ 0,
+ 0,
+ null
+ )
+
+ //Set _ExampleApiImpl() as argument for create()
+ irCall.putValueArgument(0, newCall)
+ debugLogger.log(
+ "Transformed " + argumentType.originalKotlinType.toString() + " to _$className" + "Impl"
+ )
+ return super.visitExpression(irCall)
+ }
+ }
+ return super.visitExpression(expression)
+ }
+
+}
+
+
+private val FqName?.packageName: String
+ get() {
+ return this.toString().substringBeforeLast(".")
+ }
diff --git a/compiler-plugin/src/main/java/de/jensklingenberg/transform/ElementTransformer.kt b/compiler-plugin/src/main/java/de/jensklingenberg/transform/ElementTransformer.kt
new file mode 100644
index 0000000..6a3f3e7
--- /dev/null
+++ b/compiler-plugin/src/main/java/de/jensklingenberg/transform/ElementTransformer.kt
@@ -0,0 +1,42 @@
+package de.jensklingenberg.transform
+
+import de.jensklingenberg.DebugLogger
+import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext
+import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
+import org.jetbrains.kotlin.ir.IrStatement
+import org.jetbrains.kotlin.ir.declarations.*
+import org.jetbrains.kotlin.ir.expressions.IrCall
+import org.jetbrains.kotlin.ir.expressions.IrExpression
+import org.jetbrains.kotlin.ir.expressions.IrFunctionExpression
+
+internal class ElementTransformer(
+ private val pluginContext: IrPluginContext,
+ private val debugLogger: DebugLogger
+) : IrElementTransformerVoidWithContext() {
+
+ override fun visitValueParameterNew(declaration: IrValueParameter): IrStatement {
+ declaration.transform(CreateFuncTransformer(pluginContext,debugLogger), null)
+ return super.visitValueParameterNew(declaration)
+ }
+
+ override fun visitPropertyNew(declaration: IrProperty): IrStatement {
+ declaration.transform(CreateFuncTransformer(pluginContext, debugLogger), null)
+ return super.visitPropertyNew(declaration)
+ }
+
+ override fun visitCall(expression: IrCall): IrExpression {
+ expression.transform(CreateFuncTransformer(pluginContext, debugLogger), null)
+ return super.visitCall(expression)
+ }
+
+ override fun visitVariable(declaration: IrVariable): IrStatement {
+ declaration.transform(CreateFuncTransformer(pluginContext, debugLogger), null)
+ return super.visitVariable(declaration)
+ }
+
+
+ override fun visitFunctionExpression(expression: IrFunctionExpression): IrExpression {
+ expression.transform(CreateFuncTransformer(pluginContext, debugLogger), null)
+ return super.visitFunctionExpression(expression)
+ }
+}
\ No newline at end of file
diff --git a/compiler-plugin/src/main/java/de/jensklingenberg/transform/ExampleIrGenerationExtension.kt b/compiler-plugin/src/main/java/de/jensklingenberg/transform/ExampleIrGenerationExtension.kt
new file mode 100644
index 0000000..710135f
--- /dev/null
+++ b/compiler-plugin/src/main/java/de/jensklingenberg/transform/ExampleIrGenerationExtension.kt
@@ -0,0 +1,12 @@
+package de.jensklingenberg.transform
+
+import de.jensklingenberg.DebugLogger
+import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
+import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
+import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
+
+internal class ExampleIrGenerationExtension(private val debugLogger: DebugLogger) : IrGenerationExtension {
+ override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) {
+ moduleFragment.transform(ElementTransformer(pluginContext,debugLogger), null)
+ }
+}
\ No newline at end of file
diff --git a/gradle-plugin/build.gradle.kts b/gradle-plugin/build.gradle.kts
new file mode 100644
index 0000000..e8fce68
--- /dev/null
+++ b/gradle-plugin/build.gradle.kts
@@ -0,0 +1,102 @@
+plugins {
+ kotlin("jvm") version("2.0.0")
+ kotlin("kapt") version("2.0.0")
+ id("java-gradle-plugin")
+ `maven-publish`
+}
+
+group = "de.jensklingenberg"
+version = "1.0.0"
+
+
+allprojects {
+ repositories {
+ mavenLocal()
+ mavenCentral()
+ maven("https://maven.google.com")
+ maven("https://plugins.gradle.org/m2/")
+ google()
+ }
+}
+dependencies {
+ implementation("org.jetbrains.kotlin:kotlin-gradle-plugin-api:2.0.0")
+}
+
+gradlePlugin {
+ plugins {
+
+ create("simplePlugin") {
+ id = "compiler.gradleplugin.helloworld" // users will do `apply plugin: "compiler.plugin.helloworld"`
+ implementationClass = "de.jensklingenberg.gradle.HelloWorldGradleSubPlugin" // entry-point class
+ }
+ }
+}
+
+tasks.register("sourcesJar", Jar::class) {
+ group = "build"
+ description = "Assembles Kotlin sources"
+
+ archiveClassifier.set("sources")
+ from(sourceSets.main.get().allSource)
+ dependsOn(tasks.classes)
+}
+
+publishing {
+ publications {
+ create("default") {
+ from(components["java"])
+ artifact(tasks["sourcesJar"])
+ //artifact(tasks["dokkaJar"])
+
+ pom {
+ name.set("compiler.gradleplugin.helloworld")
+ description.set("KotlinCompilerPluginExample")
+ url.set("https://github.com/Foso/KotlinCompilerPluginExample")
+
+ licenses {
+ license {
+ name.set("Apache License 2.0")
+ url.set("https://github.com/Foso/Ktorfit/blob/master/LICENSE.txt")
+ }
+ }
+ scm {
+ url.set("https://github.com/Foso/KotlinCompilerPluginExample")
+ connection.set("scm:git:git://github.com/Foso/KotlinCompilerPluginExample.git")
+ }
+ developers {
+ developer {
+ name.set("Jens Klingenberg")
+ url.set("https://github.com/Foso")
+ }
+ }
+ }
+ }
+ }
+
+ repositories {
+ if (
+ hasProperty("sonatypeUsername") &&
+ hasProperty("sonatypePassword") &&
+ hasProperty("sonatypeSnapshotUrl") &&
+ hasProperty("sonatypeReleaseUrl")
+ ) {
+ maven {
+ val url = when {
+ "SNAPSHOT" in version.toString() -> property("sonatypeSnapshotUrl")
+ else -> property("sonatypeReleaseUrl")
+ } as String
+ setUrl(url)
+ credentials {
+ username = property("sonatypeUsername") as String
+ password = property("sonatypePassword") as String
+ }
+ }
+ }
+ }
+}
+
+
+tasks.build {
+ dependsOn(":kotlin-plugin:publishToMavenLocal")
+
+}
\ No newline at end of file
diff --git a/buildSrc/compiler-plugin/gradle-plugin/src/main/java/de/jensklingenberg/gradle/HelloWorldGradleSubplugin.kt b/gradle-plugin/src/main/java/de/jensklingenberg/gradle/HelloWorldGradleSubplugin.kt
similarity index 82%
rename from buildSrc/compiler-plugin/gradle-plugin/src/main/java/de/jensklingenberg/gradle/HelloWorldGradleSubplugin.kt
rename to gradle-plugin/src/main/java/de/jensklingenberg/gradle/HelloWorldGradleSubplugin.kt
index 34a1433..fca3631 100644
--- a/buildSrc/compiler-plugin/gradle-plugin/src/main/java/de/jensklingenberg/gradle/HelloWorldGradleSubplugin.kt
+++ b/gradle-plugin/src/main/java/de/jensklingenberg/gradle/HelloWorldGradleSubplugin.kt
@@ -15,8 +15,7 @@ class HelloWorldGradleSubPlugin : KotlinCompilerPluginSupportPlugin {
companion object {
const val SERIALIZATION_GROUP_NAME = "de.jensklingenberg"
- const val ARTIFACT_NAME = "helloworld-compiler-plugin"
- const val NATIVE_ARTIFACT_NAME = "$ARTIFACT_NAME-native"
+ const val ARTIFACT_NAME = "compiler-plugin"
const val VERSION_NUMBER = "0.0.1"
}
@@ -50,9 +49,4 @@ class HelloWorldGradleSubPlugin : KotlinCompilerPluginSupportPlugin {
version = VERSION_NUMBER // remember to bump this version before any release!
)
- override fun getPluginArtifactForNative(): SubpluginArtifact = SubpluginArtifact(
- groupId = SERIALIZATION_GROUP_NAME,
- artifactId = NATIVE_ARTIFACT_NAME,
- version = VERSION_NUMBER // remember to bump this version before any release!
- )
}
diff --git a/gradle.properties b/gradle.properties
index 15327af..477f2cd 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -4,4 +4,6 @@ org.gradle.parallel=false
org.gradle.configureondemand=false
kotlin.compiler.execution.strategy=in-process
kotlin.daemon.debug.log=true
+kotlin.js.compiler=ir
+org.gradle.jvmargs=-Xmx2g
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
new file mode 100644
index 0000000..e7f9cf4
--- /dev/null
+++ b/gradle/libs.versions.toml
@@ -0,0 +1,2 @@
+[versions]
+kotlin = "2.0.0"
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
index 5c2d1cf..9bbc975 100644
Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index bb3f5af..36e4933 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,8 @@
-#Sat Aug 10 11:03:53 CEST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
+distributionSha256Sum=20f1b1176237254a6fc204d8434196fa11a4cfb387567519c61556e8710aed78
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
+networkTimeout=10000
+validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
diff --git a/gradlew b/gradlew
index 8e25e6c..faf9300 100755
--- a/gradlew
+++ b/gradlew
@@ -1,7 +1,7 @@
-#!/usr/bin/env sh
+#!/bin/sh
#
-# Copyright 2015 the original author or authors.
+# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -15,80 +15,115 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+# SPDX-License-Identifier: Apache-2.0
+#
##############################################################################
-##
-## Gradle start up script for UN*X
-##
+#
+# Gradle start up script for POSIX generated by Gradle.
+#
+# Important for running:
+#
+# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
+# noncompliant, but you have some other compliant shell such as ksh or
+# bash, then to run this script, type that shell name before the whole
+# command line, like:
+#
+# ksh Gradle
+#
+# Busybox and similar reduced shells will NOT work, because this script
+# requires all of these POSIX shell features:
+# * functions;
+# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+# * compound commands having a testable exit status, especially «case»;
+# * various built-in commands including «command», «set», and «ulimit».
+#
+# Important for patching:
+#
+# (2) This script targets any POSIX shell, so it avoids extensions provided
+# by Bash, Ksh, etc; in particular arrays are avoided.
+#
+# The "traditional" practice of packing multiple parameters into a
+# space-separated string is a well documented source of bugs and security
+# problems, so this is (mostly) avoided, by progressively accumulating
+# options in "$@", and eventually passing that to Java.
+#
+# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
+# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
+# see the in-line comments for details.
+#
+# There are tweaks for specific operating systems such as AIX, CygWin,
+# Darwin, MinGW, and NonStop.
+#
+# (3) This script is generated from the Groovy template
+# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+# within the Gradle project.
+#
+# You can find Gradle at https://github.com/gradle/gradle/.
+#
##############################################################################
# Attempt to set APP_HOME
+
# Resolve links: $0 may be a link
-PRG="$0"
-# Need this for relative symlinks.
-while [ -h "$PRG" ] ; do
- ls=`ls -ld "$PRG"`
- link=`expr "$ls" : '.*-> \(.*\)$'`
- if expr "$link" : '/.*' > /dev/null; then
- PRG="$link"
- else
- PRG=`dirname "$PRG"`"/$link"
- fi
+app_path=$0
+
+# Need this for daisy-chained symlinks.
+while
+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
+ [ -h "$app_path" ]
+do
+ ls=$( ls -ld "$app_path" )
+ link=${ls#*' -> '}
+ case $link in #(
+ /*) app_path=$link ;; #(
+ *) app_path=$APP_HOME$link ;;
+ esac
done
-SAVED="`pwd`"
-cd "`dirname \"$PRG\"`/" >/dev/null
-APP_HOME="`pwd -P`"
-cd "$SAVED" >/dev/null
-APP_NAME="Gradle"
-APP_BASE_NAME=`basename "$0"`
-
-# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+# This is normally unused
+# shellcheck disable=SC2034
+APP_BASE_NAME=${0##*/}
+# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
+APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
-MAX_FD="maximum"
+MAX_FD=maximum
warn () {
echo "$*"
-}
+} >&2
die () {
echo
echo "$*"
echo
exit 1
-}
+} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
-case "`uname`" in
- CYGWIN* )
- cygwin=true
- ;;
- Darwin* )
- darwin=true
- ;;
- MINGW* )
- msys=true
- ;;
- NONSTOP* )
- nonstop=true
- ;;
+case "$( uname )" in #(
+ CYGWIN* ) cygwin=true ;; #(
+ Darwin* ) darwin=true ;; #(
+ MSYS* | MINGW* ) msys=true ;; #(
+ NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
- JAVACMD="$JAVA_HOME/jre/sh/java"
+ JAVACMD=$JAVA_HOME/jre/sh/java
else
- JAVACMD="$JAVA_HOME/bin/java"
+ JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
@@ -97,92 +132,120 @@ Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
- JAVACMD="java"
- which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+ JAVACMD=java
+ if ! command -v java >/dev/null 2>&1
+ then
+ die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
+ fi
fi
# Increase the maximum file descriptors if we can.
-if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
- MAX_FD_LIMIT=`ulimit -H -n`
- if [ $? -eq 0 ] ; then
- if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
- MAX_FD="$MAX_FD_LIMIT"
- fi
- ulimit -n $MAX_FD
- if [ $? -ne 0 ] ; then
- warn "Could not set maximum file descriptor limit: $MAX_FD"
- fi
- else
- warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
- fi
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+ case $MAX_FD in #(
+ max*)
+ # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ MAX_FD=$( ulimit -H -n ) ||
+ warn "Could not query maximum file descriptor limit"
+ esac
+ case $MAX_FD in #(
+ '' | soft) :;; #(
+ *)
+ # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ ulimit -n "$MAX_FD" ||
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
+ esac
fi
-# For Darwin, add options to specify how the application appears in the dock
-if $darwin; then
- GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
-fi
+# Collect all arguments for the java command, stacking in reverse order:
+# * args from the command line
+# * the main class name
+# * -classpath
+# * -D...appname settings
+# * --module-path (only if needed)
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if "$cygwin" || "$msys" ; then
+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+ CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+ JAVACMD=$( cygpath --unix "$JAVACMD" )
-# For Cygwin, switch paths to Windows format before running java
-if $cygwin ; then
- APP_HOME=`cygpath --path --mixed "$APP_HOME"`
- CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
- JAVACMD=`cygpath --unix "$JAVACMD"`
-
- # We build the pattern for arguments to be converted via cygpath
- ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
- SEP=""
- for dir in $ROOTDIRSRAW ; do
- ROOTDIRS="$ROOTDIRS$SEP$dir"
- SEP="|"
- done
- OURCYGPATTERN="(^($ROOTDIRS))"
- # Add a user-defined pattern to the cygpath arguments
- if [ "$GRADLE_CYGPATTERN" != "" ] ; then
- OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
- fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
- i=0
- for arg in "$@" ; do
- CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
- CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
-
- if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
- eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
- else
- eval `echo args$i`="\"$arg\""
+ for arg do
+ if
+ case $arg in #(
+ -*) false ;; # don't mess with options #(
+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
+ [ -e "$t" ] ;; #(
+ *) false ;;
+ esac
+ then
+ arg=$( cygpath --path --ignore --mixed "$arg" )
fi
- i=$((i+1))
+ # Roll the args list around exactly as many times as the number of
+ # args, so each arg winds up back in the position where it started, but
+ # possibly modified.
+ #
+ # NB: a `for` loop captures its iteration list before it begins, so
+ # changing the positional parameters here affects neither the number of
+ # iterations, nor the values presented in `arg`.
+ shift # remove old arg
+ set -- "$@" "$arg" # push replacement arg
done
- case $i in
- (0) set -- ;;
- (1) set -- "$args0" ;;
- (2) set -- "$args0" "$args1" ;;
- (3) set -- "$args0" "$args1" "$args2" ;;
- (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
- (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
- (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
- (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
- (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
- (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
- esac
fi
-# Escape application args
-save () {
- for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
- echo " "
-}
-APP_ARGS=$(save "$@")
-# Collect all arguments for the java command, following the shell quoting and substitution rules
-eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
-# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
-if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
- cd "$(dirname "$0")"
+# Collect all arguments for the java command:
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
+# and any embedded shellness will be escaped.
+# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
+# treated as '${Hostname}' itself on the command line.
+
+set -- \
+ "-Dorg.gradle.appname=$APP_BASE_NAME" \
+ -classpath "$CLASSPATH" \
+ org.gradle.wrapper.GradleWrapperMain \
+ "$@"
+
+# Stop when "xargs" is not available.
+if ! command -v xargs >/dev/null 2>&1
+then
+ die "xargs is not available"
fi
+# Use "xargs" to parse quoted args.
+#
+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
+#
+# In Bash we could simply go:
+#
+# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
+# set -- "${ARGS[@]}" "$@"
+#
+# but POSIX shell has neither arrays nor command substitution, so instead we
+# post-process each arg (as a line of input to sed) to backslash-escape any
+# character that might be a shell metacharacter, then use eval to reverse
+# that process (while maintaining the separation between arguments), and wrap
+# the whole thing up as a single "set" statement.
+#
+# This will of course break if any of these variables contains a newline or
+# an unmatched quote.
+#
+
+eval "set -- $(
+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
+ xargs -n1 |
+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
+ tr '\n' ' '
+ )" '"$@"'
+
exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
index 9618d8d..9b42019 100644
--- a/gradlew.bat
+++ b/gradlew.bat
@@ -1,100 +1,94 @@
-@rem
-@rem Copyright 2015 the original author or authors.
-@rem
-@rem Licensed under the Apache License, Version 2.0 (the "License");
-@rem you may not use this file except in compliance with the License.
-@rem You may obtain a copy of the License at
-@rem
-@rem https://www.apache.org/licenses/LICENSE-2.0
-@rem
-@rem Unless required by applicable law or agreed to in writing, software
-@rem distributed under the License is distributed on an "AS IS" BASIS,
-@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-@rem See the License for the specific language governing permissions and
-@rem limitations under the License.
-@rem
-
-@if "%DEBUG%" == "" @echo off
-@rem ##########################################################################
-@rem
-@rem Gradle startup script for Windows
-@rem
-@rem ##########################################################################
-
-@rem Set local scope for the variables with windows NT shell
-if "%OS%"=="Windows_NT" setlocal
-
-set DIRNAME=%~dp0
-if "%DIRNAME%" == "" set DIRNAME=.
-set APP_BASE_NAME=%~n0
-set APP_HOME=%DIRNAME%
-
-@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
-
-@rem Find java.exe
-if defined JAVA_HOME goto findJavaFromJavaHome
-
-set JAVA_EXE=java.exe
-%JAVA_EXE% -version >NUL 2>&1
-if "%ERRORLEVEL%" == "0" goto init
-
-echo.
-echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:findJavaFromJavaHome
-set JAVA_HOME=%JAVA_HOME:"=%
-set JAVA_EXE=%JAVA_HOME%/bin/java.exe
-
-if exist "%JAVA_EXE%" goto init
-
-echo.
-echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:init
-@rem Get command-line arguments, handling Windows variants
-
-if not "%OS%" == "Windows_NT" goto win9xME_args
-
-:win9xME_args
-@rem Slurp the command line arguments.
-set CMD_LINE_ARGS=
-set _SKIP=2
-
-:win9xME_args_slurp
-if "x%~1" == "x" goto execute
-
-set CMD_LINE_ARGS=%*
-
-:execute
-@rem Setup the command line
-
-set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
-
-@rem Execute Gradle
-"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
-
-:end
-@rem End local scope for the variables with windows NT shell
-if "%ERRORLEVEL%"=="0" goto mainEnd
-
-:fail
-rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
-rem the _cmd.exe /c_ return code!
-if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
-exit /b 1
-
-:mainEnd
-if "%OS%"=="Windows_NT" endlocal
-
-:omega
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+@rem SPDX-License-Identifier: Apache-2.0
+@rem
+
+@if "%DEBUG%"=="" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%"=="" set DIRNAME=.
+@rem This is normally unused
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if %ERRORLEVEL% equ 0 goto execute
+
+echo. 1>&2
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo. 1>&2
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if %ERRORLEVEL% equ 0 goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+set EXIT_CODE=%ERRORLEVEL%
+if %EXIT_CODE% equ 0 set EXIT_CODE=1
+if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
+exit /b %EXIT_CODE%
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts
new file mode 100644
index 0000000..093e046
--- /dev/null
+++ b/lib/build.gradle.kts
@@ -0,0 +1,38 @@
+plugins {
+ id("org.jetbrains.kotlin.multiplatform") version libs.versions.kotlin
+}
+apply(plugin = "compiler.gradleplugin.helloworld")
+
+
+configure {
+ enabled = true
+}
+
+kotlin {
+ jvm()
+ linuxX64("linux")
+ js()
+ sourceSets {
+ val commonMain by getting {}
+
+ val jsMain by getting {
+
+ dependencies {
+
+ }
+ }
+
+ val jvmMain by getting {
+
+
+ dependencies {
+
+ }
+ }
+ val linuxMain by getting {
+
+ }
+
+ }
+}
+
diff --git a/lib/src/commonMain/kotlin/sample/Sample.kt b/lib/src/commonMain/kotlin/sample/Sample.kt
new file mode 100644
index 0000000..4cfa5b6
--- /dev/null
+++ b/lib/src/commonMain/kotlin/sample/Sample.kt
@@ -0,0 +1,25 @@
+package sample
+
+expect class Sample() {
+ fun checkMe(): Int
+}
+
+expect object Platform {
+ val name: String
+}
+
+fun hello(): String = "Hello from ${Platform.name}"
+
+class _MyTestProvider : MyTest{
+ override fun print(){
+ println("Hello from _MyTestProvider")
+ }
+}
+
+interface MyTest{
+ fun print()
+}
+
+fun create(myTestProvider: MyTest? = null): MyTest {
+ return myTestProvider!!
+}
\ No newline at end of file
diff --git a/src/jsMain/kotlin/sample/SampleJs.kt b/lib/src/jsMain/kotlin/sample/SampleJs.kt
similarity index 100%
rename from src/jsMain/kotlin/sample/SampleJs.kt
rename to lib/src/jsMain/kotlin/sample/SampleJs.kt
diff --git a/lib/src/jvmMain/kotlin/sample/SampleJvm.kt b/lib/src/jvmMain/kotlin/sample/SampleJvm.kt
new file mode 100644
index 0000000..9221341
--- /dev/null
+++ b/lib/src/jvmMain/kotlin/sample/SampleJvm.kt
@@ -0,0 +1,17 @@
+package sample
+
+actual class Sample {
+ actual fun checkMe() = 42
+}
+
+actual object Platform {
+ actual val name: String = "JVM"
+}
+
+fun main() {
+ /**
+ * The compiler plugin will replace this with create(_MyTestProvider)
+ */
+ val myTest = create()
+ myTest.print()
+}
\ No newline at end of file
diff --git a/src/linuxMain/kotlin/sample/SampleLinux.kt b/lib/src/linuxMain/kotlin/sample/SampleLinux.kt
similarity index 100%
rename from src/linuxMain/kotlin/sample/SampleLinux.kt
rename to lib/src/linuxMain/kotlin/sample/SampleLinux.kt
diff --git a/src/linuxTest/kotlin/sample/SampleTestsNative.kt b/lib/src/linuxTest/kotlin/sample/SampleTestsNative.kt
similarity index 100%
rename from src/linuxTest/kotlin/sample/SampleTestsNative.kt
rename to lib/src/linuxTest/kotlin/sample/SampleTestsNative.kt
diff --git a/settings.gradle.kts b/settings.gradle.kts
new file mode 100644
index 0000000..3f3e249
--- /dev/null
+++ b/settings.gradle.kts
@@ -0,0 +1,9 @@
+
+includeBuild("gradle-plugin") {
+ dependencySubstitution {
+ substitute(module("de.jensklingenberg:gradle-plugin:1.0.0")).using(project(":"))
+ }
+}
+includeBuild("compiler-plugin")
+
+include(":lib")
diff --git a/src/commonMain/kotlin/sample/Sample.kt b/src/commonMain/kotlin/sample/Sample.kt
deleted file mode 100644
index 8cd23de..0000000
--- a/src/commonMain/kotlin/sample/Sample.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-package sample
-
-expect class Sample() {
- fun checkMe(): Int
-}
-
-expect object Platform {
- val name: String
-}
-
-fun hello(): String = "Hello from ${Platform.name}"
\ No newline at end of file
diff --git a/src/jvmMain/kotlin/sample/SampleJvm.kt b/src/jvmMain/kotlin/sample/SampleJvm.kt
deleted file mode 100644
index b87230e..0000000
--- a/src/jvmMain/kotlin/sample/SampleJvm.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-package sample
-
-actual class Sample {
- actual fun checkMe() = 42
-}
-
-actual object Platform {
- actual val name: String = "JVM"
-}
\ No newline at end of file