#!/bin/sh

# This script sets required LOCALCLASSPATH and by default CLASSPATH if
# no arguments. Otherwise use "set" option to set CLASSPATH and use
# "quiet" option to suppress prinitng of messages It must be run by
# source its content to modify current environment
#    . classpath.sh [build|run] [set] [quiet]

# resolve links - $0 may be a softlink
PRG="$0"
while [ -h "$PRG" ] ; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '.*/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done
PRGDIR=`dirname "$PRG"`

LOCALCLASSPATH=.
LOCALCLASSPATH=`echo $PRGDIR/lib/xpp/*.jar | tr ' ' ':'`:$LOCALCLASSPATH
LOCALCLASSPATH=`echo $PRGDIR/lib/atomixmiser/*.jar | tr ' ' ':'`:$LOCALCLASSPATH
LOCALCLASSPATH=`echo $PRGDIR/lib/xbeans/*.jar | tr ' ' ':'`:$LOCALCLASSPATH
LOCALCLASSPATH=`echo $PRGDIR/lib/lead/*.jar | tr ' ' ':'`:$LOCALCLASSPATH
LOCALCLASSPATH=`echo $PRGDIR/lib/xsul/*.jar | tr ' ' ':'`:$LOCALCLASSPATH
LOCALCLASSPATH=`echo $PRGDIR/lib/gpel/*.jar | tr ' ' ':'`:$LOCALCLASSPATH
LOCALCLASSPATH=`echo $PRGDIR/lib/httpclient/*.jar | tr ' ' ':'`:$LOCALCLASSPATH
LOCALCLASSPATH=`echo $PRGDIR/lib/junit/*.jar | tr ' ' ':'`:$LOCALCLASSPATH
LOCALCLASSPATH=`echo $PRGDIR/lib/xregistry/*.jar | tr ' ' ':'`:$LOCALCLASSPATH
LOCALCLASSPATH=`echo $PRGDIR/lib/resource_catalog/*.jar | tr ' ' ':'`:$LOCALCLASSPATH
LOCALCLASSPATH=`echo $PRGDIR/lib/jython/*.jar | tr ' ' ':'`:$LOCALCLASSPATH
LOCALCLASSPATH=`echo $PRGDIR/lib/wsmg/*.jar | tr ' ' ':'`:$LOCALCLASSPATH
LOCALCLASSPATH=`echo $PRGDIR/lib/workflow_tracking/*.jar | tr ' ' ':'`:$LOCALCLASSPATH
LOCALCLASSPATH=`echo $PRGDIR/lib/karma/*.jar | tr ' ' ':'`:$LOCALCLASSPATH
LOCALCLASSPATH=`echo $PRGDIR/lib/globus/*.jar | tr ' ' ':'`:$LOCALCLASSPATH

if [ "$1" = "build" ] ; then 
    if [ "$2" = "set" ] ; then
        CLASSPATH=$LOCALCLASSPATH
        if [ ! "$3" = "quiet" ] ; then
            echo $LOCALCLASSPATH
        fi
    elif [ ! "$2" = "quiet" ] ; then
        echo $LOCALCLASSPATH
    fi
else 
    LOCALCLASSPATH=`echo $PRGDIR/build/lib/*.jar | tr ' ' ':'`:$LOCALCLASSPATH
    LOCALCLASSPATH=$PRGDIR/build/classes:$LOCALCLASSPATH
    if [ "$1" = "run" ] ; then
        if [ "$2" = "set" ] ; then
            CLASSPATH=$LOCALCLASSPATH
            if [ ! "$3" = "quiet" ] ; then
                echo $LOCALCLASSPATH
            fi
        elif [ ! "$2" = "quiet" ] ; then
            echo $LOCALCLASSPATH
        fi
    else 
        CLASSPATH=$LOCALCLASSPATH
        if [ ! "$1" = "quiet" ] ; then
            echo $CLASSPATH
        fi
    fi
fi
export CLASSPATH
