#!/usr/bin/env bash
if [ x$JVLVERSION != x ]; then
export VERSION=$JVLVERSION
else
export VERSION=1.8.3-1.2.13_JVL
fi
if [ x${VERSION%_JVL} = x$VERSION ]; then
VERSION=${VERSION}_JVL
fi
echo "Setting VERSION to '$VERSION'"
perl -p -i -e 's|()[^<]*JVL[^<]*()|${1}$ENV{VERSION}${2}|;' pom.xml */pom.xml
mvn package -Dgetdown.host.whitelist="jalview.org,*.jalview.org" -Dallow_file_protocol=false -Dconnect_timeout=8 -Dread_timeout=15
RET=$?
if [ x$RET = x0 ]; then
cp launcher/target/getdown-launcher-$VERSION.jar ../../../getdown/lib/getdown-launcher.jar && echo "Copied getdown-launcher-$VERSION.jar to getdown/lib"
cp core/target/getdown-core-$VERSION.jar ../../../getdown/lib/getdown-core.jar && echo "Copied getdown-core-$VERSION.jar to getdown/lib"
cp core/target/getdown-core-$VERSION.jar ../../../j8lib/getdown-core.jar && echo "Copied getdown-core-$VERSION.jar to j8lib"
cp core/target/getdown-core-$VERSION.jar ../../../j11lib/getdown-core.jar && echo "Copied getdown-core-$VERSION.jar to j11lib"
echo "$VERSION" > ../../../getdown/lib/JVL_VERSION
fi
VERSION=${VERSION/JVL/FJVL}
echo "Setting VERSION to '$VERSION'"
perl -p -i -e 's|()[^<]*JVL[^<]*()|${1}$ENV{VERSION}${2}|;' pom.xml */pom.xml
mvn package -Dgetdown.host.whitelist="jalview.org,*.jalview.org" -Dallow_file_protocol=true -Dconnect_timeout=4 -Dread_timeout=4
RET=$?
if [ x$RET = x0 ]; then
cp launcher/target/getdown-launcher-$VERSION.jar ../../../getdown/lib/getdown-launcher-local.jar && echo "Copied getdown-launcher-$VERSION.jar to getdown/lib/getdown-launcher-local.jar"
echo "$VERSION" > ../../../getdown/lib/FJVL_VERSION
fi