Files
intellij-slint/build.gradle.kts
2025-08-08 15:49:35 +08:00

136 lines
3.9 KiB
Plaintext

plugins {
id("java")
id("org.jetbrains.kotlin.jvm") version "1.9.23"
id("org.jetbrains.intellij") version "1.17.3"
id("org.jetbrains.grammarkit") version "2022.3.2.2"
id("de.undercouch.download") version "5.6.0"
}
val slintVersion: String by project
//github url
val slintGithubUrl = "https://github.com/slint-ui/slint/releases/download/v$slintVersion"
//download dir
val slintViewerDownloadDir = "${layout.buildDirectory.get()}/slint-lsp"
//decompression path
val slintViewerBinaryDir = "${layout.buildDirectory.get()}/slint-lsp/$slintVersion"
val grammarGeneratedRoot = "${layout.buildDirectory.get()}/generated/sources/grammar/"
//github filename-> decompression name
val slintViewerFilenames = arrayOf(
"slint-lsp-linux.tar.gz" to "slint-lsp-linux",
"slint-lsp-macos.tar.gz" to "slint-lsp-macos",
"slint-lsp-windows.zip" to "slint-lsp-windows.exe",
)
sourceSets {
main {
java {
srcDirs(file("${grammarGeneratedRoot}/main/java"))
}
}
}
group = "me.zhouxi"
version = "0.0.1"
repositories {
mavenCentral()
}
intellij {
version.set("IU-241-EAP-SNAPSHOT")
sandboxDir.set("idea-sandbox")
plugins.set(listOf("java","Git4Idea"))
}
dependencies {
}
tasks {
buildPlugin {
//copy slint-lsp to plugin dir
from(slintViewerBinaryDir) {
into("/slint-lsp")
}
}
withType<JavaExec>().configureEach {
if (name.endsWith("main()")) {
notCompatibleWithConfigurationCache("JavaExec created by IntelliJ")
}
}
runIde {
//copy slint-lsp
doFirst {
copy {
from(slintViewerBinaryDir)
into("idea-sandbox/plugins/intellij-slint/slint-lsp")
}
}
}
withType<JavaCompile> {
sourceCompatibility = "17"
targetCompatibility = "17"
}
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "17"
}
patchPluginXml {
sinceBuild.set("232")
untilBuild.set("242.*")
}
generateParser {
purgeOldFiles.set(true)
sourceFile.set(file("src/main/grammar/main.bnf"))
pathToParser.set("SlintParser")
targetRootOutputDir.set(file("${grammarGeneratedRoot}/main/java"))
pathToPsiRoot.set("psi")
}
generateLexer {
sourceFile.set(file("src/main/grammar/main.flex"))
targetOutputDir.set(file("${grammarGeneratedRoot}/main/java/me/zhouxi/slint/lang/lexer"))
purgeOldFiles.set(true)
}
withType<Test> {
jvmArgs("-Djava.awt.headless=true")
}
register("downloadSlintResource") {
doFirst {
slintViewerFilenames.forEach { fileDesc ->
val (filename, renamed) = fileDesc
val src = "$slintGithubUrl/$filename"
val fileTarget = "$slintViewerDownloadDir/$filename"
download.run {
src(src)
dest(fileTarget)
}
copy {
val fileTree = if (filename.endsWith("zip")) {
zipTree(fileTarget)
} else {
tarTree(fileTarget)
}
from(fileTree)
//include executable file path
include("slint-lsp/slint-lsp*")
eachFile {
//rename to platform name
this.relativePath = RelativePath(true, renamed)
}
into(slintViewerBinaryDir)
}
}
}
}
signPlugin {
certificateChain.set(System.getenv("CERTIFICATE_CHAIN"))
privateKey.set(System.getenv("PRIVATE_KEY"))
password.set(System.getenv("PRIVATE_KEY_PASSWORD"))
}
publishPlugin {
token.set(System.getenv("PUBLISH_TOKEN"))
}
}