diff --git a/dist/win/build.ps1 b/dist/win/build.ps1 index cd5fa805d..d9656d1f5 100644 --- a/dist/win/build.ps1 +++ b/dist/win/build.ps1 @@ -16,6 +16,19 @@ Param( # Function Definitions Section # ============================ +function Invoke-CommandWithExitCheck { + param ( + [string]$Command, + [string[]]$Arguments + ) + + & $Command @Arguments + if ($LASTEXITCODE -ne 0) { + Write-Error "Command '$Command' failed with exit code $LASTEXITCODE" + exit $LASTEXITCODE + } +} + function Main { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 @@ -65,7 +78,8 @@ Write-Host "`$Env:JAVA_HOME=$Env:JAVA_HOME" $copyright = "(C) $CopyrightStartYear - $((Get-Date).Year) $Vendor" # compile -&mvn -B -f $buildDir/../../pom.xml clean package -DskipTests -Pwin +Invoke-CommandWithExitCheck -Command ` + "mvn" -Arguments @("-B", "-f", "$buildDir/../../pom.xml", "clean", "package", "-DskipTests", "-Pwin") Copy-Item "$buildDir\..\..\target\$MainJarGlob.jar" -Destination "$buildDir\..\..\target\mods" # add runtime @@ -129,16 +143,18 @@ if ((& "$Env:JAVA_HOME\bin\jlink" --help | Select-String -Pattern "Linking from } ### create runtime -& "$Env:JAVA_HOME\bin\jlink" ` - --verbose ` - --output runtime ` - --module-path $jmodPaths ` - --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.cryptoki,jdk.crypto.ec,jdk.crypto.mscapi,java.compiler,javafx.base,javafx.graphics,javafx.controls,javafx.fxml ` - --strip-native-commands ` - --no-header-files ` - --no-man-pages ` - --strip-debug ` - --compress "zip-0" #do not compress and use msi compression +Invoke-CommandWithExitCheck -Command ` + "$Env:JAVA_HOME\bin\jlink" -Arguments @( + "--verbose", + "--output", "runtime", + "--module-path", $jmodPaths, + "--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.cryptoki,jdk.crypto.ec,jdk.crypto.mscapi,java.compiler,javafx.base,javafx.graphics,javafx.controls,javafx.fxml", + "--strip-native-commands", + "--no-header-files", + "--no-man-pages", + "--strip-debug", + "--compress", "zip-0" #do not compress and use msi compression + ) $appPath = ".\$AppName" if ($clean -and (Test-Path -Path $appPath)) { @@ -195,14 +211,15 @@ if ($LASTEXITCODE -ne 0) { } #Create RTF license for msi -&mvn -B -f $buildDir/../../pom.xml license:add-third-party ` - "-Dlicense.thirdPartyFilename=license.rtf" ` - "-Dlicense.fileTemplate=$buildDir\resources\licenseTemplate.ftl" ` - "-Dlicense.outputDirectory=$buildDir\resources\" ` - "-Dlicense.includedScopes=compile" ` - "-Dlicense.excludedGroups=^org\.cryptomator" ` - "-Dlicense.failOnMissing=true" ` - "-Dlicense.licenseMergesUrl=file:///$buildDir/../../license/merges" +Invoke-CommandWithExitCheck -Command ` + "mvn" -Arguments @("-B", "-f", "$buildDir/../../pom.xml", "license:add-third-party", ` + "-Dlicense.thirdPartyFilename=license.rtf", ` + "-Dlicense.fileTemplate=$buildDir\resources\licenseTemplate.ftl", ` + "-Dlicense.outputDirectory=$buildDir\resources\", ` + "-Dlicense.includedScopes=compile", ` + "-Dlicense.excludedGroups=^org\.cryptomator", ` + "-Dlicense.failOnMissing=true", ` + "-Dlicense.licenseMergesUrl=file:///$buildDir/../../license/merges") # patch app dir Copy-Item "contrib\*" -Destination "$AppName" @@ -212,40 +229,38 @@ attrib -r "$AppName\${AppName} (Debug).exe" # create .msi $Env:JP_WIXWIZARD_RESOURCES = "$buildDir\resources" $Env:JP_WIXHELPER_DIR = "." -& "$Env:JAVA_HOME\bin\jpackage" ` - --verbose ` - --type msi ` - --win-upgrade-uuid $UpgradeUUID ` - --app-image $AppName ` - --dest installer ` - --name $AppName ` - --vendor $Vendor ` - --copyright $copyright ` - --app-version "$semVerNo.$revisionNo" ` - --win-menu ` - --win-dir-chooser ` - --win-shortcut-prompt ` - --win-menu-group $AppName ` - --resource-dir resources ` - --license-file resources/license.rtf ` - --win-update-url $UpdateUrl ` - --about-url $AboutUrl ` - --file-associations resources/FAvaultFile.properties - -if ($LASTEXITCODE -ne 0) { - Write-Error "jpackage MSI failed with exit code $LASTEXITCODE" - return 1; -} +Invoke-CommandWithExitCheck -Command ` + "$Env:JAVA_HOME\bin\jpackage" -Arguments @( + "--verbose", + "--type", "msi", + "--win-upgrade-uuid", $UpgradeUUID, + "--app-image", $AppName, + "--dest", "installer", + "--name", $AppName, + "--vendor", $Vendor, + "--copyright", $copyright, + "--app-version", "$semVerNo.$revisionNo", + "--win-menu", + "--win-dir-chooser", + "--win-shortcut-prompt", + "--win-menu-group", $AppName, + "--resource-dir", "resources", + "--license-file", "resources/license.rtf", + "--win-update-url", $UpdateUrl, + "--about-url", $AboutUrl, + "--file-associations", "resources/FAvaultFile.properties" + ) #Create RTF license for bundle -&mvn -B -f $buildDir/../../pom.xml license:add-third-party ` - "-Dlicense.thirdPartyFilename=license.rtf" ` - "-Dlicense.fileTemplate=$buildDir\bundle\resources\licenseTemplate.ftl" ` - "-Dlicense.outputDirectory=$buildDir\bundle\resources\" ` - "-Dlicense.includedScopes=compile" ` - "-Dlicense.excludedGroups=^org\.cryptomator" ` - "-Dlicense.failOnMissing=true" ` - "-Dlicense.licenseMergesUrl=file:///$buildDir/../../license/merges" +Invoke-CommandWithExitCheck -Command ` + "mvn" -Arguments @("-B", "-f", "$buildDir/../../pom.xml", "license:add-third-party", ` + "-Dlicense.thirdPartyFilename=license.rtf", ` + "-Dlicense.fileTemplate=$buildDir\bundle\resources\licenseTemplate.ftl", ` + "-Dlicense.outputDirectory=$buildDir\bundle\resources\", ` + "-Dlicense.includedScopes=compile", ` + "-Dlicense.excludedGroups=^org\.cryptomator", ` + "-Dlicense.failOnMissing=true", ` + "-Dlicense.licenseMergesUrl=file:///$buildDir/../../license/merges") # download Winfsp $winfspMsiUrl= 'https://github.com/winfsp/winfsp/releases/download/v2.1/winfsp-2.1.25156.msi' @@ -271,18 +286,21 @@ Invoke-WebRequest $winfspUninstaller -OutFile ".\bundle\resources\winfsp-uninsta Copy-Item ".\installer\$AppName-*.msi" -Destination ".\bundle\resources\$AppName.msi" -Force # create bundle including winfsp -& wix build ` - -define BundleName="$AppName" ` - -define BundleVersion="$semVerNo.$revisionNo" ` - -define BundleVendor="$Vendor" ` - -define BundleCopyright="$copyright" ` - -define AboutUrl="$AboutUrl" ` - -define HelpUrl="$HelpUrl" ` - -define UpdateUrl="$UpdateUrl" ` - -ext "WixToolset.Util.wixext" ` - -ext "WixToolset.BootstrapperApplications.wixext" ` - .\bundle\bundleWithWinfsp.wxs ` - -out "installer\$AppName-Installer.exe" +Invoke-CommandWithExitCheck -Command ` + "wix" -Arguments @( + "build", + "-define", "BundleName=$AppName", + "-define", "BundleVersion=$semVerNo.$revisionNo", + "-define", "BundleVendor=$Vendor", + "-define", "BundleCopyright=$copyright", + "-define", "AboutUrl=$AboutUrl", + "-define", "HelpUrl=$HelpUrl", + "-define", "UpdateUrl=$UpdateUrl", + "-ext", "WixToolset.Util.wixext", + "-ext", "WixToolset.BootstrapperApplications.wixext", + ".\bundle\bundleWithWinfsp.wxs", + "-out", ".\installer\$AppName-Installer.exe" +) Write-Host "Created EXE installer .\installer\$AppName-Installer.exe" return 0;