Skip to content

Commit 62ea338

Browse files
Merge pull request #2924 from bisq-network/revert-2773-feature/jre_from_jdk
Revert "Use JRE instead of JDK Desktop Binary"
2 parents ebfb1d2 + 0f7be90 commit 62ea338

4 files changed

Lines changed: 44 additions & 127 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ hs_err_pid*
4141
*.wallet
4242
*.ser
4343
*.sh
44-
.vscode
4544
.DS_Store
4645
.gradle
4746
build

apps/desktop/desktop-app-launcher/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import java.util.Properties
2+
import java.io.File
23

34
// Function to read properties from a file - TODO find a way to reuse this code instead of copying when needed
45
fun readPropertiesFile(filePath: String): Properties {
@@ -11,7 +12,6 @@ plugins {
1112
id("bisq.java-library")
1213
id("bisq.gradle.desktop.regtest.BisqDesktopRegtestPlugin")
1314
application
14-
id("org.kordamp.gradle.jdeps") version "0.20.0"
1515
id("bisq.gradle.packaging.PackagingPlugin")
1616
alias(libs.plugins.openjfx)
1717
}

build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/JLinkTask.kt

Lines changed: 37 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@ package bisq.gradle.packaging
33
import org.gradle.api.DefaultTask
44
import org.gradle.api.file.DirectoryProperty
55
import org.gradle.api.file.RegularFileProperty
6-
import org.gradle.api.tasks.*
7-
import java.io.BufferedReader
8-
import java.io.InputStreamReader
9-
10-
11-
//import java.util.regex.Pattern
6+
import org.gradle.api.tasks.InputDirectory
7+
import org.gradle.api.tasks.InputFile
8+
import org.gradle.api.tasks.Optional
9+
import org.gradle.api.tasks.OutputDirectory
10+
import org.gradle.api.tasks.TaskAction
11+
import java.util.concurrent.TimeUnit
1212

1313
abstract class JLinkTask : DefaultTask() {
1414

15-
// companion object {
16-
// val pattern: Pattern = Pattern.compile(".*\\b(java\\..*|javax\\..*)\\b.*\$")
17-
// }
18-
1915
@get:InputDirectory
2016
abstract val jdkDirectory: DirectoryProperty
2117

@@ -31,105 +27,46 @@ abstract class JLinkTask : DefaultTask() {
3127

3228
@TaskAction
3329
fun run() {
34-
// Ensure the output directory is clean
30+
// jlink expects non-existent output directory
3531
val outputDirectoryFile = outputDirectory.asFile.get()
36-
if (outputDirectoryFile.exists() && outputDirectoryFile.listFiles()?.isNotEmpty() == true) {
37-
// In case you want to run it manually, this will stop the plugin from running the task
38-
logger.lifecycle("custom jre already created, skipping - see: ${jdkDirectory.get()}")
39-
} else {
40-
if (!outputDirectoryFile.canWrite()) {
41-
throw IllegalStateException("Output directory is not writable: ${outputDirectoryFile.absolutePath}")
42-
}
43-
outputDirectoryFile.deleteRecursively()
44-
45-
logger.lifecycle("JDK path: ${jdkDirectory.get()}")
46-
47-
// Construct the jlink command
48-
val jLinkPath = jdkDirectory.asFile.get().toPath().resolve("bin").resolve("jlink")
49-
val processBuilder = ProcessBuilder(
32+
outputDirectoryFile.deleteRecursively()
33+
34+
val jLinkPath = jdkDirectory.asFile.get().toPath().resolve("bin").resolve("jlink")
35+
val processBuilder = ProcessBuilder(
5036
jLinkPath.toAbsolutePath().toString(),
51-
"--verbose",
37+
5238
"--add-modules", parseUsedJavaModulesFromJDepsOutput(),
53-
"--include-locales=en,cs,de,es,it,pcm,pt-BR",
39+
5440
"--strip-native-commands",
5541
"--no-header-files",
5642
"--no-man-pages",
57-
"--compress=2",
58-
// "--strip-debug", // makes jlink fail in some platforms like Ubuntu linux
59-
// "--add-reads", "java.base=ALL-UNNAMED",
43+
"--strip-debug",
44+
6045
"--output", outputDirectoryFile.absolutePath
61-
)
62-
logger.lifecycle("Executing jlink command: ${processBuilder.command().joinToString(" ")}")
63-
64-
// Add module path if specified
65-
if (javaModulesDirectory.isPresent) {
66-
val commands = processBuilder.command()
67-
commands.add("--module-path")
68-
commands.add(javaModulesDirectory.asFile.get().absolutePath)
69-
logger.lifecycle("Executing jlink command: ${commands.joinToString(" ")}")
70-
}
71-
72-
logger.lifecycle("Preparing process builder..")
73-
processBuilder.inheritIO()
74-
75-
logger.lifecycle("Starting process builder..")
76-
val process = processBuilder.start()
77-
if (System.getProperty("os.name").lowercase().contains("windows")) {
78-
val reader =
79-
BufferedReader(InputStreamReader(process.inputStream))
80-
while ((reader.readLine()) != null) {
81-
// WORKAROUND: Jlink hangs in windows (11pro) when running from this custom plugin
82-
// This buffer reader is needed jus to get it going and won't affect the rest of the platforms
83-
}
84-
}
85-
logger.lifecycle("Reading errors..")
86-
val errorOutput = process.errorStream.bufferedReader().readText()
87-
val exitCode = process.waitFor()
88-
89-
if (exitCode != 0) {
90-
logger.error("jlink error output:\n$errorOutput")
91-
throw IllegalStateException("jlink couldn't create custom runtime. Exit code: $exitCode")
92-
}
46+
)
47+
48+
if (javaModulesDirectory.isPresent) {
49+
val commands = processBuilder.command()
50+
commands.add("--module-path")
51+
commands.add(javaModulesDirectory.asFile.get().absolutePath)
52+
}
53+
54+
processBuilder.inheritIO()
55+
56+
val process = processBuilder.start()
57+
process.waitFor(2, TimeUnit.MINUTES)
58+
59+
val isSuccess = process.exitValue() == 0
60+
if (!isSuccess) {
61+
throw IllegalStateException("jlink couldn't create custom runtime.")
9362
}
9463
}
9564

9665
private fun parseUsedJavaModulesFromJDepsOutput(): String {
97-
// TODO instead of hardcoding he modules process the jdeps report and generate the below so we don't need
98-
// to touch this code again in case of needed new jmods in the future
99-
// readLines.filter { pattern.matcher(it).matches() }
100-
// .flatMap { line -> line.split("->").map { it.trim() } }
101-
// .filter { it.startsWith("java.") || it == "bisq.desktop_app_launcher" }
102-
// .flatMap { line -> line.split(",").map { it.trim() } }
103-
// .distinct()
104-
// .joinToString(",")
105-
// val readLines = jDepsOutputFile.asFile.get().readLines()
106-
val modules = listOf(
107-
// base
108-
"java.base",
109-
"java.datatransfer",
110-
"java.desktop",
111-
"java.logging",
112-
"java.xml",
113-
"java.naming",
114-
"java.net.http",
115-
// security
116-
"java.se",
117-
"java.security.jgss",
118-
// javafx
119-
"javafx.base",
120-
"javafx.controls",
121-
"javafx.fxml",
122-
"javafx.graphics",
123-
"javafx.media",
124-
"javafx.swing",
125-
// "javafx.web",
126-
// jdk
127-
"jdk.unsupported",
128-
"jdk.localedata",
129-
"jdk.crypto.cryptoki",
130-
"jdk.crypto.ec"
131-
).joinToString(",")
132-
logger.lifecycle("Modules to be included: $modules")
133-
return modules
66+
var readLines = jDepsOutputFile.asFile.get().readLines()
67+
if (!javaModulesDirectory.isPresent) {
68+
readLines = readLines.filter { it.startsWith("java.") }
69+
}
70+
return readLines.joinToString(",")
13471
}
135-
}
72+
}

build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/PackagingPlugin.kt

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import org.gradle.api.file.Directory
99
import org.gradle.api.file.RegularFile
1010
import org.gradle.api.plugins.JavaApplication
1111
import org.gradle.api.provider.Provider
12-
import org.gradle.api.tasks.*
12+
import org.gradle.api.tasks.Sync
13+
import org.gradle.api.tasks.TaskProvider
1314
import org.gradle.jvm.tasks.Jar
1415
import org.gradle.jvm.toolchain.JavaLanguageVersion
1516
import org.gradle.jvm.toolchain.JavaToolchainService
@@ -42,30 +43,10 @@ class PackagingPlugin @Inject constructor(private val javaToolchainService: Java
4243
val javaApplicationExtension = project.extensions.findByType<JavaApplication>()
4344
checkNotNull(javaApplicationExtension) { "Can't find JavaApplication extension." }
4445

45-
val createCustomJre = project.tasks.register<JLinkTask>("createCustomJre") {
46-
dependsOn(project.tasks.named("jdepsReport"))
47-
48-
jdkDirectory.set(getJPackageJdkDirectory(extension))
49-
jDepsOutputFile.set(getBuildFileOf(project, "reports/jdeps/jdeps-main.txt"))
50-
outputDirectory.set(project.layout.buildDirectory.dir("custom-jre"))
51-
52-
doLast {
53-
println("JLink configuration:")
54-
println("JDK Directory: ${jdkDirectory.get()}")
55-
println("JDeps Output File: ${jDepsOutputFile.get()}")
56-
println("Output Directory: ${outputDirectory.get()}")
57-
}
58-
}
59-
6046
project.tasks.register<JPackageTask>("generateInstallers") {
6147
group = "distribution"
6248
description = "Generate the installer or the platform the project is running"
6349

64-
dependsOn(createCustomJre)
65-
66-
// Set the runtime image to the output of JLinkTask
67-
runtimeImageDirectory.set(createCustomJre.flatMap { it.outputDirectory })
68-
6950
val webcamProject = project.parent?.childProjects?.filter { e -> e.key == "webcam-app" }?.map { e -> e.value.project }?.first()
7051
webcamProject?.let { webcam ->
7152
val desktopProject = project.parent?.childProjects?.filter { e -> e.key == "desktop" }?.map { e -> e.value.project }?.first()
@@ -100,6 +81,10 @@ class PackagingPlugin @Inject constructor(private val javaToolchainService: Java
10081
val packageResourcesDirFile = File(project.projectDir, "package")
10182
packageResourcesDir.set(packageResourcesDirFile)
10283

84+
runtimeImageDirectory.set(
85+
getJPackageJdkDirectory(extension)
86+
)
87+
10388
outputDirectory.set(project.layout.buildDirectory.dir("packaging/jpackage/packages"))
10489
}
10590

@@ -142,8 +127,4 @@ class PackagingPlugin @Inject constructor(private val javaToolchainService: Java
142127
}
143128
return javaVersion.map { JavaLanguageVersion.of(it) }
144129
}
145-
146-
private fun getBuildFileOf(project: Project, relativePath: String): RegularFile {
147-
return project.layout.buildDirectory.file(relativePath).get()
148-
}
149130
}

0 commit comments

Comments
 (0)