Skip to content

Commit 2498360

Browse files
Excavator: Enabling the new Gradle Toolchains & Daemon JDK Setup
1 parent 74922d4 commit 2498360

37 files changed

+318
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ out/
3232

3333
# Log Files
3434
*/var/log/
35+
36+
# Gradle JDKs setup
37+
!gradle/*

build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ buildscript {
1010
classpath 'com.palantir.baseline:gradle-baseline-java:6.25.0'
1111
classpath 'com.palantir.gradle.consistentversions:gradle-consistent-versions:2.27.0'
1212
classpath 'com.palantir.gradle.gitversion:gradle-git-version:3.2.0'
13+
classpath 'com.palantir.gradle.jdks:gradle-jdks:0.65.0'
1314
classpath 'com.palantir.javaformat:gradle-palantir-java-format:2.62.0'
1415
classpath 'com.palantir.suppressible-error-prone:gradle-suppressible-error-prone:2.9.0'
1516
classpath 'gradle.plugin.org.inferred:gradle-processors:3.7.0'
@@ -24,6 +25,7 @@ buildscript {
2425
apply plugin: 'com.palantir.failure-reports'
2526
apply plugin: 'com.palantir.baseline'
2627
apply plugin: 'com.palantir.git-version'
28+
apply plugin: 'com.palantir.jdks'
2729
apply plugin: 'com.palantir.consistent-versions'
2830
apply plugin: 'com.palantir.baseline-java-versions'
2931
apply plugin: 'com.palantir.jdks.latest'
@@ -57,3 +59,7 @@ javaVersions {
5759
libraryTarget = 21
5860
runtime = 21
5961
}
62+
63+
jdks {
64+
daemonTarget = 17
65+
}

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ org.gradle.caching = true
22
org.gradle.parallel = true
33
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
44
palantir.native.formatter=true
5+
palantir.jdk.setup.enabled=true

gradle/gradle-daemon-jdk-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
17

gradle/gradle-jdks-functions.sh

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
#!/bin/sh
2+
3+
set -e
4+
# Set pipefail if it works in a subshell, disregard if unsupported
5+
# shellcheck disable=SC3040
6+
if (set -o pipefail 2>/dev/null); then
7+
set -o pipefail
8+
fi
9+
#
10+
# (c) Copyright 2024 Palantir Technologies Inc. All rights reserved.
11+
#
12+
# Licensed under the Apache License, Version 2.0 (the "License");
13+
# you may not use this file except in compliance with the License.
14+
# You may obtain a copy of the License at
15+
#
16+
# http://www.apache.org/licenses/LICENSE-2.0
17+
#
18+
# Unless required by applicable law or agreed to in writing, software
19+
# distributed under the License is distributed on an "AS IS" BASIS,
20+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21+
# See the License for the specific language governing permissions and
22+
# limitations under the License.
23+
#
24+
25+
TMP_WORK_DIR=$(mktemp -d)
26+
export TMP_WORK_DIR
27+
28+
# writing to stderr
29+
write() { echo "$*" >&2; }
30+
31+
cleanup() {
32+
[ -d "$TMP_WORK_DIR" ] && rm -rf "$TMP_WORK_DIR"
33+
}
34+
35+
die() {
36+
write
37+
write "$*"
38+
write
39+
cleanup
40+
exit 1
41+
} >&2
42+
43+
read_value() {
44+
if [ ! -f "$1" ]; then
45+
die "ERROR: $1 not found, aborting Gradle JDK setup"
46+
fi
47+
read -r value < "$1" || die "ERROR: Unable to read value from $1. Make sure the file ends with a newline."
48+
echo "$value"
49+
}
50+
51+
get_os() {
52+
# OS specific support; same as gradle-jdks:com.palantir.gradle.jdks.setup.common.CurrentOs.java
53+
case "$( uname )" in #(
54+
Linux* ) os_name="linux" ;; #(
55+
Darwin* ) os_name="macos" ;; #(
56+
* ) os_name="unsupported";;
57+
esac
58+
59+
if [ "$os_name" = "linux" ]; then
60+
ldd_output=$(ldd --version 2>&1 || true)
61+
if echo "$ldd_output" | grep -qi glibc; then
62+
os_name="linux-glibc"
63+
elif echo "$ldd_output" | grep -qi "gnu libc"; then
64+
os_name="linux-glibc"
65+
elif echo "$ldd_output" | grep -qi musl; then
66+
os_name="linux-musl"
67+
else
68+
die "Unable to determine glibc or musl based Linux distribution: ldd_output: $ldd_output"
69+
fi
70+
fi
71+
72+
echo "$os_name"
73+
}
74+
75+
get_arch() {
76+
# Arch specific support, see: gradle-jdks:com.palantir.gradle.jdks.setup.common.CurrentArch.java
77+
case "$(uname -m)" in #(
78+
x86_64* ) arch_name="x86-64" ;; #(
79+
x64* ) arch_name="x86-64" ;; #(
80+
amd64* ) arch_name="x86-64" ;; #(
81+
arm64* ) arch_name="aarch64" ;; #(
82+
arm* ) arch_name="aarch64" ;; #(
83+
aarch64* ) arch_name="aarch64" ;; #(
84+
x86* ) arch_name="x86" ;; #(
85+
i686* ) arch_name="x86" ;; #(
86+
* ) arch_name="unsupported";;
87+
esac
88+
89+
echo "$arch_name"
90+
}
91+
92+
get_gradle_jdks_home() {
93+
gradle_user_home=${GRADLE_USER_HOME:-"$HOME"/.gradle}
94+
gradle_jdks_home="$gradle_user_home"/gradle-jdks
95+
echo "$gradle_jdks_home"
96+
}
97+
98+
get_java_home() {
99+
java_bin=$(find "$1" -type f -name "java" -path "*/bin/java" ! -type l -print -quit)
100+
echo "${java_bin%/*/*}"
101+
}
102+
103+
GRADLE_JDKS_HOME=$(get_gradle_jdks_home)
104+
mkdir -p "$GRADLE_JDKS_HOME"
105+
export GRADLE_JDKS_HOME
106+
107+
OS=$(get_os)
108+
export OS
109+
110+
ARCH=$(get_arch)
111+
export ARCH
112+
113+
is_arch_os_supported() {
114+
if [ "$OS" = "unsupported" ] || [ "$ARCH" = "unsupported" ]; then
115+
echo false
116+
fi
117+
echo true
118+
}
119+
120+
install_and_setup_jdks() {
121+
gradle_dir=$1
122+
scripts_dir=${2:-"$1"}
123+
124+
for dir in "$gradle_dir"/jdks/*/; do
125+
major_version_dir=${dir%*/}
126+
major_version=${major_version_dir##*/}
127+
if [ "$major_version" = "8" ]; then
128+
write "Skipping JDK 8 installation as it is not supported by Gradle JDKs Setup."
129+
continue
130+
fi
131+
distribution_local_path=$(read_value "$major_version_dir"/"$OS"/"$ARCH"/local-path)
132+
distribution_url=$(read_value "$major_version_dir"/"$OS"/"$ARCH"/download-url)
133+
# Check if distribution exists in $GRADLE_JDKS_HOME
134+
jdk_installation_directory="$GRADLE_JDKS_HOME"/"$distribution_local_path"
135+
if [ ! -d "$jdk_installation_directory" ]; then
136+
write "JDK installation '$jdk_installation_directory' does not exist, installing '$distribution_url' in progress ..."
137+
elif [ ! -f "$jdk_installation_directory/bin/java" ]; then
138+
write "Java executable not found in $jdk_installation_directory/bin/java, re-installing the JDK...."
139+
else
140+
continue
141+
fi
142+
# Download and extract the distribution into a temporary directory
143+
in_progress_dir="$TMP_WORK_DIR/$distribution_local_path.in-progress"
144+
mkdir -p "$in_progress_dir"
145+
cd "$in_progress_dir" || die "failed to change dir to $in_progress_dir"
146+
if command -v curl > /dev/null 2>&1; then
147+
write "Using curl to download $distribution_url"
148+
case "$distribution_url" in
149+
*.zip)
150+
distribution_name=${distribution_url##*/}
151+
curl -L -C - "$distribution_url" -o "$distribution_name"
152+
tar -xzf "$distribution_name"
153+
;;
154+
*)
155+
curl -L -C - "$distribution_url" | tar -xzf -
156+
;;
157+
esac
158+
elif command -v wget > /dev/null 2>&1; then
159+
write "Using wget to download $distribution_url"
160+
case "$distribution_url" in
161+
*.zip)
162+
distribution_name=${distribution_url##*/}
163+
wget -c "$distribution_url" -O "$distribution_name"
164+
tar -xzf "$distribution_name"
165+
;;
166+
*)
167+
wget -qO- -c "$distribution_url" | tar -xzf -
168+
;;
169+
esac
170+
else
171+
die "ERROR: Neither curl nor wget are installed, Could not set up JAVA_HOME"
172+
fi
173+
cd - > /dev/null || die "failed to change dir to old pwd: $OLDPWD"
174+
175+
# Finding the java_home
176+
java_home=$(get_java_home "$in_progress_dir")
177+
"$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"
178+
write "Successfully installed JDK distribution in $jdk_installation_directory"
179+
done
180+
}

