Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code_completion_plugin_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "name=$NAME" >> $GITHUB_OUTPUT
echo "pluginVerifierHomeDir=~/.pluginVerifier" >> $GITHUB_OUTPUT

echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
134 changes: 134 additions & 0 deletions gradle/gradlew-include.ps1
Original file line number Diff line number Diff line change
@@ -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
}
}
67 changes: 67 additions & 0 deletions gradle/gradlew-include.sh
Original file line number Diff line number Diff line change
@@ -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
Binary file removed gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
134 changes: 134 additions & 0 deletions learning/katas/java/gradle/gradlew-include.ps1
Original file line number Diff line number Diff line change
@@ -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
}
}
Loading
Loading