diff --git a/.github/workflows/code_completion_plugin_tests.yml b/.github/workflows/code_completion_plugin_tests.yml index b183385383be..b06836bc6ee2 100644 --- a/.github/workflows/code_completion_plugin_tests.yml +++ b/.github/workflows/code_completion_plugin_tests.yml @@ -90,7 +90,7 @@ jobs: echo "version=$VERSION" >> $GITHUB_OUTPUT echo "name=$NAME" >> $GITHUB_OUTPUT echo "pluginVerifierHomeDir=~/.pluginVerifier" >> $GITHUB_OUTPUT - + echo "changelog<> $GITHUB_OUTPUT echo "$CHANGELOG" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT diff --git a/.gitignore b/.gitignore index 2bad81975ba0..e2a846750071 100644 --- a/.gitignore +++ b/.gitignore @@ -154,3 +154,7 @@ playground/cloudfunction.zip # Ignore .test-infra/metrics/github_runs_prefetcher/code.zip # as its generated with terraform .test-infra/metrics/sync/github/github_runs_prefetcher/code.zip + +# Ignore Gradle wrapper jar file and checksum files +**/gradle/wrapper/gradle-wrapper.jar +**/gradle/wrapper/gradle-wrapper-*.sha256 diff --git a/gradle/gradlew-include.ps1 b/gradle/gradlew-include.ps1 new file mode 100644 index 000000000000..16483e18a8a8 --- /dev/null +++ b/gradle/gradlew-include.ps1 @@ -0,0 +1,134 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +# Binary, especially executable binary files, shall not be in the source tree of any Apache project. +# Gradle usually requires a `gradle-wrapper.jar` file to be present in the source tree. +# This script, included from `gradlew` downloads the gradle-wrapper.jar if necessary and verifies its integrity. +# The `gradle-wrapper.jar` and its checksum are downloaded from two well-known locations. + +# This fixes an issue that Get-FileHash works fine "out of the box" on older Windows version, but fails on +# newer ones. More info via https://github.com/actions/runner-images/issues/225 +Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + +# Extract the Gradle version from gradle-wrapper.properties using a regular expression. +$GradlePropertiesPath = Join-Path -Path $env:APP_HOME -ChildPath "gradle\wrapper\gradle-wrapper.properties" +if (-not (Test-Path $GradlePropertiesPath)) { + Write-Error "Gradle properties file not found: $GradlePropertiesPath" + exit 1 +} + +# Read the content and use a regex match to capture the version number. +# Bash regex: 's/^.*gradle-\([0-9.]*\)-[a-z]*.zip$/\1/' +# PowerShell equivalent: Match the distributionUrl line, then capture the version group. +$GRADLE_DIST_VERSION = ( +Select-String -Path $GradlePropertiesPath -CaseSensitive ` + -Pattern 'distributionUrl=' | + ForEach-Object { + if ($_ -match 'gradle-([\d.]+)-[a-z]+\.zip') { + $Matches[1] + } + } +) + +# Define file paths +$GRADLE_WRAPPER_SHA256 = Join-Path -Path $env:APP_HOME -ChildPath "gradle\wrapper\gradle-wrapper-$GRADLE_DIST_VERSION.jar.sha256" +$GRADLE_WRAPPER_JAR = Join-Path -Path $env:APP_HOME -ChildPath "gradle\wrapper\gradle-wrapper.jar" + +# Checksum Verification and Cleanup +# If the checksum file does not exist, delete the wrapper jar. +if (-not (Test-Path $GRADLE_WRAPPER_SHA256)) { + Remove-Item -Path $GRADLE_WRAPPER_JAR -Force -ErrorAction SilentlyContinue +} + +# If the wrapper jar exists, verify its checksum. +if (Test-Path $GRADLE_WRAPPER_JAR) { + try { + # Calculate the SHA256 hash of the existing wrapper JAR. + # Get-FileHash is the native PowerShell equivalent for sha256sum. + $JarHashObject = Get-FileHash -Path $GRADLE_WRAPPER_JAR -Algorithm SHA256 + $JAR_CHECKSUM = $JarHashObject.Hash.ToLower() # Hash is uppercase by default, convert to lowercase + + # Read the expected checksum from the file. + # Note: 'cat' is an alias for Get-Content in PowerShell. + $EXPECTED = (Get-Content -Path $GRADLE_WRAPPER_SHA256 -Raw).Trim().ToLower() + + # Compare checksums and delete files if they do not match. + if ($JAR_CHECKSUM -ne $EXPECTED) { + Write-Warning "Checksum mismatch. Deleting $GRADLE_WRAPPER_JAR and $GRADLE_WRAPPER_SHA256." + Remove-Item -Path $GRADLE_WRAPPER_JAR -Force -ErrorAction SilentlyContinue + Remove-Item -Path $GRADLE_WRAPPER_SHA256 -Force -ErrorAction SilentlyContinue + } + } catch { + # Handle cases where Get-Content or Get-FileHash might fail (e.g., file deleted during operation). + Write-Warning "Error during checksum verification: $($_.Exception.Message)" + Remove-Item -Path $GRADLE_WRAPPER_JAR -Force -ErrorAction SilentlyContinue + Remove-Item -Path $GRADLE_WRAPPER_SHA256 -Force -ErrorAction SilentlyContinue + } +} + +# Download Checksum File +# If the checksum file is missing, download it. +if (-not (Test-Path $GRADLE_WRAPPER_SHA256)) { + $Sha256DownloadUrl = "https://services.gradle.org/distributions/gradle-$GRADLE_DIST_VERSION-wrapper.jar.sha256" + Write-Host "Downloading SHA256 checksum from $Sha256DownloadUrl" + # Invoke-WebRequest is the native PowerShell equivalent for curl --location --output. + try { + Invoke-WebRequest -Uri $Sha256DownloadUrl -OutFile $GRADLE_WRAPPER_SHA256 -UseBasicParsing -ErrorAction Stop + } catch { + Write-Error "Failed to download SHA256 checksum: $($_.Exception.Message)" + exit 1 + } +} + +# Download Wrapper JAR and Final Verification +# If the wrapper jar is missing, download it. +if (-not (Test-Path $GRADLE_WRAPPER_JAR)) { + # The original script handles a case where the version might be like 'x.y' and needs 'x.y.0'. + # Bash sed: 's/^\([0-9]*[.][0-9]*\)$/\1.0/' + # PowerShell equivalent using regex replacement. + $GRADLE_VERSION = $GRADLE_DIST_VERSION + if ($GRADLE_DIST_VERSION -match '^\d+\.\d+$') { + $GRADLE_VERSION = "$GRADLE_DIST_VERSION.0" + } + + $JarDownloadUrl = "https://raw.githubusercontent.com/gradle/gradle/v$GRADLE_VERSION/gradle/wrapper/gradle-wrapper.jar" + Write-Host "Downloading wrapper JAR from $JarDownloadUrl" + + try { + Invoke-WebRequest -Uri $JarDownloadUrl -OutFile $GRADLE_WRAPPER_JAR -UseBasicParsing -ErrorAction Stop + } catch { + Write-Error "Failed to download wrapper JAR: $($_.Exception.Message)" + exit 1 + } + + # Verify the checksum of the newly downloaded JAR. + try { + $JarHashObject = Get-FileHash -Path $GRADLE_WRAPPER_JAR -Algorithm SHA256 + $JAR_CHECKSUM = $JarHashObject.Hash.ToLower() + $EXPECTED = (Get-Content -Path $GRADLE_WRAPPER_SHA256 -Raw).Trim().ToLower() + + if ($JAR_CHECKSUM -ne $EXPECTED) { + # Critical failure: downloaded file does not match its expected checksum. + Write-Error "Expected sha256 of the downloaded $GRADLE_WRAPPER_JAR does not match the downloaded sha256!" + exit 1 + } + } catch { + Write-Error "Error during final checksum verification: $($_.Exception.Message)" + exit 1 + } +} \ No newline at end of file diff --git a/gradle/gradlew-include.sh b/gradle/gradlew-include.sh new file mode 100644 index 000000000000..0c4fe3fa32b4 --- /dev/null +++ b/gradle/gradlew-include.sh @@ -0,0 +1,67 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +# Binary, especially executable binary files, shall not be in the source tree of any Apache project. +# Gradle usually requires a `gradle-wrapper.jar` file to be present in the source tree. +# This script, included from `gradlew` downloads the gradle-wrapper.jar if necessary and verifies its integrity. +# The `gradle-wrapper.jar` and its checksum are downloaded from two well-known locations. + +# Extract the Gradle version from gradle-wrapper.properties. +GRADLE_DIST_VERSION="$(grep distributionUrl= "$APP_HOME/gradle/wrapper/gradle-wrapper.properties" | sed 's/^.*gradle-\([0-9.]*\)-[a-z]*.zip$/\1/')" +GRADLE_WRAPPER_SHA256="$APP_HOME/gradle/wrapper/gradle-wrapper-${GRADLE_DIST_VERSION}.jar.sha256" +GRADLE_WRAPPER_JAR="$APP_HOME/gradle/wrapper/gradle-wrapper.jar" +if [ -x "$(command -v sha256sum)" ] ; then + SHASUM="sha256sum" +else + if [ -x "$(command -v shasum)" ] ; then + SHASUM="shasum -a 256" + else + echo "Neither sha256sum nor shasum are available, install either." > /dev/stderr + exit 1 + fi +fi +if [ ! -e "${GRADLE_WRAPPER_SHA256}" ]; then + # Delete the wrapper jar, if the checksum file does not exist. + rm -f "${GRADLE_WRAPPER_JAR}" +fi +if [ -e "${GRADLE_WRAPPER_JAR}" ]; then + # Verify the wrapper jar, if it exists, delete wrapper jar and checksum file, if the checksums + # do not match. + JAR_CHECKSUM="$(${SHASUM} "${GRADLE_WRAPPER_JAR}" | cut -d\ -f1)" + EXPECTED="$(cat "${GRADLE_WRAPPER_SHA256}")" + if [ "${JAR_CHECKSUM}" != "${EXPECTED}" ]; then + rm -f "${GRADLE_WRAPPER_JAR}" "${GRADLE_WRAPPER_SHA256}" + fi +fi +if [ ! -e "${GRADLE_WRAPPER_SHA256}" ]; then + curl --location --output "${GRADLE_WRAPPER_SHA256}" https://services.gradle.org/distributions/gradle-${GRADLE_DIST_VERSION}-wrapper.jar.sha256 || exit 1 +fi +if [ ! -e "${GRADLE_WRAPPER_JAR}" ]; then + # The Gradle version extracted from the `distributionUrl` property does not contain ".0" patch + # versions. Need to append a ".0" in that case to download the wrapper jar. + GRADLE_VERSION="$(echo "$GRADLE_DIST_VERSION" | sed 's/^\([0-9]*[.][0-9]*\)$/\1.0/')" + curl --location --output "${GRADLE_WRAPPER_JAR}" https://raw.githubusercontent.com/gradle/gradle/v${GRADLE_VERSION}/gradle/wrapper/gradle-wrapper.jar || exit 1 + JAR_CHECKSUM="$(${SHASUM} "${GRADLE_WRAPPER_JAR}" | cut -d\ -f1)" + EXPECTED="$(cat "${GRADLE_WRAPPER_SHA256}")" + if [ "${JAR_CHECKSUM}" != "${EXPECTED}" ]; then + # If the (just downloaded) checksum and the downloaded wrapper jar do not match, something + # really bad is going on. + echo "Expected sha256 of the downloaded gradle-wrapper.jar does not match the downloaded sha256!" > /dev/stderr + exit 1 + fi +fi diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 7f93135c49b7..000000000000 Binary files a/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/gradlew b/gradlew index 1aa94a426907..61ec480bca43 100755 --- a/gradlew +++ b/gradlew @@ -86,6 +86,8 @@ APP_BASE_NAME=${0##*/} # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit +. ${APP_HOME}/gradle/gradlew-include.sh + # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum diff --git a/gradlew.bat b/gradlew.bat index 93e3f59f135d..d0bc6612197a 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -30,6 +30,8 @@ if "%DIRNAME%"=="" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +powershell -file "%APP_HOME%\gradle\gradlew-include.ps1" + @rem Resolve any "." and ".." in APP_HOME to make it shorter. for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi diff --git a/learning/katas/java/gradle/gradlew-include.ps1 b/learning/katas/java/gradle/gradlew-include.ps1 new file mode 100644 index 000000000000..16483e18a8a8 --- /dev/null +++ b/learning/katas/java/gradle/gradlew-include.ps1 @@ -0,0 +1,134 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +# Binary, especially executable binary files, shall not be in the source tree of any Apache project. +# Gradle usually requires a `gradle-wrapper.jar` file to be present in the source tree. +# This script, included from `gradlew` downloads the gradle-wrapper.jar if necessary and verifies its integrity. +# The `gradle-wrapper.jar` and its checksum are downloaded from two well-known locations. + +# This fixes an issue that Get-FileHash works fine "out of the box" on older Windows version, but fails on +# newer ones. More info via https://github.com/actions/runner-images/issues/225 +Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + +# Extract the Gradle version from gradle-wrapper.properties using a regular expression. +$GradlePropertiesPath = Join-Path -Path $env:APP_HOME -ChildPath "gradle\wrapper\gradle-wrapper.properties" +if (-not (Test-Path $GradlePropertiesPath)) { + Write-Error "Gradle properties file not found: $GradlePropertiesPath" + exit 1 +} + +# Read the content and use a regex match to capture the version number. +# Bash regex: 's/^.*gradle-\([0-9.]*\)-[a-z]*.zip$/\1/' +# PowerShell equivalent: Match the distributionUrl line, then capture the version group. +$GRADLE_DIST_VERSION = ( +Select-String -Path $GradlePropertiesPath -CaseSensitive ` + -Pattern 'distributionUrl=' | + ForEach-Object { + if ($_ -match 'gradle-([\d.]+)-[a-z]+\.zip') { + $Matches[1] + } + } +) + +# Define file paths +$GRADLE_WRAPPER_SHA256 = Join-Path -Path $env:APP_HOME -ChildPath "gradle\wrapper\gradle-wrapper-$GRADLE_DIST_VERSION.jar.sha256" +$GRADLE_WRAPPER_JAR = Join-Path -Path $env:APP_HOME -ChildPath "gradle\wrapper\gradle-wrapper.jar" + +# Checksum Verification and Cleanup +# If the checksum file does not exist, delete the wrapper jar. +if (-not (Test-Path $GRADLE_WRAPPER_SHA256)) { + Remove-Item -Path $GRADLE_WRAPPER_JAR -Force -ErrorAction SilentlyContinue +} + +# If the wrapper jar exists, verify its checksum. +if (Test-Path $GRADLE_WRAPPER_JAR) { + try { + # Calculate the SHA256 hash of the existing wrapper JAR. + # Get-FileHash is the native PowerShell equivalent for sha256sum. + $JarHashObject = Get-FileHash -Path $GRADLE_WRAPPER_JAR -Algorithm SHA256 + $JAR_CHECKSUM = $JarHashObject.Hash.ToLower() # Hash is uppercase by default, convert to lowercase + + # Read the expected checksum from the file. + # Note: 'cat' is an alias for Get-Content in PowerShell. + $EXPECTED = (Get-Content -Path $GRADLE_WRAPPER_SHA256 -Raw).Trim().ToLower() + + # Compare checksums and delete files if they do not match. + if ($JAR_CHECKSUM -ne $EXPECTED) { + Write-Warning "Checksum mismatch. Deleting $GRADLE_WRAPPER_JAR and $GRADLE_WRAPPER_SHA256." + Remove-Item -Path $GRADLE_WRAPPER_JAR -Force -ErrorAction SilentlyContinue + Remove-Item -Path $GRADLE_WRAPPER_SHA256 -Force -ErrorAction SilentlyContinue + } + } catch { + # Handle cases where Get-Content or Get-FileHash might fail (e.g., file deleted during operation). + Write-Warning "Error during checksum verification: $($_.Exception.Message)" + Remove-Item -Path $GRADLE_WRAPPER_JAR -Force -ErrorAction SilentlyContinue + Remove-Item -Path $GRADLE_WRAPPER_SHA256 -Force -ErrorAction SilentlyContinue + } +} + +# Download Checksum File +# If the checksum file is missing, download it. +if (-not (Test-Path $GRADLE_WRAPPER_SHA256)) { + $Sha256DownloadUrl = "https://services.gradle.org/distributions/gradle-$GRADLE_DIST_VERSION-wrapper.jar.sha256" + Write-Host "Downloading SHA256 checksum from $Sha256DownloadUrl" + # Invoke-WebRequest is the native PowerShell equivalent for curl --location --output. + try { + Invoke-WebRequest -Uri $Sha256DownloadUrl -OutFile $GRADLE_WRAPPER_SHA256 -UseBasicParsing -ErrorAction Stop + } catch { + Write-Error "Failed to download SHA256 checksum: $($_.Exception.Message)" + exit 1 + } +} + +# Download Wrapper JAR and Final Verification +# If the wrapper jar is missing, download it. +if (-not (Test-Path $GRADLE_WRAPPER_JAR)) { + # The original script handles a case where the version might be like 'x.y' and needs 'x.y.0'. + # Bash sed: 's/^\([0-9]*[.][0-9]*\)$/\1.0/' + # PowerShell equivalent using regex replacement. + $GRADLE_VERSION = $GRADLE_DIST_VERSION + if ($GRADLE_DIST_VERSION -match '^\d+\.\d+$') { + $GRADLE_VERSION = "$GRADLE_DIST_VERSION.0" + } + + $JarDownloadUrl = "https://raw.githubusercontent.com/gradle/gradle/v$GRADLE_VERSION/gradle/wrapper/gradle-wrapper.jar" + Write-Host "Downloading wrapper JAR from $JarDownloadUrl" + + try { + Invoke-WebRequest -Uri $JarDownloadUrl -OutFile $GRADLE_WRAPPER_JAR -UseBasicParsing -ErrorAction Stop + } catch { + Write-Error "Failed to download wrapper JAR: $($_.Exception.Message)" + exit 1 + } + + # Verify the checksum of the newly downloaded JAR. + try { + $JarHashObject = Get-FileHash -Path $GRADLE_WRAPPER_JAR -Algorithm SHA256 + $JAR_CHECKSUM = $JarHashObject.Hash.ToLower() + $EXPECTED = (Get-Content -Path $GRADLE_WRAPPER_SHA256 -Raw).Trim().ToLower() + + if ($JAR_CHECKSUM -ne $EXPECTED) { + # Critical failure: downloaded file does not match its expected checksum. + Write-Error "Expected sha256 of the downloaded $GRADLE_WRAPPER_JAR does not match the downloaded sha256!" + exit 1 + } + } catch { + Write-Error "Error during final checksum verification: $($_.Exception.Message)" + exit 1 + } +} \ No newline at end of file diff --git a/learning/katas/java/gradle/gradlew-include.sh b/learning/katas/java/gradle/gradlew-include.sh new file mode 100644 index 000000000000..0c4fe3fa32b4 --- /dev/null +++ b/learning/katas/java/gradle/gradlew-include.sh @@ -0,0 +1,67 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +# Binary, especially executable binary files, shall not be in the source tree of any Apache project. +# Gradle usually requires a `gradle-wrapper.jar` file to be present in the source tree. +# This script, included from `gradlew` downloads the gradle-wrapper.jar if necessary and verifies its integrity. +# The `gradle-wrapper.jar` and its checksum are downloaded from two well-known locations. + +# Extract the Gradle version from gradle-wrapper.properties. +GRADLE_DIST_VERSION="$(grep distributionUrl= "$APP_HOME/gradle/wrapper/gradle-wrapper.properties" | sed 's/^.*gradle-\([0-9.]*\)-[a-z]*.zip$/\1/')" +GRADLE_WRAPPER_SHA256="$APP_HOME/gradle/wrapper/gradle-wrapper-${GRADLE_DIST_VERSION}.jar.sha256" +GRADLE_WRAPPER_JAR="$APP_HOME/gradle/wrapper/gradle-wrapper.jar" +if [ -x "$(command -v sha256sum)" ] ; then + SHASUM="sha256sum" +else + if [ -x "$(command -v shasum)" ] ; then + SHASUM="shasum -a 256" + else + echo "Neither sha256sum nor shasum are available, install either." > /dev/stderr + exit 1 + fi +fi +if [ ! -e "${GRADLE_WRAPPER_SHA256}" ]; then + # Delete the wrapper jar, if the checksum file does not exist. + rm -f "${GRADLE_WRAPPER_JAR}" +fi +if [ -e "${GRADLE_WRAPPER_JAR}" ]; then + # Verify the wrapper jar, if it exists, delete wrapper jar and checksum file, if the checksums + # do not match. + JAR_CHECKSUM="$(${SHASUM} "${GRADLE_WRAPPER_JAR}" | cut -d\ -f1)" + EXPECTED="$(cat "${GRADLE_WRAPPER_SHA256}")" + if [ "${JAR_CHECKSUM}" != "${EXPECTED}" ]; then + rm -f "${GRADLE_WRAPPER_JAR}" "${GRADLE_WRAPPER_SHA256}" + fi +fi +if [ ! -e "${GRADLE_WRAPPER_SHA256}" ]; then + curl --location --output "${GRADLE_WRAPPER_SHA256}" https://services.gradle.org/distributions/gradle-${GRADLE_DIST_VERSION}-wrapper.jar.sha256 || exit 1 +fi +if [ ! -e "${GRADLE_WRAPPER_JAR}" ]; then + # The Gradle version extracted from the `distributionUrl` property does not contain ".0" patch + # versions. Need to append a ".0" in that case to download the wrapper jar. + GRADLE_VERSION="$(echo "$GRADLE_DIST_VERSION" | sed 's/^\([0-9]*[.][0-9]*\)$/\1.0/')" + curl --location --output "${GRADLE_WRAPPER_JAR}" https://raw.githubusercontent.com/gradle/gradle/v${GRADLE_VERSION}/gradle/wrapper/gradle-wrapper.jar || exit 1 + JAR_CHECKSUM="$(${SHASUM} "${GRADLE_WRAPPER_JAR}" | cut -d\ -f1)" + EXPECTED="$(cat "${GRADLE_WRAPPER_SHA256}")" + if [ "${JAR_CHECKSUM}" != "${EXPECTED}" ]; then + # If the (just downloaded) checksum and the downloaded wrapper jar do not match, something + # really bad is going on. + echo "Expected sha256 of the downloaded gradle-wrapper.jar does not match the downloaded sha256!" > /dev/stderr + exit 1 + fi +fi diff --git a/learning/katas/java/gradle/wrapper/gradle-wrapper.jar b/learning/katas/java/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 87b738cbd051..000000000000 Binary files a/learning/katas/java/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/learning/katas/java/gradlew b/learning/katas/java/gradlew index 9e22af61aebe..8ec59e818d38 100755 --- a/learning/katas/java/gradlew +++ b/learning/katas/java/gradlew @@ -42,6 +42,8 @@ cd "`dirname \"$PRG\"`/" >/dev/null APP_HOME="`pwd -P`" cd "$SAVED" >/dev/null +. ${APP_HOME}/gradle/gradlew-include.sh + APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` diff --git a/learning/katas/java/gradlew.bat b/learning/katas/java/gradlew.bat index 582415fa0b48..bf3ab9c9ce57 100644 --- a/learning/katas/java/gradlew.bat +++ b/learning/katas/java/gradlew.bat @@ -31,6 +31,8 @@ if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +powershell -file "%APP_HOME%\gradle\gradlew-include.ps1" + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS= diff --git a/learning/katas/kotlin/gradle/gradlew-include.ps1 b/learning/katas/kotlin/gradle/gradlew-include.ps1 new file mode 100644 index 000000000000..16483e18a8a8 --- /dev/null +++ b/learning/katas/kotlin/gradle/gradlew-include.ps1 @@ -0,0 +1,134 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +# Binary, especially executable binary files, shall not be in the source tree of any Apache project. +# Gradle usually requires a `gradle-wrapper.jar` file to be present in the source tree. +# This script, included from `gradlew` downloads the gradle-wrapper.jar if necessary and verifies its integrity. +# The `gradle-wrapper.jar` and its checksum are downloaded from two well-known locations. + +# This fixes an issue that Get-FileHash works fine "out of the box" on older Windows version, but fails on +# newer ones. More info via https://github.com/actions/runner-images/issues/225 +Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + +# Extract the Gradle version from gradle-wrapper.properties using a regular expression. +$GradlePropertiesPath = Join-Path -Path $env:APP_HOME -ChildPath "gradle\wrapper\gradle-wrapper.properties" +if (-not (Test-Path $GradlePropertiesPath)) { + Write-Error "Gradle properties file not found: $GradlePropertiesPath" + exit 1 +} + +# Read the content and use a regex match to capture the version number. +# Bash regex: 's/^.*gradle-\([0-9.]*\)-[a-z]*.zip$/\1/' +# PowerShell equivalent: Match the distributionUrl line, then capture the version group. +$GRADLE_DIST_VERSION = ( +Select-String -Path $GradlePropertiesPath -CaseSensitive ` + -Pattern 'distributionUrl=' | + ForEach-Object { + if ($_ -match 'gradle-([\d.]+)-[a-z]+\.zip') { + $Matches[1] + } + } +) + +# Define file paths +$GRADLE_WRAPPER_SHA256 = Join-Path -Path $env:APP_HOME -ChildPath "gradle\wrapper\gradle-wrapper-$GRADLE_DIST_VERSION.jar.sha256" +$GRADLE_WRAPPER_JAR = Join-Path -Path $env:APP_HOME -ChildPath "gradle\wrapper\gradle-wrapper.jar" + +# Checksum Verification and Cleanup +# If the checksum file does not exist, delete the wrapper jar. +if (-not (Test-Path $GRADLE_WRAPPER_SHA256)) { + Remove-Item -Path $GRADLE_WRAPPER_JAR -Force -ErrorAction SilentlyContinue +} + +# If the wrapper jar exists, verify its checksum. +if (Test-Path $GRADLE_WRAPPER_JAR) { + try { + # Calculate the SHA256 hash of the existing wrapper JAR. + # Get-FileHash is the native PowerShell equivalent for sha256sum. + $JarHashObject = Get-FileHash -Path $GRADLE_WRAPPER_JAR -Algorithm SHA256 + $JAR_CHECKSUM = $JarHashObject.Hash.ToLower() # Hash is uppercase by default, convert to lowercase + + # Read the expected checksum from the file. + # Note: 'cat' is an alias for Get-Content in PowerShell. + $EXPECTED = (Get-Content -Path $GRADLE_WRAPPER_SHA256 -Raw).Trim().ToLower() + + # Compare checksums and delete files if they do not match. + if ($JAR_CHECKSUM -ne $EXPECTED) { + Write-Warning "Checksum mismatch. Deleting $GRADLE_WRAPPER_JAR and $GRADLE_WRAPPER_SHA256." + Remove-Item -Path $GRADLE_WRAPPER_JAR -Force -ErrorAction SilentlyContinue + Remove-Item -Path $GRADLE_WRAPPER_SHA256 -Force -ErrorAction SilentlyContinue + } + } catch { + # Handle cases where Get-Content or Get-FileHash might fail (e.g., file deleted during operation). + Write-Warning "Error during checksum verification: $($_.Exception.Message)" + Remove-Item -Path $GRADLE_WRAPPER_JAR -Force -ErrorAction SilentlyContinue + Remove-Item -Path $GRADLE_WRAPPER_SHA256 -Force -ErrorAction SilentlyContinue + } +} + +# Download Checksum File +# If the checksum file is missing, download it. +if (-not (Test-Path $GRADLE_WRAPPER_SHA256)) { + $Sha256DownloadUrl = "https://services.gradle.org/distributions/gradle-$GRADLE_DIST_VERSION-wrapper.jar.sha256" + Write-Host "Downloading SHA256 checksum from $Sha256DownloadUrl" + # Invoke-WebRequest is the native PowerShell equivalent for curl --location --output. + try { + Invoke-WebRequest -Uri $Sha256DownloadUrl -OutFile $GRADLE_WRAPPER_SHA256 -UseBasicParsing -ErrorAction Stop + } catch { + Write-Error "Failed to download SHA256 checksum: $($_.Exception.Message)" + exit 1 + } +} + +# Download Wrapper JAR and Final Verification +# If the wrapper jar is missing, download it. +if (-not (Test-Path $GRADLE_WRAPPER_JAR)) { + # The original script handles a case where the version might be like 'x.y' and needs 'x.y.0'. + # Bash sed: 's/^\([0-9]*[.][0-9]*\)$/\1.0/' + # PowerShell equivalent using regex replacement. + $GRADLE_VERSION = $GRADLE_DIST_VERSION + if ($GRADLE_DIST_VERSION -match '^\d+\.\d+$') { + $GRADLE_VERSION = "$GRADLE_DIST_VERSION.0" + } + + $JarDownloadUrl = "https://raw.githubusercontent.com/gradle/gradle/v$GRADLE_VERSION/gradle/wrapper/gradle-wrapper.jar" + Write-Host "Downloading wrapper JAR from $JarDownloadUrl" + + try { + Invoke-WebRequest -Uri $JarDownloadUrl -OutFile $GRADLE_WRAPPER_JAR -UseBasicParsing -ErrorAction Stop + } catch { + Write-Error "Failed to download wrapper JAR: $($_.Exception.Message)" + exit 1 + } + + # Verify the checksum of the newly downloaded JAR. + try { + $JarHashObject = Get-FileHash -Path $GRADLE_WRAPPER_JAR -Algorithm SHA256 + $JAR_CHECKSUM = $JarHashObject.Hash.ToLower() + $EXPECTED = (Get-Content -Path $GRADLE_WRAPPER_SHA256 -Raw).Trim().ToLower() + + if ($JAR_CHECKSUM -ne $EXPECTED) { + # Critical failure: downloaded file does not match its expected checksum. + Write-Error "Expected sha256 of the downloaded $GRADLE_WRAPPER_JAR does not match the downloaded sha256!" + exit 1 + } + } catch { + Write-Error "Error during final checksum verification: $($_.Exception.Message)" + exit 1 + } +} \ No newline at end of file diff --git a/learning/katas/kotlin/gradle/gradlew-include.sh b/learning/katas/kotlin/gradle/gradlew-include.sh new file mode 100644 index 000000000000..0c4fe3fa32b4 --- /dev/null +++ b/learning/katas/kotlin/gradle/gradlew-include.sh @@ -0,0 +1,67 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +# Binary, especially executable binary files, shall not be in the source tree of any Apache project. +# Gradle usually requires a `gradle-wrapper.jar` file to be present in the source tree. +# This script, included from `gradlew` downloads the gradle-wrapper.jar if necessary and verifies its integrity. +# The `gradle-wrapper.jar` and its checksum are downloaded from two well-known locations. + +# Extract the Gradle version from gradle-wrapper.properties. +GRADLE_DIST_VERSION="$(grep distributionUrl= "$APP_HOME/gradle/wrapper/gradle-wrapper.properties" | sed 's/^.*gradle-\([0-9.]*\)-[a-z]*.zip$/\1/')" +GRADLE_WRAPPER_SHA256="$APP_HOME/gradle/wrapper/gradle-wrapper-${GRADLE_DIST_VERSION}.jar.sha256" +GRADLE_WRAPPER_JAR="$APP_HOME/gradle/wrapper/gradle-wrapper.jar" +if [ -x "$(command -v sha256sum)" ] ; then + SHASUM="sha256sum" +else + if [ -x "$(command -v shasum)" ] ; then + SHASUM="shasum -a 256" + else + echo "Neither sha256sum nor shasum are available, install either." > /dev/stderr + exit 1 + fi +fi +if [ ! -e "${GRADLE_WRAPPER_SHA256}" ]; then + # Delete the wrapper jar, if the checksum file does not exist. + rm -f "${GRADLE_WRAPPER_JAR}" +fi +if [ -e "${GRADLE_WRAPPER_JAR}" ]; then + # Verify the wrapper jar, if it exists, delete wrapper jar and checksum file, if the checksums + # do not match. + JAR_CHECKSUM="$(${SHASUM} "${GRADLE_WRAPPER_JAR}" | cut -d\ -f1)" + EXPECTED="$(cat "${GRADLE_WRAPPER_SHA256}")" + if [ "${JAR_CHECKSUM}" != "${EXPECTED}" ]; then + rm -f "${GRADLE_WRAPPER_JAR}" "${GRADLE_WRAPPER_SHA256}" + fi +fi +if [ ! -e "${GRADLE_WRAPPER_SHA256}" ]; then + curl --location --output "${GRADLE_WRAPPER_SHA256}" https://services.gradle.org/distributions/gradle-${GRADLE_DIST_VERSION}-wrapper.jar.sha256 || exit 1 +fi +if [ ! -e "${GRADLE_WRAPPER_JAR}" ]; then + # The Gradle version extracted from the `distributionUrl` property does not contain ".0" patch + # versions. Need to append a ".0" in that case to download the wrapper jar. + GRADLE_VERSION="$(echo "$GRADLE_DIST_VERSION" | sed 's/^\([0-9]*[.][0-9]*\)$/\1.0/')" + curl --location --output "${GRADLE_WRAPPER_JAR}" https://raw.githubusercontent.com/gradle/gradle/v${GRADLE_VERSION}/gradle/wrapper/gradle-wrapper.jar || exit 1 + JAR_CHECKSUM="$(${SHASUM} "${GRADLE_WRAPPER_JAR}" | cut -d\ -f1)" + EXPECTED="$(cat "${GRADLE_WRAPPER_SHA256}")" + if [ "${JAR_CHECKSUM}" != "${EXPECTED}" ]; then + # If the (just downloaded) checksum and the downloaded wrapper jar do not match, something + # really bad is going on. + echo "Expected sha256 of the downloaded gradle-wrapper.jar does not match the downloaded sha256!" > /dev/stderr + exit 1 + fi +fi diff --git a/learning/katas/kotlin/gradle/wrapper/gradle-wrapper.jar b/learning/katas/kotlin/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 87b738cbd051..000000000000 Binary files a/learning/katas/kotlin/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/learning/katas/kotlin/gradlew b/learning/katas/kotlin/gradlew index 9e22af61aebe..8ec59e818d38 100755 --- a/learning/katas/kotlin/gradlew +++ b/learning/katas/kotlin/gradlew @@ -42,6 +42,8 @@ cd "`dirname \"$PRG\"`/" >/dev/null APP_HOME="`pwd -P`" cd "$SAVED" >/dev/null +. ${APP_HOME}/gradle/gradlew-include.sh + APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` diff --git a/learning/katas/kotlin/gradlew.bat b/learning/katas/kotlin/gradlew.bat index 582415fa0b48..bf3ab9c9ce57 100644 --- a/learning/katas/kotlin/gradlew.bat +++ b/learning/katas/kotlin/gradlew.bat @@ -31,6 +31,8 @@ if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +powershell -file "%APP_HOME%\gradle\gradlew-include.ps1" + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS= diff --git a/plugins/beam-code-completion-plugin/gradle/gradlew-include.ps1 b/plugins/beam-code-completion-plugin/gradle/gradlew-include.ps1 new file mode 100644 index 000000000000..16483e18a8a8 --- /dev/null +++ b/plugins/beam-code-completion-plugin/gradle/gradlew-include.ps1 @@ -0,0 +1,134 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +# Binary, especially executable binary files, shall not be in the source tree of any Apache project. +# Gradle usually requires a `gradle-wrapper.jar` file to be present in the source tree. +# This script, included from `gradlew` downloads the gradle-wrapper.jar if necessary and verifies its integrity. +# The `gradle-wrapper.jar` and its checksum are downloaded from two well-known locations. + +# This fixes an issue that Get-FileHash works fine "out of the box" on older Windows version, but fails on +# newer ones. More info via https://github.com/actions/runner-images/issues/225 +Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + +# Extract the Gradle version from gradle-wrapper.properties using a regular expression. +$GradlePropertiesPath = Join-Path -Path $env:APP_HOME -ChildPath "gradle\wrapper\gradle-wrapper.properties" +if (-not (Test-Path $GradlePropertiesPath)) { + Write-Error "Gradle properties file not found: $GradlePropertiesPath" + exit 1 +} + +# Read the content and use a regex match to capture the version number. +# Bash regex: 's/^.*gradle-\([0-9.]*\)-[a-z]*.zip$/\1/' +# PowerShell equivalent: Match the distributionUrl line, then capture the version group. +$GRADLE_DIST_VERSION = ( +Select-String -Path $GradlePropertiesPath -CaseSensitive ` + -Pattern 'distributionUrl=' | + ForEach-Object { + if ($_ -match 'gradle-([\d.]+)-[a-z]+\.zip') { + $Matches[1] + } + } +) + +# Define file paths +$GRADLE_WRAPPER_SHA256 = Join-Path -Path $env:APP_HOME -ChildPath "gradle\wrapper\gradle-wrapper-$GRADLE_DIST_VERSION.jar.sha256" +$GRADLE_WRAPPER_JAR = Join-Path -Path $env:APP_HOME -ChildPath "gradle\wrapper\gradle-wrapper.jar" + +# Checksum Verification and Cleanup +# If the checksum file does not exist, delete the wrapper jar. +if (-not (Test-Path $GRADLE_WRAPPER_SHA256)) { + Remove-Item -Path $GRADLE_WRAPPER_JAR -Force -ErrorAction SilentlyContinue +} + +# If the wrapper jar exists, verify its checksum. +if (Test-Path $GRADLE_WRAPPER_JAR) { + try { + # Calculate the SHA256 hash of the existing wrapper JAR. + # Get-FileHash is the native PowerShell equivalent for sha256sum. + $JarHashObject = Get-FileHash -Path $GRADLE_WRAPPER_JAR -Algorithm SHA256 + $JAR_CHECKSUM = $JarHashObject.Hash.ToLower() # Hash is uppercase by default, convert to lowercase + + # Read the expected checksum from the file. + # Note: 'cat' is an alias for Get-Content in PowerShell. + $EXPECTED = (Get-Content -Path $GRADLE_WRAPPER_SHA256 -Raw).Trim().ToLower() + + # Compare checksums and delete files if they do not match. + if ($JAR_CHECKSUM -ne $EXPECTED) { + Write-Warning "Checksum mismatch. Deleting $GRADLE_WRAPPER_JAR and $GRADLE_WRAPPER_SHA256." + Remove-Item -Path $GRADLE_WRAPPER_JAR -Force -ErrorAction SilentlyContinue + Remove-Item -Path $GRADLE_WRAPPER_SHA256 -Force -ErrorAction SilentlyContinue + } + } catch { + # Handle cases where Get-Content or Get-FileHash might fail (e.g., file deleted during operation). + Write-Warning "Error during checksum verification: $($_.Exception.Message)" + Remove-Item -Path $GRADLE_WRAPPER_JAR -Force -ErrorAction SilentlyContinue + Remove-Item -Path $GRADLE_WRAPPER_SHA256 -Force -ErrorAction SilentlyContinue + } +} + +# Download Checksum File +# If the checksum file is missing, download it. +if (-not (Test-Path $GRADLE_WRAPPER_SHA256)) { + $Sha256DownloadUrl = "https://services.gradle.org/distributions/gradle-$GRADLE_DIST_VERSION-wrapper.jar.sha256" + Write-Host "Downloading SHA256 checksum from $Sha256DownloadUrl" + # Invoke-WebRequest is the native PowerShell equivalent for curl --location --output. + try { + Invoke-WebRequest -Uri $Sha256DownloadUrl -OutFile $GRADLE_WRAPPER_SHA256 -UseBasicParsing -ErrorAction Stop + } catch { + Write-Error "Failed to download SHA256 checksum: $($_.Exception.Message)" + exit 1 + } +} + +# Download Wrapper JAR and Final Verification +# If the wrapper jar is missing, download it. +if (-not (Test-Path $GRADLE_WRAPPER_JAR)) { + # The original script handles a case where the version might be like 'x.y' and needs 'x.y.0'. + # Bash sed: 's/^\([0-9]*[.][0-9]*\)$/\1.0/' + # PowerShell equivalent using regex replacement. + $GRADLE_VERSION = $GRADLE_DIST_VERSION + if ($GRADLE_DIST_VERSION -match '^\d+\.\d+$') { + $GRADLE_VERSION = "$GRADLE_DIST_VERSION.0" + } + + $JarDownloadUrl = "https://raw.githubusercontent.com/gradle/gradle/v$GRADLE_VERSION/gradle/wrapper/gradle-wrapper.jar" + Write-Host "Downloading wrapper JAR from $JarDownloadUrl" + + try { + Invoke-WebRequest -Uri $JarDownloadUrl -OutFile $GRADLE_WRAPPER_JAR -UseBasicParsing -ErrorAction Stop + } catch { + Write-Error "Failed to download wrapper JAR: $($_.Exception.Message)" + exit 1 + } + + # Verify the checksum of the newly downloaded JAR. + try { + $JarHashObject = Get-FileHash -Path $GRADLE_WRAPPER_JAR -Algorithm SHA256 + $JAR_CHECKSUM = $JarHashObject.Hash.ToLower() + $EXPECTED = (Get-Content -Path $GRADLE_WRAPPER_SHA256 -Raw).Trim().ToLower() + + if ($JAR_CHECKSUM -ne $EXPECTED) { + # Critical failure: downloaded file does not match its expected checksum. + Write-Error "Expected sha256 of the downloaded $GRADLE_WRAPPER_JAR does not match the downloaded sha256!" + exit 1 + } + } catch { + Write-Error "Error during final checksum verification: $($_.Exception.Message)" + exit 1 + } +} \ No newline at end of file diff --git a/plugins/beam-code-completion-plugin/gradle/gradlew-include.sh b/plugins/beam-code-completion-plugin/gradle/gradlew-include.sh new file mode 100644 index 000000000000..0c4fe3fa32b4 --- /dev/null +++ b/plugins/beam-code-completion-plugin/gradle/gradlew-include.sh @@ -0,0 +1,67 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +# Binary, especially executable binary files, shall not be in the source tree of any Apache project. +# Gradle usually requires a `gradle-wrapper.jar` file to be present in the source tree. +# This script, included from `gradlew` downloads the gradle-wrapper.jar if necessary and verifies its integrity. +# The `gradle-wrapper.jar` and its checksum are downloaded from two well-known locations. + +# Extract the Gradle version from gradle-wrapper.properties. +GRADLE_DIST_VERSION="$(grep distributionUrl= "$APP_HOME/gradle/wrapper/gradle-wrapper.properties" | sed 's/^.*gradle-\([0-9.]*\)-[a-z]*.zip$/\1/')" +GRADLE_WRAPPER_SHA256="$APP_HOME/gradle/wrapper/gradle-wrapper-${GRADLE_DIST_VERSION}.jar.sha256" +GRADLE_WRAPPER_JAR="$APP_HOME/gradle/wrapper/gradle-wrapper.jar" +if [ -x "$(command -v sha256sum)" ] ; then + SHASUM="sha256sum" +else + if [ -x "$(command -v shasum)" ] ; then + SHASUM="shasum -a 256" + else + echo "Neither sha256sum nor shasum are available, install either." > /dev/stderr + exit 1 + fi +fi +if [ ! -e "${GRADLE_WRAPPER_SHA256}" ]; then + # Delete the wrapper jar, if the checksum file does not exist. + rm -f "${GRADLE_WRAPPER_JAR}" +fi +if [ -e "${GRADLE_WRAPPER_JAR}" ]; then + # Verify the wrapper jar, if it exists, delete wrapper jar and checksum file, if the checksums + # do not match. + JAR_CHECKSUM="$(${SHASUM} "${GRADLE_WRAPPER_JAR}" | cut -d\ -f1)" + EXPECTED="$(cat "${GRADLE_WRAPPER_SHA256}")" + if [ "${JAR_CHECKSUM}" != "${EXPECTED}" ]; then + rm -f "${GRADLE_WRAPPER_JAR}" "${GRADLE_WRAPPER_SHA256}" + fi +fi +if [ ! -e "${GRADLE_WRAPPER_SHA256}" ]; then + curl --location --output "${GRADLE_WRAPPER_SHA256}" https://services.gradle.org/distributions/gradle-${GRADLE_DIST_VERSION}-wrapper.jar.sha256 || exit 1 +fi +if [ ! -e "${GRADLE_WRAPPER_JAR}" ]; then + # The Gradle version extracted from the `distributionUrl` property does not contain ".0" patch + # versions. Need to append a ".0" in that case to download the wrapper jar. + GRADLE_VERSION="$(echo "$GRADLE_DIST_VERSION" | sed 's/^\([0-9]*[.][0-9]*\)$/\1.0/')" + curl --location --output "${GRADLE_WRAPPER_JAR}" https://raw.githubusercontent.com/gradle/gradle/v${GRADLE_VERSION}/gradle/wrapper/gradle-wrapper.jar || exit 1 + JAR_CHECKSUM="$(${SHASUM} "${GRADLE_WRAPPER_JAR}" | cut -d\ -f1)" + EXPECTED="$(cat "${GRADLE_WRAPPER_SHA256}")" + if [ "${JAR_CHECKSUM}" != "${EXPECTED}" ]; then + # If the (just downloaded) checksum and the downloaded wrapper jar do not match, something + # really bad is going on. + echo "Expected sha256 of the downloaded gradle-wrapper.jar does not match the downloaded sha256!" > /dev/stderr + exit 1 + fi +fi diff --git a/plugins/beam-code-completion-plugin/gradle/wrapper/gradle-wrapper.jar b/plugins/beam-code-completion-plugin/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 249e5832f090..000000000000 Binary files a/plugins/beam-code-completion-plugin/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/plugins/beam-code-completion-plugin/gradlew b/plugins/beam-code-completion-plugin/gradlew index 1b6c787337ff..0323b44b8b41 100755 --- a/plugins/beam-code-completion-plugin/gradlew +++ b/plugins/beam-code-completion-plugin/gradlew @@ -82,6 +82,8 @@ done APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit +. ${APP_HOME}/gradle/gradlew-include.sh + APP_NAME="Gradle" APP_BASE_NAME=${0##*/} diff --git a/plugins/beam-code-completion-plugin/gradlew.bat b/plugins/beam-code-completion-plugin/gradlew.bat index 107acd32c4e6..d50856de020e 100644 --- a/plugins/beam-code-completion-plugin/gradlew.bat +++ b/plugins/beam-code-completion-plugin/gradlew.bat @@ -29,6 +29,8 @@ if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +powershell -file "%APP_HOME%\gradle\gradlew-include.ps1" + @rem Resolve any "." and ".." in APP_HOME to make it shorter. for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi