Skip to content

Commit

Permalink
Merge pull request #628 from AlexandrosAlexiou/refactor/dependecies/d…
Browse files Browse the repository at this point in the history
…ecompiler

refactor: use JetBrains release repository for FernFlower decompiler
  • Loading branch information
fwcd authored Jan 20, 2025
2 parents b7bc79a + 6cf3dac commit dc24041
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 173 deletions.
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ lsp4jVersion = "0.21.2"
exposedVersion = "0.37.3"
jmhVersion = "1.37"
guavaVersion = "33.4.0-jre"
fernFlowerVersion = "243.22562.218"

[libraries]
org-jetbrains-kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlinVersion" }
Expand All @@ -28,7 +29,7 @@ org-jetbrains-exposed-core = { module = "org.jetbrains.exposed:exposed-core", ve
org-jetbrains-exposed-dao = { module = "org.jetbrains.exposed:exposed-dao", version.ref = "exposedVersion" }
org-jetbrains-exposed-jdbc = { module = "org.jetbrains.exposed:exposed-jdbc", version.ref = "exposedVersion" }

org-jetbrains-fernflower = { module = "org.jetbrains:fernflower", version = "1.0" }
com-jetbrains-intellij-java-decompiler = { module = "com.jetbrains.intellij.java:java-decompiler-engine", version.ref = "fernFlowerVersion" }

com-github-fwcd-ktfmt = { module = "com.github.fwcd.ktfmt:ktfmt", version = "b5d31d1" }

Expand Down
2 changes: 1 addition & 1 deletion platform/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies {
api(libs.org.jetbrains.kotlin.sam.with.receiver.compiler.plugin)
api(libs.org.jetbrains.kotlin.reflect)
api(libs.org.jetbrains.kotlin.jvm)
api(libs.org.jetbrains.fernflower)
api(libs.com.jetbrains.intellij.java.decompiler)
api(libs.org.jetbrains.exposed.core)
api(libs.org.jetbrains.exposed.dao)
api(libs.org.jetbrains.exposed.jdbc)
Expand Down
15 changes: 6 additions & 9 deletions server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@ application {
mainClass.set(serverMainClassName)
description = "Code completions, diagnostics and more for Kotlin"
applicationDefaultJvmArgs = listOf("-DkotlinLanguageServer.version=$version")
applicationDistribution.into("bin") {
filePermissions { unix("755".toInt(radix = 8)) }
}
applicationDistribution.into("bin") { filePermissions { unix("755".toInt(radix = 8)) } }
}

repositories {
maven(url = "https://repo.gradle.org/gradle/libs-releases")
maven { url = uri("$projectDir/lib") }
maven(uri("$projectDir/lib"))
maven("https://jitpack.io")
maven(url = "https://www.jetbrains.com/intellij-repository/releases")
mavenCentral()
}

Expand All @@ -48,7 +45,7 @@ dependencies {
implementation(kotlin("scripting-jvm-host-unshaded"))
implementation(kotlin("sam-with-receiver-compiler-plugin"))
implementation(kotlin("reflect"))
implementation(libs.org.jetbrains.fernflower)
implementation(libs.com.jetbrains.intellij.java.decompiler)
implementation(libs.org.jetbrains.exposed.core)
implementation(libs.org.jetbrains.exposed.dao)
implementation(libs.org.jetbrains.exposed.jdbc)
Expand Down Expand Up @@ -79,9 +76,9 @@ tasks.register<Exec>("fixFilePermissions") {

onlyIf { !System.getProperty("os.name").lowercase().contains("windows") }
commandLine(
"chmod",
"+x",
"${tasks.installDist.get().destinationDir}/bin/kotlin-language-server"
"chmod",
"+x",
"${tasks.installDist.get().destinationDir}/bin/kotlin-language-server",
)
}

Expand Down
11 changes: 0 additions & 11 deletions server/lib/fernflower-license.txt

This file was deleted.

85 changes: 0 additions & 85 deletions server/lib/gradle-kotlin-dsl-tooling-models-0.11.0-license.txt

This file was deleted.

Binary file not shown.
19 changes: 0 additions & 19 deletions server/lib/org/jetbrains/fernflower/1.0/fernflower-1.0.pom

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ClassContentProvider(
private val cp: CompilerClassPath,
private val tempDir: TemporaryDirectory,
private val sourceArchiveProvider: SourceArchiveProvider,
private val decompiler: Decompiler = FernflowerDecompiler()
private val decompiler: Decompiler = FernFlowerDecompiler()
) {
/** Maps recently used (source-)KLS-URIs to their source contents (e.g. decompiled code) and the file extension. */
private val cachedContents = object : LinkedHashMap<String, Pair<String, String>>() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.javacs.kt.externalsources

import java.nio.file.Files
import java.nio.file.Path
import org.javacs.kt.LOG
import org.javacs.kt.util.KotlinLSException
import org.javacs.kt.util.replaceExtensionWith
import org.javacs.kt.util.withCustomStdout
import org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler

class FernFlowerDecompiler : Decompiler {
private val outputDir: Path by lazy {
Files.createTempDirectory("fernflowerOut").also {
Runtime.getRuntime().addShutdownHook(Thread { it.toFile().deleteRecursively() })
}
}

private val decompilerOptions =
arrayOf(
"-iec=1", // Include entire classpath for better context
"-jpr=1", // Include parameter names in method signatures
)

override fun decompileClass(compiledClass: Path): Path {
return decompile(compiledClass, ".java")
}

override fun decompileJar(compiledJar: Path): Path {
return decompile(compiledJar, ".jar")
}

private fun decompile(input: Path, extension: String): Path {
LOG.info("Decompiling ${input.fileName} using FernFlower...")

val args = decompilerOptions + arrayOf(input.toString(), outputDir.toString())

withCustomStdout(LOG.outStream) { ConsoleDecompiler.main(args) }

val outName = input.fileName.replaceExtensionWith(extension)
val outPath = outputDir.resolve(outName)
if (!Files.exists(outPath)) {
throw KotlinLSException(
"Could not decompile ${input.fileName}: FernFlower did not generate sources at $outName"
)
}
return outPath
}
}

This file was deleted.

0 comments on commit dc24041

Please sign in to comment.