#! /bin/sh


if [ ! -f $JONAS_ROOT/bin/unix/config_env ]
then
    echo "JONAS_ROOT must be set"
    exit 1
fi
. $JONAS_ROOT/bin/unix/config_env
 
HERE=$JONAS_ROOT/examples/alarm
OUTPUT_DIR=$JONAS_ROOT/examples/output
CLASS_DIR=$JONAS_ROOT/examples/classes
WEBAPPS=$JONAS_ROOT/webapps

set -x

# compile AlarmGenerator
cd $HERE/client/org/objectweb/alarm
javac -d $CLASS_DIR AlarmGenerator.java

# make alarm.jar (beans + alarm service)
cd $HERE/beans/org/objectweb/alarm/beans
javac -d $CLASS_DIR *.java
[ -d $CLASS_DIR/META-INF ] || mkdir -p $CLASS_DIR/META-INF
cp alarm.xml $CLASS_DIR/META-INF/ejb-jar.xml
cp jonas-alarm.xml $CLASS_DIR/META-INF/jonas-ejb-jar.xml
cd $CLASS_DIR
jar cvf org/objectweb/alarm/beans/alarm.jar META-INF/ejb-jar.xml META-INF/jonas-ejb-jar.xml org/objectweb/alarm/beans/*.class 
rm META-INF/*.xml
cd $HERE/beans/org/objectweb/alarm/beans
GenIC -d $CLASS_DIR -keepgenerated $CLASS_DIR/org/objectweb/alarm/beans/alarm.jar
cp $CLASS_DIR/org/objectweb/alarm/beans/alarm.jar $JONAS_ROOT/ejbjars

# compile servlet
cd $HERE/src/org/objectweb/alarm
$JAVAC -d $CLASS_DIR *.java

# make alarm.war (html, images, JSPs, web.xml, servlets)
[ -d $WEBAPPS/alarm/WEB-INF/lib ] || mkdir -p $WEBAPPS/alarm/WEB-INF/lib
cp $JONAS_ROOT/ejbjars/alarm.jar $WEBAPPS/alarm/WEB-INF/lib
[ -d $WEBAPPS/alarm/WEB-INF/classes ] || mkdir -p $WEBAPPS/alarm/WEB-INF/classes
cd $CLASS_DIR
find org/objectweb/alarm -name "*.class" -print | cpio -pmvdu $WEBAPPS/alarm/WEB-INF/classes
cd $HERE
cp etc/web.xml $WEBAPPS/alarm/WEB-INF
cd $HERE/web; find . ! -name "*~" -print | cpio -pmdvu $WEBAPPS/alarm
cd $WEBAPPS/alarm
jar cvf ../alarm.war .

# install alarm.war file on tomcat
echo "You must install now your application in the tomcat webapps directory, for example:"
echo "rm -rf <TOMCAT_HOME>/webapps/alarm"
echo "cp $WEBAPPS/alarm.war <TOMCAT_HOME>/webapps"
cd $HERE

echo "cp apps-alarm.xml <TOMCAT_HOME>/conf"
