[Ubuntu] Move preinstalled Java distributions to the toolcache directory (#2915)

* move preinstalled java to toolcache

* rework installation and fix software report
This commit is contained in:
Dibir Magomedsaygitov
2021-03-27 10:51:50 +03:00
committed by GitHub
parent 60459a5b04
commit 48f3c3e9b7
2 changed files with 33 additions and 24 deletions

View File

@@ -9,6 +9,7 @@ source $HELPER_SCRIPTS/etc-environment.sh
JAVA_VERSIONS_LIST=$(get_toolset_value '.java.versions | .[]')
DEFAULT_JDK_VERSION=$(get_toolset_value '.java.default')
JAVA_TOOLCACHE_PATH="$AGENT_TOOLSDIRECTORY/Java_Adopt_jdk"
# 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 -
@@ -19,19 +20,37 @@ if isUbuntu16 || isUbuntu18 ; then
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"
fi
apt-get update
for JAVA_VERSION in ${JAVA_VERSIONS_LIST[@]}; do
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
javaVersionPath="/usr/lib/jvm/adoptopenjdk-${JAVA_VERSION}-hotspot-amd64"
echo "JAVA_HOME_${JAVA_VERSION}_X64=$javaVersionPath" | tee -a /etc/environment
fullJavaVersion=$(cat "$javaVersionPath/release" | grep "^SEMANTIC" | cut -d "=" -f 2 | tr -d "\"" | tr "+" "-")
# If there is no semver in java release, then extract java version from -fullversion
if [[ -z $fullJavaVersion ]]; then
fullJavaVersion=$(java -fullversion 2>&1 | tr -d "\"" | tr "+" "-" | awk '{print $4}')
fi
javaToolcacheVersionPath="$JAVA_TOOLCACHE_PATH/$fullJavaVersion"
mkdir -p "$javaToolcacheVersionPath"
# Create a complete file
touch "$javaToolcacheVersionPath/x64.complete"
# Create symlink for Java
ln -s $javaVersionPath "$javaToolcacheVersionPath/x64"
done
# Set Default Java version.
# Set Default Java version
if isUbuntu16; then
# issue: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=825987
# stackoverflow: https://askubuntu.com/questions/1187136/update-java-alternatives-only-java-but-not-javac-is-changed
sed -i 's/(hl|jre|jdk|plugin|DUMMY) /(hl|jre|jdk|jdkhl|plugin|DUMMY) /g' /usr/sbin/update-java-alternatives
fi
update-java-alternatives -s /usr/lib/jvm/adoptopenjdk-${DEFAULT_JDK_VERSION}-hotspot-amd64
echo "JAVA_HOME=/usr/lib/jvm/adoptopenjdk-${DEFAULT_JDK_VERSION}-hotspot-amd64" | tee -a /etc/environment