diff --git a/PACKAGES.md b/PACKAGES.md deleted file mode 100644 index 17b2a9dfc..000000000 --- a/PACKAGES.md +++ /dev/null @@ -1,52 +0,0 @@ - -# Package org.ktorm.database - -Entry of Ktorm framework, providing basic features of connection and transaction management. - -# Package org.ktorm.dsl - -Constructs strong-typed SQL DSL. - -# Package org.ktorm.entity - -Provides entity sequence APIs. - -# Package org.ktorm.expression - -Expression tree and SQL generation supports, providing expression node types, tree visitor, and SQL formatter. - -# Package org.ktorm.logging - -Simple logging facade of Ktorm, provides adapters for variable logging frameworks. - -# Package org.ktorm.schema - -Database schema supports, including table and column definition, column binding, and SQL types. - -# Package org.ktorm.global - -Provide a more concise DSL syntax based on a global database instance. - -# Package org.ktorm.jackson - -Jackson extension module for Ktorm, providing JSON serialization for entity objects and JSON SQL type. - -# Package org.ktorm.support.mysql - -MySQL dialect module for Ktorm. - -# Package org.ktorm.support.oracle - -Oracle dialect module for Ktorm. - -# Package org.ktorm.support.postgresql - -PostgreSQL dialect module for Ktorm. - -# Package org.ktorm.support.sqlite - -SQLite dialect module for Ktorm. - -# Package org.ktorm.support.sqlserver - -Microsoft SqlServer dialect module for Ktorm. diff --git a/build.gradle.kts b/build.gradle.kts index 3aad8cb69..d9cc9452b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,17 +2,11 @@ group = "org.ktorm" version = file("ktorm.version").readLines()[0] -task("printClasspath") { - doLast { - val jars = subprojects - .map { it.configurations["compileClasspath"] } - .flatMap { it.files } - .filterNotTo(HashSet()) { it.name.contains("ktorm") } - .onEach { println(it.name) } +plugins { + id("ktorm.dokka") +} - val file = file("build/ktorm.classpath") - file.parentFile.mkdirs() - file.writeText(jars.joinToString(File.pathSeparator) { it.absolutePath }) - println("Classpath written to build/ktorm.classpath") - } +repositories { + mavenCentral() + gradlePluginPortal() } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 449f27dd0..89340f070 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -10,6 +10,8 @@ repositories { dependencies { api("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.23") + api("org.jetbrains.dokka:dokka-gradle-plugin:1.9.20") + api("org.jetbrains.dokka:dokka-base:1.9.20") api("org.moditect:moditect:1.0.0.RC1") api("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.23.6") } diff --git a/buildSrc/src/main/kotlin/ktorm.base.gradle.kts b/buildSrc/src/main/kotlin/ktorm.base.gradle.kts index 453a58840..654dbfbff 100644 --- a/buildSrc/src/main/kotlin/ktorm.base.gradle.kts +++ b/buildSrc/src/main/kotlin/ktorm.base.gradle.kts @@ -30,7 +30,12 @@ java { } tasks { + // Lifecycle task for code generation. + val codegen by registering { /* do nothing */ } + compileKotlin { + dependsOn(codegen) + kotlinOptions { jvmTarget = "1.8" allWarningsAsErrors = true diff --git a/buildSrc/src/main/kotlin/ktorm.dokka.gradle.kts b/buildSrc/src/main/kotlin/ktorm.dokka.gradle.kts new file mode 100644 index 000000000..09a1fc214 --- /dev/null +++ b/buildSrc/src/main/kotlin/ktorm.dokka.gradle.kts @@ -0,0 +1,45 @@ + +plugins { + id("org.jetbrains.dokka") +} + +tasks.named("dokkaHtmlMultiModule") { + val tmplDir = System.getProperty("dokka.templatesDir") + if (!tmplDir.isNullOrEmpty()) { + pluginConfiguration { + templatesDir = File(tmplDir) + } + } +} + +subprojects { + apply(plugin = "org.jetbrains.dokka") + + tasks.dokkaJavadoc { + dependsOn("codegen") + + dokkaSourceSets.named("main") { + suppressGeneratedFiles.set(false) + } + } + + tasks.named("dokkaHtmlPartial") { + dependsOn("codegen") + + val tmplDir = System.getProperty("dokka.templatesDir") + if (!tmplDir.isNullOrEmpty()) { + pluginConfiguration { + templatesDir = File(tmplDir) + } + } + + dokkaSourceSets.named("main") { + suppressGeneratedFiles.set(false) + sourceLink { + localDirectory.set(file("src/main/kotlin")) + remoteUrl.set(java.net.URL("https://github.com/kotlin-orm/ktorm/blob/master/${project.name}/src/main/kotlin")) + remoteLineSuffix.set("#L") + } + } + } +} diff --git a/buildSrc/src/main/kotlin/ktorm.publish.gradle.kts b/buildSrc/src/main/kotlin/ktorm.publish.gradle.kts index 1f40f5e26..61a3f47b6 100644 --- a/buildSrc/src/main/kotlin/ktorm.publish.gradle.kts +++ b/buildSrc/src/main/kotlin/ktorm.publish.gradle.kts @@ -3,14 +3,18 @@ plugins { id("kotlin") id("signing") id("maven-publish") + id("org.jetbrains.dokka") } val jarSources by tasks.registering(Jar::class) { - archiveClassifier.set("sources") + dependsOn("codegen") from(sourceSets.main.map { it.allSource }) + archiveClassifier.set("sources") } val jarJavadoc by tasks.registering(Jar::class) { + dependsOn(tasks.dokkaJavadoc) + from(tasks.dokkaJavadoc.flatMap { it.outputDirectory }) archiveClassifier.set("javadoc") } diff --git a/buildSrc/src/main/kotlin/ktorm.tuples-codegen.gradle.kts b/buildSrc/src/main/kotlin/ktorm.tuples-codegen.gradle.kts index 0ab69909b..9d6654a61 100644 --- a/buildSrc/src/main/kotlin/ktorm.tuples-codegen.gradle.kts +++ b/buildSrc/src/main/kotlin/ktorm.tuples-codegen.gradle.kts @@ -348,10 +348,7 @@ val generateTuples by tasks.registering { } tasks { - compileKotlin { - dependsOn(generateTuples) - } - "jarSources" { + "codegen" { dependsOn(generateTuples) } } diff --git a/detekt.yml b/detekt.yml index 8c08a5027..e915ca0b2 100644 --- a/detekt.yml +++ b/detekt.yml @@ -402,7 +402,7 @@ style: active: true maxJumpCount: 2 MagicNumber: - active: true + active: false ignoreNumbers: ['-1', '0', '1', '2', '3', '60'] ignoreHashCodeFunction: true ignorePropertyDeclaration: false diff --git a/ktorm-core/src/main/kotlin/org/ktorm/schema/SqlTypes.kt b/ktorm-core/src/main/kotlin/org/ktorm/schema/SqlTypes.kt index 507a297b9..5526bf3dd 100644 --- a/ktorm-core/src/main/kotlin/org/ktorm/schema/SqlTypes.kt +++ b/ktorm-core/src/main/kotlin/org/ktorm/schema/SqlTypes.kt @@ -450,7 +450,6 @@ public fun BaseTable<*>.yearMonth(name: String): Column { /** * [SqlType] implementation used to save [YearMonth] instances, formatting them to strings with pattern `yyyy-MM`. */ -@Suppress("MagicNumber") public object YearMonthSqlType : SqlType(Types.VARCHAR, "varchar") { private val formatter = DateTimeFormatterBuilder() .appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD) diff --git a/ktorm-jackson/ktorm-jackson.gradle.kts b/ktorm-jackson/ktorm-jackson.gradle.kts index 7827835c8..d9dac31fa 100644 --- a/ktorm-jackson/ktorm-jackson.gradle.kts +++ b/ktorm-jackson/ktorm-jackson.gradle.kts @@ -23,10 +23,7 @@ val generatePackageVersion by tasks.registering(Copy::class) { } tasks { - compileKotlin { - dependsOn(generatePackageVersion) - } - "jarSources" { + codegen { dependsOn(generatePackageVersion) } } diff --git a/ktorm-ksp-annotations/src/main/kotlin/org/ktorm/ksp/annotation/Undefined.kt b/ktorm-ksp-annotations/src/main/kotlin/org/ktorm/ksp/annotation/Undefined.kt index 3b2f095ea..3a4db5f78 100644 --- a/ktorm-ksp-annotations/src/main/kotlin/org/ktorm/ksp/annotation/Undefined.kt +++ b/ktorm-ksp-annotations/src/main/kotlin/org/ktorm/ksp/annotation/Undefined.kt @@ -145,7 +145,7 @@ public object Undefined { return defineClass(name, bytes, null) } - @Suppress("MagicNumber", "NoMultipleSpaces") + @Suppress("NoMultipleSpaces") private fun generateByteCode(className: ByteArray, superClassName: ByteArray): ByteBuffer { val buf = ByteBuffer.allocate(1024) buf.putInt(0xCAFEBABE.toInt()) // magic diff --git a/ktorm-ksp-compiler/src/main/kotlin/org/ktorm/ksp/compiler/KtormProcessorProvider.kt b/ktorm-ksp-compiler/src/main/kotlin/org/ktorm/ksp/compiler/KtormProcessorProvider.kt index 2679fc0d2..06d6ce846 100644 --- a/ktorm-ksp-compiler/src/main/kotlin/org/ktorm/ksp/compiler/KtormProcessorProvider.kt +++ b/ktorm-ksp-compiler/src/main/kotlin/org/ktorm/ksp/compiler/KtormProcessorProvider.kt @@ -65,7 +65,8 @@ public class KtormProcessorProvider : SymbolProcessorProvider { val fileSpec = FileGenerator.generate(table, environment) // Beautify the generated code. - val formattedCode = formatter.format(fileSpec.toString()) + val fileName = fileSpec.packageName.replace('.', '/') + "/" + fileSpec.name + ".kt" + val formattedCode = formatter.format(fileName, fileSpec.toString()) // Output the formatted code. val dependencies = Dependencies(false, *table.getDependencyFiles().toTypedArray()) @@ -88,7 +89,7 @@ public class KtormProcessorProvider : SymbolProcessorProvider { } catch (_: NoClassDefFoundError) { } - return CodeFormatter { code -> code } + return CodeFormatter { _, code -> code } } private fun TableMetadata.getDependencyFiles(): List { diff --git a/ktorm-ksp-compiler/src/main/kotlin/org/ktorm/ksp/compiler/formatter/CodeFormatter.kt b/ktorm-ksp-compiler/src/main/kotlin/org/ktorm/ksp/compiler/formatter/CodeFormatter.kt index 993b3b5f8..84f08b441 100644 --- a/ktorm-ksp-compiler/src/main/kotlin/org/ktorm/ksp/compiler/formatter/CodeFormatter.kt +++ b/ktorm-ksp-compiler/src/main/kotlin/org/ktorm/ksp/compiler/formatter/CodeFormatter.kt @@ -24,5 +24,5 @@ internal fun interface CodeFormatter { /** * Format the generated code to the community recommended coding style. */ - fun format(code: String): String + fun format(fileName: String, code: String): String } diff --git a/ktorm-ksp-compiler/src/main/kotlin/org/ktorm/ksp/compiler/formatter/KtLintCodeFormatter.kt b/ktorm-ksp-compiler/src/main/kotlin/org/ktorm/ksp/compiler/formatter/KtLintCodeFormatter.kt index 1e4501bc3..6515621cc 100644 --- a/ktorm-ksp-compiler/src/main/kotlin/org/ktorm/ksp/compiler/formatter/KtLintCodeFormatter.kt +++ b/ktorm-ksp-compiler/src/main/kotlin/org/ktorm/ksp/compiler/formatter/KtLintCodeFormatter.kt @@ -38,7 +38,7 @@ internal class KtLintCodeFormatter(val environment: SymbolProcessorEnvironment) ) ) - override fun format(code: String): String { + override fun format(fileName: String, code: String): String { try { // Manually fix some code styles before formatting. val snippet = code diff --git a/ktorm-ksp-compiler/src/main/kotlin/org/ktorm/ksp/compiler/formatter/StandaloneKtLintCodeFormatter.kt b/ktorm-ksp-compiler/src/main/kotlin/org/ktorm/ksp/compiler/formatter/StandaloneKtLintCodeFormatter.kt index 471b4e8f2..bbf9406d1 100644 --- a/ktorm-ksp-compiler/src/main/kotlin/org/ktorm/ksp/compiler/formatter/StandaloneKtLintCodeFormatter.kt +++ b/ktorm-ksp-compiler/src/main/kotlin/org/ktorm/ksp/compiler/formatter/StandaloneKtLintCodeFormatter.kt @@ -18,19 +18,25 @@ package org.ktorm.ksp.compiler.formatter import com.google.devtools.ksp.processing.SymbolProcessorEnvironment import java.io.File +import java.util.concurrent.TimeUnit internal class StandaloneKtLintCodeFormatter(val environment: SymbolProcessorEnvironment) : CodeFormatter { + private val logger = environment.logger private val command = buildCommand() init { - environment.logger.info("[ktorm-ksp-compiler] init ktlint formatter with command: ${command.joinToString(" ")}") + logger.info("[ktorm-ksp-compiler] init ktlint formatter with command: ${command.joinToString(" ")}") } - override fun format(code: String): String { + override fun format(fileName: String, code: String): String { try { val p = ProcessBuilder(command).start() p.outputStream.bufferedWriter(Charsets.UTF_8).use { it.write(preprocessCode(code)) } - p.waitFor() + + if (!p.waitFor(30, TimeUnit.SECONDS)) { + logger.info("[ktorm-ksp-compiler] ktlint execution timeout, skip code formatting for file: $fileName") + return code + } val formattedCode = p.inputStream.bufferedReader(Charsets.UTF_8).use { it.readText() } if (p.exitValue() == 0) { @@ -43,12 +49,12 @@ internal class StandaloneKtLintCodeFormatter(val environment: SymbolProcessorEnv } else { // Exit exceptionally. val msg = p.errorStream.bufferedReader(Charsets.UTF_8).use { it.readText() } - environment.logger.error("[ktorm-ksp-compiler] ktlint exit with code: ${p.exitValue()}\n$msg") + logger.error("[ktorm-ksp-compiler] ktlint exit with code: ${p.exitValue()}\n$msg") return code } } } catch (e: Throwable) { - environment.logger.exception(e) + logger.exception(e) return code } } diff --git a/ktorm-ksp-compiler/src/main/kotlin/org/ktorm/ksp/compiler/generator/PseudoConstructorFunctionGenerator.kt b/ktorm-ksp-compiler/src/main/kotlin/org/ktorm/ksp/compiler/generator/PseudoConstructorFunctionGenerator.kt index 14d79898c..4c2437d7f 100644 --- a/ktorm-ksp-compiler/src/main/kotlin/org/ktorm/ksp/compiler/generator/PseudoConstructorFunctionGenerator.kt +++ b/ktorm-ksp-compiler/src/main/kotlin/org/ktorm/ksp/compiler/generator/PseudoConstructorFunctionGenerator.kt @@ -90,7 +90,7 @@ internal object PseudoConstructorFunctionGenerator { } if (!prop._type.isMarkedNullable) { - statement += "·?:·error(\"`%1L` should not be null.\")" + statement += "·?:·error(\"`%1L`·should·not·be·null.\")" } addStatement(statement, prop.simpleName.asString()) diff --git a/ktorm.version b/ktorm.version index ee74734aa..627a3f43a 100644 --- a/ktorm.version +++ b/ktorm.version @@ -1 +1 @@ -4.1.0 +4.1.1 diff --git a/settings.gradle.kts b/settings.gradle.kts index 20dab7391..30cf9df7e 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,6 @@ plugins { - id("com.gradle.enterprise") version("3.14.1") + id("com.gradle.enterprise") version "3.14.1" } include("ktorm-core")