Skip to content

Commit

Permalink
Restructuring
Browse files Browse the repository at this point in the history
- Move code-processor to kotlinpoet/processor
- Move ksp-annotations to kotlinpoet/annotations
- Move @ProcessorAnnotation into ksp/annotations
- Move ksp-processor into ksp/processor
- Remove old annotations directory
  • Loading branch information
DRSchlaubi committed Sep 13, 2023
1 parent 4c10528 commit fabe21d
Show file tree
Hide file tree
Showing 49 changed files with 158 additions and 170 deletions.
4 changes: 3 additions & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions annotations/build.gradle.kts

This file was deleted.

2 changes: 0 additions & 2 deletions annotations/src/main/kotlin/GenerateInlinedConstructor.kt

This file was deleted.

10 changes: 7 additions & 3 deletions buildSrc/src/main/kotlin/code-generator.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ kotlin {
jvm()

targets {
jvm {
attributes {
attribute(generationSourceAttribute, false as java.lang.Boolean)
}
}
jvm("generationSource") {
mavenPublication { }
attributes {
attribute(generationSourceAttribute, JBoolean(true))
attribute(generationSourceAttribute, true as java.lang.Boolean)
}

compilations.all {
Expand Down Expand Up @@ -73,5 +77,5 @@ ksp {
}

dependencies {
"kspGenerationSource"(project(":code-processor"))
"kspGenerationSource"(project(":kotlinpoet:processor"))
}
62 changes: 35 additions & 27 deletions buildSrc/src/main/kotlin/kord-publishing.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.KotlinJvm
import com.vanniktech.maven.publish.KotlinMultiplatform
import gradle.kotlin.dsl.accessors._8d1ef46afdac024fc616c6e49cc7c389.kotlin
import org.intellij.lang.annotations.Language
import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget

plugins {
org.jetbrains.dokka
Expand Down Expand Up @@ -57,39 +60,44 @@ mavenPublishing {
}
}

// Since we only target JVM, we publish jvm artifacts only
plugins.withId("org.jetbrains.kotlin.multiplatform") {
val dokkaJar by tasks.registering(Jar::class) {
from(tasks.named("dokkaHtml"))
archiveClassifier = "javadoc"
}
afterEvaluate {
plugins.withId("org.jetbrains.kotlin.multiplatform") {
if (kotlin.targets.any { it !is KotlinJvmTarget && it !is KotlinMetadataTarget }) {
mavenPublishing.configure(KotlinMultiplatform(JavadocJar.Dokka("dokkaHtml")))
return@withId
}
val dokkaJar by tasks.registering(Jar::class) {
from(tasks.named("dokkaHtml"))
archiveClassifier = "javadoc"
}


// We're kinda abusing the KMP target system here
// We make an extra jvm target for the kotlinpoet source to run ksp on it, however we don't want to publish
// that target, so we emulate the "jvm" target being a normal Kotlin/JVM project and publish it that way
afterEvaluate {
publishing.publications.create<MavenPublication>("maven") {
from(kotlin.targets.getByName("jvm").components.first())
artifact(dokkaJar)
// We're kinda abusing the KMP target system here
// We make an extra jvm target for the kotlinpoet source to run ksp on it, however we don't want to publish
// that target, so we emulate the "jvm" target being a normal Kotlin/JVM project and publish it that way
afterEvaluate {
publishing.publications.create<MavenPublication>("maven") {
from(kotlin.targets.getByName("jvm").components.first())
artifact(dokkaJar)
}
}
}

// Remove auto-generated KMP publications
tasks {
withType<PublishToMavenLocal> {
enabled = name == "publishMavenPublicationToMavenLocal"
}
// Remove auto-generated KMP publications
tasks {
withType<PublishToMavenLocal> {
enabled = name == "publishMavenPublicationToMavenLocal"
}

withType<PublishToMavenRepository> {
enabled = name == "publishMavenPublicationToMavenRepository"
|| name == "publishMavenPublicationToMavenCentralRepository"
}
withType<PublishToMavenRepository> {
enabled = name == "publishMavenPublicationToMavenRepository"
|| name == "publishMavenPublicationToMavenCentralRepository"
}

// Theoretically, this makes us loose information, however, that information is not relevant, since this is
// pretty much only a JVM lib targeting JVM 1.8 (so validation of that is unnecessary)
withType<GenerateModuleMetadata> {
enabled = false
// Theoretically, this makes us loose information, however, that information is not relevant, since this is
// pretty much only a JVM lib targeting JVM 1.8 (so validation of that is unnecessary)
withType<GenerateModuleMetadata> {
enabled = false
}
}
}
}
1 change: 1 addition & 0 deletions docs/topics/Annotation-Argument-Processor.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ to generate that boiler plate for you

```kotlin
dependencies {
compileOnly("dev.kord.codegen", "ksp-annotations", "%version%")
ksp("dev.kord.codegen", "ksp-processor", "%version%")
}
```
Expand Down
29 changes: 29 additions & 0 deletions kotlinpoet/annotations/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
plugins {
org.jetbrains.kotlin.multiplatform
com.google.devtools.ksp
}

kotlin {
explicitApi()

jvm()

sourceSets {
commonMain {
dependencies {
compileOnly(projects.ksp.annotations)
}
}

named("jvmMain") {
kotlin.srcDir("build/generated/ksp/jvm/jvmMain/kotlin")
dependencies {
implementation(projects.ksp)
}
}
}
}

dependencies {
"kspJvm"(projects.ksp.processor)
}
9 changes: 7 additions & 2 deletions kotlinpoet/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ plugins {
dependencies {
commonMainApi(libs.kotlinpoet)
commonMainImplementation(kotlin("reflect"))
commonMainCompileOnly(projects.kspAnnotations)
kspCommonMainMetadata(projects.codeProcessor)
commonMainCompileOnly(projects.kotlinpoet.internalAnnotations)
kspCommonMainMetadata(projects.kotlinpoet.processor)

commonTestImplementation(kotlin("test-junit5"))
}
Expand All @@ -28,3 +28,8 @@ tasks {
useJUnitPlatform()
}
}

apiValidation {
ignoredProjects.add("internal-annotations")
ignoredProjects.add("processor")
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {
implementation(libs.codegen.kotlinpoet)
implementation(libs.kotlinpoet.ksp)
implementation(libs.ksp.api)
implementation(projects.kspAnnotations)
implementation(projects.kotlinpoet.internalAnnotations)
implementation(projects.ksp.annotations)
implementation(projects.ksp)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package dev.kord.codegen.generator.constructor_inliner
import com.google.devtools.ksp.symbol.KSValueParameter
import com.squareup.kotlinpoet.*
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
import com.squareup.kotlinpoet.jvm.jvmWildcard
import com.squareup.kotlinpoet.ksp.toClassName
import dev.kord.codegen.generator.utils.*
import dev.kord.codegen.generator.builder_functions.FactoryFunction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.kord.codegen.generator.reification

import com.google.devtools.ksp.symbol.KSClassDeclaration
import com.google.devtools.ksp.symbol.Modifier.*
import com.squareup.kotlinpoet.*
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
import com.squareup.kotlinpoet.ksp.*
Expand All @@ -10,7 +9,6 @@ import dev.kord.codegen.generator.utils.toParameterSpec
import dev.kord.codegen.generator.utils.toTypeParameterResolver
import dev.kord.codegen.kotlinpoet.CodeBlock
import dev.kord.codegen.kotlinpoet.FunSpec
import java.lang.reflect.Modifier
import kotlin.reflect.KClass

val AS_CLASS_NAME = MemberName("com.squareup.kotlinpoet", "asClassName")
Expand Down Expand Up @@ -69,8 +67,7 @@ fun MaybeReifiableFunction.reify(): FunSpec {
.map {
it.toParameterSpec(
typeVariableResolver,
simpleName.asString().endsWith("Builder"),
INLINE in this@reify.modifiers
simpleName.asString().endsWith("Builder")
)
}
.toList()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.kord.codegen.generator.reification

import com.google.devtools.ksp.containingFile
import com.google.devtools.ksp.getDeclaredFunctions
import com.google.devtools.ksp.isConstructor
import com.google.devtools.ksp.isPublic
import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import com.google.devtools.ksp.getDeclaredFunctions
import com.google.devtools.ksp.symbol.*
import com.squareup.kotlinpoet.*
import com.squareup.kotlinpoet.ksp.TypeParameterResolver
import com.squareup.kotlinpoet.ksp.toKModifier
import com.squareup.kotlinpoet.ksp.toTypeName
import com.squareup.kotlinpoet.ksp.toTypeParameterResolver

fun KSValueParameter.toParameterSpec(typeParamResolver: TypeParameterResolver = TypeParameterResolver.EMPTY, useParent: Boolean = false, noInline: Boolean = false) =
fun KSValueParameter.toParameterSpec(
typeParamResolver: TypeParameterResolver = TypeParameterResolver.EMPTY,
useParent: Boolean = false
) =
ParameterSpec.builder(name!!.asString(), type.toTypeName(typeParamResolver), modifiers)
.apply {
if (name!!.asString() == "block") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
@file:OptIn(CodeGenInternal::class)
@file:OptIn(CodeGenInternal::class, DelicateKotlinPoetApi::class)

package dev.kord.codegen.generator.utils

import com.squareup.kotlinpoet.DelicateKotlinPoetApi
import com.squareup.kotlinpoet.asClassName
import dev.kord.codegen.kotlinpoet.CodeGenDsl
import dev.kord.codegen.kotlinpoet.CodeGenInternal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package dev.kord.codegen.generator.visitors
import com.google.devtools.ksp.getDeclaredFunctions
import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
import com.google.devtools.ksp.symbol.KSClassDeclaration
import com.google.devtools.ksp.symbol.KSFunctionDeclaration
import com.google.devtools.ksp.symbol.KSValueParameter
import com.squareup.kotlinpoet.*
import com.squareup.kotlinpoet.ksp.toClassName
import com.squareup.kotlinpoet.ksp.writeTo
import dev.kord.codegen.generator.packageName
import dev.kord.codegen.generator.utils.FileSpec
import dev.kord.codegen.generator.utils.addCallsInPlaceExactlyOnce
import dev.kord.codegen.generator.utils.mapToValueParameterList
import dev.kord.codegen.generator.utils.toParameterSpec
import dev.kord.codegen.generator.builder_functions.getBuilderScopeName
Expand Down
23 changes: 0 additions & 23 deletions ksp-annotations/build.gradle.kts

This file was deleted.

54 changes: 0 additions & 54 deletions ksp-processor/api/ksp-processor.api

This file was deleted.

7 changes: 7 additions & 0 deletions ksp/annotations/api/annotations.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public abstract interface annotation class dev/kord/codegen/ksp/annotations/NullIfDefault : java/lang/annotation/Annotation {
}

public abstract interface annotation class dev/kord/codegen/ksp/annotations/ProcessorAnnotation : java/lang/annotation/Annotation {
public abstract fun packageName ()Ljava/lang/String;
}

Loading

0 comments on commit fabe21d

Please sign in to comment.