Browse Source

Make AppImage format compatible with all OS

Turns out, app-image is not an OS specific format, but a prepackaged image of packaged app
pull/45/head
Alexey Tsvetkov 4 years ago
parent
commit
e915ec6ac1
  1. 72
      gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/ApplicationPlugin.kt
  2. 11
      gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/TargetFormat.kt
  3. 2
      gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/wixToolset.kt
  4. 4
      gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt

72
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.DesktopExtension
import org.jetbrains.compose.desktop.application.dsl.Application import org.jetbrains.compose.desktop.application.dsl.Application
import org.jetbrains.compose.desktop.application.dsl.ConfigurationSource 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.OS
import org.jetbrains.compose.desktop.application.internal.configureWix import org.jetbrains.compose.desktop.application.internal.configureWix
import org.jetbrains.compose.desktop.application.internal.currentOS import org.jetbrains.compose.desktop.application.internal.currentOS
@ -91,9 +92,44 @@ internal fun Project.configurePackagingTasks(app: Application): TaskProvider<Def
} }
internal fun AbstractJPackageTask.configurePackagingTask(app: Application) { internal fun AbstractJPackageTask.configurePackagingTask(app: Application) {
enabled = (currentOS == targetOS) enabled = targetFormat.isCompatibleWithCurrentOS
val targetPlatformSettings = when (targetOS) { if (targetFormat != TargetFormat.AppImage) {
configurePlatformSettings(app)
}
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 })
}
internal fun AbstractJPackageTask.configurePlatformSettings(app: Application) {
when (currentOS) {
OS.Linux -> { OS.Linux -> {
app.nativeDistributions.linux.also { linux -> app.nativeDistributions.linux.also { linux ->
linuxShortcut.set(provider { linux.shortcut }) 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) { private fun Project.configureRunTask(app: Application) {
project.tasks.composeTask<JavaExec>(taskName("run", app)) { project.tasks.composeTask<JavaExec>(taskName("run", app)) {
mainClass.set(provider { app.mainClass }) mainClass.set(provider { app.mainClass })

11
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 package org.jetbrains.compose.desktop.application.dsl
import org.jetbrains.compose.desktop.application.internal.OS import org.jetbrains.compose.desktop.application.internal.OS
import org.jetbrains.compose.desktop.application.internal.currentOS
enum class TargetFormat( enum class TargetFormat(
internal val id: String, internal val id: String,
internal val os: OS private vararg val compatibleOSs: OS
) { ) {
AppImage("app-image", *OS.values()),
Deb("deb", OS.Linux), Deb("deb", OS.Linux),
Rpm("rpm", OS.Linux), Rpm("rpm", OS.Linux),
App("app-image", OS.MacOS),
Dmg("dmg", OS.MacOS), Dmg("dmg", OS.MacOS),
Pkg("pkg", OS.MacOS), Pkg("pkg", OS.MacOS),
Exe("exe", OS.Windows), 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
} }

2
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) { private fun Project.eachWindowsPackageTask(fn: AbstractJPackageTask.() -> Unit) {
tasks.withType(AbstractJPackageTask::class.java).configureEach { packageTask -> tasks.withType(AbstractJPackageTask::class.java).configureEach { packageTask ->
if (packageTask.targetOS == OS.Windows) { if (packageTask.targetFormat.isCompatibleWith(OS.Windows)) {
packageTask.fn() packageTask.fn()
} }
} }

4
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, objects: ObjectFactory,
providers: ProviderFactory providers: ProviderFactory
) : DefaultTask() { ) : DefaultTask() {
@get:Input
internal val targetOS: OS
get() = targetFormat.os
@get:InputFiles @get:InputFiles
val files: ConfigurableFileCollection = objects.fileCollection() val files: ConfigurableFileCollection = objects.fileCollection()

Loading…
Cancel
Save