Skip to content

Commit

Permalink
User can now specify regexes used to find binaries (#833)
Browse files Browse the repository at this point in the history
* reverted CreateSourceFolder

* Made upstream more generic

* Added windows logos to wix installer resources

* Fixed issues with cmd

* Updated jvm finding

* Added header and params

* fixed typo

* Updated ARCH for Microsoft

* Moved windows logos to seperate branch

* Added 'x86' to list of valid inputs

* Updated README.md
  • Loading branch information
jmjaffe37 authored Mar 6, 2024
1 parent 1658ec6 commit cea1f2a
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 54 deletions.
61 changes: 17 additions & 44 deletions wix/Build.OpenJDK_generic.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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" (
Expand Down
11 changes: 10 additions & 1 deletion wix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(?<major>\d*)" ^
-platform_regex "(?<platform>x86-32|x64|aarch64)" ^
-jvm_regex "(?<jvm>hotspot|openj9|dragonwell)"
```

3. Export the following environment variables:

Example:
Expand All @@ -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
Expand Down
61 changes: 52 additions & 9 deletions wix/SourceDir/CreateSourceFolder.AdoptOpenJDK.ps1
Original file line number Diff line number Diff line change
@@ -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(?<major>\d*).
.PARAMETER jvm_regex
A regular expression that matches the JVM. Default is (?<jvm>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 (?<platform>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(?<major>\d*)" -platform_regex "(?<platform>x86-32|x64|aarch64)" -jvm_regex "(?<jvm>hotspot|openj9|dragonwell)" -jvm "hotspot"
#>

param (
[Parameter(Mandatory = $false)]
[string]$openjdk_filename_regex = "^OpenJDK(?<major>\d*)",
[Parameter(Mandatory = $false)]
[string]$platform_regex = "(?<platform>x86-32|x64|aarch64)",
[Parameter(Mandatory = $false)]
[string]$jvm_regex = "(?<jvm>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(?<major>\d*)"
$openjdk_found = $filename -match $openjdk_filename_regex
if (!$openjdk_found) {
Write-Output "filename : $filename doesn't match regex $openjdk_filename_regex"
Expand All @@ -20,16 +61,18 @@ Get-ChildItem -Path .\ -Filter *.zip -File -Name| ForEach-Object {
$major=$openjdk_basedir + $Matches.major
}

$jvm_regex = "(?<jvm>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 = "(?<platform>x86-32|x64|aarch64)"
$platform_found = $filename -match $platform_regex
if (!$platform_found) {
Write-Output "filename : $filename doesn't match regex $platform_regex"
Expand All @@ -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; }
Expand Down
53 changes: 53 additions & 0 deletions wix/helpers/Validate-Input.ps1
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit cea1f2a

Please sign in to comment.