Skip to content

Commit

Permalink
Excavator: Enabling the new Gradle Toolchains & Daemon JDK Setup
Browse files Browse the repository at this point in the history
  • Loading branch information
svc-excavator-bot committed Sep 12, 2024
1 parent d08465f commit ae58fde
Show file tree
Hide file tree
Showing 55 changed files with 322 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ generated_testSrc/
# Mac
.DS_Store
build/

# Gradle JDKs setup
!gradle/*
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {

dependencies {
classpath 'com.palantir.jakartapackagealignment:jakarta-package-alignment:0.6.0'
classpath 'com.palantir.gradle.jdks:gradle-jdks:0.37.0'
classpath 'com.palantir.gradle.jdks:gradle-jdks:0.47.0'
classpath 'com.palantir.gradle.jdkslatest:gradle-jdks-latest:0.14.0'
classpath 'com.palantir.baseline:gradle-baseline-java:5.50.0'
classpath 'com.palantir.gradle.consistentversions:gradle-consistent-versions:2.24.0'
Expand All @@ -26,6 +26,7 @@ apply plugin: 'com.palantir.baseline'
apply plugin: 'com.palantir.baseline-java-versions'
apply plugin: 'com.palantir.consistent-versions'
apply plugin: 'com.palantir.git-version'
apply plugin: 'com.palantir.jdks'
apply plugin: 'com.palantir.jdks.latest'

allprojects {
Expand Down Expand Up @@ -56,3 +57,7 @@ javaVersions {
libraryTarget = 11
runtime = 21
}

jdks {
daemonTarget = 17
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
https.protocols="TLSv1.2"
org.gradle.parallel=true
org.gradle.jvmargs = --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
palantir.jdk.setup.enabled=true
1 change: 1 addition & 0 deletions gradle/gradle-daemon-jdk-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
17
166 changes: 166 additions & 0 deletions gradle/gradle-jdks-functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
#!/bin/sh

set -e
# Set pipefail if it works in a subshell, disregard if unsupported
# shellcheck disable=SC3040
if (set -o pipefail 2>/dev/null); then
set -o pipefail
fi
#
# (c) Copyright 2024 Palantir Technologies Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

TMP_WORK_DIR=$(mktemp -d)
export TMP_WORK_DIR

cleanup() {
[ -d "$TMP_WORK_DIR" ] && rm -rf "$TMP_WORK_DIR"
}

die() {
echo
echo "$*"
echo
cleanup
exit 1
} >&2

read_value() {
if [ ! -f "$1" ]; then
die "ERROR: $1 not found, aborting Gradle JDK setup"
fi
read -r value < "$1" || die "ERROR: Unable to read value from $1. Make sure the file ends with a newline."
echo "$value"
}

get_os() {
# OS specific support; same as gradle-jdks:com.palantir.gradle.jdks.setup.common.CurrentOs.java
case "$( uname )" in #(
Linux* ) os_name="linux" ;; #(
Darwin* ) os_name="macos" ;; #(
* ) die "ERROR Unsupported OS: $( uname )" ;;
esac

if [ "$os_name" = "linux" ]; then
ldd_output=$(ldd --version 2>&1 || true)
if echo "$ldd_output" | grep -qi glibc; then
os_name="linux-glibc"
elif echo "$ldd_output" | grep -qi "gnu libc"; then
os_name="linux-glibc"
elif echo "$ldd_output" | grep -qi musl; then
os_name="linux-musl"
else
die "Unable to determine glibc or musl based Linux distribution: ldd_output: $ldd_output"
fi
fi

echo "$os_name"
}

get_arch() {
# Arch specific support, see: gradle-jdks:com.palantir.gradle.jdks.setup.common.CurrentArch.java
case "$(uname -m)" in #(
x86_64* ) arch_name="x86-64" ;; #(
x64* ) arch_name="x86-64" ;; #(
amd64* ) arch_name="x86-64" ;; #(
arm64* ) arch_name="aarch64" ;; #(
arm* ) arch_name="aarch64" ;; #(
aarch64* ) arch_name="aarch64" ;; #(
x86* ) arch_name="x86" ;; #(
i686* ) arch_name="x86" ;; #(
* ) die "ERROR Unsupported architecture: $( uname -m )" ;;
esac

echo "$arch_name"
}

get_gradle_jdks_home() {
gradle_user_home=${GRADLE_USER_HOME:-"$HOME"/.gradle}
gradle_jdks_home="$gradle_user_home"/gradle-jdks
echo "$gradle_jdks_home"
}

get_java_home() {
java_bin=$(find "$1" -type f -name "java" -path "*/bin/java" ! -type l -print -quit)
echo "${java_bin%/*/*}"
}

