ci: Migrate to platform plugin 2.0

This commit is contained in:
FalsePattern 2024-06-20 01:07:56 +02:00
parent c1f1dd88f1
commit 79481eb6f3
Signed by: falsepattern
GPG key ID: E930CDEC50C50E23
16 changed files with 246 additions and 265 deletions

3
.gitignore vendored
View file

@ -146,4 +146,5 @@ gradle-app.setting
jbr
secrets
.idea/runConfigurations/Sign_Plugin.xml
.idea/runConfigurations/*.xml
.intellijPlatform

View file

@ -2,20 +2,22 @@ import groovy.xml.XmlParser
import groovy.xml.XmlSlurper
import org.jetbrains.changelog.Changelog
import org.jetbrains.changelog.markdownToHTML
import org.jetbrains.intellij.tasks.PatchPluginXmlTask
import org.jetbrains.intellij.tasks.PublishPluginTask
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.tasks.RunIdeTask
import org.jetbrains.intellij.platform.gradle.utils.extensionProvider
fun properties(key: String) = providers.gradleProperty(key)
fun environment(key: String) = providers.environmentVariable(key)
plugins {
id("java") // Java support
java
`maven-publish`
id("java-library")
id("org.jetbrains.intellij") version("1.17.3")
`java-library`
id("org.jetbrains.intellij.platform") version("2.0.0-beta7")
id("org.jetbrains.changelog") version("2.2.0")
id("org.jetbrains.grammarkit") version("2022.3.2.2")
id("com.palantir.git-version") version("3.0.0")
}
val publishVersions = listOf("232", "233", "241", "242")
@ -31,14 +33,9 @@ val rootPackagePath = rootPackage.replace('.', '/')
val javaLangVersion: JavaLanguageVersion = JavaLanguageVersion.of(17)
val javaVersion = JavaVersion.VERSION_17
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 baseIDE = properties("baseIDE").get()
val ideaVersion = properties("ideaVersion").get()
val clionVersion = properties("clionVersion").get()
val clionPlugins = listOf("com.intellij.clion", "com.intellij.cidr.lang", "com.intellij.cidr.base", "com.intellij.nativeDebug")
@ -48,27 +45,10 @@ tasks {
}
}
fun pluginVersionGit(): Provider<String> {
return provider {
try {
gitVersion()
} catch (_: java.lang.Exception) {
error("Git version not found and RELEASE_VERSION environment variable is not set!")
}
}
}
fun pluginVersion(): Provider<String> {
return provider {
System.getenv("RELEASE_VERSION")
}.orElse(pluginVersionGit().map {
val suffix = "-" + properties("pluginSinceBuild").get()
if (it.endsWith(suffix)) {
it.substring(0, it.length - suffix.length)
} else {
it
}
})
}.orElse(properties("pluginVersion"))
}
fun pluginVersionFull(): Provider<String> {
@ -77,22 +57,37 @@ fun pluginVersionFull(): Provider<String> {
allprojects {
apply {
plugin("org.jetbrains.grammarkit")
plugin("org.jetbrains.intellij")
plugin("org.jetbrains.intellij.platform")
}
repositories {
mavenCentral()
maven("https://cache-redirector.jetbrains.com/repo.maven.apache.org/maven2")
maven("https://cache-redirector.jetbrains.com/intellij-dependencies")
intellijPlatform {
localPlatformArtifacts {
content {
includeGroup("bundledPlugin")
}
}
snapshots {
content {
includeModule("com.jetbrains.intellij.clion", "clion")
includeModule("com.jetbrains.intellij.idea", "ideaIC")
}
}
}
}
dependencies {
compileOnly("org.projectlombok:lombok:1.18.30")
annotationProcessor("org.projectlombok:lombok:1.18.30")
compileOnly("org.projectlombok:lombok:1.18.32")
annotationProcessor("org.projectlombok:lombok:1.18.32")
if (path !in listOf(":", ":debugger")) {
intellijPlatform {
intellijIdeaCommunity(ideaVersion)
}
intellij {
version = baseVersion
updateSinceUntilBuild = true
instrumentCode = false
}
}
if (path in listOf(":zig", ":zon")) {
apply {
plugin("org.jetbrains.grammarkit")
}
sourceSets {
main {
@ -104,6 +99,32 @@ allprojects {
}
}
}
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")
}
}
}
configure<JavaPluginExtension> {
toolchain {
@ -125,80 +146,22 @@ allprojects {
runIde { enabled = false }
prepareSandbox { enabled = false }
buildSearchableOptions { enabled = false }
verifyPlugin { enabled = false }
buildPlugin { enabled = false }
signPlugin { enabled = false }
withType<PatchPluginXmlTask> {
sinceBuild = properties("pluginSinceBuild")
untilBuild = properties("pluginUntilBuild")
}
withType<org.jetbrains.intellij.tasks.RunIdeBase> {
rootProject.file("jbr/lib/openjdk/bin/java")
.takeIf { it.exists() }
?.let { projectExecutable.set(it.toString()) }
}
withType<org.jetbrains.intellij.tasks.RunPluginVerifierTask> {
rootProject.file("jbr/lib/openjdk")
.takeIf { it.exists() }
?.let { runtimeDir.set(it.toString()) }
}
generateLexer {
purgeOldFiles = true
}
generateParser {
targetRootOutputDir = file("${grammarKitGenDir}/parser")
purgeOldFiles = true
}
register<DefaultTask>("generateGrammars") {
description = "Generate source code from parser/lexer definitions"
group = "build setup"
dependsOn("generateLexer")
dependsOn("generateParser")
}
verifyPlugin {
enabled = false
}
intellijPlatform {
instrumentCode = false
}
}
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")
}
project(":common") {
tasks {
buildPlugin {
enabled = false
}
}
changelog {
groups.empty()
repositoryUrl = properties("pluginRepositoryUrl")
}
}
project(":debugger") {
dependencies {
implementation(project(":zig"))
implementation(project(":project"))
implementation(project(":common"))
implementation(project(":lsp-common"))
implementation(project(":lsp"))
implementation("org.eclipse.lsp4j:org.eclipse.lsp4j.debug:0.22.0")
}
intellij {
version = clionVersion
plugins = clionPlugins
}
}
project(":lsp-common") {
@ -228,22 +191,15 @@ project(":zig") {
}
tasks {
generateLexer {
enabled = true
sourceFile = file("src/main/grammar/Zig.flex")
targetOutputDir = file("${grammarKitGenDir}/lexer/${rootPackagePath}/zig/lexer")
}
generateParser {
enabled = true
sourceFile = file("src/main/grammar/Zig.bnf")
pathToParser = "${rootPackagePath}/zig/psi/ZigParser.java"
pathToPsiRoot = "${rootPackagePath}/zig/psi"
}
compileJava {
dependsOn("generateGrammars")
}
}
}
@ -254,52 +210,101 @@ project(":project") {
}
}
project(":debugger") {
dependencies {
implementation(project(":zig"))
implementation(project(":project"))
implementation(project(":common"))
implementation(project(":lsp-common"))
implementation(project(":lsp"))
implementation("org.eclipse.lsp4j:org.eclipse.lsp4j.debug:0.22.0")
intellijPlatform {
clion(clionVersion)
for (p in clionPlugins) {
bundledPlugin(p)
}
}
}
}
project(":zon") {
dependencies {
implementation(project(":common"))
}
tasks {
generateLexer {
enabled = true
sourceFile = file("src/main/grammar/Zon.flex")
targetOutputDir = file("${grammarKitGenDir}/lexer/${rootPackagePath}/zon/lexer")
}
generateParser {
enabled = true
sourceFile = file("src/main/grammar/Zon.bnf")
pathToParser = "${rootPackagePath}/zon/psi/ZonParser.java"
pathToPsiRoot = "${rootPackagePath}/zon/psi"
}
compileJava {
dependsOn("generateGrammars")
}
}
}
project(":plugin") {
apply {
plugin("org.jetbrains.changelog")
}
dependencies {
dependencies {
implementation(project(":zig"))
implementation(project(":project"))
implementation(project(":zon"))
implementation(project(":debugger"))
implementation(project(":"))
intellijPlatform {
zipSigner()
pluginVerifier()
when (baseIDE) {
"idea" -> intellijIdeaCommunity(ideaVersion)
"clion" -> clion(clionVersion)
}
}
}
intellij {
pluginName = properties("pluginName")
intellijPlatform {
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")
}
verifyPlugin {
ides {
ide(IntelliJPlatformType.IntellijIdeaCommunity, ideaVersion)
ide(IntelliJPlatformType.IntellijIdeaUltimate, ideaVersion)
ide(IntelliJPlatformType.CLion, clionVersion)
}
}
}
// 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") {
// 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")
@ -308,7 +313,7 @@ project(":plugin") {
val pluginLibDir by lazy {
val sandboxTask = tasks.prepareSandbox.get()
sandboxTask.destinationDir.resolve("${sandboxTask.pluginName.get()}/lib")
sandboxTask.destinationDir.resolve("${project.extensionProvider.map { it.projectName }.get()}/lib")
}
val pluginJars by lazy {
@ -326,14 +331,9 @@ project(":plugin") {
doLast {
delete(pluginJars)
}
}
tasks {
buildPlugin {
archiveBaseName.set("ZigBrains")
}
}
tasks {
runIde {
dependsOn(mergePluginJarTask)
enabled = true
@ -348,54 +348,29 @@ project(":plugin") {
dependsOn(mergePluginJarTask)
}
patchPluginXml {
version = pluginVersionFull()
// 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 = 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")
password = environment("PRIVATE_KEY_PASSWORD")
}
verifyPluginSignature {
certificateChainFile = rootProject.file("secrets/chain.crt")
}
verifyPlugin {
dependsOn(mergePluginJarTask)
enabled = true
}
listProductsReleases {
types = listOf("IU", "IC", "CL")
signPlugin {
enabled = true
}
verifyPluginSignature {
dependsOn(signPlugin)
}
buildPlugin {
enabled = true
}
generateLexer {
enabled = false
}
generateParser {
enabled = false
}
}
@ -403,7 +378,7 @@ fun distFile(it: String) = layout.buildDirectory.file("dist/ZigBrains-${pluginVe
publishVersions.forEach {
tasks.register<PublishPluginTask>("jbpublish-$it") {
distributionFile.set(distFile(it))
archiveFile = distFile(it)
token = environment("IJ_PUBLISH_TOKEN")
}
tasks.named("publish") {

View file

@ -64,7 +64,7 @@ fi
for i in "${branches[@]}"
do
echo "Building branch $i"
git checkout "$i" && ./gradlew :plugin:verifyPluginSignature
git checkout "$i" && ./gradlew :verifyPluginSignature
RESULT=$?
if [ $RESULT != 0 ]; then
echo "Failed to build plugin on branch $i!"
@ -76,6 +76,6 @@ git checkout "$DEFAULT_BRANCH"
mkdir -p build/dist
cp plugin/build/distributions/*-signed.zip build/dist/
cp build/distributions/*-signed.zip build/dist/
./gradlew publish

View file

@ -1,21 +1,25 @@
pluginGroup = com.falsepattern.zigbrains
pluginName = ZigBrains
pluginRepositoryUrl = https://github.com/FalsePattern/ZigBrains
pluginGroup=com.falsepattern.zigbrains
pluginName=ZigBrains
pluginRepositoryUrl=https://github.com/FalsePattern/ZigBrains
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 242
pluginUntilBuild = 242.*
pluginSinceBuild=242
pluginUntilBuild=242.*
baseIDE = clion
baseIDE=clion
ideaVersion = IC-242-EAP-SNAPSHOT
clionVersion = CL-242-EAP-SNAPSHOT
ideaVersion=242-EAP-SNAPSHOT
clionVersion=242-EAP-SNAPSHOT
pluginVersion=15.2.0-dev
# Gradle Releases -> https://github.com/gradle/gradle/releases
gradleVersion = 8.7
gradleVersion=8.8
# Enable Gradle Build Cache -> https://docs.gradle.org/current/userguide/build_cache.html
org.gradle.caching = true
org.gradle.caching=true
# Enable Gradle Kotlin DSL Lazy Property Assignment -> https://docs.gradle.org/current/userguide/kotlin_dsl.html#kotdsl:assignment
systemProp.org.gradle.unsafe.kotlin.assignment = true
systemProp.org.gradle.unsafe.kotlin.assignment=true
org.jetbrains.intellij.platform.buildFeature.useBinaryReleases=false

Binary file not shown.

View file

@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME

19
gradlew vendored
View file

@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@ -83,7 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@ -144,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
@ -152,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
@ -201,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \

20
gradlew.bat vendored
View file

@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail

View file

@ -15,7 +15,7 @@
*/
package com.falsepattern.zigbrains.lspcommon.connection;
import javax.annotation.Nullable;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

View file

@ -1,10 +1,10 @@
rootProject.name = "ZigBrains"
include("plugin")
File(rootDir, "modules").eachDir { dir ->
if (dir.resolve("src").exists()) {
include(dir.name)
project(":${dir.name}").projectDir = dir
}
}
fun File.eachDir(block: (File) -> Unit) {

View file

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB