From e915ec6ac12b8057ce69d67b220b3dbcdf773ea0 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Mon, 2 Nov 2020 09:42:40 +0300 Subject: [PATCH] Make AppImage format compatible with all OS Turns out, app-image is not an OS specific format, but a prepackaged image of packaged app --- .../desktop/application/ApplicationPlugin.kt | 72 ++++++++++--------- .../desktop/application/dsl/TargetFormat.kt | 11 ++- .../application/internal/wixToolset.kt | 2 +- .../application/tasks/AbstractJPackageTask.kt | 4 -- 4 files changed, 47 insertions(+), 42 deletions(-) diff --git a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/ApplicationPlugin.kt b/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/ApplicationPlugin.kt index 43e226f4bf..bf3a75dd39 100644 --- a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/ApplicationPlugin.kt +++ b/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/ApplicationPlugin.kt @@ -12,6 +12,7 @@ import org.jetbrains.compose.desktop.DesktopBasePlugin import org.jetbrains.compose.desktop.DesktopExtension import org.jetbrains.compose.desktop.application.dsl.Application import org.jetbrains.compose.desktop.application.dsl.ConfigurationSource +import org.jetbrains.compose.desktop.application.dsl.TargetFormat import org.jetbrains.compose.desktop.application.internal.OS import org.jetbrains.compose.desktop.application.internal.configureWix import org.jetbrains.compose.desktop.application.internal.currentOS @@ -91,9 +92,44 @@ internal fun Project.configurePackagingTasks(app: Application): TaskProvider + packageName.set(provider { executables.packageName ?: project.name }) + packageDescription.set(provider { executables.description }) + packageCopyright.set(provider { executables.copyright }) + packageVendor.set(provider { executables.vendor }) + packageVersion.set(provider { + executables.version + ?: project.version.toString().takeIf { it != "unspecified" } + }) + } + + destinationDir.set(app.nativeDistributions.outputBaseDir.map { it.dir("${app.name}/${targetFormat.id}") }) + javaHome.set(provider { app.javaHomeOrDefault() }) + + launcherMainJar.set(app.mainJar.orNull) + app._fromFiles.forEach { files.from(it) } + dependsOn(*app._dependenciesTaskNames.toTypedArray()) + + app._configurationSource?.let { configSource -> + dependsOn(configSource.jarTaskName) + files.from(configSource.runtimeClasspath) + launcherMainJar.set(app.mainJar.orElse(configSource.jarTask(project).flatMap { it.archiveFile })) + } + + modules.set(provider { app.nativeDistributions.modules }) + launcherMainClass.set(provider { app.mainClass }) + launcherJvmArgs.set(provider { app.jvmArgs }) + launcherArgs.set(provider { app.args }) +} + +internal fun AbstractJPackageTask.configurePlatformSettings(app: Application) { + when (currentOS) { OS.Linux -> { app.nativeDistributions.linux.also { linux -> linuxShortcut.set(provider { linux.shortcut }) @@ -130,40 +166,8 @@ internal fun AbstractJPackageTask.configurePackagingTask(app: Application) { } } } - - app.nativeDistributions.let { executables -> - packageName.set(provider { executables.packageName ?: project.name }) - packageDescription.set(provider { executables.description }) - packageCopyright.set(provider { executables.copyright }) - packageVendor.set(provider { executables.vendor }) - packageVersion.set(provider { - executables.version - ?: project.version.toString().takeIf { it != "unspecified" } - }) - } - - destinationDir.set(app.nativeDistributions.outputBaseDir.map { it.dir("${app.name}/${targetFormat.id}") }) - javaHome.set(provider { app.javaHomeOrDefault() }) - - launcherMainJar.set(app.mainJar.orNull) - app._fromFiles.forEach { files.from(it) } - dependsOn(*app._dependenciesTaskNames.toTypedArray()) - - app._configurationSource?.let { configSource -> - dependsOn(configSource.jarTaskName) - files.from(configSource.runtimeClasspath) - launcherMainJar.set(app.mainJar.orElse(configSource.jarTask(project).flatMap { it.archiveFile })) - } - - modules.set(provider { app.nativeDistributions.modules }) - launcherMainClass.set(provider { app.mainClass }) - launcherJvmArgs.set(provider { app.jvmArgs }) - launcherArgs.set(provider { app.args }) } -private fun AbstractJPackageTask.jarFromJarTaskByName(jarTaskName: String) = - project.tasks.named(jarTaskName).map { (it as Jar).archiveFile.get() } - private fun Project.configureRunTask(app: Application) { project.tasks.composeTask(taskName("run", app)) { mainClass.set(provider { app.mainClass }) diff --git a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/TargetFormat.kt b/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/TargetFormat.kt index 43e6a5ea67..f0384d1fd4 100644 --- a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/TargetFormat.kt +++ b/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/TargetFormat.kt @@ -1,16 +1,21 @@ package org.jetbrains.compose.desktop.application.dsl import org.jetbrains.compose.desktop.application.internal.OS +import org.jetbrains.compose.desktop.application.internal.currentOS enum class TargetFormat( internal val id: String, - internal val os: OS + private vararg val compatibleOSs: OS ) { + AppImage("app-image", *OS.values()), Deb("deb", OS.Linux), Rpm("rpm", OS.Linux), - App("app-image", OS.MacOS), Dmg("dmg", OS.MacOS), Pkg("pkg", OS.MacOS), Exe("exe", OS.Windows), - Msi("msi", OS.Windows) + Msi("msi", OS.Windows); + + val isCompatibleWithCurrentOS: Boolean by lazy { isCompatibleWith(currentOS) } + + internal fun isCompatibleWith(targetOS: OS): Boolean = targetOS in compatibleOSs } \ No newline at end of file diff --git a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/wixToolset.kt b/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/wixToolset.kt index 4e7e638c7f..80a114c627 100644 --- a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/wixToolset.kt +++ b/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/wixToolset.kt @@ -48,7 +48,7 @@ internal fun Project.configureWix() { private fun Project.eachWindowsPackageTask(fn: AbstractJPackageTask.() -> Unit) { tasks.withType(AbstractJPackageTask::class.java).configureEach { packageTask -> - if (packageTask.targetOS == OS.Windows) { + if (packageTask.targetFormat.isCompatibleWith(OS.Windows)) { packageTask.fn() } } diff --git a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt b/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt index 064170add9..442df40e83 100644 --- a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt +++ b/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt @@ -32,10 +32,6 @@ abstract class AbstractJPackageTask @Inject constructor( objects: ObjectFactory, providers: ProviderFactory ) : DefaultTask() { - @get:Input - internal val targetOS: OS - get() = targetFormat.os - @get:InputFiles val files: ConfigurableFileCollection = objects.fileCollection()