Skip to content

Commit

Permalink
feat: java templates generator plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Apehum committed Apr 6, 2024
1 parent 4fc138b commit e97cdf9
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies {
implementation(libs.toml4j)

implementation(libs.asm)
implementation(libs.idea.ext)

implementation("su.plo.voice.api:server:${libs.versions.plasmovoice.get()}")
implementation("su.plo.voice.api:client:${libs.versions.plasmovoice.get()}")
Expand Down
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ kotlinparser = "0.1.0"
snakeyaml = "2.0"
toml4j = "0.7.2"
asm = "9.6"
idea-ext = "1.1.8"

plasmovoice = "2.1.0-SNAPSHOT"

Expand All @@ -17,5 +18,5 @@ javaparser = { module = "com.github.javaparser:javaparser-core", version.ref = "
kotlinparser = { module = "com.github.kotlinx.ast:grammar-kotlin-parser-antlr-kotlin", version.ref = "kotlinparser" }
snakeyaml = { module = "org.yaml:snakeyaml", version.ref = "snakeyaml" }
toml4j = { module = "com.moandjiezana.toml:toml4j", version.ref = "toml4j" }

asm = { module = "org.ow2.asm:asm-commons", version.ref = "asm" }
idea-ext = { module = "gradle.plugin.org.jetbrains.gradle.plugin.idea-ext:gradle-idea-ext", version.ref = "idea-ext" }
6 changes: 6 additions & 0 deletions src/main/kotlin/su/plo/voice/plugin/JavaTemplatesExtension.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package su.plo.voice.plugin

open class JavaTemplatesExtension {

var inputs: Map<String, String> = emptyMap()
}
50 changes: 50 additions & 0 deletions src/main/kotlin/su/plo/voice/plugin/java-templates.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package su.plo.voice.plugin

import org.gradle.plugins.ide.idea.model.IdeaModel
import org.gradle.plugins.ide.idea.model.IdeaProject
import org.jetbrains.gradle.ext.ProjectSettings
import org.jetbrains.gradle.ext.TaskTriggersConfig
import org.jetbrains.gradle.ext.taskTriggers

plugins {
java
id("org.jetbrains.gradle.plugin.idea-ext")
}

val extension = project.extensions.create("javaTemplates", JavaTemplatesExtension::class)

val templateSource = file("src/main/java-templates")
val templateDestination: Provider<Directory> = layout.buildDirectory.dir("generated/sources/java-templates")
val generateTemplates = tasks.register<Copy>("generateTemplates") {
val props = mutableMapOf(
"version" to version
) + extension.inputs

inputs.properties(props)

from(templateSource)
into(templateDestination)
expand(props)
}

sourceSets.main.get().java.srcDir(generateTemplates.map { it.outputs })

fun Project.idea(block: IdeaModel.() -> Unit) =
(this as ExtensionAware).extensions.configure("idea", block)

fun IdeaProject.settings(block: ProjectSettings.() -> Unit) =
(this@settings as ExtensionAware).extensions.configure(block)

val ProjectSettings.taskTriggers: TaskTriggersConfig
get() = (this as ExtensionAware).extensions.getByName("taskTriggers") as TaskTriggersConfig

rootProject.idea {
project {
settings {
taskTriggers {
afterSync(generateTemplates)
beforeBuild(generateTemplates)
}
}
}
}

0 comments on commit e97cdf9

Please sign in to comment.