# patches IBM timezones
# see: http://bugs.sun.com/bugdatabase/view_bug.do;?bug_id=6530336 for the problem making this patch necessary and
# see: http://www.ibm.com/support/alerts/us/en/daylightsavingstimealert.html for ibm info
# $1 == zip file from ibm containing the patch
# $2 == SKD jre directory
# $3 == test class

if [ $# -lt 3 ]
then
  echo usage:
  echo -e "\t$0 <patch zip file> <jdk jre dir> <test class>"
  exit 1
fi

ZIP_FILE="$(readlink -f $1)"
JDK_JRE_DIR="$(readlink -f $2)"
# just to be sure ...
if [ -e $JDK_JRE_DIR/jre ]
then
  JDK_JRE_DIR="$JDK_JRE_DIR/jre"
fi
export JAVA_HOME="$JDK_JRE_DIR"
TEST_CLASS="$(readlink -f $3)"
TEST_CLASS_DIR="$(dirname $TEST_CLASS)"
TEST_CLASS_NAME="$(echo $(basename $TEST_CLASS) | sed 's/\.class//g')"

# lets do some tests to be sure
#echo -e "test 1 ... \c"
#echo "$JAVA_HOME/bin/java -cp $TEST_CLASS_DIR -Duser.timezone=America/Los_Angeles $TEST_CLASS_NAME"
#RESULT=$($JAVA_HOME/bin/java -cp $TEST_CLASS_DIR -Duser.timezone=America/Los_Angeles $TEST_CLASS_NAME)
#if [ "$RESULT" != "Wed Jun 06 12:00:00 PDT 2007" ]
#then
#  echo "... test does not fail ... I am helpless -- bye!"
#  exit 23
#fi
#echo "failed -- good!"


unzip -d patch $ZIP_FILE
cd patch
echo -e "$JDK_JRE_DIR\c" > SDKList.txt
mkdir Temp
export JTZU_HOME="$(pwd)"
cd TimeZoneInfo
export JAVA_HOME="$JDK_JRE_DIR"
echo calling: "$JAVA_HOME/bin/java" -cp "$JTZU_HOME/JTZU.jar" -Dnogui=true -Ddiscoveronly=false -Dsilentpatch=false -Dbackwardcompatibility=false JTZUMain
yes | "$JAVA_HOME/bin/java" -cp "$JTZU_HOME/JTZU.jar" -Dnogui=true -Ddiscoveronly=false -Dsilentpatch=false -Dbackwardcompatibility=false JTZUMain

# lets do some tests to be sure
#echo -e "test 1 ... \c"
#echo "$JAVA_HOME/bin/java -cp $TEST_CLASS_DIR -Duser.timezone=America/Los_Angeles $TEST_CLASS_NAME"
#RESULT=$($JAVA_HOME/bin/java -cp $TEST_CLASS_DIR -Duser.timezone=America/Los_Angeles $TEST_CLASS_NAME)
#if [ "$RESULT" != "Wed Jun 06 11:00:00 PDT 2007" ]
#then
#  echo "EEEEEEEEEEeeeeeeeeeeeeeeeeeeeee ... did not work!"
#  exit 42
#fi
#echo "succeeded!"
#
#echo -e "test 2 ... \c"
#echo "$JAVA_HOME/bin/java -cp $TEST_CLASS_DIR -Duser.timezone=America/New_York $TEST_CLASS_NAME"
#RESULT=$($JAVA_HOME/bin/java -cp $TEST_CLASS_DIR -Duser.timezone=America/New_York $TEST_CLASS_NAME)
#if [ "$RESULT" != "Wed Jun 06 14:00:00 EDT 2007" ]
#then
#  echo "EEEEEEEEEEeeeeeeeeeeeeeeeeeeeee ... did not work!"
#  exit 42
#fi
#echo "succeeded!"
echo "patch successful!"