GRADLE_JDKS_HOME=$(get_gradle_jdks_home)
mkdir -p "$GRADLE_JDKS_HOME"
export GRADLE_JDKS_HOME

OS=$(get_os)
export OS

ARCH=$(get_arch)
export ARCH

install_and_setup_jdks() {
gradle_dir=$1
scripts_dir=${2:-"$1"}

for dir in "$gradle_dir"/jdks/*/; do
major_version_dir=${dir%*/}
major_version=${major_version_dir##*/}
if [ "$major_version" = "8" ]; then
echo "Skipping JDK 8 installation as it is not supported by Gradle JDKs Setup."
continue
fi
distribution_local_path=$(read_value "$major_version_dir"/"$OS"/"$ARCH"/local-path)
distribution_url=$(read_value "$major_version_dir"/"$OS"/"$ARCH"/download-url)
# Check if distribution exists in $GRADLE_JDKS_HOME
jdk_installation_directory="$GRADLE_JDKS_HOME"/"$distribution_local_path"
if [ ! -d "$jdk_installation_directory" ]; then
# Download and extract the distribution into a temporary directory
echo "JDK installation '$jdk_installation_directory' does not exist, installing '$distribution_url' in progress ..."
in_progress_dir="$TMP_WORK_DIR/$distribution_local_path.in-progress"
mkdir -p "$in_progress_dir"
cd "$in_progress_dir" || die "failed to change dir to $in_progress_dir"
if command -v curl > /dev/null 2>&1; then
echo "Using curl to download $distribution_url"
case "$distribution_url" in
*.zip)
distribution_name=${distribution_url##*/}
curl -C - "$distribution_url" -o "$distribution_name"
tar -xzf "$distribution_name"
;;
*)
curl -C - "$distribution_url" | tar -xzf -
;;
esac
elif command -v wget > /dev/null 2>&1; then
echo "Using wget to download $distribution_url"
case "$distribution_url" in
*.zip)
distribution_name=${distribution_url##*/}
wget -c "$distribution_url" -O "$distribution_name"
tar -xzf "$distribution_name"
;;
*)
wget -qO- -c "$distribution_url" | tar -xzf -
;;
esac
else
die "ERROR: Neither curl nor wget are installed, Could not set up JAVA_HOME"
fi
cd - || exit

# Finding the java_home
java_home=$(get_java_home "$in_progress_dir")
"$java_home"/bin/java -cp "$scripts_dir"/gradle-jdks-setup.jar com.palantir.gradle.jdks.setup.GradleJdkInstallationSetup jdkSetup "$jdk_installation_directory" || die "Failed to set up JDK $jdk_installation_directory"
echo "Successfully installed JDK distribution in $jdk_installation_directory"
fi
done
}
Binary file added gradle/gradle-jdks-setup.jar
Binary file not shown.
79 changes: 79 additions & 0 deletions gradle/gradle-jdks-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/sh
#
# (c) Copyright 2024 Palantir Technologies Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

##############################################################################
#
# Gradle jdk set up script for POSIX generated by gradle-jdks.
#
# This script does the following:
# (1) Downloads all the JDK distributions that are present in `gradle/jdks`
# (2) Installs the distributions in a temporary directory
# (3) Calls the java class `GradleJdkInstallationSetup` that will move each distribution to
# `$GRADLE_USER_HOME/${local_path}` based on the local_path=`gradle/jdks/${majorVersion}/${os}/${arch}/local_path`
# and it will set up the certificates based on `gradle/certs` entries for the locally installed distribution
# (4) Sets `org.gradle.java.home` to the JDK distribution that is used by the Gradle Daemon
#
#
# Important for running:
# This script requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command» and «set».
#
##############################################################################

set -e
# Set pipefail if it works in a subshell, disregard if unsupported
# shellcheck disable=SC3040
if (set -o pipefail 2>/dev/null); then
set -o pipefail
fi

# Resolve links: $0 may be a link
app_path=$0

# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_HOME=${APP_HOME%/gradle}
APP_GRADLE_DIR="$APP_HOME"/gradle

# Loading gradle jdk functions
. "$APP_GRADLE_DIR"/gradle-jdks-functions.sh

install_and_setup_jdks "$APP_GRADLE_DIR"

gradle_daemon_jdk_version=$(read_value "$APP_GRADLE_DIR"/gradle-daemon-jdk-version)
gradle_daemon_jdk_distribution_local_path=$(read_value "$APP_GRADLE_DIR"/jdks/"$gradle_daemon_jdk_version"/"$OS"/"$ARCH"/local-path)
"$GRADLE_JDKS_HOME"/"$gradle_daemon_jdk_distribution_local_path"/bin/java -cp "$APP_GRADLE_DIR"/gradle-jdks-setup.jar com.palantir.gradle.jdks.setup.GradleJdkInstallationSetup daemonSetup "$APP_HOME" "$GRADLE_JDKS_HOME/$gradle_daemon_jdk_distribution_local_path"

# [Used by ./gradlew only] Setting the Gradle Daemon Java Home to the JDK distribution
set -- "-Dorg.gradle.java.home=$GRADLE_JDKS_HOME/$gradle_daemon_jdk_distribution_local_path" "$@"

cleanup
1 change: 1 addition & 0 deletions gradle/jdks/11/linux-glibc/aarch64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://corretto.aws/downloads/resources/11.0.23.9.1/amazon-corretto-11.0.23.9.1-linux-aarch64.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/11/linux-glibc/aarch64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
amazon-corretto-11.0.23.9.1
1 change: 1 addition & 0 deletions gradle/jdks/11/linux-glibc/x86-64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://corretto.aws/downloads/resources/11.0.23.9.1/amazon-corretto-11.0.23.9.1-linux-x64.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/11/linux-glibc/x86-64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
amazon-corretto-11.0.23.9.1
1 change: 1 addition & 0 deletions gradle/jdks/11/linux-glibc/x86/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://corretto.aws/downloads/resources/11.0.23.9.1/amazon-corretto-11.0.23.9.1-linux-i386.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/11/linux-glibc/x86/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
amazon-corretto-11.0.23.9.1
1 change: 1 addition & 0 deletions gradle/jdks/11/linux-musl/aarch64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://corretto.aws/downloads/resources/11.0.23.9.1/amazon-corretto-11.0.23.9.1-alpine-linux-aarch64.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/11/linux-musl/aarch64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
amazon-corretto-11.0.23.9.1
1 change: 1 addition & 0 deletions gradle/jdks/11/linux-musl/x86-64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://corretto.aws/downloads/resources/11.0.23.9.1/amazon-corretto-11.0.23.9.1-alpine-linux-x64.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/11/linux-musl/x86-64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
amazon-corretto-11.0.23.9.1
1 change: 1 addition & 0 deletions gradle/jdks/11/macos/aarch64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://corretto.aws/downloads/resources/11.0.23.9.1/amazon-corretto-11.0.23.9.1-macosx-aarch64.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/11/macos/aarch64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
amazon-corretto-11.0.23.9.1
1 change: 1 addition & 0 deletions gradle/jdks/11/macos/x86-64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://corretto.aws/downloads/resources/11.0.23.9.1/amazon-corretto-11.0.23.9.1-macosx-x64.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/11/macos/x86-64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
amazon-corretto-11.0.23.9.1
1 change: 1 addition & 0 deletions gradle/jdks/11/windows/x86-64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://corretto.aws/downloads/resources/11.0.23.9.1/amazon-corretto-11.0.23.9.1-windows-x64-jdk.zip
1 change: 1 addition & 0 deletions gradle/jdks/11/windows/x86-64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
amazon-corretto-11.0.23.9.1
1 change: 1 addition & 0 deletions gradle/jdks/11/windows/x86/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://corretto.aws/downloads/resources/11.0.23.9.1/amazon-corretto-11.0.23.9.1-windows-i386-jdk.zip
1 change: 1 addition & 0 deletions gradle/jdks/11/windows/x86/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
amazon-corretto-11.0.23.9.1
1 change: 1 addition & 0 deletions gradle/jdks/17/linux-glibc/aarch64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://corretto.aws/downloads/resources/17.0.11.9.1/amazon-corretto-17.0.11.9.1-linux-aarch64.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/17/linux-glibc/aarch64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
amazon-corretto-17.0.11.9.1
1 change: 1 addition & 0 deletions gradle/jdks/17/linux-glibc/x86-64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://corretto.aws/downloads/resources/17.0.11.9.1/amazon-corretto-17.0.11.9.1-linux-x64.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/17/linux-glibc/x86-64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
amazon-corretto-17.0.11.9.1
1 change: 1 addition & 0 deletions gradle/jdks/17/linux-musl/aarch64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://corretto.aws/downloads/resources/17.0.11.9.1/amazon-corretto-17.0.11.9.1-alpine-linux-aarch64.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/17/linux-musl/aarch64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
amazon-corretto-17.0.11.9.1
1 change: 1 addition & 0 deletions gradle/jdks/17/linux-musl/x86-64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://corretto.aws/downloads/resources/17.0.11.9.1/amazon-corretto-17.0.11.9.1-alpine-linux-x64.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/17/linux-musl/x86-64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
amazon-corretto-17.0.11.9.1
1 change: 1 addition & 0 deletions gradle/jdks/17/macos/aarch64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://corretto.aws/downloads/resources/17.0.11.9.1/amazon-corretto-17.0.11.9.1-macosx-aarch64.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/17/macos/aarch64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
amazon-corretto-17.0.11.9.1
1 change: 1 addition & 0 deletions gradle/jdks/17/macos/x86-64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://corretto.aws/downloads/resources/17.0.11.9.1/amazon-corretto-17.0.11.9.1-macosx-x64.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/17/macos/x86-64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
amazon-corretto-17.0.11.9.1
1 change: 1 addition & 0 deletions gradle/jdks/17/windows/x86-64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://corretto.aws/downloads/resources/17.0.11.9.1/amazon-corretto-17.0.11.9.1-windows-x64-jdk.zip
1 change: 1 addition & 0 deletions gradle/jdks/17/windows/x86-64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
amazon-corretto-17.0.11.9.1
1 change: 1 addition & 0 deletions gradle/jdks/21/linux-glibc/aarch64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://corretto.aws/downloads/resources/21.0.3.9.1/amazon-corretto-21.0.3.9.1-linux-aarch64.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/21/linux-glibc/aarch64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
amazon-corretto-21.0.3.9.1
1 change: 1 addition & 0 deletions gradle/jdks/21/linux-glibc/x86-64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://corretto.aws/downloads/resources/21.0.3.9.1/amazon-corretto-21.0.3.9.1-linux-x64.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/21/linux-glibc/x86-64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
amazon-corretto-21.0.3.9.1
1 change: 1 addition & 0 deletions gradle/jdks/21/linux-musl/aarch64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://corretto.aws/downloads/resources/21.0.3.9.1/amazon-corretto-21.0.3.9.1-alpine-linux-aarch64.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/21/linux-musl/aarch64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
amazon-corretto-21.0.3.9.1
1 change: 1 addition & 0 deletions gradle/jdks/21/linux-musl/x86-64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://corretto.aws/downloads/resources/21.0.3.9.1/amazon-corretto-21.0.3.9.1-alpine-linux-x64.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/21/linux-musl/x86-64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
amazon-corretto-21.0.3.9.1
1 change: 1 addition & 0 deletions gradle/jdks/21/macos/aarch64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://corretto.aws/downloads/resources/21.0.3.9.1/amazon-corretto-21.0.3.9.1-macosx-aarch64.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/21/macos/aarch64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
amazon-corretto-21.0.3.9.1
1 change: 1 addition & 0 deletions gradle/jdks/21/macos/x86-64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://corretto.aws/downloads/resources/21.0.3.9.1/amazon-corretto-21.0.3.9.1-macosx-x64.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/21/macos/x86-64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
amazon-corretto-21.0.3.9.1
1 change: 1 addition & 0 deletions gradle/jdks/21/windows/x86-64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://corretto.aws/downloads/resources/21.0.3.9.1/amazon-corretto-21.0.3.9.1-windows-x64-jdk.zip
1 change: 1 addition & 0 deletions gradle/jdks/21/windows/x86-64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
amazon-corretto-21.0.3.9.1
Loading

0 comments on commit ae58fde

Please sign in to comment.