build.ps1 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. $buildDir = Split-Path -Parent $PSCommandPath
  28. $version = $(mvn -f $buildDir/../../pom.xml help:evaluate -Dexpression="project.version" -q -DforceStdout)
  29. $semVerNo = $version -replace '(\d+\.\d+\.\d+).*','$1'
  30. $revisionNo = $(git rev-list --count HEAD)
  31. Write-Output "`$version=$version"
  32. Write-Output "`$semVerNo=$semVerNo"
  33. Write-Output "`$revisionNo=$revisionNo"
  34. Write-Output "`$buildDir=$buildDir"
  35. Write-Output "`$Env:JAVA_HOME=$Env:JAVA_HOME"
  36. $copyright = "(C) $CopyrightStartYear - $((Get-Date).Year) $Vendor"
  37. # compile
  38. &mvn -B -f $buildDir/../../pom.xml clean package -DskipTests -Pwin "-Djavafx.platform=win"
  39. Copy-Item "$buildDir\..\..\target\$MainJarGlob.jar" -Destination "$buildDir\..\..\target\mods"
  40. # add runtime
  41. $runtimeImagePath = '.\runtime'
  42. if ($clean -and (Test-Path -Path $runtimeImagePath)) {
  43. Remove-Item -Path $runtimeImagePath -Force -Recurse
  44. }
  45. ## download jfx jmods
  46. $javaFxVersion='22.0.2'
  47. $javaFxJmodsUrl = "https://download2.gluonhq.com/openjfx/${javaFxVersion}/openjfx-${javaFxVersion}_windows-x64_bin-jmods.zip"
  48. $javaFxJmodsSHA256 = 'f9376d200f5c5b85327d575c1ec1482e6455f19916577f7e2fc9be2f48bb29b6'
  49. $javaFxJmods = '.\resources\jfxJmods.zip'
  50. if( !(Test-Path -Path $javaFxJmods) ) {
  51. Write-Output "Downloading ${javaFxJmodsUrl}..."
  52. Invoke-WebRequest $javaFxJmodsUrl -OutFile $javaFxJmods # redirects are followed by default
  53. }
  54. $jmodsChecksumActual = $(Get-FileHash -Path $javaFxJmods -Algorithm SHA256).Hash
  55. if( $jmodsChecksumActual -ne $javaFxJmodsSHA256 ) {
  56. Write-Error "Checksum mismatch for jfxJmods.zip. Expected: $javaFxJmodsSHA256
  57. , actual: $jmodsChecksumActual"
  58. exit 1;
  59. }
  60. Expand-Archive -Path $javaFxJmods -Force -DestinationPath ".\resources\"
  61. Remove-Item -Recurse -Force -Path ".\resources\javafx-jmods"
  62. Move-Item -Force -Path ".\resources\javafx-jmods-*" -Destination ".\resources\javafx-jmods" -ErrorAction Stop
  63. ## create custom runtime
  64. & "$Env:JAVA_HOME\bin\jlink" `
  65. --verbose `
  66. --output runtime `
  67. --module-path "$Env:JAVA_HOME/jmods;$buildDir/resources/javafx-jmods" `
  68. --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,java.compiler,javafx.base,javafx.graphics,javafx.controls,javafx.fxml `
  69. --strip-native-commands `
  70. --no-header-files `
  71. --no-man-pages `
  72. --strip-debug `
  73. --compress "zip-0" #do not compress to have improved msi compression
  74. $appPath = ".\$AppName"
  75. if ($clean -and (Test-Path -Path $appPath)) {
  76. Remove-Item -Path $appPath -Force -Recurse
  77. }
  78. # create app dir
  79. & "$Env:JAVA_HOME\bin\jpackage" `
  80. --verbose `
  81. --type app-image `
  82. --runtime-image runtime `
  83. --input ../../target/libs `
  84. --module-path ../../target/mods `
  85. --module $ModuleAndMainClass `
  86. --dest . `
  87. --name $AppName `
  88. --vendor $Vendor `
  89. --copyright $copyright `
  90. --java-options "--enable-preview" `
  91. --java-options "--enable-native-access=org.cryptomator.jfuse.win,org.cryptomator.integrations.win" `
  92. --java-options "-Xss5m" `
  93. --java-options "-Xmx256m" `
  94. --java-options "-Dcryptomator.appVersion=`"$semVerNo`"" `
  95. --app-version "$semVerNo.$revisionNo" `
  96. --java-options "-Dfile.encoding=`"utf-8`"" `
  97. --java-options "-Djava.net.useSystemProxies=true" `
  98. --java-options "-Dcryptomator.logDir=`"@{localappdata}/$AppName`"" `
  99. --java-options "-Dcryptomator.pluginDir=`"@{appdata}/$AppName/Plugins`"" `
  100. --java-options "-Dcryptomator.settingsPath=`"@{appdata}/$AppName/settings.json;@{userhome}/AppData/Roaming/$AppName/settings.json`"" `
  101. --java-options "-Dcryptomator.ipcSocketPath=`"@{localappdata}/$AppName/ipc.socket`"" `
  102. --java-options "-Dcryptomator.p12Path=`"@{appdata}/$AppName/key.p12;@{userhome}/AppData/Roaming/$AppName/key.p12`"" `
  103. --java-options "-Dcryptomator.mountPointsDir=`"@{userhome}/$AppName`"" `
  104. --java-options "-Dcryptomator.loopbackAlias=`"$LoopbackAlias`"" `
  105. --java-options "-Dcryptomator.integrationsWin.autoStartShellLinkName=`"$AppName`"" `
  106. --java-options "-Dcryptomator.integrationsWin.keychainPaths=`"@{appdata}/$AppName/keychain.json;@{userhome}/AppData/Roaming/$AppName/keychain.json`"" `
  107. --java-options "-Dcryptomator.showTrayIcon=true" `
  108. --java-options "-Dcryptomator.buildNumber=`"msi-$revisionNo`"" `
  109. --resource-dir resources `
  110. --icon resources/$AppName.ico
  111. #Create RTF license for msi
  112. &mvn -B -f $buildDir/../../pom.xml license:add-third-party "-Djavafx.platform=win" `
  113. "-Dlicense.thirdPartyFilename=license.rtf" `
  114. "-Dlicense.fileTemplate=$buildDir\resources\licenseTemplate.ftl" `
  115. "-Dlicense.outputDirectory=$buildDir\resources\" `
  116. "-Dlicense.includedScopes=compile" `
  117. "-Dlicense.excludedGroups=^org\.cryptomator" `
  118. "-Dlicense.failOnMissing=true" `
  119. "-Dlicense.licenseMergesUrl=file:///$buildDir/../../license/merges"
  120. # patch app dir
  121. Copy-Item "contrib\*" -Destination "$AppName"
  122. attrib -r "$AppName\$AppName.exe"
  123. # patch batch script to set hostfile
  124. $webDAVPatcher = "$AppName\patchWebDAV.bat"
  125. try {
  126. (Get-Content $webDAVPatcher ) -replace '::REPLACE ME', "SET LOOPBACK_ALIAS=`"$LoopbackAlias`"" | Set-Content $webDAVPatcher
  127. } catch {
  128. Write-Host "Failed to set LOOPBACK_ALIAS for patchWebDAV.bat"
  129. exit 1
  130. }
  131. # create .msi
  132. $Env:JP_WIXWIZARD_RESOURCES = "$buildDir\resources"
  133. $Env:JP_WIXHELPER_DIR = "."
  134. & "$Env:JAVA_HOME\bin\jpackage" `
  135. --verbose `
  136. --type msi `
  137. --win-upgrade-uuid $UpgradeUUID `
  138. --app-image $AppName `
  139. --dest installer `
  140. --name $AppName `
  141. --vendor $Vendor `
  142. --copyright $copyright `
  143. --app-version "$semVerNo.$revisionNo" `
  144. --win-menu `
  145. --win-dir-chooser `
  146. --win-shortcut-prompt `
  147. --win-menu-group $AppName `
  148. --resource-dir resources `
  149. --license-file resources/license.rtf `
  150. --win-update-url $UpdateUrl `
  151. --about-url $AboutUrl `
  152. --file-associations resources/FAvaultFile.properties
  153. #Create RTF license for bundle
  154. &mvn -B -f $buildDir/../../pom.xml license:add-third-party "-Djavafx.platform=win" `
  155. "-Dlicense.thirdPartyFilename=license.rtf" `
  156. "-Dlicense.fileTemplate=$buildDir\bundle\resources\licenseTemplate.ftl" `
  157. "-Dlicense.outputDirectory=$buildDir\bundle\resources\" `
  158. "-Dlicense.includedScopes=compile" `
  159. "-Dlicense.excludedGroups=^org\.cryptomator" `
  160. "-Dlicense.failOnMissing=true" `
  161. "-Dlicense.licenseMergesUrl=file:///$buildDir/../../license/merges"
  162. # download Winfsp
  163. $winfspMsiUrl= 'https://github.com/winfsp/winfsp/releases/download/v2.0/winfsp-2.0.23075.msi'
  164. Write-Output "Downloading ${winfspMsiUrl}..."
  165. Invoke-WebRequest $winfspMsiUrl -OutFile ".\bundle\resources\winfsp.msi" # redirects are followed by default
  166. # download legacy-winfsp uninstaller
  167. $winfspUninstaller= 'https://github.com/cryptomator/winfsp-uninstaller/releases/latest/download/winfsp-uninstaller.exe'
  168. Write-Output "Downloading ${winfspUninstaller}..."
  169. Invoke-WebRequest $winfspUninstaller -OutFile ".\bundle\resources\winfsp-uninstaller.exe" # redirects are followed by default
  170. # copy MSI to bundle resources
  171. Copy-Item ".\installer\$AppName-*.msi" -Destination ".\bundle\resources\$AppName.msi"
  172. # create bundle including winfsp
  173. & "$env:WIX\bin\candle.exe" .\bundle\bundleWithWinfsp.wxs -ext WixBalExtension -ext WixUtilextension -out bundle\ `
  174. -dBundleVersion="$semVerNo.$revisionNo" `
  175. -dBundleVendor="$Vendor" `
  176. -dBundleCopyright="$copyright" `
  177. -dAboutUrl="$AboutUrl" `
  178. -dHelpUrl="$HelpUrl" `
  179. -dUpdateUrl="$UpdateUrl"
  180. & "$env:WIX\bin\light.exe" -b . .\bundle\BundlewithWinfsp.wixobj -ext WixBalExtension -ext WixUtilextension -out installer\$AppName-Installer.exe