gradle/gradle-jdks-setup.jar

111 KB
Binary file not shown.

gradle/gradle-jdks-setup.sh

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/bin/sh
2+
#
3+
# (c) Copyright 2024 Palantir Technologies Inc. All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
##############################################################################
19+
#
20+
# Gradle jdk set up script for POSIX generated by gradle-jdks.
21+
#
22+
# This script does the following:
23+
# (1) Downloads all the JDK distributions that are present in `gradle/jdks`
24+
# (2) Installs the distributions in a temporary directory
25+
# (3) Calls the java class `GradleJdkInstallationSetup` that will move each distribution to
26+
# `$GRADLE_USER_HOME/${local_path}` based on the local_path=`gradle/jdks/${majorVersion}/${os}/${arch}/local_path`
27+
# and it will set up the certificates based on `gradle/certs` entries for the locally installed distribution
28+
# (4) Sets `org.gradle.java.home` to the JDK distribution that is used by the Gradle Daemon
29+
#
30+
#
31+
# Important for running:
32+
# This script requires all of these POSIX shell features:
33+
# * functions;
34+
# * expansions «$var», «${var}», «${var%suffix}», and «$( cmd )»;
35+
# * compound commands having a testable exit status, especially «case»;
36+
# * various built-in commands including «command» and «set».
37+
#
38+
##############################################################################
39+
40+
set -e
41+
# Set pipefail if it works in a subshell, disregard if unsupported
42+
# shellcheck disable=SC3040
43+
if (set -o pipefail 2>/dev/null); then
44+
set -o pipefail
45+
fi
46+
47+
# Resolve links: $0 may be a link
48+
app_path=$0
49+
50+
# Need this for daisy-chained symlinks.
51+
while
52+
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
53+
[ -h "$app_path" ]
54+
do
55+
ls=$( ls -ld "$app_path" )
56+
link=${ls#*' -> '}
57+
case $link in #(
58+
/*) app_path=$link ;; #(
59+
*) app_path=$APP_HOME$link ;;
60+
esac
61+
done
62+
63+
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
64+
APP_HOME=${APP_HOME%/gradle}
65+
APP_GRADLE_DIR="$APP_HOME"/gradle
66+
67+
# Loading gradle jdk functions
68+
. "$APP_GRADLE_DIR"/gradle-jdks-functions.sh
69+
70+
if ! $(is_arch_os_supported); then
71+
echo "Skipping Gradle JDKs Setup, Unsupported OS/Arch..."
72+
cleanup
73+
return
74+
fi
75+
76+
install_and_setup_jdks "$APP_GRADLE_DIR"
77+
78+
gradle_daemon_jdk_version=$(read_value "$APP_GRADLE_DIR"/gradle-daemon-jdk-version)
79+
gradle_daemon_jdk_distribution_local_path=$(read_value "$APP_GRADLE_DIR"/jdks/"$gradle_daemon_jdk_version"/"$OS"/"$ARCH"/local-path)
80+
"$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"
81+
82+
# [Used by ./gradlew only] Setting the Gradle Daemon Java Home to the JDK distribution
83+
export GRADLE_DAEMON_JDK="$GRADLE_JDKS_HOME/$gradle_daemon_jdk_distribution_local_path"
84+
set -- "-Dorg.gradle.java.home=$GRADLE_DAEMON_JDK" "$@"
85+
86+
cleanup
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://corretto.aws/downloads/resources/17.0.12.7.1/amazon-corretto-17.0.12.7.1-linux-aarch64.tar.gz
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
amazon-corretto-17.0.12.7.1-glibc
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://corretto.aws/downloads/resources/17.0.12.7.1/amazon-corretto-17.0.12.7.1-linux-x64.tar.gz

0 commit comments

Comments
 (0)