diff --git a/.github/ci/README.md b/.github/ci/README.md new file mode 100644 index 0000000..8e166b2 --- /dev/null +++ b/.github/ci/README.md @@ -0,0 +1,17 @@ +The Training regression workflow compiles and assembles the project on Corretto 17, +then compares JUnit outcomes with the verified baseline commit recorded in +`baseline.json` (11 tests, two intentional exercise failures). + +New failures, changed failure types, missing tests, skipped tests, missing reports, +and build errors fail CI. Previously failing exercises may pass; new passing tests +are allowed. The baseline records test identities and exception types only, without +assertion messages, expected values, or solutions. Baseline changes require review. + +Raw build output and JUnit reports are not uploaded or printed by the training +workflow because assertions can disclose exercise answers. CI uploads only counts, +commit identifiers, and a generic result. To diagnose a failure locally, run +`./gradlew clean build` on JDK 17. To run the same CI gate, use +`python3 .github/ci/check_training.py`. + +This gate detects regressions relative to the baseline. It does not certify that +the exercises are complete or that all exercise tests pass. diff --git a/.github/ci/baseline.json b/.github/ci/baseline.json new file mode 100644 index 0000000..49ba6ef --- /dev/null +++ b/.github/ci/baseline.json @@ -0,0 +1,93 @@ +{ + "commit": "2a3803733de53b67af200a821aca0bcb41173d64", + "cases": [ + { + "id": [ + "app/build/test-results/test/TEST-base.project.AppTest.xml", + "base.project.AppTest", + "appHasAGreeting()" + ], + "failure_type": null + }, + { + "id": [ + "app/build/test-results/test/TEST-base.project.SampleTest$#306a#3093#304b#30c6#30b9#30c8.xml", + "base.project.SampleTest$\u306a\u3093\u304b\u30c6\u30b9\u30c8", + "test()" + ], + "failure_type": null + }, + { + "id": [ + "app/build/test-results/test/TEST-book.BookAppTest$#30b7#30c1#30e5#30a8#30fc#30b7#30e7#30f31#306e#30c6#30b9#30c8.xml", + "book.BookAppTest$\u30b7\u30c1\u30e5\u30a8\u30fc\u30b7\u30e7\u30f31\u306e\u30c6\u30b9\u30c8", + "\u8ffd\u52a0\u3059\u308b\u672c\u304c\u7a7a\u306e\u5834\u5408_\u5165\u529b\u3057\u305f\u30ea\u30b9\u30c8\u3092\u305d\u306e\u307e\u307e\u8fd4\u3059\u3053\u3068()" + ], + "failure_type": null + }, + { + "id": [ + "app/build/test-results/test/TEST-book.BookAppTest$#30b7#30c1#30e5#30a8#30fc#30b7#30e7#30f31#306e#30c6#30b9#30c8.xml", + "book.BookAppTest$\u30b7\u30c1\u30e5\u30a8\u30fc\u30b7\u30e7\u30f31\u306e\u30c6\u30b9\u30c8", + "\u8ffd\u52a0\u3059\u308b\u672c\u3068\u521d\u671f\u72b6\u614b\u306e\u672c\u306b\u91cd\u8907\u304c\u3042\u308b\u5834\u5408_\u5165\u529b\u3057\u305f\u30ea\u30b9\u30c8\u306b\u8ffd\u52a0\u3059\u308b\u672c\u3092\u91cd\u8907\u3092\u7701\u3044\u3066\u8ffd\u52a0\u3059\u308b\u3053\u3068()" + ], + "failure_type": null + }, + { + "id": [ + "app/build/test-results/test/TEST-book.BookAppTest$#30b7#30c1#30e5#30a8#30fc#30b7#30e7#30f31#306e#30c6#30b9#30c8.xml", + "book.BookAppTest$\u30b7\u30c1\u30e5\u30a8\u30fc\u30b7\u30e7\u30f31\u306e\u30c6\u30b9\u30c8", + "\u8ffd\u52a0\u3059\u308b\u672c\u3068\u521d\u671f\u72b6\u614b\u306e\u672c\u306b\u91cd\u8907\u304c\u306a\u3044\u5834\u5408_\u5165\u529b\u3057\u305f\u30ea\u30b9\u30c8\u306b\u8ffd\u52a0\u3059\u308b\u672c\u3092\u305d\u306e\u307e\u307e\u8ffd\u52a0\u3059\u308b\u3053\u3068()" + ], + "failure_type": null + }, + { + "id": [ + "app/build/test-results/test/TEST-book.BookAppTest$#30b7#30c1#30e5#30a8#30fc#30b7#30e7#30f31#306e#30c6#30b9#30c8.xml", + "book.BookAppTest$\u30b7\u30c1\u30e5\u30a8\u30fc\u30b7\u30e7\u30f31\u306e\u30c6\u30b9\u30c8", + "\u8ffd\u52a0\u3059\u308b\u672c\u306e\u4e2d\u3067\u91cd\u8907\u304c\u3042\u308b\u5834\u5408_\u5165\u529b\u3057\u305f\u30ea\u30b9\u30c8\u306b\u8ffd\u52a0\u3059\u308b\u672c\u3092\u91cd\u8907\u3092\u7701\u3044\u3066\u8ffd\u52a0\u3059\u308b\u3053\u3068()" + ], + "failure_type": null + }, + { + "id": [ + "app/build/test-results/test/TEST-book.BookAppTest$#30b7#30c1#30e5#30a8#30fc#30b7#30e7#30f31#306e#30c6#30b9#30c8.xml", + "book.BookAppTest$\u30b7\u30c1\u30e5\u30a8\u30fc\u30b7\u30e7\u30f31\u306e\u30c6\u30b9\u30c8", + "\u91cd\u8907\u3092\u7701\u3044\u305f\u7d50\u679c\u4f55\u3082\u6b8b\u3089\u306a\u304b\u3063\u305f\u5834\u5408_\u5165\u529b\u3057\u305f\u30ea\u30b9\u30c8\u3092\u305d\u306e\u307e\u307e\u51fa\u529b\u3059\u308b\u3053\u3068()" + ], + "failure_type": null + }, + { + "id": [ + "app/build/test-results/test/TEST-broker.RunnerBrokerTest.xml", + "broker.RunnerBrokerTest", + "Runnable\u306e\u767b\u9332\u3068\u5b9f\u884c\u304c\u53ef\u80fd\u3067\u3042\u308b\u3053\u3068()" + ], + "failure_type": "java.lang.NullPointerException" + }, + { + "id": [ + "app/build/test-results/test/TEST-date.DateApiTest$actualNow#306e#30c6#30b9#30c8.xml", + "date.DateApiTest$actualNow\u306e\u30c6\u30b9\u30c8", + "\u51fa\u529b\u78ba\u8a8d()" + ], + "failure_type": "org.opentest4j.AssertionFailedError" + }, + { + "id": [ + "app/build/test-results/test/TEST-pickling.PicklingTest$doPickle#306e#30c6#30b9#30c8.xml", + "pickling.PicklingTest$doPickle\u306e\u30c6\u30b9\u30c8", + "\u52d5\u4f5c\u78ba\u8a8d()" + ], + "failure_type": null + }, + { + "id": [ + "app/build/test-results/test/TEST-testability.EditedTimeTest$getTest.xml", + "testability.EditedTimeTest$getTest", + "\u51fa\u529b\u306e\u30c6\u30b9\u30c8()" + ], + "failure_type": null + } + ] +} diff --git a/.github/ci/check_training.py b/.github/ci/check_training.py new file mode 100644 index 0000000..63c1d65 --- /dev/null +++ b/.github/ci/check_training.py @@ -0,0 +1,77 @@ +"""Detect regressions without changing exercises or exposing assertion answers.""" +import json +import os +from pathlib import Path +import subprocess +import tempfile +import xml.etree.ElementTree as ET + + +def read_cases(repo): + reports = sorted(repo.glob('**/build/test-results/test/TEST-*.xml')) + if not reports: + raise ValueError('No JUnit reports were produced') + cases = {} + for report in reports: + suite = ET.parse(report).getroot() + for case in suite.iter('testcase'): + key = (report.relative_to(repo).as_posix(), case.get('classname'), case.get('name')) + if key in cases: + raise ValueError('Duplicate test identity') + if case.find('skipped') is not None or case.find('error') is not None: + raise ValueError('A test was skipped or had an execution error') + failure = case.find('failure') + cases[key] = None if failure is None else failure.get('type', 'unknown') + if not cases: + raise ValueError('JUnit reports contained no tests') + return cases + + +def compare(baseline, current, exit_code): + expected = {tuple(case['id']): case['failure_type'] for case in baseline['cases']} + if not expected or len(expected) != len(baseline['cases']): + raise ValueError('Invalid baseline') + if expected.keys() - current.keys(): + raise ValueError('Previously executed tests are missing') + failed = {key: kind for key, kind in current.items() if kind is not None} + if any(key not in expected or expected[key] != kind for key, kind in failed.items()): + raise ValueError('A new or changed test failure was detected') + if exit_code not in (0, 1) or (exit_code == 0) != (not failed): + raise ValueError('Gradle exit status does not match the test results') + return {'tests': len(current), 'existing_failures': len(failed), 'new_failures': 0, + 'baseline_failures_now_passing': sum(kind is not None and current[key] is None + for key, kind in expected.items())} + + +def main(): + repo = Path(__file__).resolve().parents[2] + baseline = json.loads((Path(__file__).with_name('baseline.json')).read_text()) + summary = {'baseline_commit': baseline['commit'], 'source_commit': os.environ.get('GITHUB_SHA'), + 'status': 'failed'} + destination = repo / 'build/ci/training-summary.json' + try: + # Capture raw compiler/test output privately: assertion output can reveal exercise answers. + with tempfile.TemporaryFile() as log: + gradle = ['bash', './gradlew', '--no-daemon', '--console=plain', '-Dorg.gradle.jvmargs=-Xmx512m'] + built = subprocess.run(gradle + ['clean', 'assemble', 'testClasses'], cwd=repo, + stdout=log, stderr=subprocess.STDOUT) + if built.returncode: + raise ValueError('Compilation or assembly failed; reproduce locally for diagnostics') + tested = subprocess.run(gradle + ['test'], cwd=repo, stdout=log, stderr=subprocess.STDOUT) + summary.update(compare(baseline, read_cases(repo), tested.returncode)) + summary['status'] = 'passed' + print('Regression check passed: {tests} tests, {existing_failures} existing failures, ' + '{new_failures} new failures.'.format(**summary)) + return 0 + except (ValueError, ET.ParseError, OSError) as exc: + # Do not print exception contents from XML, subprocesses or user exercise code. + summary['reason'] = str(exc) if type(exc) is ValueError else 'Unable to read test results or run the build' + print('Regression check failed: ' + summary['reason']) + return 1 + finally: + destination.parent.mkdir(parents=True, exist_ok=True) + destination.write_text(json.dumps(summary, indent=2) + '\n', encoding='utf-8') + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/.github/ci/test_regression_guard.py b/.github/ci/test_regression_guard.py new file mode 100644 index 0000000..89c2bee --- /dev/null +++ b/.github/ci/test_regression_guard.py @@ -0,0 +1,66 @@ +import tempfile +from pathlib import Path +import unittest + +from check_training import compare, read_cases + + +class RegressionGuardTest(unittest.TestCase): + def setUp(self): + self.key = ('app/build/test-results/test/TEST-Lesson.xml', 'Lesson', 'exercise') + self.baseline = {'cases': [{'id': list(self.key), 'failure_type': 'AssertionError'}]} + + def test_existing_failure_is_preserved(self): + self.assertEqual(compare(self.baseline, {self.key: 'AssertionError'}, 1)['new_failures'], 0) + + def test_existing_failure_may_be_fixed(self): + self.assertEqual(compare(self.baseline, {self.key: None}, 0)['baseline_failures_now_passing'], 1) + + def test_new_failure_is_rejected(self): + with self.assertRaises(ValueError): + compare(self.baseline, {self.key: 'AssertionError', ('new', 'new', 'new'): 'AssertionError'}, 1) + + def test_changed_failure_is_rejected(self): + with self.assertRaises(ValueError): + compare(self.baseline, {self.key: 'NullPointerException'}, 1) + + def test_removed_test_is_rejected(self): + with self.assertRaises(ValueError): + compare(self.baseline, {}, 0) + + def test_infrastructure_exit_is_rejected(self): + for code in [0, 2, -9]: + with self.subTest(code=code), self.assertRaises(ValueError): + compare(self.baseline, {self.key: 'AssertionError'}, code) + + def test_missing_or_empty_xml_is_rejected(self): + with tempfile.TemporaryDirectory() as directory: + repo = Path(directory) + with self.assertRaises(ValueError): + read_cases(repo) + report = repo / self.key[0] + report.parent.mkdir(parents=True) + report.write_text('') + with self.assertRaises(ValueError): + read_cases(repo) + + def test_skip_error_and_duplicate_are_rejected(self): + for child in ['', '']: + with self.subTest(child=child), tempfile.TemporaryDirectory() as directory: + repo = Path(directory) + report = repo / self.key[0] + report.parent.mkdir(parents=True) + report.write_text('' + child + '') + with self.assertRaises(ValueError): + read_cases(repo) + with tempfile.TemporaryDirectory() as directory: + repo = Path(directory) + report = repo / self.key[0] + report.parent.mkdir(parents=True) + report.write_text('' + '' * 2 + '') + with self.assertRaises(ValueError): + read_cases(repo) + + +if __name__ == '__main__': + unittest.main() diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..fd63c9d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,40 @@ +name: Training regression + +on: + push: + branches: [main] + pull_request: + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + verify: + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0 + with: + distribution: corretto + java-version: '17' + - name: Check exercise regressions without publishing answers + run: | + python3 -m unittest discover -s .github/ci -p "test_*.py" + python3 .github/ci/check_training.py + - name: Preserve sanitized regression summary + if: ${{ always() }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: training-summary-${{ github.run_attempt }} + path: | + build/ci/training-summary.json + if-no-files-found: error + retention-days: 14 diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 67a6f7e..7d5145c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -30,7 +30,7 @@ dependencies { // Use JUnit Jupiter for testing. testImplementation("org.junit.jupiter:junit-jupiter:5.8.2") // AssertJの演習用 https://mvnrepository.com/artifact/org.assertj/assertj-core - testImplementation("org.assertj:assertj-core:3.23.1") + testImplementation("org.assertj:assertj-core:3.27.7") } application { @@ -57,4 +57,4 @@ tasks { tasks.withType { gradleVersion = gradle.gradleVersion -} \ No newline at end of file +} diff --git a/app/gradle/wrapper/gradle-wrapper.jar b/app/gradle/wrapper/gradle-wrapper.jar index 033e24c..02f06ab 100644 Binary files a/app/gradle/wrapper/gradle-wrapper.jar and b/app/gradle/wrapper/gradle-wrapper.jar differ diff --git a/app/gradle/wrapper/gradle-wrapper.properties b/app/gradle/wrapper/gradle-wrapper.properties index 9f4197d..f4d62ef 100644 --- a/app/gradle/wrapper/gradle-wrapper.properties +++ b/app/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,8 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.8-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +distributionSha256Sum=94da89692fc3ca6d2d0ce6bb48548762ea0f1897ba444286f5c7f3759c7af651 diff --git a/app/gradlew b/app/gradlew index fcb6fca..23d15a9 100644 --- a/app/gradlew +++ b/app/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# 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/. @@ -83,7 +85,8 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit +# 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 @@ -111,7 +114,7 @@ case "$( uname )" in #( NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar +CLASSPATH="\\\"\\\"" # Determine the Java command to use to start the JVM. @@ -144,7 +147,7 @@ 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=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -152,7 +155,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -201,16 +204,16 @@ 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 $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. +# 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" \ -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ "$@" # Stop when "xargs" is not available. diff --git a/app/gradlew.bat b/app/gradlew.bat index 93e3f59..db3a6ac 100644 --- a/app/gradlew.bat +++ b/app/gradlew.bat @@ -13,6 +13,8 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,22 +59,22 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar +set CLASSPATH= @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* :end @rem End local scope for the variables with windows NT shell diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 249e583..02f06ab 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8049c68..61f7315 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.8-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +distributionSha256Sum=94da89692fc3ca6d2d0ce6bb48548762ea0f1897ba444286f5c7f3759c7af651 diff --git a/gradlew b/gradlew index a69d9cb..23d15a9 100644 --- a/gradlew +++ b/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# 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/. @@ -80,13 +82,11 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# 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"' +# 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 @@ -114,7 +114,7 @@ case "$( uname )" in #( NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar +CLASSPATH="\\\"\\\"" # Determine the Java command to use to start the JVM. @@ -133,22 +133,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + 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 @@ -193,16 +200,20 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# 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" \ -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ "$@" # Stop when "xargs" is not available. diff --git a/gradlew.bat b/gradlew.bat index f127cfd..db3a6ac 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,6 +13,8 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## @@ -26,6 +28,7 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -42,11 +45,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -56,22 +59,22 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar +set CLASSPATH= @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* :end @rem End local scope for the variables with windows NT shell