[Windows] Move the list of installed Java versions to toolset (#2369)

* added java to toolset

* updated java tests

* fixed windows2016.json

* fixed tests

* fixed java.Tests

* fixed Java.Tests.ps1

Co-authored-by: Nikita Bykov <v-nibyko@microsoft.com>
This commit is contained in:
Nikita Bykov
2021-01-13 10:48:09 +03:00
committed by GitHub
parent 7457b9fecb
commit d20a55914c
5 changed files with 28 additions and 13 deletions

View File

@@ -77,8 +77,8 @@ function Install-JavaFromAdoptOpenJDK {
Extract-7Zip -Path $archivePath -DestinationPath $DestinationPath
}
$jdkVersions = @(7, 8, 11, 13)
$defaultVersion = 8
$jdkVersions = (Get-ToolsetContent).java.versions
$defaultVersion = (Get-ToolsetContent).java.default
$javaRootPath = "C:\Program Files\Java\"
foreach ($jdkVersion in $jdkVersions) {

View File

@@ -1,5 +1,8 @@
Describe "Java" {
It "Java <DefaultJavaVersion> is default" -TestCases @(@{ DefaultJavaVersion = 8 }) {
[array]$jdkVersions = (Get-ToolsetContent).java.versions | ForEach-Object { @{Version = $_} }
$defaultVersion = (Get-ToolsetContent).java.default
It "Java <DefaultJavaVersion> is default" -TestCases @(@{ DefaultJavaVersion = $defaultVersion }) {
$actualJavaPath = Get-EnvironmentVariable "JAVA_HOME"
$expectedJavaPath = Get-EnvironmentVariable "JAVA_HOME_${DefaultJavaVersion}_X64"
@@ -17,20 +20,17 @@ Describe "Java" {
"$ToolName -version" | Should -ReturnZeroExitCode
}
It "Java <Version>" -TestCases @(
@{ Version = "1.7" }
@{ Version = "1.8" }
@{ Version = "11" }
@{ Version = "13" }
) {
$versionNumber = $version.Split(".") | Select-Object -Last 1
$javaVariableValue = Get-EnvironmentVariable "JAVA_HOME_${versionNumber}_X64"
It "Java <Version>" -TestCases $jdkVersions {
$javaVariableValue = Get-EnvironmentVariable "JAVA_HOME_${Version}_X64"
$javaVariableValue | Should -Not -BeNullOrEmpty
$javaPath = Join-Path $javaVariableValue "bin\java"
$result = Get-CommandResult "`"$javaPath`" -version"
$result.ExitCode | Should -Be 0
if ($Version -eq 7 -or $Version -eq 8) {
$Version = "1.${Version}"
}
$result.Output[0] | Should -Match ([regex]::Escape("openjdk version `"${Version}."))
}
}

View File

@@ -140,6 +140,12 @@
]
}
],
"java": {
"default": "8",
"versions": [
"7", "8", "11", "13"
]
},
"android": {
"platform_min_version": "19",
"build_tools_min_version": "19.1.0",

View File

@@ -140,6 +140,12 @@
]
}
],
"java": {
"default": "8",
"versions": [
"7", "8", "11", "13"
]
},
"android": {
"platform_min_version": "19",
"build_tools_min_version": "19.1.0",

View File

@@ -200,6 +200,9 @@
},
{
"type": "powershell",
"environment_vars": [
"TOOLSET_JSON_PATH={{user `toolset_json_path`}}"
],
"scripts": [
"{{ template_dir }}/scripts/Installers/Install-AzureCli.ps1",
"{{ template_dir }}/scripts/Installers/Install-AzureDevOpsCli.ps1",