Skip to content

Commit

Permalink
Add IT for PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
ia3andy committed Feb 8, 2024
1 parent 77a3300 commit d7533ce
Show file tree
Hide file tree
Showing 21 changed files with 520 additions and 4 deletions.
16 changes: 15 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<lombok.version>1.18.30</lombok.version>
<slf4j.version>1.7.36</slf4j.version>

<maven-failsafe-plugin.version>3.2.5</maven-failsafe-plugin.version>
<maven-compiler-plugin.version>3.12.1</maven-compiler-plugin.version>
<maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
<maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
Expand All @@ -86,7 +87,6 @@

<modules>
<module>recipes</module>
<module>recipes-unit-tests</module>
</modules>

<dependencyManagement>
Expand Down Expand Up @@ -148,6 +148,11 @@
<profiles>
<profile>
<id>release</id>
<activation>
<property>
<name>performRelease</name>
</property>
</activation>
<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -192,6 +197,15 @@
</plugins>
</build>
</profile>
<profile>
<id>test</id>
<activation>
<property><name>!performRelease</name></property>
</activation>
<modules>
<module>recipes-tests</module>
</modules>
</profile>
</profiles>

</project>
239 changes: 239 additions & 0 deletions recipes-tests/jbang
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
#!/usr/bin/env bash

#
# To run this script remotely type this in your shell
# (where <args>... are the arguments you want to pass to JBang):
# curl -Ls https://sh.jbang.dev | bash -s - <args>...
#

# The Java version to install when it's not installed on the system yet
javaVersion=${JBANG_DEFAULT_JAVA_VERSION:-11}

