build.ps1 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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
  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. $jfxJmodsChecksum = 'd00767334c43b8832b5cf10267d34ca8f563d187c4655b73eb6020dd79c054b5'
  47. $jfxJmodsZip = '.\resources\jfxJmods.zip'
  48. if( !(Test-Path -Path $jfxJmodsZip) ) {
  49. $jmodsUrl = "https://download2.gluonhq.com/openjfx/20.0.1/openjfx-20.0.1_windows-x64_bin-jmods.zip"
  50. Write-Output "Downloading ${jmodsUrl}..."
  51. Invoke-WebRequest $jmodsUrl -OutFile $jfxJmodsZip # redirects are followed by default
  52. }
  53. $jmodsChecksumActual = $(Get-FileHash -Path $jfxJmodsZip -Algorithm SHA256).Hash
  54. if( $jmodsChecksumActual -ne $jfxJmodsChecksum ) {
  55. Write-Error "Checksum mismatch for jfxJmods.zip. Expected: $jfxJmodsChecksum, actual: $jmodsChecksumActual"
  56. exit 1;
  57. }
  58. Expand-Archive -Force -Path $jfxJmodsZip -DestinationPath ".\resources\"
  59. & "$Env:JAVA_HOME\bin\jlink" `
  60. --verbose `
  61. --output runtime `
  62. --module-path "$Env:JAVA_HOME/jmods;$buildDir/resources/javafx-jmods-20.0.1" `
  63. --add-modules java.base,java.desktop,java.instrument,java.logging,java.naming,java.net.http,java.scripting,java.sql,java.xml,jdk.unsupported,jdk.crypto.ec,jdk.accessibility,jdk.management.jfr,javafx.base,javafx.graphics,javafx.controls,javafx.fxml `
  64. --strip-native-commands `
  65. --no-header-files `
  66. --no-man-pages `
  67. --strip-debug `
  68. --compress=1
  69. $appPath = ".\$AppName"
  70. if ($clean -and (Test-Path -Path $appPath)) {
  71. Remove-Item -Path $appPath -Force -Recurse
  72. }
  73. # create app dir
  74. & "$Env:JAVA_HOME\bin\jpackage" `
  75. --verbose `
  76. --type app-image `
  77. --runtime-image runtime `
  78. --input ../../target/libs `
  79. --module-path ../../target/mods `
  80. --module $ModuleAndMainClass `
  81. --dest . `
  82. --name $AppName `
  83. --vendor $Vendor `
  84. --copyright $copyright `
  85. --java-options "--enable-preview" `
  86. --java-options "--enable-native-access=org.cryptomator.jfuse.win" `
  87. --java-options "-Xss5m" `
  88. --java-options "-Xmx256m" `
  89. --java-options "-Dcryptomator.appVersion=`"$semVerNo`"" `
  90. --app-version "$semVerNo.$revisionNo" `
  91. --java-options "-Dfile.encoding=`"utf-8`"" `
  92. --java-options "-Djava.net.useSystemProxies=true" `
  93. --java-options "-Dcryptomator.logDir=`"@{localappdata}/$AppName`"" `
  94. --java-options "-Dcryptomator.pluginDir=`"@{appdata}/$AppName/Plugins`"" `
  95. --java-options "-Dcryptomator.settingsPath=`"@{appdata}/$AppName/settings.json;@{userhome}/AppData/Roaming/$AppName/settings.json`"" `
  96. --java-options "-Dcryptomator.ipcSocketPath=`"@{localappdata}/$AppName/ipc.socket`"" `
  97. --java-options "-Dcryptomator.p12Path=`"@{appdata}/$AppName/key.p12;@{userhome}/AppData/Roaming/$AppName/key.p12`"" `
  98. --java-options "-Dcryptomator.mountPointsDir=`"@{userhome}/$AppName`"" `
  99. --java-options "-Dcryptomator.loopbackAlias=`"$LoopbackAlias`"" `
  100. --java-options "-Dcryptomator.integrationsWin.autoStartShellLinkName=`"$AppName`"" `
  101. --java-options "-Dcryptomator.integrationsWin.keychainPaths=`"@{appdata}/$AppName/keychain.json;@{userhome}/AppData/Roaming/$AppName/keychain.json`"" `
  102. --java-options "-Dcryptomator.showTrayIcon=true" `
  103. --java-options "-Dcryptomator.buildNumber=`"msi-$revisionNo`"" `
  104. --resource-dir resources `
  105. --icon resources/$AppName.ico
  106. #Create RTF license for msi
  107. &mvn -B -f $buildDir/../../pom.xml license:add-third-party `
  108. "-Dlicense.thirdPartyFilename=license.rtf" `
  109. "-Dlicense.fileTemplate=$buildDir\resources\licenseTemplate.ftl" `
  110. "-Dlicense.outputDirectory=$buildDir\resources\" `
  111. "-Dlicense.includedScopes=compile" `
  112. "-Dlicense.excludedGroups=^org\.cryptomator" `
  113. "-Dlicense.failOnMissing=true" `
  114. "-Dlicense.licenseMergesUrl=file:///$buildDir/../../license/merges"
  115. # patch app dir
  116. Copy-Item "contrib\*" -Destination "$AppName"
  117. attrib -r "$AppName\$AppName.exe"
  118. # patch batch script to set hostfile
  119. $webDAVPatcher = "$AppName\patchWebDAV.bat"
  120. try {
  121. (Get-Content $webDAVPatcher ) -replace '::REPLACE ME', "SET LOOPBACK_ALIAS=`"$LoopbackAlias`"" | Set-Content $webDAVPatcher
  122. } catch {
  123. Write-Host "Failed to set LOOPBACK_ALIAS for patchWebDAV.bat"
  124. exit 1
  125. }
  126. # create .msi
  127. $Env:JP_WIXWIZARD_RESOURCES = "$buildDir\resources"
  128. & "$Env:JAVA_HOME\bin\jpackage" `
  129. --verbose `
  130. --type msi `
  131. --win-upgrade-uuid $UpgradeUUID `
  132. --app-image $AppName `
  133. --dest installer `
  134. --name $AppName `
  135. --vendor $Vendor `
  136. --copyright $copyright `
  137. --app-version "$semVerNo.$revisionNo" `
  138. --win-menu `
  139. --win-dir-chooser `
  140. --win-shortcut-prompt `
  141. --win-menu-group $AppName `
  142. --resource-dir resources `
  143. --license-file resources/license.rtf `
  144. --win-update-url $UpdateUrl `
  145. --about-url $AboutUrl `
  146. --file-associations resources/FAvaultFile.properties
  147. #Create RTF license for bundle
  148. &mvn -B -f $buildDir/../../pom.xml license:add-third-party `
  149. "-Dlicense.thirdPartyFilename=license.rtf" `
  150. "-Dlicense.fileTemplate=$buildDir\bundle\resources\licenseTemplate.ftl" `
  151. "-Dlicense.outputDirectory=$buildDir\bundle\resources\" `
  152. "-Dlicense.includedScopes=compile" `
  153. "-Dlicense.excludedGroups=^org\.cryptomator" `
  154. "-Dlicense.failOnMissing=true" `
  155. "-Dlicense.licenseMergesUrl=file:///$buildDir/../../license/merges"
  156. # download Winfsp
  157. $winfspMsiUrl= (Select-String -Path ".\bundle\resources\winFspMetaData.wxi" -Pattern '<\?define BundledWinFspDownloadLink="(.+)".*?>').Matches.Groups[1].Value
  158. Write-Output "Downloading ${winfspMsiUrl}..."
  159. Invoke-WebRequest $winfspMsiUrl -OutFile ".\bundle\resources\winfsp.msi" # redirects are followed by default
  160. # copy MSI to bundle resources
  161. Copy-Item ".\installer\$AppName-*.msi" -Destination ".\bundle\resources\$AppName.msi"
  162. # create bundle including winfsp
  163. & "$env:WIX\bin\candle.exe" .\bundle\bundleWithWinfsp.wxs -ext WixBalExtension -ext WixUtilextension -out bundle\ `
  164. -dBundleVersion="$semVerNo.$revisionNo" `
  165. -dBundleVendor="$Vendor" `
  166. -dBundleCopyright="$copyright" `
  167. -dAboutUrl="$AboutUrl" `
  168. -dHelpUrl="$HelpUrl" `
  169. -dUpdateUrl="$UpdateUrl"
  170. & "$env:WIX\bin\light.exe" -b . .\bundle\BundlewithWinfsp.wixobj -ext WixBalExtension -ext WixUtilextension -out installer\$AppName-Installer.exe