Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to codegen.kt #965

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Projects.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ val Project.isRelease get() = tag != null

object Repo {
const val releasesUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
const val snapshotsUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
lukellmann marked this conversation as resolved.
Show resolved Hide resolved
const val snapshotsUrl = "https://repo.kord.dev/snapshots"
}
23 changes: 17 additions & 6 deletions buildSrc/src/main/kotlin/kord-publishing.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,23 @@ publishing {
}

repositories {
maven {
url = uri(if (isRelease) Repo.releasesUrl else Repo.snapshotsUrl)
if(isRelease) {
maven {
url = uri(Repo.releasesUrl)

credentials {
username = getenv("NEXUS_USER")
password = getenv("NEXUS_PASSWORD")
credentials {
username = getenv("NEXUS_USER")
password = getenv("NEXUS_PASSWORD")
}
}
} else {
maven {
url = uri(Repo.snapshotsUrl)

credentials {
username = getenv("REPOSILITE_USER")
password = getenv("REPOSILITE_PASSWORD")
}
}
}
}
Expand All @@ -75,5 +86,5 @@ signing {
val secretKey = getenv("SIGNING_KEY")?.let { String(Base64.getDecoder().decode(it)) }
val password = getenv("SIGNING_PASSWORD")
useInMemoryPgpKeys(secretKey, password)
sign(publishing.publications)
// sign(publishing.publications)
}
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dokka = "1.9.20" # https://github.com/Kotlin/dokka
kotlinx-atomicfu = "0.25.0" # https://github.com/Kotlin/kotlinx-atomicfu
binary-compatibility-validator = "0.15.1" # https://github.com/Kotlin/binary-compatibility-validator
buildconfig = "5.4.0" # https://github.com/gmazzo/gradle-buildconfig-plugin
codegen-kt = "main-SNAPSHOT" # https://github.com/kordlib/codegen-kt


[libraries]
Expand Down Expand Up @@ -71,6 +72,8 @@ stately-collections = { module = "co.touchlab:stately-concurrent-collections", v
ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }
kotlinpoet = { module = "com.squareup:kotlinpoet", version.ref = "kotlinpoet" }
kotlinpoet-ksp = { module = "com.squareup:kotlinpoet-ksp", version.ref = "kotlinpoet" }
codegen-kt-dsl = { module = "dev.kord.codegen:kotlinpoet", version.ref = "codegen-kt" }
codegen-kt-ksp = { module = "dev.kord.codegen:ksp", version.ref = "codegen-kt" }

# tests
kotlin-test-annotations-common = { module = "org.jetbrains.kotlin:kotlin-test-annotations-common", version.ref = "kotlin" }
Expand Down
7 changes: 6 additions & 1 deletion ksp-processors/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ plugins {
`kord-internal-module`
}

repositories {
maven("https://oss.sonatype.org/content/repositories/snapshots")
}

kotlin {
compilerOptions {
freeCompilerArgs.add("-Xcontext-receivers")
Expand All @@ -12,8 +16,9 @@ dependencies {
implementation(projects.kspAnnotations)

implementation(libs.ksp.api)
implementation(libs.kotlinpoet)
implementation(libs.kotlinpoet.ksp)
implementation(libs.codegen.kt.dsl)
implementation(libs.codegen.kt.ksp)

implementation(libs.kotlinx.serialization.json) // use types directly
}
84 changes: 42 additions & 42 deletions ksp-processors/src/main/kotlin/KSPUtils.kt
DRSchlaubi marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,45 @@ import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.symbol.*
import kotlin.reflect.KProperty1

internal inline fun <reified A : Annotation> Resolver.getSymbolsWithAnnotation(inDepth: Boolean = false) =
getSymbolsWithAnnotation(A::class.qualifiedName!!, inDepth)

internal fun Resolver.getNewClasses() = getNewFiles().flatMap { it.declarations.filterIsInstance<KSClassDeclaration>() }

internal inline fun <reified A : Annotation> KSAnnotation.isOfType() = isOfType(A::class.qualifiedName!!)

internal fun KSAnnotation.isOfType(qualifiedName: String) = annotationType.resolve()
.declaration.let { if (it is KSTypeAlias) it.findActualType() else it }
.qualifiedName?.asString() == qualifiedName

@OptIn(KspExperimental::class)
internal inline fun <reified A : Annotation> KSAnnotated.getAnnotationsByType() = getAnnotationsByType(A::class)

internal class AnnotationArguments<A : Annotation> private constructor(
private val arguments: Map<String, KSValueArgument>,
) {
private fun getArgument(parameter: KProperty1<A, Any>) = arguments.getValue(parameter.name)
private val KProperty1<A, Any>.value get() = getArgument(this).value

fun isDefault(parameter: KProperty1<A, Any>) = getArgument(parameter).isDefault()

// can't return non-nullable values because of https://github.com/google/ksp/issues/885
operator fun get(parameter: KProperty1<A, Annotation>) = parameter.value as KSAnnotation?
operator fun get(parameter: KProperty1<A, Array<out Annotation>>) =
@Suppress("UNCHECKED_CAST") (parameter.value as List<KSAnnotation>?)

companion object {
fun <A : Annotation> KSAnnotation.arguments() =
AnnotationArguments<A>(arguments.associateBy { it.name!!.asString() })
}
}

@Suppress("RecursivePropertyAccessor")
internal val KSReferenceElement.isClassifierReference: Boolean
get() = when (this) {
is KSDynamicReference, is KSCallableReference -> false
is KSClassifierReference -> true
is KSDefNonNullReference -> enclosedType.isClassifierReference
is KSParenthesizedReference -> element.isClassifierReference
else -> error("Unexpected KSReferenceElement: $this")
}
//internal inline fun <reified A : Annotation> Resolver.getSymbolsWithAnnotation(inDepth: Boolean = false) =
// getSymbolsWithAnnotation(A::class.qualifiedName!!, inDepth)
//
//internal fun Resolver.getNewClasses() = getNewFiles().flatMap { it.declarations.filterIsInstance<KSClassDeclaration>() }
//
//internal inline fun <reified A : Annotation> KSAnnotation.isOfType() = isOfType(A::class.qualifiedName!!)
//
//internal fun KSAnnotation.isOfType(qualifiedName: String) = annotationType.resolve()
// .declaration.let { if (it is KSTypeAlias) it.findActualType() else it }
// .qualifiedName?.asString() == qualifiedName
//
//@OptIn(KspExperimental::class)
//internal inline fun <reified A : Annotation> KSAnnotated.getAnnotationsByType() = getAnnotationsByType(A::class)
//
//internal class AnnotationArguments<A : Annotation> private constructor(
// private val arguments: Map<String, KSValueArgument>,
//) {
// private fun getArgument(parameter: KProperty1<A, Any>) = arguments.getValue(parameter.name)
// private val KProperty1<A, Any>.value get() = getArgument(this).value
//
// fun isDefault(parameter: KProperty1<A, Any>) = getArgument(parameter).isDefault()
//
// // can't return non-nullable values because of https://github.com/google/ksp/issues/885
// operator fun get(parameter: KProperty1<A, Annotation>) = parameter.value as KSAnnotation?
// operator fun get(parameter: KProperty1<A, Array<out Annotation>>) =
// @Suppress("UNCHECKED_CAST") (parameter.value as List<KSAnnotation>?)
//
// companion object {
// fun <A : Annotation> KSAnnotation.arguments() =
// AnnotationArguments<A>(arguments.associateBy { it.name!!.asString() })
// }
//}
//
//@Suppress("RecursivePropertyAccessor")
//internal val KSReferenceElement.isClassifierReference: Boolean
// get() = when (this) {
// is KSDynamicReference, is KSCallableReference -> false
// is KSClassifierReference -> true
// is KSDefNonNullReference -> enclosedType.isClassifierReference
// is KSParenthesizedReference -> element.isClassifierReference
// else -> error("Unexpected KSReferenceElement: $this")
// }
Loading
Loading