Skip to content

Commit

Permalink
add option for running PiT projects in different JDKs
Browse files Browse the repository at this point in the history
  • Loading branch information
manolo committed Dec 6, 2024
1 parent 6330bca commit b8e41ba
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 21 deletions.
6 changes: 4 additions & 2 deletions scripts/pit/lib/lib-args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
## the usage message, it should be synchronized with the function used for extracting the arguments below
usage() {
cat <<EOF
Use: $0 [version=] [starters=] [port=] [timeout=] [verbose] [offline] [interactive] [skiptests] [pnpm] [vite] [help]
Use: $0 with the next options:
--version=string Vaadin version to test, if not given it only tests current stable, otherwise it runs tests against current stable and then against given version.
--starters=list List of demos or presets separated by comma to run (default: all) valid options:`echo ,$DEFAULT_STARTERS | sed -e 's/,/\n · /g'`
--demos Run all demo projects
--generated Run all generated projects (start and archetypes)
--port=number HTTP port for thee servlet container (default: $DEFAULT_PORT)
--timeout=number Time in secs to wait for server to start (default $DEFAULT_TIMEOUT)
--jdk=NN Use a specific JDK version to run the tests
--verbose Show server output (default silent)
--offline Do not remove already downloaded projects, and do not use network for mvn (default online)
--interactive Play a bell and ask user to manually test the application (default non interactive)
Expand All @@ -33,6 +33,7 @@ Use: $0 [version=] [starters=] [port=] [timeout=] [verbose] [offline] [interacti
everything after this argument is the function name and arguments passed to the function.
you should take care with arguments that contain spaces, they should be quoted twice.
--help Show this message
--starters=list List of demos or presets separated by comma to run (default: all) valid options:`echo ,$DEFAULT_STARTERS | sed -e 's/,/\n · /g'`
EOF
exit 1
}
Expand Down Expand Up @@ -60,6 +61,7 @@ checkArgs() {
STARTERS="$S";;
--version=*) VERSION="$arg";;
--timeout=*) TIMEOUT="$arg";;
--jdk=*) JDK="$arg";;
--verbose|--debug) VERBOSE=true;;
--offline) OFFLINE=true;;
--interactive) INTERACTIVE=true;;
Expand Down
4 changes: 3 additions & 1 deletion scripts/pit/lib/lib-patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ applyPatches() {
downgradeJava

case $app_ in
archetype-hotswap) enableJBRAutoreload ;;
archetype-hotswap)
## need to happen in patch phase not in the run phase
enableJBRAutoreload ;;
vaadin-oauth-example)
setPropertyInFile src/main/resources/application.properties \
spring.security.oauth2.client.registration.google.client-id \
Expand Down
5 changes: 1 addition & 4 deletions scripts/pit/lib/lib-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ downloadStarter() {
## TODO: add support for vaadi cli
generateStarter() {
_name=$1
[ -z "$TEST" ] && log "Generating $1"
case $_name in
*spring) cmd="$MVN -ntp -q -B archetype:generate -DarchetypeGroupId=com.vaadin -DarchetypeArtifactId=vaadin-archetype-spring-application -DarchetypeVersion=LATEST -DgroupId=com.vaadin.starter -DartifactId=$_name" ;;
archetype*) cmd="$MVN -ntp -q -B archetype:generate -DarchetypeGroupId=com.vaadin -DarchetypeArtifactId=vaadin-archetype-application -DarchetypeVersion=LATEST -DgroupId=com.vaadin.starter -DartifactId=$_name" ;;
vaadin-quarkus) cmd="$MVN -ntp -q -B io.quarkus.platform:quarkus-maven-plugin:3.1.1.Final:create -Dextensions=vaadin -DwithCodestart -DprojectGroupId=com.vaadin.starter -DprojectArtifactId=$_name" ;;
vaadin-quarkus) cmd="$MVN -ntp -q -B io.quarkus.platform:quarkus-maven-plugin:create -Dextensions=vaadin -DwithCodestart -DprojectGroupId=com.vaadin.starter -DprojectArtifactId=$_name" ;;
hilla-*-cli) cmd="npx @hilla/cli init --react $_name" ;;
esac
runCmd false "Generating $1" "$cmd" || return 1
Expand Down Expand Up @@ -192,8 +191,6 @@ runStarter() {
esac
fi

[ "$_preset" = archetype-hotswap ] && installJBRRuntime

computeMvn
computeGradle
printVersions || return 1
Expand Down
57 changes: 45 additions & 12 deletions scripts/pit/lib/lib-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ killAll() {
## restore system as before running the script
cleanAll() {
restoreProKey
unsetJBR
unsetJavaPath
}

## Exit the script after some process cleanup
Expand Down Expand Up @@ -673,7 +673,9 @@ printVersions() {
MAVEN_OPTS='$MAVEN_OPTS' MAVEN_ARGS='$MAVEN_ARGS' $MVN -version
$_vers
NODE=$NODE
Node version: `"$NODE" --version`
NPM=$NPM
Npm version: `"$NPM" --version`
"
}
Expand Down Expand Up @@ -759,27 +761,58 @@ installJBRRuntime() {
mkdir -p /tmp/jbr
runCmd false "Extracting JBR" "tar -xf /tmp/JBR.tgz -C /tmp/jbr --strip-components 1" || return 1
fi

[ -d /tmp/jbr/Contents/Home/ ] && H=/tmp/jbr/Contents/Home || H=/tmp/jbr
[ -z "$TEST" ] && log "Setting JAVA_HOME=$H PATH=$H/bin:\$PATH"
cmd "export PATH=$H/bin:\$PATH JAVA_HOME=$H"
__PATH=$PATH
__HOME=$JAVA_HOME
export PATH="$H/bin:$PATH" JAVA_HOME="$H" HOT="-XX:+AllowEnhancedClassRedefinition -XX:HotswapAgent=fatjar"

if [ ! -f $H/lib/hotswap/hotswap-agent.jar ] ; then
mkdir -p $H/lib/hotswap
download "$__hsau" "$H/lib/hotswap/hotswap-agent.jar" || return 1
log "Installed "`ls -1 $H/lib/hotswap/hotswap-agent.jar`
fi

setJavaPath "/tmp/jbr" || return 1
}

## Installs a certain version of OPENJDK
# $1: version (eg: 17, 21, 23)
installJDKRuntime() {
__version=$1
base_url="https://download.oracle.com/java"
isLinux && os_suffix="linux-x64" && __ext="tar.gz"
isMac && os_suffix="macos-x64" && __ext="tar.gz"
isWindows && os_suffix="windows-x64" && __ext="zip"
[ -z "$__version" -o -z "$os_suffix" ] && return 1
__nversion="$__version"
__vpath="latest"
[ "$__version" = "18" ] && __nversion="18.0.1" && __vpath="archive"
[ "$__version" = "17" ] && __nversion="17.0.12" && __vpath="archive"
tar_file="jdk-${__nversion}_${os_suffix}_bin.${__ext}"
tmp_dir="/tmp/jdk-${__version}"
__jurl="${base_url}/${__version}/${__vpath}/${tar_file}"
if [ ! -f "/tmp/$tar_file" ]; then
download "$__jurl" "/tmp/$tar_file" || return 1
fi
[ -d "$tmp_dir" ] && rm -rf "$tmp_dir"
mkdir -p "$tmp_dir"
runCmd false "Extracting JDK-$__version" "tar -xf "/tmp/$tar_file" -C "$tmp_dir" --strip-components 1" || return 1

setJavaPath "$tmp_dir" || return 1
}

setJavaPath() {
H=`find "$1" -name Home -type d`
[ -z "$H" ] && H=$tmp_dir
[ -z "$TEST" ] && log "Setting JAVA_HOME=$H PATH=$H/bin:\$PATH"
[ ! -d "$H/bin" ] && return 1
cmd "export PATH=$H/bin:\$PATH JAVA_HOME=$H"
__PATH=$PATH
__HOME=$JAVA_HOME
export PATH="$H/bin:$PATH" JAVA_HOME="$H"
}

## Unsets the jet brains java runtime used for testing the hotswap agent
unsetJBR() {
[ -z "$HOT" ] && return 0 || unset HOT
warn "Un-setting PATH and JAVA_HOME ($JAVA_HOME)"
unsetJavaPath() {
[ -n "$__HOME" ] && warn "Un-setting PATH and JAVA_HOME ($JAVA_HOME)"
[ -n "$__PATH" ] && export PATH=$__PATH && unset __PATH
[ -n "$__HOME" ] && export JAVA_HOME=$__HOME && unset __HOME || unset JAVA_HOME
[ -n "$HOT" ] && unset HOT
}

## enables autoreload for preparing jet brains java runtime
Expand Down
16 changes: 14 additions & 2 deletions scripts/pit/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,36 @@ main() {

## Run presets (star.vaadin.com) or archetypes
for i in $presets; do
if expr "$i" : '.*-hotswap' >/dev/null; then
installJBRRuntime || continue
elif [ -n "$JDK" ]; then
installJDKRuntime "$JDK" || continue
fi
run runStarter "$i" "$tmp"
done

## Run demos (proper starters in github)
for i in $demos; do
if expr "$i" : '.*_jdk' >/dev/null; then
_jdk=`echo "$i" | sed -e 's|.*_jdk||'`
i=`echo "$i" | sed -e 's|_jdk.*||'`
installJDKRuntime "$_jdk" || continue
elif [ -n "$JDK" ]; then
installJDKRuntime "$JDK" || continue
fi
run runDemo "$i" "$tmp"
done

cd "$pwd"

[ -n "$TEST" ] && return

_error=0
## Report success and failed projects
for i in $success
do
bold "🟢 Starter $i built successfully"
done
_error=0
for i in $failed
do
files=`echo $tmp/$i/*.out`
Expand All @@ -113,7 +126,6 @@ main() {
done

printTime $_start

return $_error
}

Expand Down
1 change: 1 addition & 0 deletions scripts/repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ bookstore-example:rtl-demo
bakery-app-starter-flow-spring
k8s-demo-app
mpr-demo
mpr-demo_jdk17
testbench-demo
ce-demo
start
Expand Down

0 comments on commit b8e41ba

Please sign in to comment.