From b6f1597f458400b76b3c60ab637f334c1b098ca7 Mon Sep 17 00:00:00 2001 From: Nikolai Rykunov Date: Wed, 11 Oct 2023 12:34:57 +0200 Subject: [PATCH] Support different IntelliJ versions (#165) --------- Co-authored-by: Sebastiano Poggi --- .github/workflows/build.yml | 18 ++++++-- .github/workflows/publish.yml | 33 ++++++++++++-- buildSrc/src/main/kotlin/IdeaConfiguration.kt | 26 +++++++++++ buildSrc/src/main/kotlin/LocalProperties.kt | 12 ++++++ .../src/main/kotlin/PublishConfiguration.kt | 35 +++++++++++++++ .../main/kotlin/jewel-ij-publish.gradle.kts | 43 +++++++++++++++++++ .../src/main/kotlin/jewel-publish.gradle.kts | 26 ++--------- gradle/libs.versions.toml | 17 +++++--- ide-laf-bridge/build.gradle.kts | 18 ++++++-- .../ide-laf-bridge-232/build.gradle.kts | 15 +++++++ .../ide-laf-bridge-233/build.gradle.kts | 15 +++++++ samples/ide-plugin/build.gradle.kts | 8 +++- settings.gradle.kts | 3 ++ 13 files changed, 231 insertions(+), 38 deletions(-) create mode 100644 buildSrc/src/main/kotlin/IdeaConfiguration.kt create mode 100644 buildSrc/src/main/kotlin/LocalProperties.kt create mode 100644 buildSrc/src/main/kotlin/PublishConfiguration.kt create mode 100644 buildSrc/src/main/kotlin/jewel-ij-publish.gradle.kts create mode 100644 ide-laf-bridge/ide-laf-bridge-232/build.gradle.kts create mode 100644 ide-laf-bridge/ide-laf-bridge-233/build.gradle.kts diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dc763b0f1..ad2e981e8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,6 +8,12 @@ jobs: assemble: runs-on: ubuntu-latest + strategy: + matrix: + supported-ij-version: + - 232 +# - 233 + steps: - uses: actions/checkout@v3 - name: Set up JDK 17 @@ -20,11 +26,17 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Run :assemble task - run: ./gradlew assemble + run: ./gradlew assemble -Psupported.ij.version=${{ matrix.supported-ij-version }} checks: runs-on: ubuntu-latest + strategy: + matrix: + supported-ij-version: + - 232 +# - 233 + steps: - uses: actions/checkout@v3 @@ -39,11 +51,11 @@ jobs: run: chmod +x gradlew - name: Run :check task - run: ./gradlew check --continue + run: ./gradlew check -Psupported.ij.version=${{ matrix.supported-ij-version }} --continue - name: Merge SARIF reports # Necessary because upload-sarif only takes up to 15 SARIF files and we have more - run: ./gradlew :mergeSarifReports + run: ./gradlew :mergeSarifReports -Psupported.ij.version=${{ matrix.supported-ij-version }} if: ${{ always() }} - uses: github/codeql-action/upload-sarif@v2 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 376b39f3f..a25c136b7 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -5,9 +5,10 @@ on: push: branches: [ main ] jobs: - publish: - name: Publish + publish-core: + name: Publish Jewel Core runs-on: ubuntu-latest + steps: - uses: actions/checkout@v3 - uses: actions/setup-java@v3 @@ -17,7 +18,33 @@ jobs: - name: Setup Gradle run: chmod +x gradlew - name: Run Gradle - run: ./gradlew publishAllPublicationsToSpaceRepository + # supported.ij.version is needed here for project configuration and won't be used during publishing + run: ./gradlew publishMainPublicationsToSpaceRepository -Psupported.ij.version=232 env: MAVEN_SPACE_USERNAME: ${{secrets.MAVEN_SPACE_USERNAME}} MAVEN_SPACE_PASSWORD: ${{secrets.MAVEN_SPACE_PASSWORD}} + + publish-ide: + name: Publish Jewel IDE part + needs: publish-core + runs-on: ubuntu-latest + + strategy: + matrix: + supported-ij-version: + - 232 + # - 233 + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 17 + - name: Setup Gradle + run: chmod +x gradlew + - name: Run Gradle + run: ./gradlew publishIdeMainPublicationsToSpaceRepository -Psupported.ij.version=${{ matrix.supported-ij-version }} + env: + MAVEN_SPACE_USERNAME: ${{secrets.MAVEN_SPACE_USERNAME}} + MAVEN_SPACE_PASSWORD: ${{secrets.MAVEN_SPACE_PASSWORD}} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/IdeaConfiguration.kt b/buildSrc/src/main/kotlin/IdeaConfiguration.kt new file mode 100644 index 000000000..d632be9fa --- /dev/null +++ b/buildSrc/src/main/kotlin/IdeaConfiguration.kt @@ -0,0 +1,26 @@ +import org.gradle.api.Project + +enum class SupportedIJVersion { + IJ_232, + IJ_233 +} + +fun Project.supportedIJVersion(): SupportedIJVersion { + val prop = localProperty("supported.ij.version") + ?: rootProject.property("supported.ij.version") + ?: error( + "'supported.ij.version' gradle property is missing. " + + "Please, provide it using local.properties file or -Psupported.ij.version argument in CLI" + ) + + return when (prop) { + "232" -> SupportedIJVersion.IJ_232 + "233" -> SupportedIJVersion.IJ_233 + else -> { + error( + "Invalid 'supported.ij.version' with value '$prop' is provided. " + + "It should be in set of these values: ('232', '233')" + ) + } + } +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/LocalProperties.kt b/buildSrc/src/main/kotlin/LocalProperties.kt new file mode 100644 index 000000000..526aa08f3 --- /dev/null +++ b/buildSrc/src/main/kotlin/LocalProperties.kt @@ -0,0 +1,12 @@ +import org.gradle.api.Project +import java.util.Properties + +internal fun Project.localProperty(propertyName: String): String? { + val localPropertiesFile = rootProject.file("local.properties") + if (!localPropertiesFile.exists()) { + return null + } + val properties = Properties() + localPropertiesFile.inputStream().use { properties.load(it) } + return properties.getProperty(propertyName) +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/PublishConfiguration.kt b/buildSrc/src/main/kotlin/PublishConfiguration.kt new file mode 100644 index 000000000..b2ea7d2f8 --- /dev/null +++ b/buildSrc/src/main/kotlin/PublishConfiguration.kt @@ -0,0 +1,35 @@ +@file:Suppress("UnstableApiUsage") + +import org.gradle.api.publish.PublishingExtension +import org.gradle.api.publish.maven.MavenPom +import org.gradle.kotlin.dsl.assign +import org.gradle.kotlin.dsl.maven + +internal fun PublishingExtension.configureJewelRepositories() { + repositories { + maven("https://packages.jetbrains.team/maven/p/kpm/public") { + name = "Space" + credentials { + username = System.getenv("MAVEN_SPACE_USERNAME") + password = System.getenv("MAVEN_SPACE_PASSWORD") + } + } + } +} + +internal fun MavenPom.configureJewelPom() { + name = "Jewel" + description = "A theme for Compose for Desktop that implements the IntelliJ Platform look and feel." + url = "https://github.com/JetBrains/jewel" + licenses { + license { + name = "Apache License 2.0" + url = "http://www.apache.org/licenses/LICENSE-2.0.txt" + } + } + scm { + connection = "scm:git:https://github.com/JetBrains/jewel.git" + developerConnection = "scm:git:https://github.com/JetBrains/jewel.git" + url = "https://github.com/JetBrains/jewel" + } +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/jewel-ij-publish.gradle.kts b/buildSrc/src/main/kotlin/jewel-ij-publish.gradle.kts new file mode 100644 index 000000000..cb83ff39a --- /dev/null +++ b/buildSrc/src/main/kotlin/jewel-ij-publish.gradle.kts @@ -0,0 +1,43 @@ +@file:Suppress("UnstableApiUsage") + +import SupportedIJVersion.IJ_232 +import SupportedIJVersion.IJ_233 + +plugins { + kotlin("jvm") + `maven-publish` + id("org.jetbrains.dokka") +} + +val sourcesJar by tasks.registering(Jar::class) { + from(kotlin.sourceSets.main.map { it.kotlin }) + archiveClassifier = "sources" + destinationDirectory = layout.buildDirectory.dir("artifacts") +} + +val javadocJar by tasks.registering(Jar::class) { + from(tasks.dokkaHtml) + archiveClassifier = "javadoc" + destinationDirectory = layout.buildDirectory.dir("artifacts") +} + +publishing { + configureJewelRepositories() + + publications { + register("IdeMain") { + from(components["kotlin"]) + artifact(javadocJar) + artifact(sourcesJar) + val ijVersionRaw = when (supportedIJVersion()) { + IJ_232 -> "232" + IJ_233 -> "233" + } + version = "${project.version}-ij-$ijVersionRaw" + artifactId = "jewel-${project.name}" + pom { + configureJewelPom() + } + } + } +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/jewel-publish.gradle.kts b/buildSrc/src/main/kotlin/jewel-publish.gradle.kts index e7a20b84e..b41f71b36 100644 --- a/buildSrc/src/main/kotlin/jewel-publish.gradle.kts +++ b/buildSrc/src/main/kotlin/jewel-publish.gradle.kts @@ -19,15 +19,8 @@ val javadocJar by tasks.registering(Jar::class) { } publishing { - repositories { - maven("https://packages.jetbrains.team/maven/p/kpm/public") { - name = "Space" - credentials { - username = System.getenv("MAVEN_SPACE_USERNAME") - password = System.getenv("MAVEN_SPACE_PASSWORD") - } - } - } + configureJewelRepositories() + publications { register("main") { from(components["kotlin"]) @@ -36,20 +29,7 @@ publishing { version = project.version.toString() artifactId = "jewel-${project.name}" pom { - name = "Jewel" - description = "intelliJ theming system in for Compose." - url = "https://github.com/JetBrains/jewel" - licenses { - license { - name = "Apache License 2.0" - url = "http://www.apache.org/licenses/LICENSE-2.0.txt" - } - } - scm { - connection = "scm:git:https://github.com/JetBrains/jewel.git" - developerConnection = "scm:git:https://github.com/JetBrains/jewel.git" - url = "https://github.com/JetBrains/jewel" - } + configureJewelPom() } } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 14862f22a..370a2df4d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,7 +2,8 @@ composeDesktop = "1.5.2" coroutines = "1.7.3" detekt = "1.23.1" -idea = "232.8660.185" +idea232 = "232.8660.185" +idea233 = "233.9102.97-EAP-SNAPSHOT" ideaGradlePlugin = "1.15.0" javaSarif = "2.0" kotlinSarif = "0.4.0" @@ -19,9 +20,14 @@ javaSarif = { module = "com.contrastsecurity:java-sarif", version.ref = "javaSar kotlinSarif = { module = "io.github.detekt.sarif4k:sarif4k", version.ref = "kotlinSarif" } kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerialization" } kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" } -ij-platform-ide-core = { module = "com.jetbrains.intellij.platform:ide-core", version.ref = "idea" } -ij-platform-ide-impl = { module = "com.jetbrains.intellij.platform:ide-impl", version.ref = "idea" } -ij-platform-core-ui = { module = "com.jetbrains.intellij.platform:core-ui", version.ref = "idea" } + +ij-platform-ide-core-232 = { module = "com.jetbrains.intellij.platform:ide-core", version.ref = "idea232" } +ij-platform-ide-impl-232 = { module = "com.jetbrains.intellij.platform:ide-impl", version.ref = "idea232" } +ij-platform-core-ui-232 = { module = "com.jetbrains.intellij.platform:core-ui", version.ref = "idea232" } + +ij-platform-ide-core-233 = { module = "com.jetbrains.intellij.platform:ide-core", version.ref = "idea233" } +ij-platform-ide-impl-233 = { module = "com.jetbrains.intellij.platform:ide-impl", version.ref = "idea233" } +ij-platform-core-ui-233 = { module = "com.jetbrains.intellij.platform:core-ui", version.ref = "idea233" } semVer = { module = "net.swiftzer.semver:semver", version.ref = "semVer" } simpleXml = { module = "org.simpleframework:simple-xml", version.ref = "simpleXml" } @@ -33,7 +39,8 @@ dokka-gradlePlugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", versi kotlinpoet = { module = "com.squareup:kotlinpoet", version.ref = "kotlinpoet" } [bundles] -idea = ["ij-platform-ide-core", "ij-platform-ide-impl", "ij-platform-core-ui"] +idea232 = ["ij-platform-ide-core-232", "ij-platform-ide-impl-232", "ij-platform-core-ui-232"] +idea233 = ["ij-platform-ide-core-233", "ij-platform-ide-impl-233", "ij-platform-core-ui-233"] [plugins] composeDesktop = { id = "org.jetbrains.compose", version.ref = "composeDesktop" } diff --git a/ide-laf-bridge/build.gradle.kts b/ide-laf-bridge/build.gradle.kts index 8193e5e7b..186521f93 100644 --- a/ide-laf-bridge/build.gradle.kts +++ b/ide-laf-bridge/build.gradle.kts @@ -1,6 +1,8 @@ +import SupportedIJVersion.* + plugins { jewel - `jewel-publish` + `jewel-ij-publish` alias(libs.plugins.composeDesktop) } @@ -8,10 +10,20 @@ dependencies { api(projects.intUi.intUiStandalone) { exclude(group = "org.jetbrains.kotlinx") } - compileOnly(libs.bundles.idea) + when (supportedIJVersion()) { + IJ_232 -> { + api(projects.ideLafBridge.ideLafBridge232) + compileOnly(libs.bundles.idea232) + } + + IJ_233 -> { + api(projects.ideLafBridge.ideLafBridge233) + compileOnly(libs.bundles.idea233) + } + } testImplementation(compose.desktop.uiTestJUnit4) testImplementation(compose.desktop.currentOs) { exclude(group = "org.jetbrains.compose.material") } -} +} \ No newline at end of file diff --git a/ide-laf-bridge/ide-laf-bridge-232/build.gradle.kts b/ide-laf-bridge/ide-laf-bridge-232/build.gradle.kts new file mode 100644 index 000000000..cb3d89359 --- /dev/null +++ b/ide-laf-bridge/ide-laf-bridge-232/build.gradle.kts @@ -0,0 +1,15 @@ +plugins { + jewel + `jewel-ij-publish` + alias(libs.plugins.composeDesktop) +} + +dependencies { + api(projects.intUi.intUiStandalone) + compileOnly(libs.bundles.idea232) +} + +tasks.withType().configureEach { + publication.artifactId = "jewel-ide-laf-bridge-platform-specific" + enabled = supportedIJVersion() == SupportedIJVersion.IJ_232 +} \ No newline at end of file diff --git a/ide-laf-bridge/ide-laf-bridge-233/build.gradle.kts b/ide-laf-bridge/ide-laf-bridge-233/build.gradle.kts new file mode 100644 index 000000000..743a7e8e7 --- /dev/null +++ b/ide-laf-bridge/ide-laf-bridge-233/build.gradle.kts @@ -0,0 +1,15 @@ +plugins { + jewel + `jewel-ij-publish` + alias(libs.plugins.composeDesktop) +} + +dependencies { + api(projects.intUi.intUiStandalone) + compileOnly(libs.bundles.idea233) +} + +tasks.withType().configureEach { + publication.artifactId = "jewel-ide-laf-bridge-platform-specific" + enabled = supportedIJVersion() == SupportedIJVersion.IJ_233 +} \ No newline at end of file diff --git a/samples/ide-plugin/build.gradle.kts b/samples/ide-plugin/build.gradle.kts index 02765b509..839531cb0 100644 --- a/samples/ide-plugin/build.gradle.kts +++ b/samples/ide-plugin/build.gradle.kts @@ -1,3 +1,5 @@ +import SupportedIJVersion.* + plugins { jewel alias(libs.plugins.composeDesktop) @@ -8,7 +10,11 @@ plugins { intellij { pluginName.set("Jewel Demo") plugins.set(listOf("org.jetbrains.kotlin")) - version.set("2023.2.1") + val versionRaw = when (supportedIJVersion()) { + IJ_232 -> libs.versions.idea232.get() + IJ_233 -> libs.versions.idea233.get() + } + version.set(versionRaw) } // TODO remove this once the IJ Gradle plugin fixes their repositories bug diff --git a/settings.gradle.kts b/settings.gradle.kts index 2ef0906cc..0d8e601ff 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -19,6 +19,7 @@ dependencyResolutionManagement { maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") maven("https://androidx.dev/storage/compose-compiler/repository/") maven("https://www.jetbrains.com/intellij-repository/releases") + maven("https://www.jetbrains.com/intellij-repository/snapshots") maven("https://cache-redirector.jetbrains.com/intellij-dependencies") mavenCentral() } @@ -27,6 +28,8 @@ dependencyResolutionManagement { include( ":core", ":ide-laf-bridge", + ":ide-laf-bridge:ide-laf-bridge-232", + ":ide-laf-bridge:ide-laf-bridge-233", ":samples:standalone", ":samples:ide-plugin", ":int-ui:int-ui-core",