absolute_path() {
# if the given path to the jbang launcher is absolute (i.e. it is either starting with / or a
# 'letter:/' when using gitbash on windows) it is returned unchanged, otherwise we construct an absolute path
[[ $1 = /* ]] || [[ $1 =~ ^[A-z]:/ ]] && echo "$1" || echo "$PWD/${1#./}"
}

resolve_symlink() {
if [[ $OSTYPE != darwin* ]]; then minusFarg="-f"; fi
sym_resolved=$(readlink ${minusFarg} "$1")

if [[ -n $sym_resolved ]]; then
echo "$sym_resolved"
else
echo "$1"
fi
}

download() {
if [ -x "$(command -v curl)" ]; then
curl -sLf -o "$2" "$1"
retval=$?
elif [ -x "$(command -v wget)" ]; then
wget -q -O "$2" "$1"
retval=$?
else
echo "Error: curl or wget not found, please make sure one of them is installed" 1>&2
exit 1
fi
}

unpack() {
if [[ "$1" == *.tar.gz ]]; then
gzip -cd "$1" | tar xf - -C "$2"
retval=$?
if [[ $os == mac && $retval -eq 0 ]]; then
mv "$TDIR/jdks/$javaVersion.tmp/"*/Contents/Home/* "$TDIR/jdks/$javaVersion.tmp/"
retval=$?
else
mv "$TDIR/jdks/$javaVersion.tmp/"*/* "$TDIR/jdks/$javaVersion.tmp/"
fi
else
unzip -qq -o "$1" -d "$2"
retval=$?
mv "$TDIR/jdks/$javaVersion.tmp/"*/* "$TDIR/jdks/$javaVersion.tmp/"
fi
}

javacInPath() {
[[ -x "$(command -v javac)" && ( $os != "mac" || $(/usr/libexec/java_home &> /dev/null) ) ]]
}

abs_jbang_dir=$(dirname "$(resolve_symlink "$(absolute_path "$0")")")

# todo might vary by os so can be overwritten below
libc_type=glibc
file_type=tar.gz

case "$(uname -s)" in
Linux*)
os=linux
if [ -f /etc/alpine-release ]; then
os=alpine-linux
javaVersion=16
fi
;;
Darwin*)
os=mac
libc_type=libc;;
CYGWIN*|MINGW*|MSYS*)
os=windows
libc_type=c_std_lib
file_type=zip;;
AIX)
os=aix;;
*)
os=
esac

case "$(uname -m)" in
i?86)
arch=x32;;
x86_64|amd64)
arch=x64;;
aarch64)
arch=aarch64;;
armv7l)
arch=arm;;
ppc64le)
arch=ppc64le;;
s390x)
arch=s390x;;
arm64)
if [ "$os" = "mac" ]; then
arch=arm64
## force use of 17 as 11 not yet available https://github.com/adoptium/adoptium/issues/96
javaVersion=17
else
arch=arm64
fi
;;
*)
## AIX gives a machine ID for `uname -m` but it only supports ppc64
if [ "$os" = "aix" ]; then
arch=ppc64
else
arch=
fi
;;
esac

## when using cygwin fall out to just running the bat file.
if [[ $os == windows && -f "$abs_jbang_dir/jbang.cmd" && "$(uname -s)" == CYGWIN* ]]; then
cmd /c "$(cygpath -m "$abs_jbang_dir"/jbang.cmd)" "$@"
exit $?
fi

if [[ -z "$JBANG_JDK_VENDOR" ]]; then
if [[ "$javaVersion" -eq 8 || "$javaVersion" -eq 11 || "$javaVersion" -ge 17 ]]; then
distro="temurin";
else
distro="aoj"; fi
else
distro=$JBANG_JDK_VENDOR
fi
if [[ -z "$JBANG_JDK_RELEASE" ]]; then release="ga"; else release="$JBANG_JDK_RELEASE"; fi

if [[ -z "$JBANG_DIR" ]]; then JBDIR="$HOME/.jbang"; else JBDIR="$JBANG_DIR"; fi
if [[ -z "$JBANG_CACHE_DIR" ]]; then TDIR="$JBDIR/cache"; else TDIR="$JBANG_CACHE_DIR"; fi

## resolve application jar path from script location
if [ -f "$abs_jbang_dir/jbang.jar" ]; then
jarPath=$abs_jbang_dir/jbang.jar
elif [ -f "$abs_jbang_dir/.jbang/jbang.jar" ]; then
jarPath=$abs_jbang_dir/.jbang/jbang.jar
else
if [[ ! -f "$JBDIR/bin/jbang.jar" || ! -f "$JBDIR/bin/jbang" ]]; then
echo "Downloading JBang..." 1>&2
mkdir -p "$TDIR/urls"
jburl="https://github.com/jbangdev/jbang/releases/latest/download/jbang.tar"
download $jburl "$TDIR/urls/jbang.tar"
if [ $retval -ne 0 ]; then echo "Error downloading JBang" 1>&2; exit $retval; fi
echo "Installing JBang..." 1>&2
rm -rf "$TDIR/urls/jbang"
tar xf "$TDIR/urls/jbang.tar" -C "$TDIR/urls"
if [ $retval -ne 0 ]; then echo "Error installing JBang" 1>&2; exit $retval; fi
mkdir -p "$JBDIR/bin"
rm -f "$JBDIR/bin/jbang" "$JBDIR/bin"/jbang.*
cp -f "$TDIR/urls/jbang/bin"/* "$JBDIR/bin"
fi
"$JBDIR"/bin/jbang "$@"
exit $?
fi
if [ -f "$jarPath.new" ]; then
# a new jbang version was found, we replace the old one with it
mv "$jarPath.new" "$jarPath"
fi

# Find/get a JDK
unset JAVA_EXEC
if [[ -n "$JAVA_HOME" ]]; then
# Determine if a (working) JDK is available in JAVA_HOME
if [ -x "$(command -v "$JAVA_HOME"/bin/javac)" ]; then
JAVA_EXEC="$JAVA_HOME/bin/java"
else
echo "JAVA_HOME is set but does not seem to point to a valid Java JDK" 1>&2
fi
fi
if [[ -z "$JAVA_EXEC" ]]; then
# Determine if a (working) JDK is available on the PATH
if javacInPath; then
unset JAVA_HOME
JAVA_EXEC="java"
elif [ -x "$JBDIR/currentjdk/bin/javac" ]; then
export JAVA_HOME="$JBDIR/currentjdk"
JAVA_EXEC="$JBDIR/currentjdk/bin/java"
else
export JAVA_HOME="$TDIR/jdks/$javaVersion"
JAVA_EXEC="$JAVA_HOME/bin/java"
# Check if we installed a JDK before
if [ ! -d "$TDIR/jdks/$javaVersion" ]; then
# If not, download and install it
if [[ $os == "" ]]; then
echo "Unable to download JDK, unsupported Operating System: $(uname -s)" 1>&2
exit 1
fi
if [[ $arch == "" ]]; then
echo "Unable to download JDK, unsupported Architecture: $(uname -m)" 1>&2
exit 1
fi
mkdir -p "$TDIR/jdks"
echo "Downloading JDK $javaVersion. Be patient, this can take several minutes..." 1>&2
jdkurl="https://api.foojay.io/disco/v2.0/directuris?distro=$distro&javafx_bundled=false&libc_type=$libc_type&archive_type=$file_type&operating_system=$os&package_type=jdk&version=$javaVersion&release_status=$release&architecture=$arch&latest=available"
download "$jdkurl" "$TDIR/bootstrap-jdk.$file_type"
if [ $retval -ne 0 ]; then echo "Error downloading JDK" 1>&2; exit $retval; fi
echo "Installing JDK $javaVersion..." 1>&2
rm -rf "$TDIR/jdks/$javaVersion.tmp/"
mkdir -p "$TDIR/jdks/$javaVersion.tmp"
unpack "$TDIR/bootstrap-jdk.$file_type" "$TDIR/jdks/$javaVersion.tmp"
if [ $retval -ne 0 ]; then
# Check if the JDK was installed properly
javac -version > /dev/null 2>&1
retval=$?
fi
if [ $retval -ne 0 ]; then echo "Error installing JDK" 1>&2; exit $retval; fi
# Activate the downloaded JDK giving it its proper name
mv "$TDIR/jdks/$javaVersion.tmp" "$TDIR/jdks/$javaVersion"
# Set the current JDK
${JAVA_EXEC} -classpath "${jarPath}" dev.jbang.Main jdk default $javaVersion
fi
fi
fi

## https://stackoverflow.com/questions/1668649/how-to-keep-quotes-in-bash-arguments
## attempt to ensure each argument keeps its original quoting

## run it using command substitution to have just the user process once jbang is done
export JBANG_RUNTIME_SHELL=bash
export JBANG_STDIN_NOTTY=$([ -t 0 ] && echo "false" || echo "true")
output=$(CLICOLOR_FORCE=1 ${JAVA_EXEC} ${JBANG_JAVA_OPTIONS} -classpath "${jarPath}" dev.jbang.Main "$@")
err=$?
if [ $err -eq 255 ]; then
eval "exec $output"
elif [ -n "$output" ]; then
echo "$output"
exit $err
else
exit $err
fi
87 changes: 87 additions & 0 deletions recipes-tests/jbang.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
@echo off
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

rem The Java version to install when it's not installed on the system yet
if "%JBANG_DEFAULT_JAVA_VERSION%"=="" (set javaVersion=11) else (set javaVersion=%JBANG_DEFAULT_JAVA_VERSION%)

if "%JBANG_DIR%"=="" (set JBDIR=%userprofile%\.jbang) else (set JBDIR=%JBANG_DIR%)
if "%JBANG_CACHE_DIR%"=="" (set TDIR=%JBDIR%\cache) else (set TDIR=%JBANG_CACHE_DIR%)

rem resolve application jar path from script location and convert to windows path when using cygwin
if exist "%~dp0jbang.jar" (
set jarPath=%~dp0jbang.jar
) else if exist "%~dp0.jbang\jbang.jar" (
set jarPath=%~dp0.jbang\jbang.jar
) else (
if not exist "%JBDIR%\bin\jbang.jar" (
powershell -NoProfile -ExecutionPolicy Bypass -NonInteractive -Command "%~dp0jbang.ps1 version" > nul
if !ERRORLEVEL! NEQ 0 ( exit /b %ERRORLEVEL% )
)
call "%JBDIR%\bin\jbang.cmd" %*
exit /b %ERRORLEVEL%
)
if exist "%jarPath%.new" (
rem a new jbang version was found, we replace the old one with it
copy /y "%jarPath%.new" "%jarPath%" > nul 2>&1
del /f /q "%jarPath%.new"
)

rem Find/get a JDK
set JAVA_EXEC=
if not "%JAVA_HOME%"=="" (
rem Determine if a (working) JDK is available in JAVA_HOME
if exist "%JAVA_HOME%\bin\javac.exe" (
set JAVA_EXEC="%JAVA_HOME%\bin\java.exe"
) else (
echo JAVA_HOME is set but does not seem to point to a valid Java JDK 1>&2
)
)
if "!JAVA_EXEC!"=="" (
rem Determine if a (working) JDK is available on the PATH
where javac > nul 2>&1
if !errorlevel! equ 0 (
set JAVA_HOME=
set JAVA_EXEC=java.exe
) else if exist "%JBDIR%\currentjdk\bin\javac" (
set JAVA_HOME=%JBDIR%\currentjdk
set JAVA_EXEC=%JBDIR%\currentjdk\bin\java
) else (
set JAVA_HOME=%TDIR%\jdks\%javaVersion%
set JAVA_EXEC=!JAVA_HOME!\bin\java.exe
rem Check if we installed a JDK before
if not exist "%TDIR%\jdks\%javaVersion%" (
rem If not, download and install it
echo powershell -NoProfile -ExecutionPolicy Bypass -NonInteractive -Command "%~dp0jbang.ps1 jdk install %JBANG_DEFAULT_JAVA_VERSION%"
if !ERRORLEVEL! NEQ 0 ( exit /b %ERRORLEVEL% )
rem Set the current JDK
!JAVA_EXEC! -classpath "%jarPath%" dev.jbang.Main jdk default "%javaVersion%"
)
)
)

if not exist "%TDIR%" ( mkdir "%TDIR%" )
set tmpfile=%TDIR%\%RANDOM%.jbang.tmp
rem execute jbang and pipe to temporary random file
set JBANG_RUNTIME_SHELL=cmd
2>nul >nul timeout /t 0 && (set JBANG_STDIN_NOTTY=false) || (set JBANG_STDIN_NOTTY=true)
set "CMD=!JAVA_EXEC!"
SETLOCAL DISABLEDELAYEDEXPANSION
%CMD% > "%tmpfile%" %JBANG_JAVA_OPTIONS% -classpath "%jarPath%" dev.jbang.Main %*
set ERROR=%ERRORLEVEL%
rem catch errorlevel straight after; rem or FOR /F swallow would have swallowed the errorlevel

if %ERROR% EQU 255 (
rem read generated java command by jang, delete temporary file and execute.
for %%A in ("%tmpfile%") do for /f "usebackq delims=" %%B in (%%A) do (
set "OUTPUT=%%B"
goto :break
)
:break
del /f /q "%tmpfile%"
%OUTPUT%
exit /b %ERRORLEVEL%
) else (
type "%tmpfile%"
del /f /q "%tmpfile%"
exit /b %ERROR%
)
Loading

0 comments on commit d7533ce

Please sign in to comment.