diff options
author | Florian Schmaus <flow@gentoo.org> | 2023-01-06 13:25:33 +0100 |
---|---|---|
committer | Florian Schmaus <flow@gentoo.org> | 2023-01-06 13:25:33 +0100 |
commit | 2d2c19e5aaf4b320c5b030d0389bddd447d922be (patch) | |
tree | 68676dc02bd7b25913bf839ee21472c7ae801f1c | |
parent | dev-java/openjdk-bin: add 20_beta20221125 (diff) | |
download | java-2d2c19e5aaf4b320c5b030d0389bddd447d922be.tar.gz java-2d2c19e5aaf4b320c5b030d0389bddd447d922be.tar.bz2 java-2d2c19e5aaf4b320c5b030d0389bddd447d922be.zip |
gradle.eclass: add gradle-set_EGRADLE and tests
Signed-off-by: Florian Schmaus <flow@gentoo.org>
-rw-r--r-- | eclass/gradle.eclass | 91 | ||||
-rwxr-xr-x | eclass/tests/gradle.sh | 59 | ||||
-rw-r--r-- | eclass/tests/tests-common.sh | 12 |
3 files changed, 158 insertions, 4 deletions
diff --git a/eclass/gradle.eclass b/eclass/gradle.eclass index f609c122..ad7b1440 100644 --- a/eclass/gradle.eclass +++ b/eclass/gradle.eclass @@ -1,4 +1,4 @@ -# Copyright 2021 Gentoo Authors +# Copyright 2021-2023 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 # @ECLASS: gradle.eclass @@ -12,13 +12,95 @@ # WARNING: This eclass is currently experimental and # subject to change. -EGRADLE_BIN="gradle" +case ${EAPI} in + 7|8) ;; + *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;; +esac + +if [[ -z ${_GRADLE_ECLASS} ]] ; then +_GRADLE_ECLASS=1 + +inherit edo + +# @ECLASS_VARIABLE: EGRADLE_MIN +# @DEFAULT_UNSET +# @DESCRIPTION: +# Minimum required gradle version. + +# @ECLASS_VARIABLE: EGRADLE_MAX_EXCLUSIVE +# @DEFAULT_UNSET +# @DESCRIPTION: +# First gradle version that is not supported. + +# @ECLASS_VARIABLE: EGRADLE_OVERWRITE +# @USER_VARIABLE +# @DEFAULT_UNSET +# @DESCRIPTION: +# User-specified overwrite of the used gradle binary. + +# @FUNCTION: gradle-set_EGRADLE +# @DESCRIPTION: +# Set the EGRADLE environment variable. +gradle-set_EGRADLE() { + [[ -n ${EGRADLE} ]] && return + + if [[ -n ${EGRADLE_OVERWRITE} ]]; then + export EGRADLE="${EGRADLE_OVERWRITE}" + return + fi + + local candidates candidate selected selected_ver + + candidates=$(compgen -c gradle-) + for candidate in ${candidates}; do + if [[ ! ${candidate} =~ gradle(-bin)?-([.0-9]+) ]]; then + continue + fi + + local ver + if (( ${#BASH_REMATCH[@]} == 3 )); then + ver="${BASH_REMATCH[2]}" + else + ver="${BASH_REMATCH[1]}" + fi + + if [[ -n ${EGRADLE_MIN} ]] \ + && ver_test "${ver}" -lt "${EGRADLE_MIN}"; then + # Candidate does not stisfy EGRADLE_MIN condition. + continue + fi + + if [[ -n ${EGRADLE_MAX_EXCLUSIVE} ]] \ + && ver_test "${ver}" -ge "${EGRADLE_MAX_EXCLUSIVE}"; then + # Candidate does not satisfy EGRADLE_MAX_EXCLUSIVE condition. + continue + fi + + if [[ -n ${selected_ver} ]] \ + && ver_test "${selected_ver}" -gt "${ver}"; then + # Candidate is older than the currently selected candidate. + continue + fi + + selected="${candidate}" + selected_ver="${ver}" + done + + if [[ -z ${selected} ]]; then + die "Could not find (suitable) gradle installation in PATH" + fi + + export EGRADLE="${selected}" + export EGRADLE_VER="${ver}" +} # @FUNCTION: egradle # @USAGE: [gradle-args] # @DESCRIPTION # Invoke gradle egradle() { + gradle-set_EGRADLE + # TODO --no-build-cache ? local gradle_args=( --console=plain @@ -31,6 +113,7 @@ egradle() { --project-cache-dir "${T}/gradle_project_cache" ) - einfo "gradle "${gradle_args[@]}" ${@}" - "${EGRADLE_BIN}" "${gradle_args[@]}" ${@} || die "gradle failed" + edo "${EGRADLE}" "${gradle_args[@]}" ${@} } + +fi diff --git a/eclass/tests/gradle.sh b/eclass/tests/gradle.sh new file mode 100755 index 00000000..dac9c9cc --- /dev/null +++ b/eclass/tests/gradle.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash +# Copyright 2022-2023 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 + +source tests-common.sh || exit + +inherit gradle + +# TODO: hack because tests-common don't implement ver_cut +EAPI=6 inherit eapi7-ver + +test_set_EGRADLE() { + local expected_EGRADLE="${1}" + + shift + + local tmpdir + tmpdir=$(mktemp -d || die) + for pseudo_gradle in "${@}"; do + local pseudo_gradle_path="${tmpdir}/${pseudo_gradle}" + touch "${pseudo_gradle_path}" + chmod 755 "${pseudo_gradle_path}" + done + + local saved_PATH="${PATH}" + PATH="${tmpdir}" + + local test_desc=( + test_set_EGRADLE + ) + [[ -v EGRADLE_MIN ]] && test_desc+=( "EGRADLE_MIN=${EGRADLE_MIN}" ) + [[ -v EGRADLE_MAX_EXCLUSIVE ]] && test_desc+=( "EGRADLE_MAX_EXCLUSIVE=${EGRADLE_MAX_EXCLUSIVE}" ) + test_desc+=( $@ ) + + tbegin "${test_desc[@]}" + gradle-set_EGRADLE + + local saved_EGRADLE="${EGRADLE}" + unset EGRADLE + + PATH="${saved_PATH}" + rm -rf "${tmpdir}" + + [[ "${saved_EGRADLE}" == "${expected_EGRADLE}" ]] + tend $? + + if (( $? > 0 )); then + >&2 echo -e "\t expected=${expected_EGRADLE} actual=${saved_EGRADLE}" + fi +} + +test_set_EGRADLE gradle-2.0 gradle-1.0 gradle-2.0 +EGRADLE_MIN=2.0 test_set_EGRADLE gradle-2.2.3 gradle-1.0 gradle-2.0 gradle-2.2.3 +EGRADLE_MAX_EXCLUSIVE=2.2 test_set_EGRADLE gradle-2.0 gradle-1.0 gradle-2.0 gradle-2.2.3 + + +texit diff --git a/eclass/tests/tests-common.sh b/eclass/tests/tests-common.sh new file mode 100644 index 00000000..73903657 --- /dev/null +++ b/eclass/tests/tests-common.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +# Copyright 2022-2023 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +GENTOO_REPO_PATH=$(portageq get_repo_path / gentoo) +JAVA_REPO_PATH=$(portageq get_repo_path / java) + +source "${GENTOO_REPO_PATH}/eclass/tests/tests-common.sh" +TESTS_ECLASS_SEARCH_PATHS=( + "${GENTOO_REPO_PATH}/eclass" + "${JAVA_REPO_PATH}/eclass" +) |