Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A sizeable plugin update #24

Merged
merged 8 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 11
java-version: 17
cache: gradle

# Set environment variables
Expand All @@ -78,13 +78,9 @@ jobs:
- name: Run Tests
run: ./gradlew test

# Run verifyPlugin Gradle task
# Run IntelliJ Plugin Verifier
- name: Verify Plugin
run: ./gradlew verifyPlugin

# Run IntelliJ Plugin Verifier action using GitHub Action
- name: Run Plugin Verifier
run: ./gradlew runPluginVerifier -Pplugin.verifier.home.dir=${{ steps.properties.outputs.pluginVerifierHomeDir }}
run: ./gradlew verifyPlugin -Pplugin.verifier.home.dir=${{ steps.properties.outputs.pluginVerifierHomeDir }}

# Build plugin with buildPlugin Gradle task and provide the artifact for the next workflow jobs
# Requires test job to be passed
Expand All @@ -106,7 +102,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 11
java-version: 17
cache: gradle

# Set environment variables
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 11
java-version: 17
cache: gradle

# Update Unreleased section with the current release note
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-ui-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 11
java-version: 17
cache: gradle

# Run IDEA prepared for UI testing
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.idea
.qodana
build
.intellijPlatform
83 changes: 57 additions & 26 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import org.jetbrains.changelog.markdownToHTML
import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

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

plugins {
// Java support
id("java")
// Kotlin support
kotlin("jvm") version "1.8.0"
kotlin("jvm") version "1.9.22"
// Gradle IntelliJ Plugin
id("org.jetbrains.intellij") version "1.13.2"
id("org.jetbrains.intellij.platform") version "2.0.1"
// Gradle Changelog Plugin
id("org.jetbrains.changelog") version "1.3.0"
}
Expand All @@ -23,15 +24,42 @@ repositories {
}

