ZigBrains/build.gradle.kts

380 lines
11 KiB
Text
Raw Normal View History

2023-08-18 23:58:39 +02:00
import groovy.xml.XmlParser
2023-07-29 12:22:51 +02:00
import org.jetbrains.changelog.Changelog
import org.jetbrains.changelog.markdownToHTML
2023-08-08 22:59:16 +02:00
import org.jetbrains.grammarkit.tasks.GenerateLexerTask
import org.jetbrains.grammarkit.tasks.GenerateParserTask
2023-08-18 23:58:39 +02:00
import org.jetbrains.intellij.tasks.PatchPluginXmlTask
2023-08-10 22:25:04 +02:00
import org.jetbrains.intellij.tasks.RunPluginVerifierTask
2023-07-29 12:22:51 +02:00
fun properties(key: String) = providers.gradleProperty(key)
fun environment(key: String) = providers.environmentVariable(key)
plugins {
id("java") // Java support
2023-08-18 23:58:39 +02:00
id("java-library")
2023-07-29 12:22:51 +02:00
alias(libs.plugins.gradleIntelliJPlugin) // Gradle IntelliJ Plugin
alias(libs.plugins.changelog) // Gradle Changelog Plugin
2023-08-08 22:59:16 +02:00
alias(libs.plugins.grammarkit)
2023-07-29 12:22:51 +02:00
}
2023-08-16 13:33:22 +02:00
val grammarKitGenDir = "build/generated/sources/grammarkit/java"
val rootPackage = "com.falsepattern.zigbrains"
val rootPackagePath = rootPackage.replace('.', '/')
2023-07-31 15:32:41 +02:00
// Keep these in sync with whatever the oldest IDE version we're targeting in gradle.properties needs
val javaLangVersion: JavaLanguageVersion? = JavaLanguageVersion.of(17)
val javaVersion = JavaVersion.VERSION_17
2023-08-19 00:37:12 +02:00
val baseIDE: String = properties("baseIDE").get()
val ideaVersion: String = properties("ideaVersion").get()
val clionVersion: String = properties("clionVersion").get()
val baseVersion = when(baseIDE) {
"idea" -> ideaVersion
"clion" -> clionVersion
else -> error("Unexpected IDE name: `$baseIDE")
}
val clionPlugins = listOf("com.intellij.cidr.base", "com.intellij.clion")
2023-08-18 23:58:39 +02:00
tasks {
wrapper {
gradleVersion = properties("gradleVersion").get()
2023-07-31 15:32:41 +02:00
}
}
2023-08-18 23:58:39 +02:00
allprojects {
apply {
plugin("org.jetbrains.grammarkit")
plugin("org.jetbrains.intellij")
}
repositories {
mavenCentral()
maven("https://cache-redirector.jetbrains.com/repo.maven.apache.org/maven2")
maven("https://cache-redirector.jetbrains.com/intellij-dependencies")
}
dependencies {
compileOnly("org.jetbrains:annotations:24.0.1")
2023-08-19 21:49:45 +02:00
compileOnly("org.projectlombok:lombok:1.18.28")
annotationProcessor("org.projectlombok:lombok:1.18.28")
2023-08-18 23:58:39 +02:00
}
intellij {
2023-08-19 00:37:12 +02:00
version = baseVersion
2023-08-18 23:58:39 +02:00
updateSinceUntilBuild = true
2023-08-19 22:26:29 +02:00
instrumentCode = false
2023-08-18 23:58:39 +02:00
}
sourceSets {
main {
java {
srcDirs(
"${grammarKitGenDir}/lexer",
"${grammarKitGenDir}/parser"
)
}
}
}
2023-07-29 12:22:51 +02:00
2023-08-18 23:58:39 +02:00
configure<JavaPluginExtension> {
toolchain {
languageVersion.set(javaLangVersion)
}
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
2023-07-29 12:22:51 +02:00
}
2023-08-18 23:58:39 +02:00
group = properties("pluginGroup").get()
version = properties("pluginVersion").get()
2023-07-29 12:22:51 +02:00
2023-08-18 23:58:39 +02:00
tasks {
runIde { enabled = false }
prepareSandbox { enabled = false }
buildSearchableOptions { enabled = false }
2023-07-29 12:22:51 +02:00
2023-08-18 23:58:39 +02:00
withType<PatchPluginXmlTask> {
sinceBuild = properties("pluginSinceBuild")
untilBuild = properties("pluginUntilBuild")
}
2023-07-29 12:22:51 +02:00
2023-08-18 23:58:39 +02:00
withType<org.jetbrains.intellij.tasks.RunIdeBase> {
rootProject.file("jbr/bin/java")
.takeIf { it.exists() }
?.let { projectExecutable.set(it.toString()) }
}
withType<org.jetbrains.intellij.tasks.RunPluginVerifierTask> {
rootProject.file("jbr")
.takeIf { it.exists() }
?.let { runtimeDir.set(it.toString()) }
}
generateLexer {
purgeOldFiles = true
}
generateParser {
targetRoot = "${grammarKitGenDir}/parser"
purgeOldFiles = true
}
register<DefaultTask>("generateGrammars") {
description = "Generate source code from parser/lexer definitions"
group = "build setup"
dependsOn("generateLexer")
dependsOn("generateParser")
2023-08-08 22:59:16 +02:00
}
2023-08-19 00:37:12 +02:00
verifyPlugin {
enabled = false
}
2023-08-08 22:59:16 +02:00
}
}
2023-08-18 23:58:39 +02:00
project(":") {
apply {
plugin("org.jetbrains.changelog")
}
task<Exec>("nixos_jbr") {
description = "Create a symlink to package jetbrains.jdk"
group = "build setup"
commandLine("nix-build", "<nixpkgs>", "-A", "jetbrains.jdk", "-o", "jbr")
}
2023-07-29 12:22:51 +02:00
2023-08-18 23:58:39 +02:00
tasks {
buildPlugin {
enabled = false
}
2023-07-29 12:22:51 +02:00
}
2023-08-18 23:58:39 +02:00
changelog {
groups.empty()
repositoryUrl = properties("pluginRepositoryUrl")
2023-08-08 22:59:16 +02:00
}
2023-08-18 23:58:39 +02:00
}
2023-08-08 22:59:16 +02:00
2023-08-19 00:37:12 +02:00
project(":debugger") {
dependencies {
implementation(project(":zig"))
}
intellij {
version = clionVersion
plugins = clionPlugins
}
}
2023-08-18 23:58:39 +02:00
project(":lsp") {
apply {
plugin("java-library")
}
dependencies {
api("org.eclipse.lsp4j:org.eclipse.lsp4j:0.21.0")
implementation("com.vladsch.flexmark:flexmark:0.64.8")
api("org.apache.commons:commons-lang3:3.13.0")
2023-08-08 22:59:16 +02:00
}
2023-08-18 23:58:39 +02:00
}
2023-08-08 22:59:16 +02:00
2023-08-18 23:58:39 +02:00
project(":zig") {
dependencies {
implementation(project(":lsp"))
implementation(project(":common"))
2023-08-08 22:59:16 +02:00
}
2023-08-18 23:58:39 +02:00
tasks {
generateLexer {
enabled = true
sourceFile = file("src/main/grammar/Zig.flex")
targetDir = "${grammarKitGenDir}/lexer/${rootPackagePath}/zig/lexer"
targetClass = "ZigFlexLexer"
}
2023-08-08 22:59:16 +02:00
2023-08-18 23:58:39 +02:00
generateParser {
enabled = true
sourceFile = file("src/main/grammar/Zig.bnf")
pathToParser = "${rootPackagePath}/zig/psi/ZigParser.java"
pathToPsiRoot = "${rootPackagePath}/zig/psi"
}
compileJava {
dependsOn("generateGrammars")
}
2023-08-19 00:37:12 +02:00
2023-08-08 22:59:16 +02:00
}
2023-08-18 23:58:39 +02:00
}
2023-08-08 22:59:16 +02:00
2023-08-19 21:49:45 +02:00
project(":project") {
dependencies {
implementation(project(":common"))
implementation(project(":zig"))
}
}
2023-08-18 23:58:39 +02:00
project(":zon") {
dependencies {
implementation(project(":common"))
}
2023-08-18 23:58:39 +02:00
tasks {
generateLexer {
enabled = true
sourceFile = file("src/main/grammar/Zon.flex")
targetDir = "${grammarKitGenDir}/lexer/${rootPackagePath}/zon/lexer"
targetClass = "ZonFlexLexer"
}
2023-08-18 23:58:39 +02:00
generateParser {
enabled = true
sourceFile = file("src/main/grammar/Zon.bnf")
pathToParser = "${rootPackagePath}/zon/psi/ZonParser.java"
pathToPsiRoot = "${rootPackagePath}/zon/psi"
}
compileJava {
dependsOn("generateGrammars")
}
}
2023-08-18 23:58:39 +02:00
}
2023-08-18 23:58:39 +02:00
project(":plugin") {
apply {
plugin("org.jetbrains.changelog")
2023-08-08 22:59:16 +02:00
}
2023-08-18 23:58:39 +02:00
dependencies {
implementation(project(":zig"))
2023-08-19 21:49:45 +02:00
implementation(project(":project"))
2023-08-18 23:58:39 +02:00
implementation(project(":zon"))
2023-08-19 00:37:12 +02:00
implementation(project(":debugger"))
2023-08-18 23:58:39 +02:00
implementation(project(":"))
2023-08-08 22:59:16 +02:00
}
2023-08-18 23:58:39 +02:00
intellij {
pluginName = properties("pluginName")
}
2023-07-29 12:22:51 +02:00
2023-08-18 23:58:39 +02:00
// Include the generated files in the source set
// Collects all jars produced by compilation of project modules and merges them into singe one.
// We need to put all plugin manifest files into single jar to make new plugin model work
val mergePluginJarTask = task<Jar>("mergePluginJars") {
duplicatesStrategy = DuplicatesStrategy.FAIL
archiveBaseName.set("ZigBrains")
exclude("META-INF/MANIFEST.MF")
exclude("**/classpath.index")
val pluginLibDir by lazy {
val sandboxTask = tasks.prepareSandbox.get()
sandboxTask.destinationDir.resolve("${sandboxTask.pluginName.get()}/lib")
2023-07-29 12:22:51 +02:00
}
2023-08-18 23:58:39 +02:00
val pluginJars by lazy {
pluginLibDir.listFiles().orEmpty().filter { it.isPluginJar() }
}
destinationDirectory.set(project.layout.dir(provider { pluginLibDir }))
doFirst {
for (file in pluginJars) {
from(zipTree(file))
2023-07-29 12:22:51 +02:00
}
}
2023-08-18 23:58:39 +02:00
doLast {
delete(pluginJars)
}
2023-07-31 23:46:45 +02:00
}
2023-08-18 23:58:39 +02:00
tasks {
2023-07-31 23:46:45 +02:00
2023-08-18 23:58:39 +02:00
buildPlugin {
archiveBaseName.set("ZigBrains")
}
2023-08-10 22:25:13 +02:00
2023-08-18 23:58:39 +02:00
runIde {
dependsOn(mergePluginJarTask)
enabled = true
}
2023-08-08 23:49:28 +02:00
2023-08-18 23:58:39 +02:00
prepareSandbox {
finalizedBy(mergePluginJarTask)
enabled = true
}
buildSearchableOptions {
dependsOn(mergePluginJarTask)
}
patchPluginXml {
version = properties("pluginVersion")
// Extract the <!-- Plugin description --> section from README.md and provide for the plugin's manifest
pluginDescription = providers.fileContents(rootProject.layout.projectDirectory.file("README.md")).asText.map {
val start = "<!-- Plugin description -->"
val end = "<!-- Plugin description end -->"
with (it.lines()) {
if (!containsAll(listOf(start, end))) {
throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
}
subList(indexOf(start) + 1, indexOf(end)).joinToString("\n").let(::markdownToHTML)
}
}
val changelog = rootProject.changelog // local variable for configuration cache compatibility
// Get the latest available change notes from the changelog file
changeNotes = properties("pluginVersion").map { pluginVersion ->
with(changelog) {
renderItem(
(getOrNull(pluginVersion) ?: getUnreleased())
.withHeader(false)
.withEmptySections(false),
Changelog.OutputType.HTML,
)
}
}
}
signPlugin {
certificateChainFile = rootProject.file("secrets/chain.crt")
privateKeyFile = rootProject.file("secrets/private.pem")
2023-08-18 23:58:39 +02:00
password = environment("PRIVATE_KEY_PASSWORD")
}
verifyPluginSignature {
certificateChainFile = rootProject.file("secrets/chain.crt")
2023-08-18 23:58:39 +02:00
}
2023-08-08 23:49:28 +02:00
2023-08-19 00:37:12 +02:00
verifyPlugin {
dependsOn(mergePluginJarTask)
enabled = true
}
listProductsReleases {
types = listOf("IU", "IC", "CL")
}
2023-07-29 12:22:51 +02:00
// publishPlugin {
// dependsOn("patchChangelog")
// token = environment("PUBLISH_TOKEN")
// // The pluginVersion is based on the SemVer (https://semver.org) and supports pre-release labels, like 2.1.7-alpha.3
// // Specify pre-release label to publish the plugin in a custom Release Channel automatically. Read more:
// // https://plugins.jetbrains.com/docs/intellij/deployment.html#specifying-a-release-channel
// channels = properties("pluginVersion").map { listOf(it.split('-').getOrElse(1) { "default" }.split('.').first()) }
// }
2023-08-18 23:58:39 +02:00
}
}
fun File.isPluginJar(): Boolean {
if (!isFile) return false
if (extension != "jar") return false
return zipTree(this).files.any { it.isManifestFile() }
}
fun File.isManifestFile(): Boolean {
if (extension != "xml") return false
val rootNode = try {
val parser = XmlParser()
parser.parse(this)
} catch (e: Exception) {
logger.error("Failed to parse $path", e)
return false
}
return rootNode.name() == "idea-plugin"
2023-07-29 12:22:51 +02:00
}