build.ps1 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. Param(
  2. [Parameter(Mandatory, HelpMessage="Please provide a name for the app")][string] $AppName,
  3. [Parameter(Mandatory, HelpMessage="Please provide the glob pattern to identify the main jar")][string] $MainJarGlob,
  4. [Parameter(Mandatory, HelpMessage="Please provide the module- and main class path to start the app")][string] $ModuleAndMainClass,
  5. [Parameter(Mandatory, HelpMessage="Please provide the windows upgrade uuid for the installer")][string] $UpgradeUUID,
  6. [Parameter(Mandatory, HelpMessage="Please provide the name of the vendor")][string] $Vendor,
  7. [Parameter(Mandatory, HelpMessage="Please provide the starting year for the copyright notice")][int] $CopyrightStartYear,
  8. [Parameter(Mandatory, HelpMessage="Please provide a help url")][string] $HelpUrl,
  9. [Parameter(Mandatory, HelpMessage="Please provide an update url")][string] $UpdateUrl,
  10. [Parameter(Mandatory, HelpMessage="Please provide an about url")][string] $AboutUrl,
  11. [Parameter(Mandatory, HelpMessage="Please provide an alias for localhost")][string] $LoopbackAlias,
  12. [bool] $clean
  13. )
  14. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  15. $ProgressPreference = 'SilentlyContinue' # disables Invoke-WebRequest's progress bar, which slows down downloads to a few bytes/s
  16. # check preconditions
  17. if ((Get-Command "git" -ErrorAction SilentlyContinue) -eq $null)
  18. {
  19. Write-Host "Unable to find git.exe in your PATH (try: choco install git)"
  20. exit 1
  21. }
  22. if ((Get-Command "mvn" -ErrorAction SilentlyContinue) -eq $null)
  23. {
  24. Write-Host "Unable to find mvn.cmd in your PATH (try: choco install maven)"
  25. exit 1
  26. }
  27. if ((Get-Command 'wix' -ErrorAction SilentlyContinue) -eq $null)
  28. {
  29. Write-Error 'Unable to find wix in your PATH (try: dotnet tool install --global wix --version 6.0.0)'
  30. exit 1
  31. }
  32. $wixExtensions = & wix.exe extension list --global | Out-String
  33. if ($wixExtensions -notmatch 'WixToolset.UI.wixext') {
  34. Write-Error 'UI wix extension missing. Please install it with: wix.exe extension add WixToolset.UI.wixext/6.0.0 --global)'
  35. exit 1
  36. }
  37. if ($wixExtensions -notmatch 'WixToolset.Util.wixext') {
  38. Write-Error 'Util wix extension missing. Please install it with: wix.exe extension add WixToolset.Util.wixext/6.0.0 --global)'
  39. exit 1
  40. }
  41. if ($wixExtensions -notmatch 'WixToolset.BootstrapperApplications.wixext') {
  42. Write-Error 'Util wix extension missing. Please install it with: wix.exe extension add WixToolset.BootstrapperApplications.wixext/6.0.0 --global)'
  43. exit 1
  44. }
  45. $buildDir = Split-Path -Parent $PSCommandPath
  46. $version = $(mvn -f $buildDir/../../pom.xml help:evaluate -Dexpression="project.version" -q -DforceStdout)
  47. $semVerNo = $version -replace '(\d+\.\d+\.\d+).*','$1'
  48. $revisionNo = $(git rev-list --count HEAD)
  49. Write-Output "`$version=$version"
  50. Write-Output "`$semVerNo=$semVerNo"
  51. Write-Output "`$revisionNo=$revisionNo"
  52. Write-Output "`$buildDir=$buildDir"
  53. Write-Output "`$Env:JAVA_HOME=$Env:JAVA_HOME"
  54. $copyright = "(C) $CopyrightStartYear - $((Get-Date).Year) $Vendor"
  55. # compile
  56. &mvn -B -f $buildDir/../../pom.xml clean package -DskipTests -Pwin "-Djavafx.platform=win"
  57. Copy-Item "$buildDir\..\..\target\$MainJarGlob.jar" -Destination "$buildDir\..\..\target\mods"
  58. # add runtime
  59. $runtimeImagePath = '.\runtime'
  60. if ($clean -and (Test-Path -Path $runtimeImagePath)) {
  61. Remove-Item -Path $runtimeImagePath -Force -Recurse
  62. }
  63. ## download jfx jmods
  64. $javaFxVersion='23.0.2'
  65. $javaFxJmodsUrl = "https://download2.gluonhq.com/openjfx/${javaFxVersion}/openjfx-${javaFxVersion}_windows-x64_bin-jmods.zip"
  66. $javaFxJmodsSHA256 = 'ee176dcee3bd78bde7910735bd67f67c792882f5b89626796ae06f7a1c0119d3'
  67. $javaFxJmods = '.\resources\jfxJmods.zip'
  68. if( !(Test-Path -Path $javaFxJmods) ) {
  69. Write-Output "Downloading ${javaFxJmodsUrl}..."
  70. Invoke-WebRequest $javaFxJmodsUrl -OutFile $javaFxJmods # redirects are followed by default
  71. }
  72. $jmodsChecksumActual = $(Get-FileHash -Path $javaFxJmods -Algorithm SHA256).Hash.ToLower()
  73. if( $jmodsChecksumActual -ne $javaFxJmodsSHA256 ) {
  74. Write-Error "Checksum mismatch for jfxJmods.zip. Expected: $javaFxJmodsSHA256
  75. , actual: $jmodsChecksumActual"
  76. exit 1;
  77. }
  78. Expand-Archive -Path $javaFxJmods -Force -DestinationPath ".\resources\"
  79. Remove-Item -Recurse -Force -Path ".\resources\javafx-jmods" -ErrorAction Ignore
  80. Move-Item -Force -Path ".\resources\javafx-jmods-*" -Destination ".\resources\javafx-jmods" -ErrorAction Stop
  81. ## create custom runtime
  82. & "$Env:JAVA_HOME\bin\jlink" `
  83. --verbose `
  84. --output runtime `
  85. --module-path "$Env:JAVA_HOME/jmods;$buildDir/resources/javafx-jmods" `
  86. --add-modules java.base,java.desktop,java.instrument,java.logging,java.naming,java.net.http,java.scripting,java.sql,java.xml,jdk.unsupported,jdk.accessibility,jdk.management.jfr,jdk.crypto.mscapi,java.compiler,javafx.base,javafx.graphics,javafx.controls,javafx.fxml `
  87. --strip-native-commands `
  88. --no-header-files `
  89. --no-man-pages `
  90. --strip-debug `
  91. --compress "zip-0" #do not compress to have improved msi compression
  92. $appPath = ".\$AppName"
  93. if ($clean -and (Test-Path -Path $appPath)) {
  94. Remove-Item -Path $appPath -Force -Recurse
  95. }
  96. # create app dir
  97. & "$Env:JAVA_HOME\bin\jpackage" `
  98. --verbose `
  99. --type app-image `
  100. --runtime-image runtime `
  101. --input ../../target/libs `
  102. --module-path ../../target/mods `
  103. --module $ModuleAndMainClass `
  104. --dest . `
  105. --name $AppName `
  106. --vendor $Vendor `
  107. --copyright $copyright `
  108. --java-options "--enable-preview" `
  109. --java-options "--enable-native-access=org.cryptomator.jfuse.win,org.cryptomator.integrations.win" `
  110. --java-options "-Xss5m" `
  111. --java-options "-Xmx256m" `
  112. --java-options "-Dcryptomator.appVersion=`"$semVerNo`"" `
  113. --app-version "$semVerNo.$revisionNo" `
  114. --java-options "-Dfile.encoding=`"utf-8`"" `
  115. --java-options "-Djava.net.useSystemProxies=true" `
  116. --java-options "-Dcryptomator.logDir=`"@{localappdata}/$AppName`"" `
  117. --java-options "-Dcryptomator.pluginDir=`"@{appdata}/$AppName/Plugins`"" `
  118. --java-options "-Dcryptomator.settingsPath=`"@{appdata}/$AppName/settings.json;@{userhome}/AppData/Roaming/$AppName/settings.json`"" `
  119. --java-options "-Dcryptomator.ipcSocketPath=`"@{localappdata}/$AppName/ipc.socket`"" `
  120. --java-options "-Dcryptomator.p12Path=`"@{appdata}/$AppName/key.p12;@{userhome}/AppData/Roaming/$AppName/key.p12`"" `
  121. --java-options "-Dcryptomator.mountPointsDir=`"@{userhome}/$AppName`"" `
  122. --java-options "-Dcryptomator.loopbackAlias=`"$LoopbackAlias`"" `
  123. --java-options "-Dcryptomator.integrationsWin.autoStartShellLinkName=`"$AppName`"" `
  124. --java-options "-Dcryptomator.integrationsWin.keychainPaths=`"@{appdata}/$AppName/keychain.json;@{userhome}/AppData/Roaming/$AppName/keychain.json`"" `
  125. --java-options "-Dcryptomator.showTrayIcon=true" `
  126. --java-options "-Dcryptomator.buildNumber=`"msi-$revisionNo`"" `
  127. --resource-dir resources `
  128. --icon resources/$AppName.ico
  129. #Create RTF license for msi
  130. &mvn -B -f $buildDir/../../pom.xml license:add-third-party "-Djavafx.platform=win" `
  131. "-Dlicense.thirdPartyFilename=license.rtf" `
  132. "-Dlicense.fileTemplate=$buildDir\resources\licenseTemplate.ftl" `
  133. "-Dlicense.outputDirectory=$buildDir\resources\" `
  134. "-Dlicense.includedScopes=compile" `
  135. "-Dlicense.excludedGroups=^org\.cryptomator" `
  136. "-Dlicense.failOnMissing=true" `
  137. "-Dlicense.licenseMergesUrl=file:///$buildDir/../../license/merges"
  138. # patch app dir
  139. Copy-Item "contrib\*" -Destination "$AppName"
  140. attrib -r "$AppName\$AppName.exe"
  141. # patch batch script to set hostfile
  142. $webDAVPatcher = "$AppName\patchWebDAV.bat"
  143. try {
  144. (Get-Content $webDAVPatcher ) -replace '::REPLACE ME', "SET LOOPBACK_ALIAS=`"$LoopbackAlias`"" | Set-Content $webDAVPatcher
  145. } catch {
  146. Write-Host "Failed to set LOOPBACK_ALIAS for patchWebDAV.bat"
  147. exit 1
  148. }
  149. # create .msi
  150. $Env:JP_WIXWIZARD_RESOURCES = "$buildDir\resources"
  151. $Env:JP_WIXHELPER_DIR = "."
  152. & "$Env:JAVA_HOME\bin\jpackage" `
  153. --verbose `
  154. --type msi `
  155. --win-upgrade-uuid $UpgradeUUID `
  156. --app-image $AppName `
  157. --dest installer `
  158. --name $AppName `
  159. --vendor $Vendor `
  160. --copyright $copyright `
  161. --app-version "$semVerNo.$revisionNo" `
  162. --win-menu `
  163. --win-dir-chooser `
  164. --win-shortcut-prompt `
  165. --win-menu-group $AppName `
  166. --resource-dir resources `
  167. --license-file resources/license.rtf `
  168. --win-update-url $UpdateUrl `
  169. --about-url $AboutUrl `
  170. --file-associations resources/FAvaultFile.properties
  171. #Create RTF license for bundle
  172. &mvn -B -f $buildDir/../../pom.xml license:add-third-party "-Djavafx.platform=win" `
  173. "-Dlicense.thirdPartyFilename=license.rtf" `
  174. "-Dlicense.fileTemplate=$buildDir\bundle\resources\licenseTemplate.ftl" `
  175. "-Dlicense.outputDirectory=$buildDir\bundle\resources\" `
  176. "-Dlicense.includedScopes=compile" `
  177. "-Dlicense.excludedGroups=^org\.cryptomator" `
  178. "-Dlicense.failOnMissing=true" `
  179. "-Dlicense.licenseMergesUrl=file:///$buildDir/../../license/merges"
  180. # download Winfsp
  181. $winfspMsiUrl= 'https://github.com/winfsp/winfsp/releases/download/v2.0/winfsp-2.0.23075.msi'
  182. Write-Output "Downloading ${winfspMsiUrl}..."
  183. Invoke-WebRequest $winfspMsiUrl -OutFile ".\bundle\resources\winfsp.msi" # redirects are followed by default
  184. # download legacy-winfsp uninstaller
  185. $winfspUninstaller= 'https://github.com/cryptomator/winfsp-uninstaller/releases/latest/download/winfsp-uninstaller.exe'
  186. Write-Output "Downloading ${winfspUninstaller}..."
  187. Invoke-WebRequest $winfspUninstaller -OutFile ".\bundle\resources\winfsp-uninstaller.exe" # redirects are followed by default
  188. # copy MSI to bundle resources
  189. Copy-Item ".\installer\$AppName-*.msi" -Destination ".\bundle\resources\$AppName.msi"
  190. # create bundle including winfsp
  191. & wix build `
  192. -define BundleVersion="$semVerNo.$revisionNo" `
  193. -define BundleVendor="$Vendor" `
  194. -define BundleCopyright="$copyright" `
  195. -define AboutUrl="$AboutUrl" `
  196. -define HelpUrl="$HelpUrl" `
  197. -define UpdateUrl="$UpdateUrl" `
  198. -ext "WixToolset.Util.wixext" `
  199. -ext "WixToolset.BootstrapperApplications.wixext" `
  200. .\bundle\bundleWithWinfsp.wxs `
  201. -out "installer\$AppName-Installer.exe"