From 7457b9fecb38ad6c1bebcca7c62d182407abd19f Mon Sep 17 00:00:00 2001 From: Nikita Bykov <49442273+nikita-bykov@users.noreply.github.com> Date: Wed, 13 Jan 2021 10:47:03 +0300 Subject: [PATCH] [Ubuntu] Move the list of installed Java versions to toolset (#2393) * added java to toolset * fixed java-tools and updated tests * fixed java-tools.sh * fixed tests * fixed java.Tests * fixed java versions check * fixed Java.Tests.ps1 Co-authored-by: Nikita Bykov --- images/linux/scripts/installers/java-tools.sh | 35 ++++++++----------- images/linux/scripts/tests/Java.Tests.ps1 | 34 ++++++------------ images/linux/toolsets/toolset-1604.json | 6 ++++ images/linux/toolsets/toolset-1804.json | 6 ++++ images/linux/toolsets/toolset-2004.json | 6 ++++ 5 files changed, 42 insertions(+), 45 deletions(-) diff --git a/images/linux/scripts/installers/java-tools.sh b/images/linux/scripts/installers/java-tools.sh index b8dbd710f..91802398b 100644 --- a/images/linux/scripts/installers/java-tools.sh +++ b/images/linux/scripts/installers/java-tools.sh @@ -7,6 +7,10 @@ source $HELPER_SCRIPTS/os.sh source $HELPER_SCRIPTS/etc-environment.sh +toolset="$INSTALLER_SCRIPT_FOLDER/toolset.json" +JAVA_VERSIONS_LIST=$(jq -r '.java.versions | .[]' $toolset) +DEFAULT_JDK_VERSION=$(jq -r '.java.default' $toolset) + # Install GPG Key for Adopt Open JDK. See https://adoptopenjdk.net/installation.html wget -qO - "https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public" | apt-key add - add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/ @@ -15,24 +19,18 @@ if isUbuntu16 || isUbuntu18 ; then # Install GPG Key for Azul Open JDK. See https://www.azul.com/downloads/azure-only/zulu/ apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0xB1998361219BD9C9 apt-add-repository "deb https://repos.azul.com/azure-only/zulu/apt stable main" - apt-get update - apt-get -y install zulu-7-azure-jdk=\* - # Open JDP Adopt does not exist for Ubuntu 20 - apt-get -y install adoptopenjdk-12-hotspot=\* - echo "JAVA_HOME_7_X64=/usr/lib/jvm/zulu-7-azure-amd64" | tee -a /etc/environment - DEFAULT_JDK_VERSION=8 - defaultLabel8="(default)" fi +apt-get update -if isUbuntu20 ; then - DEFAULT_JDK_VERSION=11 - defaultLabel11="(default)" - apt-get update -fi - -# Install only LTS versions. -apt-get -y install adoptopenjdk-8-hotspot=\* -apt-get -y install adoptopenjdk-11-hotspot=\* +for JAVA_VERSION in ${JAVA_VERSIONS_LIST[@]}; do + if [[ $JAVA_VERSION == "7" ]]; then + apt-get -y install zulu-7-azure-jdk=\* + echo "JAVA_HOME_7_X64=/usr/lib/jvm/zulu-7-azure-amd64" | tee -a /etc/environment + else + apt-get -y install adoptopenjdk-$JAVA_VERSION-hotspot=\* + echo "JAVA_HOME_${JAVA_VERSION}_X64=/usr/lib/jvm/adoptopenjdk-${JAVA_VERSION}-hotspot-amd64" | tee -a /etc/environment + fi +done # Set Default Java version. if isUbuntu16; then @@ -42,11 +40,6 @@ if isUbuntu16; then fi update-java-alternatives -s /usr/lib/jvm/adoptopenjdk-${DEFAULT_JDK_VERSION}-hotspot-amd64 -echo "JAVA_HOME_8_X64=/usr/lib/jvm/adoptopenjdk-8-hotspot-amd64" | tee -a /etc/environment -echo "JAVA_HOME_11_X64=/usr/lib/jvm/adoptopenjdk-11-hotspot-amd64" | tee -a /etc/environment -if isUbuntu16 || isUbuntu18 ; then -echo "JAVA_HOME_12_X64=/usr/lib/jvm/adoptopenjdk-12-hotspot-amd64" | tee -a /etc/environment -fi echo "JAVA_HOME=/usr/lib/jvm/adoptopenjdk-${DEFAULT_JDK_VERSION}-hotspot-amd64" | tee -a /etc/environment # Install Ant diff --git a/images/linux/scripts/tests/Java.Tests.ps1 b/images/linux/scripts/tests/Java.Tests.ps1 index 70a5d40d3..29c1a9712 100644 --- a/images/linux/scripts/tests/Java.Tests.ps1 +++ b/images/linux/scripts/tests/Java.Tests.ps1 @@ -1,28 +1,12 @@ Import-Module "$PSScriptRoot/../helpers/Common.Helpers.psm1" -DisableNameChecking Describe "Java" { + [array]$jdkVersions = (Get-ToolsetContent).java.versions | ForEach-Object { @{Version = $_} } + $defaultJavaVersion = (Get-ToolsetContent).java.default - if (Test-IsUbuntu20) { - $defaultJavaVersion = "11" - $javaTestCases = @( - @{ Version = "1.8" } - @{ Version = "11" } - ) - } - - if ((Test-IsUbuntu16) -or (Test-IsUbuntu18)) { - $defaultJavaVersion = "8" - $javaTestCases = @( - @{ Version = "1.7" } - @{ Version = "1.8" } - @{ Version = "11" } - @{ Version = "12" } - ) - } - - It "Java is default" -TestCases @{ defaultJavaVersion = $defaultJavaVersion } { + It "Java is default" -TestCases @{ DefaultJavaVersion = $defaultJavaVersion } { $actualJavaPath = Get-EnvironmentVariable "JAVA_HOME" - $expectedJavaPath = Get-EnvironmentVariable "JAVA_HOME_${defaultJavaVersion}_X64" + $expectedJavaPath = Get-EnvironmentVariable "JAVA_HOME_${DefaultJavaVersion}_X64" $actualJavaPath | Should -Not -BeNullOrEmpty $expectedJavaPath | Should -Not -BeNullOrEmpty @@ -39,15 +23,17 @@ Describe "Java" { "$ToolName -version" | Should -ReturnZeroExitCode } - It "Java " -TestCases $javaTestCases { - $versionNumber = $version.Split(".") | Select-Object -Last 1 - - $javaVariableValue = Get-EnvironmentVariable "JAVA_HOME_${versionNumber}_X64" + It "Java " -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 | Should -Match ([regex]::Escape("openjdk version `"${Version}.")) } } \ No newline at end of file diff --git a/images/linux/toolsets/toolset-1604.json b/images/linux/toolsets/toolset-1604.json index b322cab0f..556f0ef65 100644 --- a/images/linux/toolsets/toolset-1604.json +++ b/images/linux/toolsets/toolset-1604.json @@ -79,6 +79,12 @@ ] } ], + "java": { + "default": "8", + "versions": [ + "7", "8", "11", "12" + ] + }, "android": { "platform_min_version": "10", "build_tools_min_version": "19.1.0", diff --git a/images/linux/toolsets/toolset-1804.json b/images/linux/toolsets/toolset-1804.json index ce69e0595..732828ff4 100644 --- a/images/linux/toolsets/toolset-1804.json +++ b/images/linux/toolsets/toolset-1804.json @@ -79,6 +79,12 @@ ] } ], + "java": { + "default": "8", + "versions": [ + "7", "8", "11", "12" + ] + }, "android": { "platform_min_version": "17", "build_tools_min_version": "19.1.0", diff --git a/images/linux/toolsets/toolset-2004.json b/images/linux/toolsets/toolset-2004.json index 669cf5c45..3012c2dc1 100644 --- a/images/linux/toolsets/toolset-2004.json +++ b/images/linux/toolsets/toolset-2004.json @@ -67,6 +67,12 @@ ] } ], + "java": { + "default": "11", + "versions": [ + "8", "11" + ] + }, "android": { "platform_min_version": "27", "build_tools_min_version": "27.0.0",