diff --git a/wix/Build.OpenJDK_generic.cmd b/wix/Build.OpenJDK_generic.cmd index 4a89e3c3c..f175529dd 100644 --- a/wix/Build.OpenJDK_generic.cmd +++ b/wix/Build.OpenJDK_generic.cmd @@ -7,7 +7,7 @@ REM PRODUCT_MAINTENANCE_VERSION=0 REM PRODUCT_PATCH_VERSION=0 REM PRODUCT_BUILD_NUMBER=28 REM MSI_PRODUCT_VERSION=11.0.0.28 -REM ARCH=x64|x86-32|arm64 or all "x64 x86-32 arm64" +REM ARCH=x64|x86-32|x86|arm64 or all "x64 x86-32 arm64" REM JVM=hotspot|openj9|dragonwell or both JVM=hotspot openj9 REM PRODUCT_CATEGORY=jre|jdk (only one at a time) REM SKIP_MSI_VALIDATION=true (Add -sval option to light.exe to skip MSI/MSM validation and skip smoke.exe ) @@ -36,55 +36,28 @@ IF NOT DEFINED PRODUCT_HELP_LINK SET PRODUCT_HELP_LINK=https://github.com/adopti IF NOT DEFINED PRODUCT_SUPPORT_LINK SET PRODUCT_SUPPORT_LINK=https://adoptium.net/support IF NOT DEFINED PRODUCT_UPDATE_INFO_LINK SET PRODUCT_UPDATE_INFO_LINK=https://adoptium.net/temurin/releases -REM This needs tidying up, it's got out of control now -IF NOT "%ARCH%" == "x64" ( - IF NOT "%ARCH%" == "x86-32" ( - IF NOT "%ARCH%" == "arm64" ( - IF NOT "%ARCH%" == "x86-32 x64" ( - IF NOT "%ARCH%" == "x86-32 arm64" ( - IF NOT "%ARCH%" == "arm64 x86-32" ( - IF NOT "%ARCH%" == "x64 x86-32" ( - IF NOT "%ARCH%" == "x64 arm64" ( - IF NOT "%ARCH%" == "arm64 x64" ( - IF NOT "%ARCH%" == "x86-32 x64 arm64" ( - IF NOT "%ARCH%" == "x86-32 arm64 x64" ( - IF NOT "%ARCH%" == "arm64 x86-32 x64" ( - IF NOT "%ARCH%" == "arm64 x64 x86-32" ( - IF NOT "%ARCH%" == "x86-32 x64 arm64" ( - IF NOT "%ARCH%" == "x64 x86-32 arm64" ( - ECHO ARCH %ARCH% not supported : valid values : x64, x86-32, arm64, x86-32 x64, x64 x86-32, x86-32 x64 arm64, x86-32 arm64 x64, arm64 x86-32 x64, arm64 x64 x86-32, x86-32 x64 arm64, x64 x86-32 arm64 - GOTO FAILED - ) - ) - ) - ) - ) - ) - ) - ) - ) - ) - ) - ) - ) - ) +powershell -ExecutionPolicy Bypass -File "%~dp0\helpers\Validate-Input.ps1" ^ + -toValidate '%ARCH%' ^ + -validInputs "x64 x86-32 x86 arm64" ^ + -delimiter " " + +IF %ERRORLEVEL% == 1 ( + ECHO ARCH %ARCH% not supported : valid values are any combination of : x64, x86-32, arm64 + GOTO FAILED ) REM Update to handle the change of build variant until implications REM of setting this to Temurin can be evaluated IF "%JVM%" == "temurin" SET JVM=hotspot -IF NOT "%JVM%" == "hotspot" ( - IF NOT "%JVM%" == "openj9" ( - IF NOT "%JVM%" == "dragonwell" ( - IF NOT "%JVM%" == "openj9 hotspot" ( - IF NOT "%JVM%" == "hotspot openj9" ( - ECHO JVM "%JVM%" not supported : valid values : hotspot, openj9, dragonwell, hotspot openj9, openj9 hotspot - GOTO FAILED - ) - ) - ) - ) +powershell -ExecutionPolicy Bypass -File "%~dp0\helpers\Validate-Input.ps1" ^ + -toValidate '%JVM%' ^ + -validInputs "hotspot,openj9,dragonwell,openj9 hotspot,hotspot openj9" ^ + -delimiter "," + +IF %ERRORLEVEL% == 1 ( + ECHO JVM "%JVM%" not supported : valid values : hotspot, openj9, dragonwell, hotspot openj9, openj9 hotspot + GOTO FAILED ) IF NOT "%PRODUCT_CATEGORY%" == "jre" ( diff --git a/wix/README.md b/wix/README.md index 0bf5f591b..dde23eab9 100644 --- a/wix/README.md +++ b/wix/README.md @@ -15,6 +15,15 @@ call powershell.exe ./CreateSourceFolder.AdoptOpenJDK.ps1 ``` +If your file structure/names are different than expected, we now support user-input regexes: +(default values shown below. Note: `-jvm` flag also available, used in place of `-jvm_regex` result ) +```batch +call powershell.exe ./CreateSourceFolder.AdoptOpenJDK.ps1 ^ + -openjdk_filename_regex "^OpenJDK(?\d*)" ^ + -platform_regex "(?x86-32|x64|aarch64)" ^ + -jvm_regex "(?hotspot|openj9|dragonwell)" +``` + 3. Export the following environment variables: Example: @@ -24,7 +33,7 @@ call powershell.exe ./CreateSourceFolder.AdoptOpenJDK.ps1 SET PRODUCT_MINOR_VERSION=0 SET PRODUCT_MAINTENANCE_VERSION=2 SET PRODUCT_PATCH_VERSION=8 - SET ARCH=x64|x86|arm64 or all "x64 x86 arm64" + SET ARCH=x64|x86-32|x86|arm64 or all "x64 x86-32 arm64" SET JVM=hotspot|openj9|dragonwell or both JVM=hotspot openj9 SET PRODUCT_CATEGORY=jre|jdk (only one at a time) cmd /c Build.OpenJDK_generic.cmd diff --git a/wix/SourceDir/CreateSourceFolder.AdoptOpenJDK.ps1 b/wix/SourceDir/CreateSourceFolder.AdoptOpenJDK.ps1 index c1e4e9927..1da044277 100644 --- a/wix/SourceDir/CreateSourceFolder.AdoptOpenJDK.ps1 +++ b/wix/SourceDir/CreateSourceFolder.AdoptOpenJDK.ps1 @@ -1,10 +1,51 @@ +<# +.SYNOPSIS + This script extracts the contents of a zip file to a directory structure that is expected by the Wix toolset. + +.DESCRIPTION + The script takes a zip file and extracts its contents to a directory structure that is expected by the Wix toolset. + The script also performs some cleanup on the extracted files. + +.PARAMETER openjdk_filename_regex + A regular expression that matches the OpenJDK filename. Default is ^OpenJDK(?\d*). + +.PARAMETER jvm_regex + A regular expression that matches the JVM. Default is (?hotspot|openj9|dragonwell). + +.PARAMETER jvm + The JVM to be used. If not provided, the script will attempt to extract the JVM from the filename. + +.PARAMETER platform_regex + A regular expression that matches the platform. Default is (?x86-32|x64|aarch64). + +.NOTES + File Name: CreateSourceFolder.AdoptOpenJDK.ps1 + Author : AdoptOpenJDK + Version : 1.0 + Date : March. 01, 2024 + +.EXAMPLE + PS> .\CreateSourceFolder.AdoptOpenJDK.ps1 -openjdk_filename_regex "^OpenJDK(?\d*)" -platform_regex "(?x86-32|x64|aarch64)" -jvm_regex "(?hotspot|openj9|dragonwell)" -jvm "hotspot" + +#> + +param ( + [Parameter(Mandatory = $false)] + [string]$openjdk_filename_regex = "^OpenJDK(?\d*)", + [Parameter(Mandatory = $false)] + [string]$platform_regex = "(?x86-32|x64|aarch64)", + [Parameter(Mandatory = $false)] + [string]$jvm_regex = "(?hotspot|openj9|dragonwell)", + [Parameter(Mandatory = $false)] + [string]$jvm = "" +) + Get-ChildItem -Path .\ -Filter *.zip -File -Name| ForEach-Object { $filename = [System.IO.Path]::GetFileName($_) Write-Output "Processing filename : $filename" # validate that the zip file is OpenJDK with an optional major version number - $openjdk_filename_regex = "^OpenJDK(?\d*)" $openjdk_found = $filename -match $openjdk_filename_regex if (!$openjdk_found) { Write-Output "filename : $filename doesn't match regex $openjdk_filename_regex" @@ -20,16 +61,18 @@ Get-ChildItem -Path .\ -Filter *.zip -File -Name| ForEach-Object { $major=$openjdk_basedir + $Matches.major } - $jvm_regex = "(?hotspot|openj9|dragonwell)" - $jvm_found = $filename -match $jvm_regex - if (!$jvm_found) { - Write-Output "filename : $filename doesn't match regex $jvm_regex" - exit 2 + if ([string]::IsNullOrEmpty($jvm)) { + + $jvm_found = $filename -match $jvm_regex + if (!$jvm_found) { + Write-Output "filename : $filename doesn't match regex $jvm_regex" + exit 2 + } + $jvm = $Matches.jvm + } - $jvm = $Matches.jvm # Windows Architecture supported - $platform_regex = "(?x86-32|x64|aarch64)" $platform_found = $filename -match $platform_regex if (!$platform_found) { Write-Output "filename : $filename doesn't match regex $platform_regex" @@ -56,7 +99,7 @@ Get-ChildItem -Path .\ -Filter *.zip -File -Name| ForEach-Object { } elseif ( $_.Name -Match "(.*)_(.*)$" ) { $NewName = $_.Name -replace "(.*)_(.*)$",'$1' } - + $Destination = Join-Path -Path $SourcePath -ChildPath $NewName if (Test-Path $Destination) { Remove-Item $Destination -Recurse; } diff --git a/wix/helpers/Validate-Input.ps1 b/wix/helpers/Validate-Input.ps1 new file mode 100644 index 000000000..1349a335c --- /dev/null +++ b/wix/helpers/Validate-Input.ps1 @@ -0,0 +1,53 @@ +<# +.SYNOPSIS + This script verifies the validity an input, given a list of possible inputs. + +.DESCRIPTION + The script takes a string as input and checks if it is valid against a list of valid inputs. + If the input is valid, the script returns 0. If the input is invalid, the script returns 1. + +.PARAMETER validInputs + A comma seperated list of valid inputs. + +.PARAMETER toValidate + The input to be verified. + +.PARAMETER delimiter + The delimiter used to split the input string. Default is a space. + +.NOTES + File Name: Validate-Input.ps1 + Author : Joshua Martin-Jaffe + Version : 1.0 + Date : Feb. 29, 2024 + +.EXAMPLE + PS> .\Validate-Input.ps1 -validInputs 'x86-32 x64' -toValidate 'x86-32 x64' -delimiter ' ' + + True + +#> + +param ( + [Parameter(Mandatory = $true)] + [string]$validInputs, + [Parameter(Mandatory = $true)] + [string]$toValidate, + [Parameter(Mandatory = $true)] + [string]$delimiter +) + +$validInputs = $validInputs.Trim("'") +$validInputArray = $validInputs -split "$delimiter" + +$toValidate = $toValidate.Trim("'") +$inputArray = $toValidate -split "$delimiter" + + +for ($i = 0; $i -lt $inputArray.Length; $i++) { + if ($validInputArray -notcontains $inputArray[$i]) { + echo $inputArray[$i] ' is an invalid input' + exit 1 # Invalid input + } +} +exit 0 # Valid input \ No newline at end of file