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

Release 4.1.1 #576

Merged
merged 13 commits into from
Sep 3, 2024
52 changes: 0 additions & 52 deletions PACKAGES.md

This file was deleted.

18 changes: 6 additions & 12 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
2 changes: 2 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
5 changes: 5 additions & 0 deletions buildSrc/src/main/kotlin/ktorm.base.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions buildSrc/src/main/kotlin/ktorm.dokka.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

plugins {
id("org.jetbrains.dokka")
}

tasks.named<org.jetbrains.dokka.gradle.DokkaMultiModuleTask>("dokkaHtmlMultiModule") {
val tmplDir = System.getProperty("dokka.templatesDir")
if (!tmplDir.isNullOrEmpty()) {
pluginConfiguration<org.jetbrains.dokka.base.DokkaBase, org.jetbrains.dokka.base.DokkaBaseConfiguration> {
templatesDir = File(tmplDir)
}
}
}

subprojects {
apply(plugin = "org.jetbrains.dokka")

tasks.dokkaJavadoc {
dependsOn("codegen")

dokkaSourceSets.named("main") {
suppressGeneratedFiles.set(false)
}
}

tasks.named<org.jetbrains.dokka.gradle.DokkaTaskPartial>("dokkaHtmlPartial") {
dependsOn("codegen")

val tmplDir = System.getProperty("dokka.templatesDir")
if (!tmplDir.isNullOrEmpty()) {
pluginConfiguration<org.jetbrains.dokka.base.DokkaBase, org.jetbrains.dokka.base.DokkaBaseConfiguration> {
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")
}
}
}
}
6 changes: 5 additions & 1 deletion buildSrc/src/main/kotlin/ktorm.publish.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
5 changes: 1 addition & 4 deletions buildSrc/src/main/kotlin/ktorm.tuples-codegen.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,7 @@ val generateTuples by tasks.registering {
}

tasks {
compileKotlin {
dependsOn(generateTuples)
}
"jarSources" {
"codegen" {
dependsOn(generateTuples)
}
}
Expand Down
2 changes: 1 addition & 1 deletion detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion ktorm-core/src/main/kotlin/org/ktorm/schema/SqlTypes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ public fun BaseTable<*>.yearMonth(name: String): Column<YearMonth> {
/**
* [SqlType] implementation used to save [YearMonth] instances, formatting them to strings with pattern `yyyy-MM`.
*/
@Suppress("MagicNumber")
public object YearMonthSqlType : SqlType<YearMonth>(Types.VARCHAR, "varchar") {
private val formatter = DateTimeFormatterBuilder()
.appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD)
Expand Down
5 changes: 1 addition & 4 deletions ktorm-jackson/ktorm-jackson.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ val generatePackageVersion by tasks.registering(Copy::class) {
}

tasks {
compileKotlin {
dependsOn(generatePackageVersion)
}
"jarSources" {
codegen {
dependsOn(generatePackageVersion)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -88,7 +89,7 @@ public class KtormProcessorProvider : SymbolProcessorProvider {
} catch (_: NoClassDefFoundError) {
}

return CodeFormatter { code -> code }
return CodeFormatter { _, code -> code }
}

private fun TableMetadata.getDependencyFiles(): List<KSFile> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion ktorm.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1.0
4.1.1
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

plugins {
id("com.gradle.enterprise") version("3.14.1")
id("com.gradle.enterprise") version "3.14.1"
}

include("ktorm-core")
Expand Down