build.ps1 6.3 KB

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