Skip to content

Commit

Permalink
Migrate to org.jetbrains.intellij.platform v2.0.0 (#5657)
Browse files Browse the repository at this point in the history
* Migrate to org.jetbrains.intellij.platform v2.0.0

* Move more configuration to intellijPlatform {} instead of customizing tasks

* Fix verifyPlugin

* Move dependencies before intellijPlatform so verifyPlugin works

* Move dependencies back at the bottom and add pluginVerifier() dependencies

* Add testFramework() to dependencies

* Bump to 2.0.0-beta1

* Add .intellijPlatform to .gitignore

* Fix testFramework and toml plugin

* Fix plugin name in descriptor

* Add zipSigner() to dependencies

* Add a runLocalIde task that uses the apolloIntellijPlugin.ideDir property

* Update intellij-platform-plugin to 2.0.0-beta2

* Bump intellij-platform-gradle-plugin to 2.0.0-beta3

* Bump intellij-platform-gradle-plugin to 2.0.0-beta4

* Bump intellij-platform-gradle-plugin to 2.0.0-beta5

* Bump intellij-platform-gradle-plugin to 2.0.0-beta6

* Use project.provider instead of Callable in registerCheckVersionsTask to avoid a ConcurrentModificationException

* Revert calling project.provider instead of Callable in registerCheckVersionsTask

* Bump intellij-platform-gradle-plugin to 2.0.0-beta7

* Bump intellij-platform-gradle-plugin to 2.0.0-beta8

* Bump intellij-platform-gradle-plugin to 2.0.0-beta9

* Try to fix using a local IDE

* Bump intellij-platform-gradle-plugin to 2.0.0-rc1
  • Loading branch information
BoD authored Jul 24, 2024
1 parent 6b16509 commit 8b0699b
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 116 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
- name: Fetch Sources
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 #v4.1.7

# Setup Java 11 environment for the next steps
# Setup Java environment for the next steps
- name: Setup Java
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 #v4.2.1
with:
Expand All @@ -124,7 +124,7 @@ jobs:
echo "::set-output name=version::$VERSION"
echo "::set-output name=pluginVerifierHomeDir::~/.pluginVerifier"
./gradlew :intellij-plugin:listProductsReleases # prepare list of IDEs for Plugin Verifier
./gradlew :intellij-plugin:printProductsReleases # prepare list of IDEs for Plugin Verifier
# Trigger code generation in test project, as the plugin's tests depend on it
- name: Test project codegen
Expand All @@ -151,7 +151,7 @@ jobs:

# Run Verify Plugin task and IntelliJ Plugin Verifier tool
- name: Run Plugin Verification tasks
run: ./gradlew :intellij-plugin:runPluginVerifier -Pplugin.verifier.home.dir=${{ steps.properties.outputs.pluginVerifierHomeDir }}
run: ./gradlew :intellij-plugin:verifyPlugin -Pplugin.verifier.home.dir=${{ steps.properties.outputs.pluginVerifierHomeDir }}

# Collect Plugin Verifier Result
- name: Collect Plugin Verifier Result
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ package-lock.json

# IntelliJ plugin
intellij-plugin/mockJDK
.intellijPlatform
5 changes: 3 additions & 2 deletions .idea/runConfigurations/Run_IntelliJ_plugin.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {
implementation(libs.kotlinx.serialization.json)
implementation(libs.poet.java)
implementation(libs.poet.kotlin)
implementation(libs.intellij.plugin)
implementation(libs.intellij.platform.plugin)
implementation(libs.intellij.changelog)
implementation(libs.androidx.lint.gradle.plugin)
implementation(libs.kotlin.plugin.compose)
Expand Down
2 changes: 1 addition & 1 deletion gradle/libraries.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ http4k-bom = "org.http4k:http4k-bom:5.8.0.0"
http4k-core = { module = "org.http4k:http4k-core" }
http4k-server-undertow = { module = "org.http4k:http4k-server-undertow" }
http4k-server-jetty = { module = "org.http4k:http4k-server-jetty" }
intellij-plugin = "org.jetbrains.intellij.plugins:gradle-intellij-plugin:1.17.0"
intellij-platform-plugin = "org.jetbrains.intellij.platform:intellij-platform-gradle-plugin:2.0.0-rc1"
intellij-changelog = "org.jetbrains.intellij.plugins:gradle-changelog-plugin:2.0.0"
jetbrains-annotations = { group = "org.jetbrains", name = "annotations", version.ref = "jetbrains-annotations" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
Expand Down
7 changes: 4 additions & 3 deletions gradle/repositories.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ listOf(pluginManagement.repositories, dependencyResolutionManagement.repositorie
includeModule("com.github.ben-manes", "gradle-versions-plugin")
includeModule("com.gradle", "develocity-gradle-plugin")

// For org.jetbrains.intellij
includeModule("org.jetbrains.intellij", "org.jetbrains.intellij.gradle.plugin")
includeModule("org.jetbrains.intellij.plugins", "gradle-intellij-plugin")
// For org.jetbrains.intellij.platform
includeModule("gradle.plugin.org.jetbrains.gradle.plugin.idea-ext", "gradle-idea-ext")

// For org.jetbrains.changelog
includeModule("org.jetbrains.changelog", "org.jetbrains.changelog.gradle.plugin")
includeModule("org.jetbrains.intellij.plugins", "gradle-changelog-plugin")

// For org.jetbrains.intellij.platform
includeModule("org.jetbrains.intellij.platform", "intellij-platform-gradle-plugin")
}
}
}
Expand Down
205 changes: 106 additions & 99 deletions intellij-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.changelog.markdownToHTML
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
import java.net.URL
import java.text.SimpleDateFormat
import java.util.Date

fun properties(key: String) = project.findProperty(key).toString()

fun isSnapshotBuild() = System.getenv("IJ_PLUGIN_SNAPSHOT").toBoolean()


plugins {
id("org.jetbrains.kotlin.jvm")
id("org.jetbrains.intellij")
id("org.jetbrains.intellij.platform")
alias(libs.plugins.apollo.published)
}

Expand All @@ -21,6 +25,10 @@ repositories {
// Uncomment this one to use the Kotlin "dev" repository
// maven { url = uri("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/") }
mavenCentral()

intellijPlatform {
defaultRepositories()
}
}

group = properties("pluginGroup")
Expand All @@ -36,109 +44,40 @@ fun getSnapshotVersionSuffix(): String {
// Set the JVM language level used to build project. Use Java 11 for 2020.3+, and Java 17 for 2022.2+.
kotlin {
jvmToolchain {
(this as JavaToolchainSpec).languageVersion.set(JavaLanguageVersion.of(properties("javaVersion").toInt()))
languageVersion = JavaLanguageVersion.of(17)
}
}

// Configure Gradle IntelliJ Plugin - read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html
intellij {
pluginName.set(properties("pluginName"))
version.set(properties("platformVersion"))
type.set(properties("platformType"))

// Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file.
plugins.set(properties("platformPlugins").split(',').map(String::trim).filter(String::isNotEmpty))

// Uncomment to use a local repository e.g. for testing not yet published versions of the GraphQL plugin
// pluginsRepositories {
// maven("file://${System.getProperty("user.home")}/.m2/repository")
// // Note: using 2 repositories doesn't work currently - see https://github.com/JetBrains/gradle-intellij-plugin/issues/1292
// // marketplace()
// }
}

val apolloDependencies = configurations.create("apolloDependencies").apply {
listOf(":apollo-annotations", ":apollo-api", ":apollo-runtime").forEach {
dependencies.add(project.dependencies.project(it, "jvmApiElements"))
}
}

tasks {
withType<KotlinCompile> {
kotlinOptions {
withType<KotlinCompilationTask<*>> {
compilerOptions {
freeCompilerArgs = listOf("-Xcontext-receivers")
}
}

patchPluginXml {
pluginId.set(properties("pluginId"))
version.set(project.version.toString())
sinceBuild.set(properties("pluginSinceBuild"))
untilBuild.set(properties("pluginUntilBuild"))

// Extract the <!-- Plugin description --> section from README.md and provide for the plugin's manifest
pluginDescription.set(
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) }
)

changeNotes.set(
if (isSnapshotBuild()) {
"Weekly snapshot builds contain the latest changes from the <code>main</code> branch."
} else {
"See the <a href=\"https://github.com/apollographql/apollo-kotlin/releases/tag/v${project.version}\">release notes</a>."
}
)
}

// Configure UI tests plugin
// Read more: https://github.com/JetBrains/intellij-ui-test-robot
runIdeForUiTests {
systemProperty("robot-server.port", "8082")
systemProperty("ide.mac.message.dialogs.as.sheets", "false")
systemProperty("jb.privacy.policy.text", "<!--999.999-->")
systemProperty("jb.consents.confirmation.enabled", "false")

// Enables debug logging for the plugin
systemProperty("idea.log.debug.categories", "Apollo")
}

runIde {
// Enables debug logging for the plugin
systemProperty("idea.log.debug.categories", "Apollo")

// Disable hiding frequent exceptions in logs (annoying for debugging). See com.intellij.idea.IdeaLogger.
systemProperty("idea.logger.exception.expiration.minutes", "0")

// Use a custom IntelliJ installation. Set this property in your local ~/.gradle/gradle.properties file.
val runLocalIde by intellijPlatformTesting.runIde.registering {
// Use a custom IJ/AS installation. Set this property in your local ~/.gradle/gradle.properties file.
// (for AS, it should be something like '/Applications/Android Studio.app/Contents')
// See https://plugins.jetbrains.com/docs/intellij/android-studio.html#configuring-the-plugin-gradle-build-script
if (project.hasProperty("apolloIntellijPlugin.ideDir")) {
ideDir.set(file(project.property("apolloIntellijPlugin.ideDir")!!))
providers.gradleProperty("apolloIntellijPlugin.ideDir").orNull?.let {
localPath = file(it)
}

// Uncomment to disable internal mode - see https://plugins.jetbrains.com/docs/intellij/enabling-internal.html
// systemProperty("idea.is.internal", "false")
}
task {
// Enables debug logging for the plugin
systemProperty("idea.log.debug.categories", "Apollo")

signPlugin {
certificateChain.set(System.getenv("CERTIFICATE_CHAIN"))
privateKey.set(System.getenv("PRIVATE_KEY"))
password.set(System.getenv("PRIVATE_KEY_PASSWORD"))
}
// Disable hiding frequent exceptions in logs (annoying for debugging). See com.intellij.idea.IdeaLogger.
systemProperty("idea.logger.exception.expiration.minutes", "0")

publishPlugin {
token.set(System.getenv("PUBLISH_TOKEN"))
if (isSnapshotBuild()) {
// Read more: https://plugins.jetbrains.com/docs/intellij/publishing-plugin.html#specifying-a-release-channel
channels.set(listOf("snapshots"))
// Uncomment to disable internal mode - see https://plugins.jetbrains.com/docs/intellij/enabling-internal.html
// systemProperty("idea.is.internal", "false")
}
}

Expand All @@ -164,7 +103,9 @@ tasks.register("downloadMockJdk") {
val rtJar = mockJdkRoot.resolve("java/mockJDK-1.7/jre/lib/rt.jar")
if (!rtJar.exists()) {
rtJar.parentFile.mkdirs()
rtJar.writeBytes(URL("https://github.com/JetBrains/intellij-community/raw/master/java/mockJDK-1.7/jre/lib/rt.jar").openStream().readBytes())
rtJar.writeBytes(URL("https://github.com/JetBrains/intellij-community/raw/master/java/mockJDK-1.7/jre/lib/rt.jar").openStream()
.readBytes()
)
}
}
}
Expand All @@ -177,19 +118,6 @@ tasks.test.configure {
systemProperty("idea.home.path", mockJdkRoot.relativeTo(project.projectDir).path)
}

dependencies {
implementation(project(":apollo-gradle-plugin-external"))
implementation(project(":apollo-ast"))
implementation(project(":apollo-tooling"))
implementation(project(":apollo-normalized-cache-sqlite"))
implementation(libs.sqlite.jdbc)
implementation(libs.apollo.runtime.published)
runtimeOnly(libs.slf4j.simple)
testImplementation(libs.google.testparameterinjector)
}

fun isSnapshotBuild() = System.getenv("IJ_PLUGIN_SNAPSHOT").toBoolean()

apollo {
service("apolloDebugServer") {
packageName.set("com.apollographql.ijplugin.apollodebugserver")
Expand All @@ -207,3 +135,82 @@ tasks.configureEach {
enabled = false
}
}

// IntelliJ Platform Gradle Plugin configuration
// See https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-extension.html#intellijPlatform-pluginConfiguration
intellijPlatform {
pluginConfiguration {
id.set(properties("pluginId"))
name.set(properties("pluginName"))
version.set(project.version.toString())
ideaVersion {
sinceBuild = properties("pluginSinceBuild")
untilBuild = properties("pluginUntilBuild")
}
// Extract the <!-- Plugin description --> section from README.md and provide it to the plugin's manifest
description.set(
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) }
)
changeNotes.set(
if (isSnapshotBuild()) {
"Weekly snapshot builds contain the latest changes from the <code>main</code> branch."
} else {
"See the <a href=\"https://github.com/apollographql/apollo-kotlin/releases/tag/v${project.version}\">release notes</a>."
}
)
}

signing {
certificateChain.set(System.getenv("CERTIFICATE_CHAIN"))
privateKey.set(System.getenv("PRIVATE_KEY"))
password.set(System.getenv("PRIVATE_KEY_PASSWORD"))
}

publishing {
token.set(System.getenv("PUBLISH_TOKEN"))
if (isSnapshotBuild()) {
// Read more: https://plugins.jetbrains.com/docs/intellij/publishing-plugin.html#specifying-a-release-channel
channels.set(listOf("snapshots"))
}
}

verifyPlugin {
ides {
recommended()
}
}
}

dependencies {
intellijPlatform {
val localIdeDir = providers.gradleProperty("apolloIntellijPlugin.ideDir").orNull
if (localIdeDir != null) {
local(localIdeDir)
} else {
create(type = properties("platformType"), version = properties("platformVersion"))
}

bundledPlugins(properties("platformBundledPlugins").split(',').map(String::trim).filter(String::isNotEmpty))
plugins(properties("platformPlugins").split(',').map(String::trim).filter(String::isNotEmpty))
instrumentationTools()
pluginVerifier()
testFramework(TestFrameworkType.Plugin.Java)
zipSigner()
}
implementation(project(":apollo-gradle-plugin-external"))
implementation(project(":apollo-ast"))
implementation(project(":apollo-tooling"))
implementation(project(":apollo-normalized-cache-sqlite"))
implementation(libs.sqlite.jdbc)
implementation(libs.apollo.runtime.published)
runtimeOnly(libs.slf4j.simple)
testImplementation(libs.google.testparameterinjector)
}
12 changes: 5 additions & 7 deletions intellij-plugin/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# IntelliJ Platform Artifacts Repositories
# -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html
pluginGroup=com.apollographql
pluginName=apollo-intellij-plugin
pluginName=Apollo GraphQL
pluginId=com.apollographql.ijplugin
pluginRepositoryUrl=https://github.com/apollographql/apollo-kotlin

Expand All @@ -17,16 +17,14 @@ platformType=IC
# Corresponds to AS Iguana 2023.2.1 -> https://plugins.jetbrains.com/docs/intellij/android-studio-releases-list.html
# and https://developer.android.com/studio/archive (more up to date)
# See also https://plugins.jetbrains.com/docs/intellij/android-studio.html
platformVersion=232.10227.8
platformVersion=2023.2.5


# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# To find the version of a plugin relative to the platoform version, see the plugin's page on the Marketplace,
# To find the version of a plugin relative to the platform version, see the plugin's page on the Marketplace,
# e.g. for the toml plugin: https://plugins.jetbrains.com/plugin/8195-toml/versions/stable
platformPlugins=com.intellij.java, org.jetbrains.kotlin, com.intellij.gradle, com.intellij.lang.jsgraphql:4.0.2, org.toml.lang, org.jetbrains.android

# JVM language level used to build project. Use Java 11 for 2020.3+, and Java 17 for 2022.2+.
javaVersion=17
platformBundledPlugins=com.intellij.java, org.jetbrains.kotlin, com.intellij.gradle, org.jetbrains.android, org.toml.lang
platformPlugins=com.intellij.lang.jsgraphql:4.0.2

# Opt-out flag for bundling Kotlin standard library.
# See https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library for details.
Expand Down

0 comments on commit 8b0699b

Please sign in to comment.