Skip to content

Commit

Permalink
Generate dependencies for lsp
Browse files Browse the repository at this point in the history
  • Loading branch information
Enaium committed Dec 22, 2024
1 parent 8d3e126 commit 8cf6bf2
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 14 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "cn.enaium"
version = "0.0.18"
version = "${properties["version"]}"

repositories {
mavenCentral()
Expand All @@ -17,6 +17,7 @@ dependencies {
implementation(libs.javapoet)
implementation(libs.jetbrainsAnnotations)
implementation(libs.jimmer)
implementation(libs.jackson)
testImplementation(libs.testcontainers.postgresql)
testImplementation(libs.testcontainers.mariadb)
testImplementation(libs.testcontainers.mysql)
Expand Down
9 changes: 1 addition & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
kotlin.code.style=official
kotlinpoet=1.16.0
javapoet=1.13.0
testcontainers=1.19.6
postgresql=42.6.0
mariadb=3.3.3
mysql=8.3.0
jimmer=0.8.131
jetbrainsAnnotations=24.1.0
version=0.0.19
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ testcontainers = "1.19.7"
postgresql = "42.7.3"
mariadb = "3.3.3"
mysql = "8.3.0"
jimmer = "0.9.25"
jimmer = "0.9.35"
jetbrainsAnnotations = "24.1.0"
jackson = "2.18.2"

[libraries]
kotlinpoet = { module = "com.squareup:kotlinpoet", version.ref = "kotlinpoet" }
javapoet = { module = "com.squareup:javapoet", version.ref = "javapoet" }
jetbrainsAnnotations = { module = "org.jetbrains:annotations", version.ref = "jetbrainsAnnotations" }
jimmer = { module = "org.babyfish.jimmer:jimmer-core", version.ref = "jimmer" }
jackson = { module = "com.fasterxml.jackson.core:jackson-core", version.ref = "jackson" }
testcontainers-postgresql = { module = "org.testcontainers:postgresql", version.ref = "testcontainers" }
testcontainers-mariadb = { module = "org.testcontainers:mariadb", version.ref = "testcontainers" }
testcontainers-mysql = { module = "org.testcontainers:mysql", version.ref = "testcontainers" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Feb 21 13:43:28 CST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
9 changes: 6 additions & 3 deletions src/main/kotlin/cn/enaium/jimmer/gradle/JimmerPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cn.enaium.jimmer.gradle
import cn.enaium.jimmer.gradle.extension.JimmerExtension
import cn.enaium.jimmer.gradle.extension.Language
import cn.enaium.jimmer.gradle.task.GenerateEntityTask
import cn.enaium.jimmer.gradle.task.GenerateLspDependenciesTask
import cn.enaium.jimmer.gradle.utility.*
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand All @@ -43,9 +44,9 @@ class JimmerPlugin : Plugin<Project> {
}

project.afterEvaluate { afterProject ->
afterProject.tasks.create("generateEntity", GenerateEntityTask::class.java) {
it.group = "jimmer"
}
val generateEntity = afterProject.tasks.register("generateEntity", GenerateEntityTask::class.java)
val generateLspDependencies =
afterProject.tasks.register("generateLspDependencies", GenerateLspDependenciesTask::class.java)

if (extension.language.get() == Language.JAVA) {
afterProject.tasks.compileJava { compile ->
Expand Down Expand Up @@ -143,6 +144,7 @@ class JimmerPlugin : Plugin<Project> {
}
}
afterProject.tasks.compileJava { compile ->
compile.dependsOn(generateLspDependencies)
compile.options.compilerArgs.firstOrNull {
it.startsWith("-A$DTO_DIRS=")
}?.let {
Expand Down Expand Up @@ -180,6 +182,7 @@ class JimmerPlugin : Plugin<Project> {
}

fun addInputs(task: Task) {
task.dependsOn(generateLspDependencies)
kspArguments(afterProject.extensions.getByName("ksp"))[DTO_DIRS]?.let { dirs ->
dirs.split("\\s*[,:;]\\s*".toRegex()).mapNotNull {
when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ import java.util.logging.Logger
* @author Enaium
*/
open class GenerateEntityTask : DefaultTask() {

init {
group = "jimmer"
description = "Generate entity"
}

@TaskAction
fun generateEntity() {
val extension = project.extensions.getByType(JimmerExtension::class.java)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2024 Enaium
*
* 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 cn.enaium.jimmer.gradle.task

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.node.ArrayNode
import com.fasterxml.jackson.databind.node.JsonNodeFactory
import com.fasterxml.jackson.databind.node.ObjectNode
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
import java.io.File
import kotlin.io.path.*

/**
* @author Enaium
*/
open class GenerateLspDependenciesTask : DefaultTask() {
init {
group = "jimmer"
description = "Generate dependencies for LSP"
}

@TaskAction
fun generateLspDependency() {
val lspHome = Path(System.getProperty("user.home")).resolve("jimmer-dto-lsp")

if (lspHome.resolve("server.jar").exists().not()) {
return
}

val dependenciesFile = lspHome.resolve("dependencies.json")

if (dependenciesFile.exists().not()) {
dependenciesFile.createParentDirectories()
dependenciesFile.createFile()
dependenciesFile.writeText("{}")
}

val dependenciesJson = ObjectMapper().readTree(dependenciesFile.readText())
val dependencies = project.configurations.named("runtimeClasspath").get()

(dependenciesJson as ObjectNode).set<ArrayNode>(
project.projectDir.absolutePath,
JsonNodeFactory.instance.arrayNode().apply {
dependencies.forEach {
add(it.absolutePath)
}
})

dependenciesFile.writeText(ObjectMapper().writeValueAsString(dependenciesJson))
}
}

0 comments on commit 8cf6bf2

Please sign in to comment.