Skip to content

Commit

Permalink
Add option to enable Class data sharing (CDS)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas-Vos committed May 28, 2022
1 parent bb32831 commit 6e98378
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.Optional
import org.gradle.process.ExecResult
import org.jetbrains.compose.desktop.application.internal.RuntimeCompressionLevel
import org.jetbrains.compose.desktop.application.internal.*
import org.jetbrains.compose.desktop.application.internal.JavaRuntimeProperties
Expand Down Expand Up @@ -43,6 +44,9 @@ abstract class AbstractJLinkTask : AbstractJvmToolOperationTask("jlink") {
@get:Input
internal val stripNativeCommands: Property<Boolean> = objects.notNullProperty(true)

@get:Input
internal val cds: Property<Boolean> = objects.notNullProperty(false)

@get:Input
@get:Optional
internal val compressionLevel: Property<RuntimeCompressionLevel?> = objects.nullableProperty()
Expand All @@ -56,12 +60,30 @@ abstract class AbstractJLinkTask : AbstractJvmToolOperationTask("jlink") {
cliArg("--add-modules", m)
}

val cds = cds.get()

cliArg("--strip-debug", stripDebug)
cliArg("--no-header-files", noHeaderFiles)
cliArg("--no-man-pages", noManPages)
cliArg("--strip-native-commands", stripNativeCommands)
// Native commands cannot be stripped if CDS is enabled, because bin/java is used by the CDS option.
if (!cds) {
cliArg("--strip-native-commands", stripNativeCommands)
}
cliArg("--generate-cds-archive", cds)
cliArg("--compress", compressionLevel.orNull?.id)

cliArg("--output", destinationDir)
}

override fun checkResult(result: ExecResult) {
super.checkResult(result)
if (stripNativeCommands.get() && cds.get()) {
// Native files were not removed yet, so do it here.
destinationDir.get().asFile.walk().forEach { file ->
if (file.isDirectory && file.name == "bin") {
file.deleteRecursively()
}
}
}
}
}

0 comments on commit 6e98378

Please sign in to comment.