// Configure Gradle IntelliJ Plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
intellij {
pluginName.set(properties("pluginName"))
version.set(properties("platformVersion"))
type.set(properties("platformType"))
downloadSources.set(properties("platformDownloadSources").toBoolean())
updateSinceUntilBuild.set(false)

// Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file.
plugins.set(properties("platformPlugins").split(',').map(String::trim).filter(String::isNotEmpty))
intellijPlatform {
pluginConfiguration {
name = properties("pluginName")
version = properties("pluginVersion")

ideaVersion {
sinceBuild = properties("pluginSinceBuild")
untilBuild = provider { null } // Specify no latest build
}
}

pluginVerification {
ides {
properties("pluginVerifierIdeVersions").split(',').map(String::trim).filter(String::isNotEmpty).forEach {
ide(IntelliJPlatformType.IntellijIdeaCommunity, it)
}
recommended()
}
}
}

repositories {
mavenCentral()
intellijPlatform.defaultRepositories()
}

dependencies {
intellijPlatform {
intellijIdeaCommunity(properties("platformVersion"))
plugins(properties("platformPlugins").split(',').map(String::trim).filter(String::isNotEmpty))
bundledPlugins(properties("platformBundledPlugins").split(',').map(String::trim).filter(String::isNotEmpty))

pluginVerifier()
instrumentationTools()
zipSigner()
}
}

tasks {
Expand All @@ -43,7 +71,7 @@ tasks {
}
withType<KotlinCompile> {
kotlinOptions.jvmTarget = it
kotlinOptions.freeCompilerArgs += listOf("-Xjvm-default=enable")
kotlinOptions.freeCompilerArgs += listOf("-Xjvm-default=all-compatibility")
}
}

Expand All @@ -52,9 +80,6 @@ tasks {
}

patchPluginXml {
version.set(properties("pluginVersion"))
sinceBuild.set(properties("pluginSinceBuild"))

// Extract the <!-- Plugin description --> section from README.md and provide for the plugin's manifest
pluginDescription.set(
projectDir.resolve("README.md").readText().lines().run {
Expand All @@ -76,17 +101,23 @@ tasks {
})
}

runPluginVerifier {
ideVersions.set(properties("pluginVerifierIdeVersions").split(',').map(String::trim).filter(String::isNotEmpty))
}

// 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")
val runIdeForUiTests by intellijPlatformTesting.runIde.registering {
task {
jvmArgumentProviders += CommandLineArgumentProvider {
listOf(
"robot-server.port=8082",
"ide.mac.message.dialogs.as.sheets=false",
"jb.privacy.policy.text=<!--999.999-->",
"jb.consents.confirmation.enabled=false",
)
}
}

plugins {
robotServerPlugin()
}
}

signPlugin {
Expand All @@ -101,7 +132,7 @@ tasks {
// 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.set(listOf(properties("pluginVersion").split('-').getOrElse(1) { "default" }.split('.').first()))
channels.set(properties("pluginVersion").split('-').getOrElse(1) { "default" }.split('.').take(1))
}

buildSearchableOptions {
Expand Down
18 changes: 8 additions & 10 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,26 @@

pluginGroup = org.vineflower.ijplugin
pluginName = Vineflower
pluginVersion = 1.1
pluginVersion = 1.1.0

# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
pluginSinceBuild = 231
pluginSinceBuild = 241

# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
# See https://jb.gg/intellij-platform-builds-list for available build versions.
pluginVerifierIdeVersions = 2023.1.2
pluginVerifierIdeVersions = 2024.1

platformType = IC
platformVersion = 2023.1.2
platformDownloadSources = true
platformVersion = 2024.1

# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
platformPlugins = com.intellij.java, org.jetbrains.kotlin, org.jetbrains.java.decompiler
platformBundledPlugins = com.intellij.java, org.jetbrains.kotlin, org.jetbrains.java.decompiler

# Java language level used to compile sources and to generate the files for - Java 11 is required since 2020.3
javaVersion = 11
# Java language level used to compile sources and to generate the files for - Java 17 is required since 2022.2
javaVersion = 17

gradleVersion = 7.2
gradleVersion = 8.9

# Opt-out flag for bundling Kotlin standard library.
# See https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library for details.
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ abstract class VineflowerDecompilerBase : ClassFileDecompilers.Full() {
}
}

override fun createFileViewProvider(file: VirtualFile, manager: PsiManager, physical: Boolean) =
override fun createFileViewProvider(file: VirtualFile, manager: PsiManager, physical: Boolean): FileViewProvider =
MyFileViewProvider(manager, file, physical)

abstract fun createDecompiledFile(viewProvider: FileViewProvider, contents: ResettableLazy<String>): PsiFile
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package org.vineflower.ijplugin

import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.progress.ProcessCanceledException
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.FileViewProvider
import com.intellij.psi.PsiManager
import com.intellij.psi.compiled.ClsStubBuilder
import com.intellij.psi.stubs.PsiFileStub
import com.intellij.psi.stubs.PsiFileStubImpl
import com.intellij.util.indexing.FileContent
import org.jetbrains.kotlin.analysis.decompiler.psi.KotlinDecompiledFileViewProvider
import org.jetbrains.kotlin.analysis.decompiler.psi.file.KtDecompiledFile
import org.jetbrains.kotlin.analysis.decompiler.psi.text.DecompiledText
import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.idea.KotlinLanguage
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.stubs.KotlinFileStub
import org.jetbrains.kotlin.psi.stubs.KotlinImportDirectiveStub

class VineflowerDecompilerKotlin : VineflowerDecompilerBase() {
private val myStubBuilder = StubBuilder()

override val language = KotlinLanguage.INSTANCE
override val sourceFileType = KotlinFileType.INSTANCE

override fun acceptsLanguage(language: String) = language == "kotlin"

override fun getStubBuilder(): ClsStubBuilder = myStubBuilder

override fun createFileViewProvider(file: VirtualFile, manager: PsiManager, physical: Boolean) =
KotlinDecompiledFileViewProvider(manager, file, physical) {
MyDecompiledFile(it) { f ->
val text = getText(f)
DecompiledText(text)
}
}

override fun createDecompiledFile(viewProvider: FileViewProvider, contents: ResettableLazy<String>) =
error("Should not be called")

private inner class StubBuilder : ClsStubBuilder() {
private val logger = logger<StubBuilder>()

override fun getStubVersion() = -1

override fun buildFileStub(content: FileContent): PsiFileStub<*>? {
try {
val text = getText(content.file)
val viewProvider = KotlinDecompiledFileViewProvider(
PsiManager.getInstance(content.project),
content.file,
true
) { null }
val file = MyDecompiledFile(viewProvider) { DecompiledText(text) }
return DecompiledPsiStub(file)
} catch (e: ProcessCanceledException) {
throw e
} catch (e: Exception) {
logger.error("Failed to decompile ${content.file.url}", e)
return null
}
}
}

private class DecompiledPsiStub(file: KtDecompiledFile) : PsiFileStubImpl<KtFile>(file), KotlinFileStub {
override fun findImportsByAlias(alias: String) = emptyList<KotlinImportDirectiveStub>()
override fun getPackageFqName() = psi.packageFqName
override fun isScript() = false
}

private class MyDecompiledFile(viewProvider: KotlinDecompiledFileViewProvider, contents: (VirtualFile) -> DecompiledText) : KtDecompiledFile(viewProvider, contents) {
override fun getStub() = stubTree?.root as KotlinFileStub?
}
}
Loading
Loading