ZigBrains/build.gradle.kts

469 lines
14 KiB
Text
Raw Permalink Normal View History

2024-07-12 13:42:59 +02:00
import de.undercouch.gradle.tasks.download.Download
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
2024-10-25 18:12:33 +02:00
import org.jetbrains.grammarkit.tasks.GenerateLexerTask
2024-06-19 23:07:56 +02:00
import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType
import org.jetbrains.intellij.platform.gradle.tasks.PatchPluginXmlTask
import org.jetbrains.intellij.platform.gradle.tasks.PublishPluginTask
import org.jetbrains.intellij.platform.gradle.utils.extensionProvider
2023-07-29 12:22:51 +02:00
2024-09-20 10:19:48 +02:00
fun properties(key: String) = providers.gradleProperty(key) as Provider<String>
fun environment(key: String) = providers.environmentVariable(key) as Provider<String>
2023-07-29 12:22:51 +02:00
plugins {
2024-06-19 23:07:56 +02:00
java
2024-06-02 19:54:39 +02:00
`maven-publish`
2024-06-19 23:07:56 +02:00
`java-library`
2024-09-20 14:10:49 +02:00
id("org.jetbrains.intellij.platform") version("2.1.0")
2024-06-19 23:07:56 +02:00
id("org.jetbrains.changelog") version("2.2.1")
id("org.jetbrains.grammarkit") version("2022.3.2.2")
2024-07-12 13:42:59 +02:00
id("de.undercouch.download") version("5.6.0")
2023-07-29 12:22:51 +02:00
}
2024-09-20 10:19:48 +02:00
val publishVersions = listOf("232", "233", "241", "242", "243")
2024-06-02 19:54:39 +02:00
2024-03-02 19:40:58 +01:00
val gitVersion: groovy.lang.Closure<String> by extra
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
2024-05-15 18:13:16 +02:00
val javaLangVersion: JavaLanguageVersion = JavaLanguageVersion.of(17)
2023-07-31 15:32:41 +02:00
val javaVersion = JavaVersion.VERSION_17
2024-06-19 23:07:56 +02:00
val baseIDE = properties("baseIDE").get()
val ideaVersion = properties("ideaVersion").get()
val clionVersion = properties("clionVersion").get()
2023-08-19 00:37:12 +02:00
2024-02-01 19:32:58 +01:00
val clionPlugins = listOf("com.intellij.clion", "com.intellij.cidr.lang", "com.intellij.cidr.base", "com.intellij.nativeDebug")
2023-08-19 00:37:12 +02:00
2024-06-19 23:07:56 +02:00
val lsp4jVersion = "0.21.1"
2024-10-17 10:24:19 +02:00
val lsp4ijVersion = "0.7.0"
2024-06-19 23:07:56 +02:00
val lsp4ijNightly = lsp4ijVersion.contains("-")
val lsp4ijDepString = "${if (lsp4ijNightly) "nightly." else ""}com.jetbrains.plugins:com.redhat.devtools.lsp4ij:$lsp4ijVersion"
val lsp4ijPluginString = "com.redhat.devtools.lsp4ij:$lsp4ijVersion${if (lsp4ijNightly) "@nightly" else ""}"
val lsp4ijDep: DependencyHandler.() -> Unit = {
intellijPlatformPluginDependency(lsp4ijDepString)
compileOnlyApi(lsp4ijDepString)
compileOnlyApi("org.eclipse.lsp4j:org.eclipse.lsp4j:$lsp4jVersion")
}
2023-08-18 23:58:39 +02:00
tasks {
wrapper {
gradleVersion = properties("gradleVersion").get()
2023-07-31 15:32:41 +02:00
}
}
fun pluginVersion(): Provider<String> {
return provider {
System.getenv("RELEASE_VERSION")
2024-06-19 23:07:56 +02:00
}.orElse(properties("pluginVersion"))
2024-03-02 19:40:58 +01:00
}
fun pluginVersionFull(): Provider<String> {
return pluginVersion().map { it + "-" + properties("pluginSinceBuild").get() }
}
2023-08-18 23:58:39 +02:00
allprojects {
apply {
2024-06-19 23:07:56 +02:00
plugin("org.jetbrains.intellij.platform")
2023-08-18 23:58:39 +02:00
}
repositories {
mavenCentral()
2024-06-19 23:07:56 +02:00
intellijPlatform {
localPlatformArtifacts {
content {
includeGroup("bundledPlugin")
}
}
marketplace {
content {
includeGroup("com.jetbrains.plugins")
includeGroup("nightly.com.jetbrains.plugins")
}
}
releases {
content {
includeModule("com.jetbrains.intellij.clion", "clion")
includeModule("com.jetbrains.intellij.idea", "ideaIC")
includeModule("com.jetbrains.intellij.idea", "ideaIU")
}
}
2024-09-20 10:19:48 +02:00
jetbrainsIdeInstallers {
content {
includeModule("cpp", "CLion")
includeModule("idea", "ideaIC")
includeModule("idea", "ideaIU")
}
}
2024-06-19 23:07:56 +02:00
}
2023-08-18 23:58:39 +02:00
}
dependencies {
2024-06-19 23:07:56 +02:00
compileOnly("org.projectlombok:lombok:1.18.32")
annotationProcessor("org.projectlombok:lombok:1.18.32")
2024-09-20 14:10:49 +02:00
if (path !in listOf(":", ":plugin", ":debugger", ":cidr")) {
2024-06-19 23:07:56 +02:00
intellijPlatform {
2024-07-25 00:44:37 +02:00
intellijIdeaCommunity(ideaVersion, useInstaller = false)
2024-06-19 23:07:56 +02:00
}
}
2023-08-18 23:58:39 +02:00
}
2024-06-19 23:07:56 +02:00
if (path in listOf(":zig", ":zon")) {
apply {
plugin("org.jetbrains.grammarkit")
}
sourceSets {
main {
java {
srcDirs(
"${grammarKitGenDir}/lexer",
"${grammarKitGenDir}/parser"
)
}
}
}
tasks {
generateLexer {
enabled = true
purgeOldFiles = true
}
generateParser {
enabled = true
targetRootOutputDir = file("${grammarKitGenDir}/parser")
}
register<DefaultTask>("generateGrammars") {
description = "Generate source code from parser/lexer definitions"
group = "build setup"
dependsOn("generateLexer")
dependsOn("generateParser")
}
compileJava {
dependsOn("generateGrammars")
2023-08-18 23:58:39 +02:00
}
}
}
2023-07-29 12:22:51 +02:00
2023-08-18 23:58:39 +02:00
configure<JavaPluginExtension> {
toolchain {
languageVersion.set(javaLangVersion)
2024-07-12 13:42:59 +02:00
vendor = JvmVendorSpec.JETBRAINS
2023-08-18 23:58:39 +02:00
}
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
2023-07-29 12:22:51 +02:00
}
2024-03-08 17:26:47 +01:00
tasks.withType(JavaCompile::class) {
options.encoding = "UTF-8"
}
2023-08-18 23:58:39 +02:00
group = properties("pluginGroup").get()
2024-03-02 19:40:58 +01:00
version = pluginVersionFull().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 }
2024-06-19 23:07:56 +02:00
verifyPlugin { enabled = false }
buildPlugin { enabled = false }
signPlugin { enabled = false }
verifyPluginProjectConfiguration { enabled = false }
2023-07-29 12:22:51 +02:00
2023-08-18 23:58:39 +02:00
withType<PatchPluginXmlTask> {
sinceBuild = properties("pluginSinceBuild")
2024-09-20 10:19:48 +02:00
untilBuild = properties("pluginUntilBuild").flatMap {provider { it.ifBlank { null } }}
2023-08-18 23:58:39 +02:00
}
}
2024-06-19 23:07:56 +02:00
intellijPlatform {
instrumentCode = false
2024-10-03 14:53:49 +02:00
buildSearchableOptions = false
2023-08-08 22:59:16 +02:00
}
2023-08-18 23:58:39 +02:00
}
2023-08-08 22:59:16 +02:00
2024-06-19 23:07:56 +02:00
project(":common") {
2023-08-19 00:37:12 +02:00
}
2024-06-19 23:07:56 +02:00
project(":zig") {
2023-08-18 23:58:39 +02:00
apply {
plugin("java-library")
}
dependencies {
implementation(project(":common"))
2024-06-19 23:07:56 +02:00
lsp4ijDep()
intellijPlatform {
plugin(lsp4ijPluginString)
2024-10-17 11:29:50 +02:00
bundledPlugin("org.intellij.intelliLang")
2024-06-19 23:07:56 +02:00
}
2023-08-08 22:59:16 +02:00
}
2023-08-18 23:58:39 +02:00
tasks {
generateLexer {
sourceFile = file("src/main/grammar/Zig.flex")
targetOutputDir = file("${grammarKitGenDir}/lexer/${rootPackagePath}/zig/lexer")
2023-08-18 23:58:39 +02:00
}
2023-08-08 22:59:16 +02:00
2024-10-25 18:12:33 +02:00
register<GenerateLexerTask>("generateStringLexer") {
sourceFile = file("src/main/grammar/ZigString.flex")
targetOutputDir = file("${grammarKitGenDir}/lexer/${rootPackagePath}/zig/stringlexer")
purgeOldFiles = true
}
2023-08-18 23:58:39 +02:00
generateParser {
sourceFile = file("src/main/grammar/Zig.bnf")
pathToParser = "${rootPackagePath}/zig/psi/ZigParser.java"
pathToPsiRoot = "${rootPackagePath}/zig/psi"
}
2024-10-25 18:12:33 +02:00
named("generateGrammars") {
dependsOn("generateStringLexer")
}
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"))
}
}
2024-09-20 14:10:49 +02:00
project(":cidr") {
dependencies {
implementation(project(":common"))
implementation(project(":project"))
intellijPlatform {
clion(clionVersion, useInstaller = false)
for (p in clionPlugins) {
bundledPlugin(p)
}
}
}
}
2024-06-19 23:07:56 +02:00
project(":debugger") {
dependencies {
implementation(project(":zig"))
implementation(project(":project"))
implementation(project(":common"))
implementation("org.eclipse.lsp4j:org.eclipse.lsp4j.debug:$lsp4jVersion") {
exclude("org.eclipse.lsp4j", "org.eclipse.lsp4j")
exclude("org.eclipse.lsp4j", "org.eclipse.lsp4j.jsonrpc")
exclude("com.google.code.gson", "gson")
}
intellijPlatform {
2024-07-25 00:44:37 +02:00
clion(clionVersion, useInstaller = false)
2024-06-19 23:07:56 +02:00
for (p in clionPlugins) {
bundledPlugin(p)
}
}
}
2024-07-12 13:42:59 +02:00
val genOutputDir = layout.buildDirectory.dir("generated-resources")
sourceSets["main"].resources.srcDir(genOutputDir)
tasks {
register<Download>("downloadProps") {
src("https://falsepattern.com/zigbrains/msvc.properties")
dest(genOutputDir.map { it.file("msvc.properties") })
}
processResources {
dependsOn("downloadProps")
}
}
2024-06-19 23:07:56 +02:00
}
2023-08-18 23:58:39 +02:00
project(":zon") {
dependencies {
implementation(project(":common"))
}
2023-08-18 23:58:39 +02:00
tasks {
generateLexer {
sourceFile = file("src/main/grammar/Zon.flex")
targetOutputDir = file("${grammarKitGenDir}/lexer/${rootPackagePath}/zon/lexer")
2023-08-18 23:58:39 +02:00
}
2023-08-18 23:58:39 +02:00
generateParser {
sourceFile = file("src/main/grammar/Zon.bnf")
pathToParser = "${rootPackagePath}/zon/psi/ZonParser.java"
pathToPsiRoot = "${rootPackagePath}/zon/psi"
}
}
2023-08-18 23:58:39 +02:00
}
2023-08-18 23:58:39 +02:00
project(":plugin") {
dependencies {
2024-06-19 23:07:56 +02:00
implementation(project(":common"))
2023-08-18 23:58:39 +02:00
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"))
2024-09-20 14:10:49 +02:00
implementation(project(":cidr"))
2023-08-19 00:37:12 +02:00
implementation(project(":debugger"))
2024-06-19 23:07:56 +02:00
intellijPlatform {
zipSigner()
pluginVerifier()
when (baseIDE) {
2024-07-25 00:44:37 +02:00
"idea" -> intellijIdeaCommunity(ideaVersion, useInstaller = false)
"clion" -> clion(clionVersion, useInstaller = false)
2024-06-19 23:07:56 +02:00
}
plugin(lsp4ijPluginString)
}
2023-08-08 22:59:16 +02:00
}
2024-06-19 23:07:56 +02:00
intellijPlatform {
projectName = "ZigBrains"
pluginConfiguration {
name = properties("pluginName")
description = 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)
}
}
changeNotes = pluginVersion().map { pluginVersion ->
with(rootProject.changelog) {
renderItem(
(getOrNull(pluginVersion) ?: getUnreleased())
.withHeader(false)
.withEmptySections(false),
Changelog.OutputType.HTML,
)
}
}
version = pluginVersionFull()
}
signing {
certificateChainFile = rootProject.file("secrets/chain.crt")
privateKeyFile = rootProject.file("secrets/private.pem")
password = environment("PRIVATE_KEY_PASSWORD")
}
2024-09-20 10:19:48 +02:00
pluginVerification {
2024-06-19 23:07:56 +02:00
ides {
ide(IntelliJPlatformType.IntellijIdeaCommunity, ideaVersion)
ide(IntelliJPlatformType.IntellijIdeaUltimate, ideaVersion)
ide(IntelliJPlatformType.CLion, clionVersion)
}
}
2023-08-18 23:58:39 +02:00
}
2023-07-29 12:22:51 +02:00
2023-08-18 23:58:39 +02:00
tasks {
runIde {
enabled = true
}
2023-08-08 23:49:28 +02:00
2023-08-18 23:58:39 +02:00
prepareSandbox {
enabled = true
}
2024-06-19 23:07:56 +02:00
verifyPlugin {
enabled = true
}
2023-08-18 23:58:39 +02:00
2024-06-19 23:07:56 +02:00
verifyPluginProjectConfiguration {
enabled = true
2023-08-18 23:58:39 +02:00
}
signPlugin {
2024-06-19 23:07:56 +02:00
enabled = true
2023-08-18 23:58:39 +02:00
}
verifyPluginSignature {
2024-06-19 23:07:56 +02:00
dependsOn(signPlugin)
2023-08-18 23:58:39 +02:00
}
2023-08-08 23:49:28 +02:00
2024-06-19 23:07:56 +02:00
buildPlugin {
2023-08-19 00:37:12 +02:00
enabled = true
}
2024-06-19 23:07:56 +02:00
}
}
2023-08-19 00:37:12 +02:00
2024-06-19 23:07:56 +02:00
dependencies {
intellijPlatform {
when (baseIDE) {
2024-07-25 00:44:37 +02:00
"idea" -> intellijIdeaCommunity(ideaVersion, useInstaller = false)
"clion" -> clion(clionVersion, useInstaller = false)
2023-08-19 00:37:12 +02:00
}
2024-06-02 19:54:39 +02:00
}
}
2024-06-19 23:07:56 +02:00
tasks {
generateLexer {
enabled = false
}
generateParser {
enabled = false
}
}
2024-06-02 19:54:39 +02:00
fun distFile(it: String) = layout.buildDirectory.file("dist/ZigBrains-${pluginVersion().get()}-$it-signed.zip")
publishVersions.forEach {
2024-06-19 23:07:56 +02:00
tasks.register<PublishPluginTask>("jbpublish-$it").configure {
archiveFile = distFile(it)
2024-06-02 19:54:39 +02:00
token = environment("IJ_PUBLISH_TOKEN")
2024-06-19 23:07:56 +02:00
channels = if (pluginVersion().get().contains("-")) listOf("nightly") else listOf("default")
2024-06-02 19:54:39 +02:00
}
2024-06-19 23:07:56 +02:00
tasks.named("publish").configure {
2024-06-02 19:54:39 +02:00
dependsOn("jbpublish-$it")
}
}
2023-08-19 00:37:12 +02:00
2024-06-02 19:54:39 +02:00
publishing {
publications {
create<MavenPublication>("maven") {
groupId = "com.falsepattern"
artifactId = "zigbrains"
version = pluginVersion().get()
publishVersions.forEach {
artifact(distFile(it)) {
classifier = "$it-signed"
extension = "zip"
}
}
}
}
repositories {
maven {
name = "mavenpattern"
url = uri("https://mvn.falsepattern.com/releases/");
credentials {
username = System.getenv("MAVEN_DEPLOY_USER")
password = System.getenv("MAVEN_DEPLOY_PASSWORD")
}
}
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"
2024-06-19 23:07:56 +02:00
}