Skip to content

Commit

Permalink
Merge pull request #84 from NixOS/intellij-platform-plugin-v2
Browse files Browse the repository at this point in the history
Intellij Platform Gradle Plugin v2 and IDEA 2024.2
  • Loading branch information
JojOatXGME authored Aug 14, 2024
2 parents 852ed2c + b668043 commit 9700fca
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 98 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ jobs:
- name: Collect metadata for upcoming steps and jobs
id: metadata
run: |
./gradlew --stacktrace metadata listProductsReleases
echo "products-releases=$(jq -Rnc '[inputs]' < build/listProductsReleases.txt)" >> "$GITHUB_OUTPUT"
./gradlew --stacktrace metadata
echo "products-releases=$(./gradlew -q printProductsReleases | jq -Rnc '[inputs]')" >> "$GITHUB_OUTPUT"
# Build
- name: Build project
run: ./gradlew --stacktrace assemble
- name: Package and verify plugin
run: ./gradlew --stacktrace verifyPlugin
run: ./gradlew --stacktrace assemble buildPlugin
- name: Verify plugin
run: ./gradlew --stacktrace verifyPluginStructure
- name: Run linters and tests
run: ./gradlew --stacktrace check
# Upload artifacts
Expand Down Expand Up @@ -99,7 +99,7 @@ jobs:
key: pluginVerifier-${{ matrix.idea-release }}-${{ runner.os }}
# Run checks
- name: Check plugin compatibility
run: ./gradlew --stacktrace -PverifierIdeVersionOverride="${{ matrix.idea-release }}" runPluginVerifier
run: ./gradlew --stacktrace -PverifierIdeVersionOverride="${{ matrix.idea-release }}" verifyPlugin
# Upload artifacts
- name: Upload build reports
if: always()
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ out/
build/
!src/**/build/

/.intellijPlatform
src/gen
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

### Added

- Support for IDEA 2024.2

### Changed

### Deprecated

### Removed

- Support for IDEA 2023.2

### Fixed

### Security
Expand Down
147 changes: 84 additions & 63 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import org.jetbrains.changelog.Changelog
import org.jetbrains.changelog.markdownToHTML
import org.jetbrains.intellij.tasks.RunPluginVerifierTask.FailureLevel
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
import org.jetbrains.intellij.platform.gradle.tasks.VerifyPluginTask.FailureLevel
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import java.util.EnumSet

