This is an automated email from the ASF dual-hosted git repository. maciej pushed a commit to branch gradle-wrapper in repository https://gitbox.apache.org/repos/asf/iggy.git
commit d49dc99c274b21cd0dc341c42fc95ff6c9d43ccd Author: Maciej Modzelewski <[email protected]> AuthorDate: Mon Feb 2 12:42:52 2026 +0100 feat(java): add gradle wrapper with jar file autofetch --- .github/actions/java-gradle/post-merge/action.yml | 18 +- .github/actions/java-gradle/pre-merge/action.yml | 10 +- .../actions/utils/setup-java-with-cache/action.yml | 22 +- bdd/java/.gitignore | 3 + bdd/java/gradle/wrapper/gradle-wrapper.properties | 7 + bdd/java/gradlew | 297 +++++++++++++++++++++ examples/java/.gitignore | 3 + examples/java/README.md | 24 +- .../java/gradle/wrapper/gradle-wrapper.properties | 7 + examples/java/gradlew | 297 +++++++++++++++++++++ foreign/java/.gitignore | 3 + foreign/java/BUILD_AND_TEST.md | 34 +-- foreign/java/README.md | 24 +- .../java/gradle/wrapper/gradle-wrapper.properties | 7 + foreign/java/gradlew | 297 +++++++++++++++++++++ scripts/run-java-examples-from-readme.sh | 4 +- 16 files changed, 990 insertions(+), 67 deletions(-) diff --git a/.github/actions/java-gradle/post-merge/action.yml b/.github/actions/java-gradle/post-merge/action.yml index b638ddc9d..b09dbba36 100644 --- a/.github/actions/java-gradle/post-merge/action.yml +++ b/.github/actions/java-gradle/post-merge/action.yml @@ -30,23 +30,15 @@ inputs: runs: using: "composite" steps: - - name: Setup Java - uses: actions/setup-java@v4 - with: - distribution: "temurin" - java-version: "17" - - - name: Setup Gradle - uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 - with: - gradle-version: '9.2.1' + - name: Setup Java with cache + uses: ./.github/actions/utils/setup-java-with-cache - name: Build for publishing shell: bash working-directory: foreign/java run: | echo "📦 Building Java SDK for publishing..." - gradle build -x test -x checkstyleMain -x checkstyleTest + ./gradlew build -x test -x checkstyleMain -x checkstyleTest BUILD_EXIT_CODE=$? # List artifacts only if build succeeded @@ -73,7 +65,7 @@ runs: echo "" # Extract version from build.gradle.kts - gradle_version=$(gradle -p java-sdk properties -q | grep "version:" | cut -d: -f2 | tr -d ' ') + gradle_version=$(./gradlew -p java-sdk properties -q | grep "version:" | cut -d: -f2 | tr -d ' ') echo "Version from gradle: $gradle_version" echo "Input version: ${{ inputs.version }}" @@ -107,7 +99,7 @@ runs: echo "" # Run the publish task - gradle build -x test -x checkstyleMain -x checkstyleTest sign publish + ./gradlew build -x test -x checkstyleMain -x checkstyleTest sign publish PUBLISH_EXIT_CODE=$? if [ $PUBLISH_EXIT_CODE -eq 0 ]; then diff --git a/.github/actions/java-gradle/pre-merge/action.yml b/.github/actions/java-gradle/pre-merge/action.yml index 7a424f109..74fb781dc 100644 --- a/.github/actions/java-gradle/pre-merge/action.yml +++ b/.github/actions/java-gradle/pre-merge/action.yml @@ -37,7 +37,7 @@ runs: working-directory: foreign/java run: | echo "::group::Linting foreign/java" - gradle check -x test + ./gradlew check -x test echo "::endgroup::" - name: Lint examples @@ -46,7 +46,7 @@ runs: working-directory: examples/java run: | echo "::group::Linting examples/java" - gradle check -x test + ./gradlew check -x test echo "::endgroup::" - name: Lint BDD @@ -55,7 +55,7 @@ runs: working-directory: bdd/java run: | echo "::group::Linting bdd/java" - gradle check -x test + ./gradlew check -x test echo "::endgroup::" - name: Build @@ -63,7 +63,7 @@ runs: if: inputs.task == 'build' working-directory: foreign/java run: | - gradle build -x test -x checkstyleMain -x checkstyleTest -x spotlessCheck + ./gradlew build -x test -x checkstyleMain -x checkstyleTest -x spotlessCheck BUILD_EXIT_CODE=$? # List artifacts only if build succeeded @@ -94,7 +94,7 @@ runs: working-directory: foreign/java env: USE_EXTERNAL_SERVER: true - run: gradle test + run: ./gradlew test - name: Copy test reports if: ${{ !cancelled() && inputs.task == 'test' }} diff --git a/.github/actions/utils/setup-java-with-cache/action.yml b/.github/actions/utils/setup-java-with-cache/action.yml index ac9332a1e..64205e9d8 100644 --- a/.github/actions/utils/setup-java-with-cache/action.yml +++ b/.github/actions/utils/setup-java-with-cache/action.yml @@ -15,11 +15,11 @@ # specific language governing permissions and limitations # under the License. -# NOTE: this action sets up the Java toolchain + Gradle with caching, -# it is a convenience wrapper, so that we can use it in all workflows. +# NOTE: this action sets up the Java toolchain with optional Gradle caching. +# Gradle itself is provided via the wrapper (gradlew) in each project. name: setup-java-with-cache -description: Setup Java toolchain and Gradle with caching +description: Setup Java toolchain with optional Gradle caching (uses gradlew wrapper) inputs: java-version: description: "Java version to use" @@ -29,10 +29,6 @@ inputs: description: "Java distribution to use" required: false default: "temurin" - gradle-version: - description: "Gradle version to use" - required: false - default: "9.2.1" gradle-cache-disabled: description: "Whether to disable Gradle caching" required: false @@ -41,7 +37,7 @@ inputs: runs: using: "composite" steps: - - name: Setup Java (with cache) + - name: Setup Java (with Gradle cache) if: inputs.gradle-cache-disabled != 'true' uses: actions/setup-java@v4 with: @@ -56,15 +52,9 @@ runs: distribution: ${{ inputs.java-distribution }} java-version: ${{ inputs.java-version }} - - name: Setup Gradle - uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 - with: - gradle-version: ${{ inputs.gradle-version }} - cache-disabled: ${{ inputs.gradle-cache-disabled }} - - name: Verify Java installation run: | - echo "Java setup complete" + echo "Java setup complete (Gradle provided via wrapper)" java --version - gradle --version + ./gradlew --version shell: bash diff --git a/bdd/java/.gitignore b/bdd/java/.gitignore index 2bdccb0b4..2d92e8251 100644 --- a/bdd/java/.gitignore +++ b/bdd/java/.gitignore @@ -4,3 +4,6 @@ .gradle/ build/ out/ + +# Gradle wrapper jar (auto-fetched by gradlew script) +gradle/wrapper/gradle-wrapper.jar diff --git a/bdd/java/gradle/wrapper/gradle-wrapper.properties b/bdd/java/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..37f78a6af --- /dev/null +++ b/bdd/java/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/bdd/java/gradlew b/bdd/java/gradlew new file mode 100755 index 000000000..1149f8ec6 --- /dev/null +++ b/bdd/java/gradlew @@ -0,0 +1,297 @@ +#!/bin/sh + +# +# Copyright © 2015 the original authors. +# +# 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 +# +# https://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. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# 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 + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +############################################################################## +# +# Gradle Wrapper JAR Auto-Fetch +# +# Since the Apache Software Foundation prohibits binary files in source +# repositories, we download the gradle-wrapper.jar from the official +# Gradle repository if it's missing. +# +############################################################################## + +GRADLE_WRAPPER_VERSION=9.3.1 +REQUIRED_WRAPPER_JAR_CHECKSUM="b3a875ddc1f044746e1b1a55f645584505f4a10438c1afea9f15e92a7c42ec13" + +for attempt in 1 2 3; do + if [ ! -e "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" ]; then + if ! curl -s -S --retry 3 -L -o "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" "https://raw.githubusercontent.com/gradle/gradle/v$GRADLE_WRAPPER_VERSION/gradle/wrapper/gradle-wrapper.jar"; then + rm -f "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" + sleep 5 + continue + fi + fi + + if [ -e "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" ]; then + if command -v sha256sum >/dev/null 2>&1; then + LOCAL_WRAPPER_JAR_CHECKSUM=$(sha256sum "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" | awk '{print $1}') + elif command -v shasum >/dev/null 2>&1; then + LOCAL_WRAPPER_JAR_CHECKSUM=$(shasum -a 256 "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" | awk '{print $1}') + else + warn "Cannot find sha256sum or shasum to verify wrapper JAR." + break + fi + + if [ "$LOCAL_WRAPPER_JAR_CHECKSUM" != "$REQUIRED_WRAPPER_JAR_CHECKSUM" ]; then + rm -f "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" + else + break + fi + fi +done + +if [ ! -e "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" ]; then + die "ERROR: Failed to download gradle-wrapper.jar after multiple attempts. + +Please check your network connection or manually download the file from: +https://raw.githubusercontent.com/gradle/gradle/v$GRADLE_WRAPPER_VERSION/gradle/wrapper/gradle-wrapper.jar + +and place it in $APP_HOME/gradle/wrapper/gradle-wrapper.jar" +fi + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/examples/java/.gitignore b/examples/java/.gitignore index 2bdccb0b4..2d92e8251 100644 --- a/examples/java/.gitignore +++ b/examples/java/.gitignore @@ -4,3 +4,6 @@ .gradle/ build/ out/ + +# Gradle wrapper jar (auto-fetched by gradlew script) +gradle/wrapper/gradle-wrapper.jar diff --git a/examples/java/README.md b/examples/java/README.md index 41d2644b4..93c1e63b3 100644 --- a/examples/java/README.md +++ b/examples/java/README.md @@ -71,8 +71,8 @@ IGGY_HTTP_ENABLED=true IGGY_TCP_ADDRESS=0.0.0.0:8090 cargo run --bin iggy-server A good introduction for newcomers to Iggy: ```bash -gradle runGettingStartedProducer -gradle runGettingStartedConsumer +./gradlew runGettingStartedProducer +./gradlew runGettingStartedConsumer ``` ### Message Headers @@ -80,8 +80,8 @@ gradle runGettingStartedConsumer Shows metadata management using custom headers: ```bash -gradle runMessageHeadersProducer -gradle runMessageHeadersConsumer +./gradlew runMessageHeadersProducer +./gradlew runMessageHeadersConsumer ``` Demonstrates using header keys and values for message metadata instead of payload-based typing, with header-based message routing. @@ -91,8 +91,8 @@ Demonstrates using header keys and values for message metadata instead of payloa JSON envelope pattern for polymorphic message handling: ```bash -gradle runMessageEnvelopeProducer -gradle runMessageEnvelopeConsumer +./gradlew runMessageEnvelopeProducer +./gradlew runMessageEnvelopeConsumer ``` Uses MessagesGenerator to create OrderCreated, OrderConfirmed, and OrderRejected messages wrapped in JSON envelopes for type identification. @@ -104,8 +104,8 @@ Uses MessagesGenerator to create OrderCreated, OrderConfirmed, and OrderRejected Complex example demonstrating enterprise-level isolation: ```bash -gradle runMultiTenantProducer -gradle runMultiTenantConsumer +./gradlew runMultiTenantProducer +./gradlew runMultiTenantConsumer ``` Features multiple tenant setup, user creation with stream-specific permissions, concurrent producers/consumers across tenants, and security isolation. @@ -115,7 +115,7 @@ Features multiple tenant setup, user creation with stream-specific permissions, Testing and benchmarking support: ```bash -gradle runSinkDataProducer +./gradlew runSinkDataProducer ``` Produces high-throughput data (1000+ messages per batch) with realistic user records. @@ -127,7 +127,7 @@ Produces high-throughput data (1000+ messages per batch) with realistic user rec Building streams with advanced configuration: ```bash -gradle runStreamBasic +./gradlew runStreamBasic ``` Shows how to use the stream builder API to create and configure streams with custom settings. @@ -139,11 +139,11 @@ The following example demonstrates how to use the asynchronous client: Async producer example: ```bash -gradle runAsyncProducer +./gradlew runAsyncProducer ``` Async consumer example: ```bash -gradle runAsyncConsumerExample +./gradlew runAsyncConsumerExample ``` diff --git a/examples/java/gradle/wrapper/gradle-wrapper.properties b/examples/java/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..37f78a6af --- /dev/null +++ b/examples/java/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/examples/java/gradlew b/examples/java/gradlew new file mode 100755 index 000000000..1149f8ec6 --- /dev/null +++ b/examples/java/gradlew @@ -0,0 +1,297 @@ +#!/bin/sh + +# +# Copyright © 2015 the original authors. +# +# 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 +# +# https://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. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# 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 + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +############################################################################## +# +# Gradle Wrapper JAR Auto-Fetch +# +# Since the Apache Software Foundation prohibits binary files in source +# repositories, we download the gradle-wrapper.jar from the official +# Gradle repository if it's missing. +# +############################################################################## + +GRADLE_WRAPPER_VERSION=9.3.1 +REQUIRED_WRAPPER_JAR_CHECKSUM="b3a875ddc1f044746e1b1a55f645584505f4a10438c1afea9f15e92a7c42ec13" + +for attempt in 1 2 3; do + if [ ! -e "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" ]; then + if ! curl -s -S --retry 3 -L -o "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" "https://raw.githubusercontent.com/gradle/gradle/v$GRADLE_WRAPPER_VERSION/gradle/wrapper/gradle-wrapper.jar"; then + rm -f "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" + sleep 5 + continue + fi + fi + + if [ -e "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" ]; then + if command -v sha256sum >/dev/null 2>&1; then + LOCAL_WRAPPER_JAR_CHECKSUM=$(sha256sum "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" | awk '{print $1}') + elif command -v shasum >/dev/null 2>&1; then + LOCAL_WRAPPER_JAR_CHECKSUM=$(shasum -a 256 "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" | awk '{print $1}') + else + warn "Cannot find sha256sum or shasum to verify wrapper JAR." + break + fi + + if [ "$LOCAL_WRAPPER_JAR_CHECKSUM" != "$REQUIRED_WRAPPER_JAR_CHECKSUM" ]; then + rm -f "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" + else + break + fi + fi +done + +if [ ! -e "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" ]; then + die "ERROR: Failed to download gradle-wrapper.jar after multiple attempts. + +Please check your network connection or manually download the file from: +https://raw.githubusercontent.com/gradle/gradle/v$GRADLE_WRAPPER_VERSION/gradle/wrapper/gradle-wrapper.jar + +and place it in $APP_HOME/gradle/wrapper/gradle-wrapper.jar" +fi + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/foreign/java/.gitignore b/foreign/java/.gitignore index 2bdccb0b4..2d92e8251 100644 --- a/foreign/java/.gitignore +++ b/foreign/java/.gitignore @@ -4,3 +4,6 @@ .gradle/ build/ out/ + +# Gradle wrapper jar (auto-fetched by gradlew script) +gradle/wrapper/gradle-wrapper.jar diff --git a/foreign/java/BUILD_AND_TEST.md b/foreign/java/BUILD_AND_TEST.md index fff63a7cd..9a1a003d9 100644 --- a/foreign/java/BUILD_AND_TEST.md +++ b/foreign/java/BUILD_AND_TEST.md @@ -31,23 +31,23 @@ READ the README.md and start iggy-server as prescribed there. cd iggy/foreign/java/java-sdk # Clean previous builds -gradle clean +./gradlew clean # Build without running tests -gradle build -x test +./gradlew build -x test # Or build with tests (skip checkstyle) -gradle build -x checkstyleMain -x checkstyleTest +./gradlew build -x checkstyleMain -x checkstyleTest ``` ### 2. Compile Only ```bash # Compile main source code -gradle compileJava +./gradlew compileJava # Compile test code -gradle compileTestJava +./gradlew compileTestJava ``` ## Running Tests @@ -56,24 +56,24 @@ gradle compileTestJava ```bash # Run all tests (skip checkstyle) -gradle test -x checkstyleMain -x checkstyleTest +./gradlew test -x checkstyleMain -x checkstyleTest ``` ### 2. Run Specific Test Class ```bash # Run AsyncPollMessageTest specifically -gradle test --tests AsyncPollMessageTest -x checkstyleMain -x checkstyleTest +./gradlew test --tests AsyncPollMessageTest -x checkstyleMain -x checkstyleTest # Run with detailed output -gradle test --tests AsyncPollMessageTest --info -x checkstyleMain -x checkstyleTest +./gradlew test --tests AsyncPollMessageTest --info -x checkstyleMain -x checkstyleTest ``` ### 3. Run Test Suite by Package ```bash # Run all async client tests -gradle test --tests "org.apache.iggy.client.async.*" -x checkstyleMain -x checkstyleTest +./gradlew test --tests "org.apache.iggy.client.async.*" -x checkstyleMain -x checkstyleTest ``` ### 4. View Test Results @@ -103,7 +103,7 @@ This test validates the async client's polling functionality and demonstrates im ```bash # Run with full output cd iggy/foreign/java/java-sdk -gradle test --tests AsyncPollMessageTest -x checkstyleMain -x checkstyleTest --info +./gradlew test --tests AsyncPollMessageTest -x checkstyleMain -x checkstyleTest --info ``` Expected output: @@ -177,7 +177,7 @@ if (consumer == null) { - For other tests, check network connectivity 3. **Build Failures** - - Run `../gradlew clean` before building + - Run `./gradlew clean` before building - Ensure Java 17+ is installed - Check `JAVA_HOME` environment variable @@ -220,17 +220,17 @@ vim src/main/java/org/apache/iggy/client/async/... ### 2. Compile ```bash -gradle compileJava +./gradlew compileJava ``` ### 3. Test ```bash # Run specific test -gradle test --tests AsyncPollMessageTest -x checkstyleMain -x checkstyleTest +./gradlew test --tests AsyncPollMessageTest -x checkstyleMain -x checkstyleTest # Or run all async tests -gradle test --tests "org.apache.iggy.client.async.*" -x checkstyleMain -x checkstyleTest +./gradlew test --tests "org.apache.iggy.client.async.*" -x checkstyleMain -x checkstyleTest ``` ### 4. View Results @@ -261,19 +261,19 @@ When contributing changes: 1. **Always compile after changes** ```bash - gradle compileJava compileTestJava + ./gradlew compileJava compileTestJava ``` 2. **Run relevant tests** ```bash - gradle test --tests "*Test" -x checkstyleMain -x checkstyleTest + ./gradlew test --tests "*Test" -x checkstyleMain -x checkstyleTest ``` 3. **Check for warnings** ```bash - gradle build 2>&1 | grep -i warning + ./gradlew build 2>&1 | grep -i warning ``` 4. **Clean up test files** diff --git a/foreign/java/README.md b/foreign/java/README.md index e70c71c36..3ef3cfa16 100644 --- a/foreign/java/README.md +++ b/foreign/java/README.md @@ -199,11 +199,31 @@ See the [`examples`](examples/) module for basic consumer and producer implement For Apache Flink integration, see the [Flink Connector Library](external-processors/iggy-connector-flink/iggy-connector-library/README.md). +## Building from Source + +This project uses the Gradle Wrapper. Due to Apache Software Foundation policy, the `gradle-wrapper.jar` binary is not checked into the repository. Instead, the `gradlew` script automatically downloads it on first run. + +```bash +# Build the project +./gradlew build + +# Run tests +./gradlew test +``` + +The wrapper script will: + +1. Download `gradle-wrapper.jar` from the official Gradle repository if missing +2. Verify the SHA256 checksum for security +3. Execute the requested Gradle command + +No manual Gradle installation is required. + ## Contributing Before opening a pull request: -1. **Format code:** `gradle spotlessApply` -2. **Validate build:** `gradle check` +1. **Format code:** `./gradlew spotlessApply` +2. **Validate build:** `./gradlew check` This ensures code style compliance and that all tests and checkstyle validations pass. diff --git a/foreign/java/gradle/wrapper/gradle-wrapper.properties b/foreign/java/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..37f78a6af --- /dev/null +++ b/foreign/java/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/foreign/java/gradlew b/foreign/java/gradlew new file mode 100755 index 000000000..1149f8ec6 --- /dev/null +++ b/foreign/java/gradlew @@ -0,0 +1,297 @@ +#!/bin/sh + +# +# Copyright © 2015 the original authors. +# +# 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 +# +# https://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. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# 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 + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +############################################################################## +# +# Gradle Wrapper JAR Auto-Fetch +# +# Since the Apache Software Foundation prohibits binary files in source +# repositories, we download the gradle-wrapper.jar from the official +# Gradle repository if it's missing. +# +############################################################################## + +GRADLE_WRAPPER_VERSION=9.3.1 +REQUIRED_WRAPPER_JAR_CHECKSUM="b3a875ddc1f044746e1b1a55f645584505f4a10438c1afea9f15e92a7c42ec13" + +for attempt in 1 2 3; do + if [ ! -e "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" ]; then + if ! curl -s -S --retry 3 -L -o "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" "https://raw.githubusercontent.com/gradle/gradle/v$GRADLE_WRAPPER_VERSION/gradle/wrapper/gradle-wrapper.jar"; then + rm -f "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" + sleep 5 + continue + fi + fi + + if [ -e "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" ]; then + if command -v sha256sum >/dev/null 2>&1; then + LOCAL_WRAPPER_JAR_CHECKSUM=$(sha256sum "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" | awk '{print $1}') + elif command -v shasum >/dev/null 2>&1; then + LOCAL_WRAPPER_JAR_CHECKSUM=$(shasum -a 256 "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" | awk '{print $1}') + else + warn "Cannot find sha256sum or shasum to verify wrapper JAR." + break + fi + + if [ "$LOCAL_WRAPPER_JAR_CHECKSUM" != "$REQUIRED_WRAPPER_JAR_CHECKSUM" ]; then + rm -f "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" + else + break + fi + fi +done + +if [ ! -e "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" ]; then + die "ERROR: Failed to download gradle-wrapper.jar after multiple attempts. + +Please check your network connection or manually download the file from: +https://raw.githubusercontent.com/gradle/gradle/v$GRADLE_WRAPPER_VERSION/gradle/wrapper/gradle-wrapper.jar + +and place it in $APP_HOME/gradle/wrapper/gradle-wrapper.jar" +fi + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/scripts/run-java-examples-from-readme.sh b/scripts/run-java-examples-from-readme.sh index bd91d00e0..9fa768d6f 100755 --- a/scripts/run-java-examples-from-readme.sh +++ b/scripts/run-java-examples-from-readme.sh @@ -28,7 +28,7 @@ set -euo pipefail # If not provided, uses the default target # # This script scans examples/java/README.md for commands starting with -# `gradle` and executes them in order. If any command fails, the script +# `./gradlew` and executes them in order. If any command fails, the script # stops immediately and prints the relevant iggy-server logs. readonly LOG_FILE="iggy-server.log" @@ -120,7 +120,7 @@ if [ -f "${README_FILE}" ]; then # Small delay between runs to avoid thrashing the server sleep 2 - done < <(grep -E '^gradle' "${README_FILE}") + done < <(grep -E '^\./gradlew' "${README_FILE}") else echo "README file ${README_FILE} not found in examples/java." fi
