diff --git a/README.md b/README.md index 05b334c..1eb4140 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,13 @@ # panache-kotlin-dsl A dynamic, type-safe way to write your queries +## Requirements +- Quarkus version `3.9.2` or newer +- Kotlin version `1.9.23` or newer +- KSP version `1.9.23-1.0.20` or newer + - Your KSP version needs to match your Kotlin version. This is a strict requirement! + - For example, when your Kotlin version is `2.0.21`, your KSP version needs to be built for and start with the same version, such as `2.0.21-1.0.25` + ## Features ### Queries - Supports the following expressions in a type-safe and null-safe way for all columns @@ -30,5 +37,6 @@ Allows you to handle no/multiple results with a `when (result) { ... }` block in - Code generation does not handle fields of generic types (e.g. `List`, `Set`, etc.), but as far as I'm aware this is difficult to get working with Hibernate anyway. Consider using a JPA `@Converter` in combination with `@ColumnType` ## Planned Features +These features will be added some time in the future. Please do submit an issue if you'd like these sooner rather than later :) - DSL for sorting expressions - DSL for UPDATE queries diff --git a/build.gradle.kts b/build.gradle.kts index 2b09e26..98f0b97 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -47,7 +47,6 @@ dependencies { testImplementation("io.quarkus:quarkus-junit5") testImplementation("io.mockk:mockk:$mockkVersion") - testImplementation("com.github.tschuchortdev:kotlin-compile-testing:$compileTestingVersion") testImplementation("com.github.tschuchortdev:kotlin-compile-testing-ksp:$compileTestingVersion") } @@ -60,11 +59,9 @@ kotlin { } mavenPublishing { publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, false) - signAllPublications() coordinates(groupId, artifactId, version) - pom { name = artifactId description = "A dynamic, type-safe way to write your queries" diff --git a/gradle.properties b/gradle.properties index 4b2875c..98972b1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -41,8 +41,7 @@ kotlinPoetVersion=1.16.0 mockkVersion=1.13.11 #https://github.com/tschuchortdev/kotlin-compile-testing -# TODO might be upgradable, test implementation needed to be sure -compileTestingVersion=1.5.0 +compileTestingVersion=1.6.0 #https://github.com/Kotlin/kotlinx-kover koverVersion=0.8.3 diff --git a/src/test/kotlin/ch/icken/processor/PanacheCompanionBaseTests.kt b/src/test/kotlin/ch/icken/processor/PanacheCompanionBaseProcessorMockTests.kt similarity index 99% rename from src/test/kotlin/ch/icken/processor/PanacheCompanionBaseTests.kt rename to src/test/kotlin/ch/icken/processor/PanacheCompanionBaseProcessorMockTests.kt index 044f66c..633ef7d 100644 --- a/src/test/kotlin/ch/icken/processor/PanacheCompanionBaseTests.kt +++ b/src/test/kotlin/ch/icken/processor/PanacheCompanionBaseProcessorMockTests.kt @@ -37,7 +37,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @ExtendWith(MockKExtension::class) -class PanacheCompanionBaseTests : TestCommon() { +class PanacheCompanionBaseProcessorMockTests : ProcessorMockTestCommon() { @MockK private lateinit var resolver: Resolver diff --git a/src/test/kotlin/ch/icken/processor/PanacheEntityBaseTests.kt b/src/test/kotlin/ch/icken/processor/PanacheEntityBaseProcessorMockTests.kt similarity index 99% rename from src/test/kotlin/ch/icken/processor/PanacheEntityBaseTests.kt rename to src/test/kotlin/ch/icken/processor/PanacheEntityBaseProcessorMockTests.kt index 2e3bb78..a094049 100644 --- a/src/test/kotlin/ch/icken/processor/PanacheEntityBaseTests.kt +++ b/src/test/kotlin/ch/icken/processor/PanacheEntityBaseProcessorMockTests.kt @@ -40,7 +40,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @ExtendWith(MockKExtension::class) -class PanacheEntityBaseTests : TestCommon() { +class PanacheEntityBaseProcessorMockTests : ProcessorMockTestCommon() { @MockK private lateinit var resolver: Resolver diff --git a/src/test/kotlin/ch/icken/processor/TestCommon.kt b/src/test/kotlin/ch/icken/processor/ProcessorMockTestCommon.kt similarity index 97% rename from src/test/kotlin/ch/icken/processor/TestCommon.kt rename to src/test/kotlin/ch/icken/processor/ProcessorMockTestCommon.kt index c0eb005..659eb36 100644 --- a/src/test/kotlin/ch/icken/processor/TestCommon.kt +++ b/src/test/kotlin/ch/icken/processor/ProcessorMockTestCommon.kt @@ -22,7 +22,7 @@ import com.squareup.kotlinpoet.ksp.toClassName import io.mockk.mockkStatic import org.junit.jupiter.api.BeforeAll -abstract class TestCommon { +abstract class ProcessorMockTestCommon { companion object { @JvmStatic @BeforeAll diff --git a/src/test/kotlin/ch/icken/processor/ProcessorTests.kt b/src/test/kotlin/ch/icken/processor/ProcessorTests.kt new file mode 100644 index 0000000..6167a27 --- /dev/null +++ b/src/test/kotlin/ch/icken/processor/ProcessorTests.kt @@ -0,0 +1,75 @@ +/* + * Copyright 2024 Thijs Koppen + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.icken.processor + +import com.tschuchort.compiletesting.KotlinCompilation +import com.tschuchort.compiletesting.SourceFile +import com.tschuchort.compiletesting.kspSourcesDir +import com.tschuchort.compiletesting.symbolProcessorProviders +import org.intellij.lang.annotations.Language +import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +@OptIn(ExperimentalCompilerApi::class) +class ProcessorTests { + + @Test + fun testEmptyEntity() { + + // Given + val compilation = kotlinCompilation("Employee.kt", + """ + import io.quarkus.hibernate.orm.panache.kotlin.PanacheEntity + import jakarta.persistence.Entity + + @Entity + class Employee : PanacheEntity() + """ + ) + + // When + val result = compilation.compile() + + // Then + assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode) + + compilation.kspSourcesDir.walkTopDown().forEach { println(it.absolutePath) } + //TODO validate generated file content + } + + //region Utils + private fun kotlinResource(resourceName: String, sourceFileName: String = resourceName) = + SourceFile.kotlin(sourceFileName, javaClass.classLoader.getResource(resourceName)?.readText() ?: "") + + private fun compilation(vararg source: SourceFile) = KotlinCompilation().apply { + inheritClassPath = true + sources = listOf(*source) + symbolProcessorProviders = listOf( + PanacheCompanionBaseProcessorProvider(), + PanacheEntityBaseProcessorProvider() + ) + verbose = false + } + + private fun kotlinCompilation(sourceFileName: String, @Language("kotlin") contents: String) = + compilation(SourceFile.kotlin(sourceFileName, contents)) + + private fun kotlinResourceCompilation(resourceName: String, sourceFileName: String = resourceName) = + compilation(kotlinResource(resourceName, sourceFileName)) + //endregion +}