2020-09-22 18:18:28 +02:00
|
|
|
import org.apache.tools.ant.taskdefs.condition.Os
|
|
|
|
|
2022-09-15 09:41:15 +02:00
|
|
|
import java.time.LocalDateTime
|
2020-09-22 18:18:28 +02:00
|
|
|
|
|
|
|
task jpackageSanityChecks {
|
|
|
|
description 'Interactive sanity checks on the version of the code that will be packaged'
|
|
|
|
|
|
|
|
doLast {
|
2021-11-24 18:59:24 +01:00
|
|
|
// Enforce JDK 15 for packaging. This will ensure:
|
|
|
|
// - Java 15 is used to compile the jars
|
|
|
|
// - jpackager from JDK 15 is used to package the binaries
|
|
|
|
// - JRE 15 is bundled in the released binaries
|
|
|
|
// TODO Use jpackage flag "--runtime-image jdk-11" to include another version of JRE in generated binaries
|
|
|
|
// (But buggy in jpackager v15? Flag didn't work in last v15 test)
|
|
|
|
assert JavaVersion.current() == JavaVersion.VERSION_15: "JDK 15 is required when packaging"
|
2021-05-20 23:35:26 +02:00
|
|
|
|
2020-09-22 18:18:28 +02:00
|
|
|
executeCmd("git --no-pager log -5 --oneline")
|
|
|
|
ant.input(message: "Above you see the current HEAD and its recent history.\n" +
|
|
|
|
"Is this the right commit for packaging? (y=continue, n=abort)",
|
|
|
|
addproperty: "sanity-check-1",
|
|
|
|
validargs: "y,n")
|
|
|
|
if (ant.properties['sanity-check-1'] == 'n') {
|
|
|
|
ant.fail('Aborting')
|
|
|
|
}
|
|
|
|
|
|
|
|
executeCmd("git status --short --branch")
|
|
|
|
ant.input(message: "Above you see any local changes that are not in the remote branch.\n" +
|
|
|
|
"If you have any local changes, please abort, get them merged, get the latest branch and try again.\n" +
|
|
|
|
"Continue with packaging? (y=continue, n=abort)",
|
|
|
|
addproperty: "sanity-check-2",
|
|
|
|
validargs: "y,n")
|
|
|
|
if (ant.properties['sanity-check-2'] == 'n') {
|
|
|
|
ant.fail('Aborting')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-24 18:59:24 +01:00
|
|
|
task createNewTempFolder {
|
|
|
|
description 'Create new temp folder where the packaging files will be placed'
|
2020-09-22 18:18:28 +02:00
|
|
|
dependsOn 'jpackageSanityChecks'
|
|
|
|
|
|
|
|
doLast {
|
|
|
|
// The build directory will be deleted next time the clean task runs
|
|
|
|
// Therefore, we can use it to store any temp files (separate JDK for jpackage, etc) and resulting build artefacts
|
|
|
|
// We create a temp folder in the build directory which holds all jpackage-related artefacts (not just the final installers)
|
2020-12-13 14:25:10 +01:00
|
|
|
String tempRootDirName = 'temp-' + LocalDateTime.now().format('yyyy.MM.dd-HHmmssSSS')
|
2020-09-22 18:18:28 +02:00
|
|
|
File tempRootDir = new File(project.buildDir, tempRootDirName)
|
|
|
|
tempRootDir.mkdirs()
|
|
|
|
ext.tempRootDir = tempRootDir
|
|
|
|
println "Created temp root folder " + tempRootDir
|
|
|
|
|
|
|
|
File binariesFolderPath = new File(tempRootDir, "binaries")
|
2021-01-09 21:33:59 +01:00
|
|
|
binariesFolderPath.mkdirs()
|
2020-09-22 18:18:28 +02:00
|
|
|
ext.binariesFolderPath = binariesFolderPath
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
task packageInstallers {
|
|
|
|
description 'Call jpackage to prepare platform-specific binaries for this platform'
|
2021-11-24 18:59:24 +01:00
|
|
|
dependsOn 'createNewTempFolder'
|
2020-09-26 12:02:15 +02:00
|
|
|
dependsOn rootProject.clean
|
2021-05-20 22:56:59 +02:00
|
|
|
dependsOn ':desktop:build' // Full build needed for "desktop/build/app/lib", used for raspi package
|
2020-09-22 18:18:28 +02:00
|
|
|
|
|
|
|
doLast {
|
2021-11-24 18:59:24 +01:00
|
|
|
String jPackageFilePath = "jpackage" // Binary is in the PATH because we're running JDK v15
|
|
|
|
File binariesFolderPath = file(createNewTempFolder.property('binariesFolderPath'))
|
2020-09-22 18:18:28 +02:00
|
|
|
|
2021-11-24 18:59:24 +01:00
|
|
|
File tempRootDir = createNewTempFolder.property("tempRootDir") as File
|
2021-01-13 22:40:15 +01:00
|
|
|
// The jpackageTempDir stores temp files used by jpackage for building the installers
|
2020-10-04 22:14:12 +02:00
|
|
|
// It can be inspected in order to troubleshoot the packaging process
|
2021-01-13 22:40:15 +01:00
|
|
|
File jpackageTempDir = new File(tempRootDir, "jpackage-temp")
|
|
|
|
jpackageTempDir.mkdirs()
|
2020-10-04 22:14:12 +02:00
|
|
|
|
2020-09-22 18:18:28 +02:00
|
|
|
// ALL contents of this folder will be included in the resulting installers
|
|
|
|
// However, the fat jar is the only one we need
|
|
|
|
// Therefore, this location should point to a folder that ONLY contains the fat jar
|
|
|
|
// If later we will need to include other non-jar resources, we can do that by adding --resource-dir to the jpackage opts
|
2021-01-13 09:53:48 +01:00
|
|
|
String fatJarFolderPath = "${project(':desktop').buildDir}/libs/fatJar"
|
|
|
|
String mainJarName = shadowJar.getArchiveFileName().get()
|
|
|
|
|
|
|
|
delete(fatJarFolderPath)
|
|
|
|
mkdir(fatJarFolderPath)
|
|
|
|
copy {
|
|
|
|
from "${project(':desktop').buildDir}/libs/${mainJarName}"
|
|
|
|
into fatJarFolderPath
|
|
|
|
}
|
2020-09-22 18:18:28 +02:00
|
|
|
|
2021-02-01 18:41:56 +01:00
|
|
|
// We convert the fat jar into a deterministic one by stripping out comments with date, etc.
|
|
|
|
// jar file created from https://github.com/ManfredKarrer/tools
|
|
|
|
executeCmd("java -jar \"${project(':desktop').projectDir}/package/tools-1.0.jar\" ${fatJarFolderPath}/${mainJarName}")
|
2021-02-01 19:25:50 +01:00
|
|
|
|
2020-09-22 18:18:28 +02:00
|
|
|
// TODO For non-modular applications: use jlink to create a custom runtime containing only the modules required
|
|
|
|
|
|
|
|
// See jpackager argument documentation:
|
|
|
|
// https://docs.oracle.com/en/java/javase/15/docs/specs/man/jpackage.html
|
|
|
|
|
2020-12-03 16:23:58 +01:00
|
|
|
// Remove the -SNAPSHOT suffix from the version string (originally defined in build.gradle)
|
|
|
|
// Having it in would have resulted in an invalid version property for several platforms (mac, linux/rpm)
|
|
|
|
String appVersion = version.replaceAll("-SNAPSHOT", "")
|
2020-09-22 18:18:28 +02:00
|
|
|
println "Packaging Bisq version ${appVersion}"
|
|
|
|
|
2021-05-20 22:56:59 +02:00
|
|
|
// zip jar lib for Raspberry Pi only on macOS as it is only needed once for the release
|
2021-04-20 15:26:12 +02:00
|
|
|
if (Os.isFamily(Os.FAMILY_MAC)) {
|
|
|
|
println "Zipping jar lib for raspberry pi"
|
|
|
|
ant.zip(basedir: "${project(':desktop').buildDir}/app/lib",
|
|
|
|
destfile: "${binariesFolderPath}/jar-lib-for-raspberry-pi-${appVersion}.zip")
|
|
|
|
}
|
2021-04-10 13:34:49 +02:00
|
|
|
|
2021-01-14 10:28:06 +01:00
|
|
|
String appDescription = 'A decentralized bitcoin exchange network.'
|
2022-01-25 22:33:15 +01:00
|
|
|
String appCopyright = 'Copyright © 2013-2022 - The Bisq developers'
|
2021-01-14 10:28:06 +01:00
|
|
|
String appNameAndVendor = 'Bisq'
|
|
|
|
|
2021-04-21 09:52:54 +02:00
|
|
|
String commonOpts = new String(
|
2020-09-22 18:18:28 +02:00
|
|
|
// Generic options
|
|
|
|
" --dest \"${binariesFolderPath}\"" +
|
2021-04-21 09:52:54 +02:00
|
|
|
" --name ${appNameAndVendor}" +
|
|
|
|
" --description \"${appDescription}\"" +
|
|
|
|
" --app-version ${appVersion}" +
|
|
|
|
" --copyright \"${appCopyright}\"" +
|
|
|
|
" --vendor ${appNameAndVendor}" +
|
|
|
|
" --temp \"${jpackageTempDir}\"" +
|
|
|
|
|
|
|
|
// Options for creating the application image
|
|
|
|
" --input ${fatJarFolderPath}" +
|
|
|
|
|
|
|
|
// Options for creating the application launcher
|
|
|
|
" --main-jar ${mainJarName}" +
|
|
|
|
" --main-class bisq.desktop.app.BisqAppMain" +
|
|
|
|
" --java-options -Xss1280k" +
|
2021-07-19 20:51:13 +02:00
|
|
|
" --java-options -XX:MaxRAM=8g" +
|
2021-07-19 14:18:18 +02:00
|
|
|
" --java-options -XX:+UseG1GC" +
|
|
|
|
" --java-options -XX:MaxHeapFreeRatio=10" +
|
|
|
|
" --java-options -XX:MinHeapFreeRatio=5" +
|
|
|
|
" --java-options -XX:+UseStringDeduplication" +
|
2021-04-21 09:52:54 +02:00
|
|
|
" --java-options -Djava.net.preferIPv4Stack=true"
|
2020-10-08 13:15:08 +02:00
|
|
|
// Warning: this will cause guice reflection exceptions and lead to issues with the guice internal cache
|
|
|
|
// resulting in the UI not loading
|
|
|
|
// " --java-options -Djdk.module.illegalAccess=deny" +
|
2020-10-04 12:16:29 +02:00
|
|
|
)
|
2020-09-22 18:18:28 +02:00
|
|
|
|
|
|
|
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
2020-10-23 20:13:09 +02:00
|
|
|
// TODO Found no benefit in using --resource-dir "..package/windows", it has the same outcome as opts below
|
2021-04-21 09:52:54 +02:00
|
|
|
String windowsOpts = new String(
|
|
|
|
" --icon \"${project(':desktop').projectDir}/package/windows/Bisq.ico\"" +
|
|
|
|
" --resource-dir \"${project(':desktop').projectDir}/package/windows\"" +
|
|
|
|
" --win-dir-chooser" +
|
|
|
|
" --win-per-user-install" +
|
|
|
|
" --win-menu" +
|
|
|
|
" --win-shortcut"
|
2020-10-04 12:16:29 +02:00
|
|
|
)
|
2020-09-22 18:18:28 +02:00
|
|
|
|
|
|
|
executeCmd(jPackageFilePath + commonOpts + windowsOpts + " --type exe")
|
|
|
|
} else if (Os.isFamily(Os.FAMILY_MAC)) {
|
2020-10-04 22:14:12 +02:00
|
|
|
// See https://docs.oracle.com/en/java/javase/14/jpackage/override-jpackage-resources.html
|
|
|
|
// for details of "--resource-dir"
|
|
|
|
|
2021-04-21 09:52:54 +02:00
|
|
|
String macOpts = new String(
|
|
|
|
" --resource-dir \"${project(':desktop').projectDir}/package/macosx\""
|
2020-10-04 12:16:29 +02:00
|
|
|
)
|
2020-09-22 18:18:28 +02:00
|
|
|
|
2022-09-15 09:41:15 +02:00
|
|
|
executeCmd(jPackageFilePath + commonOpts + macOpts + " --type dmg")
|
2020-09-22 18:18:28 +02:00
|
|
|
} else {
|
2021-04-21 09:52:54 +02:00
|
|
|
String linuxOpts = new String(
|
|
|
|
" --icon ${project(':desktop').projectDir}/package/linux/icon.png" +
|
2020-12-03 16:23:58 +01:00
|
|
|
|
2021-04-21 09:52:54 +02:00
|
|
|
// This defines the first part of the resulting packages (the application name)
|
|
|
|
// deb requires lowercase letters, therefore the application name is written in lowercase
|
|
|
|
" --linux-package-name bisq" +
|
2020-12-03 16:23:58 +01:00
|
|
|
|
2021-04-21 09:52:54 +02:00
|
|
|
// This represents the linux package version (revision)
|
|
|
|
// By convention, this is part of the deb/rpm package names, in addition to the software version
|
|
|
|
" --linux-app-release 1" +
|
2020-12-03 16:23:58 +01:00
|
|
|
|
2021-04-21 09:52:54 +02:00
|
|
|
" --linux-menu-group Network" +
|
|
|
|
" --linux-shortcut"
|
2020-10-04 12:16:29 +02:00
|
|
|
)
|
2020-09-22 18:18:28 +02:00
|
|
|
|
2020-12-03 13:07:38 +01:00
|
|
|
// Package deb
|
2020-09-22 18:18:28 +02:00
|
|
|
executeCmd(jPackageFilePath + commonOpts + linuxOpts +
|
2021-04-21 09:52:54 +02:00
|
|
|
" --linux-deb-maintainer noreply@bisq.network" +
|
|
|
|
" --type deb")
|
2020-12-03 13:07:38 +01:00
|
|
|
|
|
|
|
// Clean jpackage temp folder, needs to be empty for the next packaging step (rpm)
|
2021-01-13 22:40:15 +01:00
|
|
|
jpackageTempDir.deleteDir()
|
|
|
|
jpackageTempDir.mkdirs()
|
2020-12-03 13:07:38 +01:00
|
|
|
|
|
|
|
// Package rpm
|
2020-09-22 18:18:28 +02:00
|
|
|
executeCmd(jPackageFilePath + commonOpts + linuxOpts +
|
2021-04-21 09:52:54 +02:00
|
|
|
" --linux-rpm-license-type AGPLv3" + // https://fedoraproject.org/wiki/Licensing:Main?rd=Licensing#Good_Licenses
|
|
|
|
" --type rpm")
|
2020-09-22 18:18:28 +02:00
|
|
|
}
|
|
|
|
|
2021-05-12 01:17:50 +02:00
|
|
|
// After binaries have been generated, copy the (deterministic, signed) fat jar to the binaries folder
|
|
|
|
copy {
|
|
|
|
from "${fatJarFolderPath}/${mainJarName}"
|
|
|
|
into binariesFolderPath
|
2021-05-20 20:38:52 +02:00
|
|
|
// desktop-1.6.4-SNAPSHOT-all.jar => desktop-1.6.4-SNAPSHOT-all-mac.jar (or -win.jar, or -linux.jar)
|
|
|
|
rename { String fileName -> fileName.replace('-all.jar', "-all-" + os + ".jar") }
|
2021-05-12 01:17:50 +02:00
|
|
|
}
|
|
|
|
|
2021-05-20 22:47:59 +02:00
|
|
|
// Checksum each file present in the binaries folder
|
|
|
|
ant.checksum(algorithm: 'SHA-256') {
|
|
|
|
ant.fileset(dir: "${binariesFolderPath}")
|
|
|
|
}
|
|
|
|
|
|
|
|
println "The binaries and checksums are ready:"
|
|
|
|
FileCollection collection = layout.files { binariesFolderPath.listFiles() }
|
|
|
|
collection.collect { it.path }.sort().each { println it }
|
|
|
|
|
|
|
|
// After binaries are ready, copy them to shared folder
|
2021-01-12 19:05:09 +01:00
|
|
|
// Env variable can be set by calling "export BISQ_SHARED_FOLDER='Some value'"
|
|
|
|
// This is to copy the final binary/ies to a shared folder for further processing if a VM is used.
|
|
|
|
String envVariableSharedFolder = "$System.env.BISQ_SHARED_FOLDER"
|
|
|
|
println "Environment variable BISQ_SHARED_FOLDER is: ${envVariableSharedFolder}"
|
|
|
|
ant.input(message: "Copy the created binary to a shared folder? (y=yes, n=no)",
|
|
|
|
addproperty: "copy-to-shared-folder",
|
|
|
|
validargs: "y,n")
|
|
|
|
if (ant.properties['copy-to-shared-folder'] == 'y') {
|
|
|
|
copy {
|
|
|
|
from binariesFolderPath
|
|
|
|
into envVariableSharedFolder
|
|
|
|
}
|
|
|
|
|
2021-05-20 22:47:59 +02:00
|
|
|
// Try to open a native file explorer window at the shared folder location
|
|
|
|
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
|
|
executeCmd("start '${envVariableSharedFolder}'")
|
|
|
|
} else if (Os.isFamily(Os.FAMILY_MAC)) {
|
|
|
|
executeCmd("open '${envVariableSharedFolder}'")
|
|
|
|
} else {
|
|
|
|
executeCmd("nautilus '${envVariableSharedFolder}'")
|
|
|
|
}
|
2020-09-22 18:18:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def executeCmd(String cmd) {
|
|
|
|
String shell
|
|
|
|
String shellArg
|
|
|
|
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
|
|
shell = 'cmd'
|
|
|
|
shellArg = '/c'
|
|
|
|
} else {
|
|
|
|
shell = 'bash'
|
|
|
|
shellArg = '-c'
|
|
|
|
}
|
|
|
|
|
|
|
|
println "Executing command:\n${cmd}\n"
|
|
|
|
// See "Executing External Processes" section of
|
|
|
|
// http://docs.groovy-lang.org/next/html/documentation/
|
|
|
|
def commands = [shell, shellArg, cmd]
|
|
|
|
def process = commands.execute(null, project.rootDir)
|
2020-12-23 19:52:20 +01:00
|
|
|
def result
|
2020-09-22 18:18:28 +02:00
|
|
|
if (process.waitFor() == 0) {
|
2021-01-09 21:33:59 +01:00
|
|
|
result = process.text
|
2020-12-23 19:52:20 +01:00
|
|
|
println "Command output (stdout):\n${result}"
|
2020-09-22 18:18:28 +02:00
|
|
|
} else {
|
2021-01-09 21:33:59 +01:00
|
|
|
result = process.err.text
|
2020-12-23 19:52:20 +01:00
|
|
|
println "Command output (stderr):\n${result}"
|
2020-09-22 18:18:28 +02:00
|
|
|
}
|
2021-01-09 21:33:59 +01:00
|
|
|
return result
|
2020-09-22 18:18:28 +02:00
|
|
|
}
|