#!/bin/bash

currentdir=`pwd`
dir=$1
name=${dir##*/}

LIBJARS=; for j in `find /home/qingzhou/projects/rv-monitor/lib/ -name "*.jar"`; do LIBJARS=$LIBJARS:$j; done
cd ${dir}
javamop ${name}.mop
#javamop ${name}.mop -translate2RV
#java -cp /home/qingzhou/projects/rv-monitor/bin rvmonitor.Main ${name}.rvm
#/home/qingzhou/projects/rv-monitor/bin/rv-monitor ${name}.rvm
#java -cp /home/qingzhou/projects/javamop/build/ javamop.util.AJFileCombiner ${name}RuntimeMonitor.java ${name}MonitorAspect.aj
#javac -cp /home/qingzhou/projects/rv-monitor/lib/rvmonitorrt.jar ${name}RVRuntimeMonitor.java -d .
#echo $LIBJARS
num=`find -name '*_[0-9]'|wc -l`
for((c=1;c<=$num;c++))
do
    cd ${name}_${c}
    cp ../${name}MonitorAspect.aj ./
    ajc -1.6 -cp "$CLASSPATH":${LIBJARS}:.:./mop/ -d . ${name}_${c}.java ${name}MonitorAspect.aj
    java -cp "${CLASSPATH}":/home/qingzhou/projects/rv-monitor/lib/rvmonitorrt.jar:"${LIBJARS}" ${name}_${c}
    cd -
done
cd ${currentdir}