build.ps1 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. # check preconditions
  15. if ((Get-Command "git" -ErrorAction SilentlyContinue) -eq $null)
  16. {
  17. Write-Host "Unable to find git.exe in your PATH (try: choco install git)"
  18. exit 1
  19. }
  20. if ((Get-Command "mvn" -ErrorAction SilentlyContinue) -eq $null)
  21. {
  22. Write-Host "Unable to find mvn.cmd in your PATH (try: choco install maven)"
  23. exit 1
  24. }
  25. $buildDir = Split-Path -Parent $PSCommandPath
  26. $version = $(mvn -f $buildDir/../../pom.xml help:evaluate -Dexpression="project.version" -q -DforceStdout)
  27. $semVerNo = $version -replace '(\d\.\d\.\d).*','$1'
  28. $revisionNo = $(git rev-list --count HEAD)
  29. Write-Output "`$version=$version"
  30. Write-Output "`$semVerNo=$semVerNo"
  31. Write-Output "`$revisionNo=$revisionNo"
  32. Write-Output "`$buildDir=$buildDir"
  33. Write-Output "`$Env:JAVA_HOME=$Env:JAVA_HOME"
  34. $copyright = "(C) $CopyrightStartYear - $((Get-Date).Year) $Vendor"
  35. # compile
  36. &mvn -B -f $buildDir/../../pom.xml clean package -DskipTests -Pwin
  37. Copy-Item "$buildDir\..\..\target\$MainJarGlob.jar" -Destination "$buildDir\..\..\target\mods"
  38. # add runtime
  39. $runtimeImagePath = '.\runtime'
  40. if ($clean -and (Test-Path -Path $runtimeImagePath)) {
  41. Remove-Item -Path $runtimeImagePath -Force -Recurse
  42. }
  43. & "$Env:JAVA_HOME\bin\jlink" `
  44. --verbose `
  45. --output runtime `
  46. --module-path "$Env:JAVA_HOME/jmods" `
  47. --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 `
  48. --strip-native-commands `
  49. --no-header-files `
  50. --no-man-pages `
  51. --strip-debug `
  52. --compress=1
  53. $appPath = ".\$AppName"
  54. if ($clean -and (Test-Path -Path $appPath)) {
  55. Remove-Item -Path $appPath -Force -Recurse
  56. }
  57. # create app dir
  58. & "$Env:JAVA_HOME\bin\jpackage" `
  59. --verbose `
  60. --type app-image `
  61. --runtime-image runtime `
  62. --input ../../target/libs `
  63. --module-path ../../target/mods `
  64. --module $ModuleAndMainClass `
  65. --dest . `
  66. --name $AppName `
  67. --vendor $Vendor `
  68. --copyright $copyright `
  69. --java-options "--enable-preview" `
  70. --java-options "--enable-native-access=org.cryptomator.jfuse.win" `
  71. --java-options "-Xss5m" `
  72. --java-options "-Xmx256m" `
  73. --java-options "-Dcryptomator.appVersion=`"$semVerNo`"" `
  74. --app-version "$semVerNo.$revisionNo" `
  75. --java-options "-Dfile.encoding=`"utf-8`"" `
  76. --java-options "-Dcryptomator.logDir=`"~/AppData/Roaming/$AppName`"" `
  77. --java-options "-Dcryptomator.pluginDir=`"~/AppData/Roaming/$AppName/Plugins`"" `
  78. --java-options "-Dcryptomator.settingsPath=`"~/AppData/Roaming/$AppName/settings.json`"" `
  79. --java-options "-Dcryptomator.ipcSocketPath=`"~/AppData/Roaming/$AppName/ipc.socket`"" `
  80. --java-options "-Dcryptomator.p12Path=`"~/AppData/Roaming/$AppName/key.p12`"" `
  81. --java-options "-Dcryptomator.mountPointsDir=`"~/$AppName`"" `
  82. --java-options "-Dcryptomator.loopbackAlias=`"$LoopbackAlias`"" `
  83. --java-options "-Dcryptomator.integrationsWin.autoStartShellLinkName=`"$AppName`"" `
  84. --java-options "-Dcryptomator.integrationsWin.keychainPaths=`"~/AppData/Roaming/$AppName/keychain.json`"" `
  85. --java-options "-Dcryptomator.showTrayIcon=true" `
  86. --java-options "-Dcryptomator.buildNumber=`"msi-$revisionNo`"" `
  87. --resource-dir resources `
  88. --icon resources/$AppName.ico
  89. #Create RTF license for msi
  90. &mvn -B -f $buildDir/../../pom.xml license:add-third-party `
  91. "-Dlicense.thirdPartyFilename=license.rtf" `
  92. "-Dlicense.fileTemplate=$buildDir\resources\licenseTemplate.ftl" `
  93. "-Dlicense.outputDirectory=$buildDir\resources\" `
  94. "-Dlicense.includedScopes=compile" `
  95. "-Dlicense.excludedGroups=^org\.cryptomator" `
  96. "-Dlicense.failOnMissing=true" `
  97. "-Dlicense.licenseMergesUrl=file:///$buildDir/../../license/merges"
  98. # patch app dir
  99. Copy-Item "contrib\*" -Destination "$AppName"
  100. attrib -r "$AppName\$AppName.exe"
  101. # patch batch script to set hostfile
  102. $webDAVPatcher = "$AppName\patchWebDAV.bat"
  103. try {
  104. (Get-Content $webDAVPatcher ) -replace '::REPLACE ME', "SET LOOPBACK_ALIAS=`"$LoopbackAlias`"" | Set-Content $webDAVPatcher
  105. } catch {
  106. Write-Host "Failed to set LOOPBACK_ALIAS for patchWebDAV.bat"
  107. exit 1
  108. }
  109. # create .msi
  110. $Env:JP_WIXWIZARD_RESOURCES = "$buildDir\resources"
  111. & "$Env:JAVA_HOME\bin\jpackage" `
  112. --verbose `
  113. --type msi `
  114. --win-upgrade-uuid $UpgradeUUID `
  115. --app-image $AppName `
  116. --dest installer `
  117. --name $AppName `
  118. --vendor $Vendor `
  119. --copyright $copyright `
  120. --app-version "$semVerNo.$revisionNo" `
  121. --win-menu `
  122. --win-dir-chooser `
  123. --win-shortcut-prompt `
  124. --win-menu-group $AppName `
  125. --resource-dir resources `
  126. --license-file resources/license.rtf `
  127. --win-update-url $UpdateUrl `
  128. --about-url $AboutUrl `
  129. --file-associations resources/FAvaultFile.properties
  130. #Create RTF license for bundle
  131. &mvn -B -f $buildDir/../../pom.xml license:add-third-party `
  132. "-Dlicense.thirdPartyFilename=license.rtf" `
  133. "-Dlicense.fileTemplate=$buildDir\bundle\resources\licenseTemplate.ftl" `
  134. "-Dlicense.outputDirectory=$buildDir\bundle\resources\" `
  135. "-Dlicense.includedScopes=compile" `
  136. "-Dlicense.excludedGroups=^org\.cryptomator" `
  137. "-Dlicense.failOnMissing=true" `
  138. "-Dlicense.licenseMergesUrl=file:///$buildDir/../../license/merges"
  139. # download Winfsp
  140. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  141. $ProgressPreference = 'SilentlyContinue' # disables Invoke-WebRequest's progress bar, which slows down downloads to a few bytes/s
  142. $winfspMsiUrl= (Select-String -Path ".\bundle\resources\winFspMetaData.wxi" -Pattern '<\?define BundledWinFspDownloadLink="(.+)".*?>').Matches.Groups[1].Value
  143. Write-Output "Downloading ${winfspMsiUrl}..."
  144. Invoke-WebRequest $winfspMsiUrl -OutFile ".\bundle\resources\winfsp.msi" # redirects are followed by default
  145. # copy MSI to bundle resources
  146. Copy-Item ".\installer\$AppName-*.msi" -Destination ".\bundle\resources\$AppName.msi"
  147. # create bundle including winfsp
  148. & "$env:WIX\bin\candle.exe" .\bundle\bundleWithWinfsp.wxs -ext WixBalExtension -ext WixUtilextension -out bundle\ `
  149. -dBundleVersion="$semVerNo.$revisionNo" `
  150. -dBundleVendor="$Vendor" `
  151. -dBundleCopyright="$copyright" `
  152. -dAboutUrl="$AboutUrl" `
  153. -dHelpUrl="$HelpUrl" `
  154. -dUpdateUrl="$UpdateUrl"
  155. & "$env:WIX\bin\light.exe" -b . .\bundle\BundlewithWinfsp.wixobj -ext WixBalExtension -ext WixUtilextension -out installer\$AppName-Installer.exe