@ -23,11 +23,14 @@ import org.jetbrains.compose.desktop.application.internal.JvmRuntimeProperties
import org.jetbrains.compose.desktop.application.internal.validation.validate
import org.jetbrains.compose.desktop.application.internal.validation.validate
import org.jetbrains.compose.internal.utils.*
import org.jetbrains.compose.internal.utils.*
import java.io.*
import java.io.*
import java.nio.file.LinkOption
import java.util.*
import java.util.*
import javax.inject.Inject
import javax.inject.Inject
import kotlin.collections.HashMap
import kotlin.collections.HashMap
import kotlin.collections.HashSet
import kotlin.collections.HashSet
import kotlin.collections.ArrayList
import kotlin.collections.ArrayList
import kotlin.io.path.isExecutable
import kotlin.io.path.isRegularFile
abstract class AbstractJPackageTask @Inject constructor (
abstract class AbstractJPackageTask @Inject constructor (
@get : Input
@get : Input
@ -237,12 +240,17 @@ abstract class AbstractJPackageTask @Inject constructor(
@get : Nested
@get : Nested
internal var nonValidatedMacSigningSettings : MacOSSigningSettings ? = null
internal var nonValidatedMacSigningSettings : MacOSSigningSettings ? = null
private val shouldSign : Boolean
get ( ) = nonValidatedMacSigningSettings ?. sign ?. get ( ) == true
private val macSigner : MacSigner ? by lazy {
private val macSigner : MacSigner ? by lazy {
val nonValidatedSettings = nonValidatedMacSigningSettings
val nonValidatedSettings = nonValidatedMacSigningSettings
if ( currentOS == OS . MacOS && nonValidatedSettings ?. sign ?. get ( ) == true ) {
if ( currentOS == OS . MacOS ) {
if ( shouldSign ) {
val validatedSettings =
val validatedSettings =
nonValidatedSettings . validate ( nonValidatedMacBundleID , project , macAppStore )
nonValidatedSettings !! . validate ( nonValidatedMacBundleID , project , macAppStore )
MacSigner ( validatedSettings , runExternalTool )
MacSignerImpl ( validatedSettings , runExternalTool )
} else NoCertificateSigner ( runExternalTool )
} else null
} else null
}
}
@ -389,11 +397,11 @@ abstract class AbstractJPackageTask @Inject constructor(
cliArg ( " --mac-app-category " , macAppCategory )
cliArg ( " --mac-app-category " , macAppCategory )
cliArg ( " --mac-entitlements " , macEntitlementsFile )
cliArg ( " --mac-entitlements " , macEntitlementsFile )
macSigner ?. let { signer ->
macSigner ?. settings ?. let { signingSettings ->
cliArg ( " --mac-sign " , true )
cliArg ( " --mac-sign " , true )
cliArg ( " --mac-signing-key-user-name " , signer . s ettings . identity )
cliArg ( " --mac-signing-key-user-name " , signingS ettings . identity )
cliArg ( " --mac-signing-keychain " , signer . s ettings . keychain )
cliArg ( " --mac-signing-keychain " , signingS ettings . keychain )
cliArg ( " --mac-package-signing-prefix " , signer . s ettings . prefix )
cliArg ( " --mac-package-signing-prefix " , signingS ettings . prefix )
}
}
}
}
}
}
@ -434,19 +442,16 @@ abstract class AbstractJPackageTask @Inject constructor(
return outdatedLibs
return outdatedLibs
}
}
override fun prepareWorkingDir ( inputChanges : InputChanges ) {
private fun jarCopyingProcessor ( ) : FileCopyingProcessor =
val libsDir = libsDir . ioFile
if ( currentOS == OS . MacOS ) {
val fileProcessor =
macSigner ?. let { signer ->
val tmpDirForSign = signDir . ioFile
val tmpDirForSign = signDir . ioFile
fileOperations . clearDirs ( tmpDirForSign )
fileOperations . clearDirs ( tmpDirForSign )
MacJarSignFileCopyingProcessor ( macSigner !! , tmpDirForSign , jvmRuntimeInfo . majorVersion )
} else SimpleFileCopyingProcessor
MacJarSignFileCopyingProcessor (
override fun prepareWorkingDir ( inputChanges : InputChanges ) {
signer ,
val libsDir = libsDir . ioFile
tmpDirForSign ,
val fileProcessor = jarCopyingProcessor ( )
jvmRuntimeVersion = jvmRuntimeInfo . majorVersion
)
} ?: SimpleFileCopyingProcessor
val mangleJarFilesNames = mangleJarFilesNames . get ( )
val mangleJarFilesNames = mangleJarFilesNames . get ( )
fun copyFileToLibsDir ( sourceFile : File ) : File {
fun copyFileToLibsDir ( sourceFile : File ) : File {
@ -525,17 +530,30 @@ abstract class AbstractJPackageTask @Inject constructor(
private fun modifyRuntimeOnMacOsIfNeeded ( ) {
private fun modifyRuntimeOnMacOsIfNeeded ( ) {
if ( currentOS != OS . MacOS || targetFormat != TargetFormat . AppImage ) return
if ( currentOS != OS . MacOS || targetFormat != TargetFormat . AppImage ) return
macSigner ?. let { macSigner ->
val macSigningHelper = MacSigningHelper (
val appDir = destinationDir . ioFile . resolve ( " ${packageName.get()} .app " )
macSigner = macSigner ,
val runtimeDir = appDir . resolve ( " Contents/runtime " )
runtimeProvisioningProfile = macRuntimeProvisioningProfile . ioFileOrNull ,
entitlementsFile = macEntitlementsFile . ioFileOrNull ,
// Add the provisioning profile
runtimeEntitlementsFile = macRuntimeEntitlementsFile . ioFileOrNull ,
macRuntimeProvisioningProfile . ioFileOrNull ?. copyTo (
destinationDir = destinationDir . ioFile ,
target = runtimeDir . resolve ( " Contents/embedded.provisionprofile " ) ,
packageName = packageName . get ( )
overwrite = true
)
)
macSigningHelper . modifyRuntimeIfNeeded ( )
val appEntitlementsFile = macEntitlementsFile . ioFileOrNull
val runtimeEntitlementsFile = macRuntimeEntitlementsFile . ioFileOrNull
val macSigner = macSigner !!
// Resign the runtime completely (and also the app dir only)
// Sign all libs and executables in runtime
runtimeDir . walk ( ) . forEach { file ->
val path = file . toPath ( )
if ( path . isRegularFile ( LinkOption . NOFOLLOW _LINKS ) && ( path . isExecutable ( ) || file . name . isDylibPath ) ) {
macSigner . sign ( file , runtimeEntitlementsFile )
}
}
}
macSigner . sign ( runtimeDir , runtimeEntitlementsFile , forceEntitlements = true )
macSigner . sign ( appDir , appEntitlementsFile , forceEntitlements = true )
}
}
override fun initState ( ) {
override fun initState ( ) {