plugins {
id("java")
kotlin("jvm") version embeddedKotlinVersion
alias(libs.plugins.jetbrains.intellij)
alias(libs.plugins.jetbrains.intellij.platform)
alias(libs.plugins.jetbrains.changelog)
alias(libs.plugins.jetbrains.grammarkit)
id("local.bump-version")
Expand Down Expand Up @@ -44,22 +45,96 @@ kotlin {
// Configure project's dependencies
repositories {
mavenCentral()
intellijPlatform {
defaultRepositories()
}
}

dependencies {
compileOnly(libs.jetbrains.annotations)

testImplementation(platform(libs.junit5.bom))
testImplementation(libs.junit5.jupiter)
testImplementation(libs.junit5.platform.testkit)
testImplementation(libs.junit4)
testRuntimeOnly(libs.junit5.vintage.engine)

intellijPlatform {
create(platformType, platformVersion)
testFramework(TestFrameworkType.Platform)
//testFramework(TestFrameworkType.JUnit5)
instrumentationTools()
// Version 1.364 seems to be broken and always complains about supposedly missing 'plugin.xml':
// https://youtrack.jetbrains.com/issue/MP-6388
pluginVerifier("1.307")
}
}

// Configure gradle-intellij-plugin plugin.
// Read more: https://github.com/JetBrains/gradle-intellij-plugin
intellij.pluginName = pluginName
intellij {
version = platformVersion
type = platformType
updateSinceUntilBuild = true
// Configure intellij-platform-gradle-plugin plugin.
// Read more: https://github.com/JetBrains/intellij-platform-gradle-plugin
intellijPlatform {
projectName = pluginName
pluginConfiguration {
id = "nix-idea"
name = "NixIDEA"
version = pluginVersion
vendor {
name = "NixOS"
}
ideaVersion {
sinceBuild = pluginSinceBuild
untilBuild = pluginUntilBuild
}
// Extract the <!-- Plugin description --> section from README.md and provide for the plugin's manifest
description = providers.provider {
projectDir.resolve("README.md").readText().lines()
.run {
val start = "<!-- Plugin description -->"
val end = "<!-- Plugin description end -->"
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")
.run { markdownToHTML(this) }
}
// Get the latest available change notes from the changelog file
changeNotes = provider {
with(changelog) {
renderItem(
(getOrNull(pluginVersion) ?: getUnreleased())
.withHeader(false)
.withEmptySections(false),
Changelog.OutputType.HTML
)
}
}
}
verifyPlugin {
ides {
ides(
providers.gradleProperty("verifierIdeVersionOverride")
// Verify only against the IDE specified by the property
.map { listOf(it) }
// If property is not set, verify against the recommended list of IDEs
.orElse(ProductReleasesValueSource())
)
}
failureLevel = EnumSet.complementOf(
EnumSet.of(
FailureLevel.DEPRECATED_API_USAGES,
FailureLevel.SCHEDULED_FOR_REMOVAL_API_USAGES,
FailureLevel.EXPERIMENTAL_API_USAGES,
)
)
}
publishing {
token = providers.environmentVariable("JETBRAINS_TOKEN")
// Note: `listOf("foo").first()` does not what you think on Java 21 and Gradle 8.6. (The return type is TaskProvider<Task>)
// See https://github.com/gradle/gradle/issues/27699 and https://youtrack.jetbrains.com/issue/KT-65235.
channels = listOf(pluginVersion.split('-').getOrElse(1) { "default" }.split('.')[0])
}
}

changelog {
Expand Down Expand Up @@ -151,58 +226,4 @@ tasks {
}
}

patchPluginXml {
version = pluginVersion
sinceBuild = pluginSinceBuild
untilBuild = pluginUntilBuild

// Extract the <!-- Plugin description --> section from README.md and provide for the plugin's manifest
pluginDescription = providers.provider {
projectDir.resolve("README.md").readText().lines()
.run {
val start = "<!-- Plugin description -->"
val end = "<!-- Plugin description end -->"
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")
.run { markdownToHTML(this) }
}

// Get the latest available change notes from the changelog file
changeNotes = provider {
with(changelog) {
renderItem(
(getOrNull(pluginVersion) ?: getUnreleased())
.withHeader(false)
.withEmptySections(false),
Changelog.OutputType.HTML
)
}
}
}

runPluginVerifier {
ideVersions = providers.gradleProperty("verifierIdeVersionOverride").map { listOf(it) }.orElse(listOf())
failureLevel = EnumSet.complementOf(
EnumSet.of(
FailureLevel.DEPRECATED_API_USAGES,
FailureLevel.SCHEDULED_FOR_REMOVAL_API_USAGES,
FailureLevel.EXPERIMENTAL_API_USAGES,
)
)
// Version 1.364 seems to be broken and always complains about supposedly missing 'plugin.xml':
// https://youtrack.jetbrains.com/issue/MP-6388
verifierVersion = "1.307"
}

publishPlugin {
token = providers.environmentVariable("JETBRAINS_TOKEN")
// Note: `listOf("foo").first()` does not what you think on Java 21 and Gradle 8.6. (The return type is TaskProvider<Task>)
// See https://github.com/gradle/gradle/issues/27699 and https://youtrack.jetbrains.com/issue/KT-65235.
channels = listOf(pluginVersion.split('-').getOrElse(1) { "default" }.split('.')[0])
}

}
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
pluginGroup = org.nixos.idea
pluginName = NixIDEA
pluginVersion = 0.4.0.15
pluginSinceBuild = 232
pluginUntilBuild = 241.*
pluginSinceBuild = 233
pluginUntilBuild = 242.*

platformType = IU
platformVersion = 2023.2.6
platformVersion = 2023.3.7

# Gradle Configuration
# -> https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties
Expand Down
10 changes: 6 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
# -> https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format

[libraries]
jetbrains-annotations = { module = "org.jetbrains:annotations", version = "24.1.0" }
junit5-bom = { module = "org.junit:junit-bom", version = "5.9.1" }
junit5-jupiter = { module = "org.junit.jupiter:junit-jupiter" }
junit5-platform-testkit = { module = "org.junit.platform:junit-platform-testkit" }
junit5-vintage-engine = { module = "org.junit.vintage:junit-vintage-engine" }
junit4 = { module = "junit:junit", version = "4.13.2" }

[plugins]
# gradle-intellij-plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
jetbrains-intellij = { id = "org.jetbrains.intellij", version = "1.17.2" }
# gradle-changelog-plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
# read more: https://github.com/JetBrains/intellij-platform-gradle-plugin
jetbrains-intellij-platform = { id = "org.jetbrains.intellij.platform", version = "2.0.1" }
# read more: https://github.com/JetBrains/gradle-changelog-plugin
jetbrains-changelog = { id = "org.jetbrains.changelog", version = "2.2.0" }
# grammarkit - read more: https://github.com/JetBrains/gradle-grammar-kit-plugin
# read more: https://github.com/JetBrains/gradle-grammar-kit-plugin
jetbrains-grammarkit = { id = "org.jetbrains.grammarkit", version = "2022.3.2.2" }
2 changes: 1 addition & 1 deletion gradle/plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repositories {
}

dependencies {
implementation(plugin(libs.plugins.jetbrains.intellij))
implementation(plugin(libs.plugins.jetbrains.intellij.platform))
}

/**
Expand Down
28 changes: 11 additions & 17 deletions gradle/plugins/src/main/kotlin/local.jbr-guidance.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import org.gradle.tooling.Failure
import org.gradle.tooling.events.FailureResult
import org.gradle.tooling.events.FinishEvent
import org.gradle.tooling.events.OperationCompletionListener
import org.jetbrains.intellij.tasks.RunIdeBase
import org.jetbrains.intellij.platform.gradle.tasks.VerifyPluginTask
import org.jetbrains.intellij.platform.gradle.tasks.aware.RuntimeAware
import java.util.function.Predicate

val jbrHome = rootProject.file("jbr")
Expand All @@ -15,29 +16,22 @@ task<Exec>("jbr") {
}

jbrHome.resolve("bin/java").takeIf { it.exists() }
?.also { jbrExecutable ->
// Override JVM of gradle-intellij-plugin with JVM at `jbr/bin/java`
// https://github.com/JetBrains/gradle-intellij-plugin/issues/1437#issuecomment-1987310948
tasks.withType<RunIdeBase> {
projectExecutable = jbrExecutable.toString()
}
pluginManager.withPlugin("org.jetbrains.intellij") {
// Uses `withPlugin` because the following code must run after the gradle-intellij-plugin got applied.
// We must also use `afterEvaluate`, as the gradle-intellij-plugin uses `afterEvaluate` as well.
// Otherwise, gradle-intellij-plugin would just overwrite our configuration.
afterEvaluate {
tasks.withType<Test> {
executable = jbrExecutable.toString()
}
?.also { _ ->
// Use JVM at `jbr/bin/java`. The JVM otherwise downloaded by intellij-platform-gradle-plugin wouldn't work on NixOS.
// https://github.com/JetBrains/intellij-platform-gradle-plugin/issues/1437#issuecomment-1987310948
// VerifyPluginTask doesn't execute the JVM, so we can ignore this task for the sake of consistency with other platforms.
tasks.configureEach {
if (this is RuntimeAware && this !is VerifyPluginTask) {
runtimeDirectory = jbrHome
}
}
}
?: run {
// There is no JVM at `jbr/bin/java`. Monitor the build and provide some helpful message when it fails.
val service = gradle.sharedServices.registerIfAbsent("jbr-guidance", JbrGuidance::class) {}
serviceOf<BuildEventsListenerRegistry>().onTaskCompletion(service)
// If the configuration cache is enabled, the JBR failure was triggered during serialization
// before any task gets executed. (As of gradle-intellij-plugin 1.17.2 and Gradle 8.6.)
// If the configuration cache is enabled, the JBR failure may be triggered during serialization
// before any task gets executed. (As of intellij-platform-gradle-plugin 2.0.0 and Gradle 8.6.)
// Unfortunately, only failures in tasks are reported to the JbrGuidance build service.
// If there are tasks scheduled, but none of them is executed, we therefore also print the message.
project.gradle.taskGraph.whenReady {
Expand Down
4 changes: 0 additions & 4 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<idea-plugin>

<id>nix-idea</id>
<name>NixIDEA</name>
<vendor>NixOS</vendor>

<depends>com.intellij.modules.platform</depends>
<depends>com.intellij.modules.lang</depends>
<depends optional="true" config-file="nix-idea-ultimate.xml">com.intellij.modules.ultimate</depends>
Expand Down

0 comments on commit 9700fca

Please sign in to comment.