From 4c88c423cd2f1853c69fca27559aa90f653108e2 Mon Sep 17 00:00:00 2001 From: junkfactory <2998269+junkfactory@users.noreply.github.com> Date: Sat, 1 Feb 2025 17:05:45 -0800 Subject: [PATCH 1/3] Builder class always being added --- build.gradle.kts | 178 ++++-------------- gradle.properties | 19 -- settings.gradle.kts | 8 +- .../generators/InnerBuilderGenerator.java | 3 +- 4 files changed, 42 insertions(+), 166 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 32c0d56..c3312a4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,155 +1,47 @@ -import org.jetbrains.changelog.Changelog -import org.jetbrains.changelog.markdownToHTML -import org.jetbrains.intellij.platform.gradle.Constants.Constraints -import org.jetbrains.intellij.platform.gradle.TestFrameworkType - plugins { - id("java") // Java support - alias(libs.plugins.kotlin) // Kotlin support - alias(libs.plugins.intelliJPlatform) // IntelliJ Platform Gradle Plugin - alias(libs.plugins.changelog) // Gradle Changelog Plugin - alias(libs.plugins.qodana) // Gradle Qodana Plugin - alias(libs.plugins.kover) // Gradle Kover Plugin + id("java") + id("org.jetbrains.kotlin.jvm") version "1.9.25" + id("org.jetbrains.intellij") version "1.17.4" } -group = providers.gradleProperty("pluginGroup").get() -version = providers.gradleProperty("pluginVersion").get() - -// Set the JVM language level used to build the project. -kotlin { - jvmToolchain(17) -} +group = "com.github.junkfactory" +version = "1.0-SNAPSHOT" -// Configure project's dependencies repositories { - mavenCentral() - - // IntelliJ Platform Gradle Plugin Repositories Extension - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-repositories-extension.html - intellijPlatform { - defaultRepositories() - } -} - -// Dependencies are managed with Gradle version catalog - read more: https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog -dependencies { - testImplementation(libs.junit) - - // IntelliJ Platform Gradle Plugin Dependencies Extension - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-dependencies-extension.html - intellijPlatform { - create(providers.gradleProperty("platformType"), providers.gradleProperty("platformVersion")) - - // Plugin Dependencies. Uses `platformBundledPlugins` property from the gradle.properties file for bundled IntelliJ Platform plugins. - bundledPlugins(providers.gradleProperty("platformBundledPlugins").map { it.split(',') }) - - // Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file for plugin from JetBrains Marketplace. - plugins(providers.gradleProperty("platformPlugins").map { it.split(',') }) - - instrumentationTools() - pluginVerifier() - zipSigner() - testFramework(TestFrameworkType.Platform) - bundledPlugin("com.intellij.java") - } -} - -// Configure IntelliJ Platform Gradle Plugin - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-extension.html -intellijPlatform { - pluginConfiguration { - version = providers.gradleProperty("pluginVersion") - - // Extract the section from README.md and provide for the plugin's manifest - description = providers.fileContents(layout.projectDirectory.file("README.md")).asText.map { - val start = "" - val 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 = project.changelog // local variable for configuration cache compatibility - // Get the latest available change notes from the changelog file - changeNotes = providers.gradleProperty("pluginVersion").map { pluginVersion -> - with(changelog) { - renderItem( - (getOrNull(pluginVersion) ?: getUnreleased()) - .withHeader(false) - .withEmptySections(false), - Changelog.OutputType.HTML, - ) - } - } - - ideaVersion { - sinceBuild = providers.gradleProperty("pluginSinceBuild") - untilBuild = providers.gradleProperty("pluginUntilBuild") - } - } - - signing { - certificateChain = providers.environmentVariable("CERTIFICATE_CHAIN") - privateKey = providers.environmentVariable("PRIVATE_KEY") - password = providers.environmentVariable("PRIVATE_KEY_PASSWORD") - } - - publishing { - token = providers.environmentVariable("PUBLISH_TOKEN") - // The pluginVersion is based on the SemVer (https://semver.org) and supports pre-release labels, like 2.1.7-alpha.3 - // Specify pre-release label to publish the plugin in a custom Release Channel automatically. Read more: - // https://plugins.jetbrains.com/docs/intellij/deployment.html#specifying-a-release-channel - channels = providers.gradleProperty("pluginVersion").map { listOf(it.substringAfter('-', "").substringBefore('.').ifEmpty { "default" }) } - } - - pluginVerification { - ides { - recommended() - } - } + mavenCentral() } -// Configure Gradle Changelog Plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin -changelog { - groups.empty() - repositoryUrl = providers.gradleProperty("pluginRepositoryUrl") -} +// Configure Gradle IntelliJ Plugin +// Read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html +intellij { + version.set("2024.1.7") + type.set("IC") // Target IDE Platform -// Configure Gradle Kover Plugin - read more: https://github.com/Kotlin/kotlinx-kover#configuration -kover { - reports { - total { - xml { - onCheck = true - } - } - } + plugins.set(listOf("com.intellij.java")) } tasks { - wrapper { - gradleVersion = providers.gradleProperty("gradleVersion").get() - } - - publishPlugin { - dependsOn(patchChangelog) - } -} - -val runIdeForUiTests by intellijPlatformTesting.runIde.registering { - task { - jvmArgumentProviders += CommandLineArgumentProvider { - listOf( - "-Drobot-server.port=8082", - "-Dide.mac.message.dialogs.as.sheets=false", - "-Djb.privacy.policy.text=", - "-Djb.consents.confirmation.enabled=false", - ) - } - } - - plugins { - robotServerPlugin(Constraints.LATEST_VERSION) - } + // Set the JVM compatibility versions + withType { + sourceCompatibility = "17" + targetCompatibility = "17" + } + withType { + kotlinOptions.jvmTarget = "17" + } + + patchPluginXml { + sinceBuild.set("241") + untilBuild.set("243.*") + } + + signPlugin { + certificateChain.set(System.getenv("CERTIFICATE_CHAIN")) + privateKey.set(System.getenv("PRIVATE_KEY")) + password.set(System.getenv("PRIVATE_KEY_PASSWORD")) + } + + publishPlugin { + token.set(System.getenv("PUBLISH_TOKEN")) + } } diff --git a/gradle.properties b/gradle.properties index d2bc0b8..24630b3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,22 +1,3 @@ -# IntelliJ Platform Artifacts Repositories -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html -pluginGroup=com.github.junkfactory.innerbuilder -pluginName=Java Inner Builder -pluginRepositoryUrl=https://github.com/junkfactory/java-inner-builder -# SemVer format -> https://semver.org -pluginVersion=snapshot -# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html -pluginSinceBuild=232 -pluginUntilBuild=243.* -# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension -platformType=IC -platformVersion=243.15521.24 -# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html -# Example: platformPlugins = com.jetbrains.php:203.4449.22, org.intellij.scala:2023.3.27@EAP -platformPlugins= -# Example: platformBundledPlugins = com.intellij.java -platformBundledPlugins= -# Gradle Releases -> https://github.com/gradle/gradle/releases -gradleVersion=8.9 # Opt-out flag for bundling Kotlin standard library -> https://jb.gg/intellij-platform-kotlin-stdlib kotlin.stdlib.default.dependency=false # Enable Gradle Configuration Cache -> https://docs.gradle.org/current/userguide/configuration_cache.html diff --git a/settings.gradle.kts b/settings.gradle.kts index fa32169..3c909b4 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,4 +1,8 @@ -plugins { - id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" +pluginManagement { + repositories { + mavenCentral() + gradlePluginPortal() + } } + rootProject.name = "java-inner-builder" \ No newline at end of file diff --git a/src/main/java/com/github/junkfactory/innerbuilder/generators/InnerBuilderGenerator.java b/src/main/java/com/github/junkfactory/innerbuilder/generators/InnerBuilderGenerator.java index a9e541b..6268380 100644 --- a/src/main/java/com/github/junkfactory/innerbuilder/generators/InnerBuilderGenerator.java +++ b/src/main/java/com/github/junkfactory/innerbuilder/generators/InnerBuilderGenerator.java @@ -60,7 +60,6 @@ public GenerationResult generate() { .build(); var result = generatorFactory.createBuilderClassGenerator(generatorParams, params).generate(); generationResult.merge(result); - targetClass.add(builderClass); var codeStyleManager = generatorParams.psi().codeStyleManager(); generationResult.when(ANNOTATIONS_ADDED, () -> codeStyleManager.shortenClassReferences(targetClass)); generationResult.when(IMPORTS_ADDED, () -> codeStyleManager.removeRedundantImports((PsiJavaFile) file)); @@ -155,7 +154,7 @@ private PsiMethod generateTargetConstructor(final PsiClass targetClass, final Ps private PsiClass findOrCreateBuilderClass(final PsiClass targetClass) { var builderClass = targetClass.findInnerClassByName(BUILDER_CLASS_NAME, false); if (builderClass == null) { - return createBuilderClass(targetClass); + return (PsiClass) targetClass.add(createBuilderClass(targetClass)); } return builderClass; From 3bb8028c24591f8304b689404eec00b40a8bb08e Mon Sep 17 00:00:00 2001 From: junkfactory <2998269+junkfactory@users.noreply.github.com> Date: Sat, 1 Feb 2025 17:13:16 -0800 Subject: [PATCH 2/3] Upgrade setup-gradle to v4 --- .github/workflows/build.yml | 6 +++--- .github/workflows/release.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cb68f01..5029485 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -57,7 +57,7 @@ jobs: # Setup Gradle - name: Setup Gradle - uses: gradle/actions/setup-gradle@v3 + uses: gradle/actions/setup-gradle@v4 with: gradle-home-cache-cleanup: true @@ -117,7 +117,7 @@ jobs: # Setup Gradle - name: Setup Gradle - uses: gradle/actions/setup-gradle@v3 + uses: gradle/actions/setup-gradle@v4 with: gradle-home-cache-cleanup: true @@ -159,7 +159,7 @@ jobs: # Setup Gradle - name: Setup Gradle - uses: gradle/actions/setup-gradle@v3 + uses: gradle/actions/setup-gradle@v4 with: gradle-home-cache-cleanup: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f4d844d..bc61e30 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -38,7 +38,7 @@ jobs: # Setup Gradle - name: Setup Gradle - uses: gradle/actions/setup-gradle@v3 + uses: gradle/actions/setup-gradle@v4 with: gradle-home-cache-cleanup: true From 49d1ea9c2f661c960e1027574b754ea12299df7e Mon Sep 17 00:00:00 2001 From: junkfactory <2998269+junkfactory@users.noreply.github.com> Date: Sat, 1 Feb 2025 17:26:11 -0800 Subject: [PATCH 3/3] Add back description in plugin.xml --- src/main/resources/META-INF/plugin.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 8bc342f..9958f46 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -13,6 +13,14 @@ Java Inner Builder + + + + com.intellij.modules.platform