#!/bin/sh # detect cygwin CYGWIN=0 if [ `uname -s | grep -i 'cygwin'` ]; then CYGWIN=1 fi # prints usage of script function usage { echo 'sssdyntracer [--tsegment=]* [--dynt-exclude=]* [--dynt-include=]* [--weave-verbose] ' echo ' Invokes java and integrates SSSDynTracer using AspectJ 5 load time weaving' echo echo ' --tsegment= A pointcut that designates a trace segment. Specify at least one.' echo ' For example: --tsegment="execution(* *.main(..))"' echo ' --dynt-exclude= Allows you to exclude certain pieces of code from tracer' echo ' --dynt-include= Allows you to include certain pieces of code for tracer' echo ' --weave-verbose The load time weaver will show debugging messages' echo echo 'A matches a "within" AspectJ 5 pattern.' echo 'If you use --dynt-include then only those classes matching your pattern will be' echo 'included. You should always include your class containing main in the list of' echo 'include patterns, or the trace output will not be written.' } # gets the "real path" that we can use to pass to non-posix programs (in cygwin, windows programs) function real_path { if [ "$CYGWIN" == "1" ]; then echo `cygpath -m "$1"` else echo "$1" fi } # generates aop.xml file with options for load time weaver function gen_aop_xml { echo "" echo " " let MAXLOOP=NUMTSEGMENT-1 for ((i=0; i <= MAXLOOP; i++)); do DATA=${TSEGMENT[$i]} echo " " echo ' ' echo ' ' done echo " " echo " " echo " " let MAXLOOP=NUMINC-1 for ((i=0; i <= MAXLOOP; i++)); do DATA=${INCPAT[$i]} echo " " done let MAXLOOP=NUMEXC-1 for ((i=0; i <= MAXLOOP; i++)); do DATA=${EXCPAT[$i]} echo " " done echo " " echo " " echo "" } # Detect correct path separate -- on Linux it's : but in cygwin it's ; CYGWIN=0 PATH_SEP=: if [ `uname -s | grep -i 'cygwin'` ]; then CYGWIN=1 PATH_SEP=";" fi #Build path to SSSDynTracer.jar DTPATH=`dirname $0` if [ "$DTPATH" == "" ]; then DTPATH=. fi DTPATH_REAL=`real_path "$DTPATH"` #Build temporary directory that is valid for java executable if [ -d "$TEMP" ]; then SAFETEMP="$TEMP" else SAFETEMP="/tmp" fi # Option definitions EXTRACP="${PAT_SEP}${CLASSPATH}" NUMTSEGMENT=0 #TSEGMENT=( ) NUMINC=0 #INCPAT=( ) NUMEXC=0 #EXCPAT=( ) WEAVE_OPTIONS= GENJAR=0 GENJARPATH= GENJARDIR= # Parse options # Must manually parse -cp and -classpath PARSE=1 while [ $PARSE -gt 0 ]; do case $1 in "-help") usage exit -1 ;; "-cp" | "-classpath") shift EXTRACP="${PATH_SEP}$1" shift ;; --tsegment=*) ARG=`echo $1 | cut -c 12-` shift TSEGMENT[$NUMTSEGMENT]="$ARG" let NUMTSEGMENT=NUMTSEGMENT+1 ;; --dynt-exclude=*) ARG=`echo $1 | cut -c 16-` shift EXCPAT[$NUMEXC]="$ARG" let NUMEXC=NUMEXC+1 ;; --dynt-include=*) ARG=`echo $1 | cut -c 16-` shift INCPAT[$NUMINC]="$ARG" let NUMINC=NUMINC+1 ;; --weave-verbose) shift GENJAR=1 WEAVE_OPTIONS="-verbose $WEAVE_OPTIONS" ;; *) PARSE=0 ;; esac done if [ $NUMTSEGMENT -gt 0 ] || [ $NUMINC -gt 0 ] || [ $NUMEXC -gt 0 ]; then # must generate JAR GENJAR=1 else # don't have to generate JAR, but if we do, then make sure we include everything NUMINC=1 INCPATH[0]="*" fi # Generate JAR file with META-INF/aop.xml with options in it if we need to if [ "$GENJAR" == "1" ]; then # Get path for temporary .jar file GENJARDIR="$SAFETEMP/sssdyntrace-aop-options-temp" rm -Rf "$GENJARDIR/META-INF" mkdir -p "$GENJARDIR/META-INF" GENJARPATH="$GENJARDIR/`date +%F-%H-%M-%S`.jar" GENJARPATH_REAL=`real_path "$GENJARPATH"` #Generate .jar with META-INF/aop.xml file gen_aop_xml > "$GENJARDIR/META-INF/aop.xml" jar -cf "$GENJARPATH_REAL" -C `real_path "$GENJARDIR"` META-INF if [ "$?" != "0" ]; then echo "************************** FAILED TO GENERATE JAR WITH aop.xml" rm -f "$GENJARPATH" exit 1 fi fi ASPECTPATH="${DTPATH_REAL}/SSSDynTracer.jar${PATH_SEP}$ASPECTPATH" CLASSPATH="${DTPATH_REAL}/SSSDynTracer.jar${EXTRACP}" if [ "$GENJARPATH" != "" ]; then CLASSPATH="${CLASSPATH}${PATH_SEP}${GENJARPATH_REAL}" fi aj5 "$@" #Cleanup temporary JAR file if [ "$GENJARPATH" != "" ]; then rm -f "$GENJARPATH" rm -Rf "$GENJARDIR/META-INF" rmdir "$GENJARDIR" >/dev/null 2>&1 fi