#!/bin/sh
# ---------------------------------------------------------------------------
# Fractal
# Copyright (C) 2006-2007 INRIA - ADAM Team
# Contact: fdf-users@lists.gforge.inria.fr
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
# USA
#
# Initial developer(s): Philippe Merle
#
# Contributor(s): Nicolas Dolet
#
# ---------------------------------------------------------------------------
# $Id: fdf.sh
# ---------------------------------------------------------------------------

# -----------------------------------------------------------------------
# Check JONAS_ROOT
# -----------------------------------------------------------------------

if [ -z "${JONAS_ROOT}" ]
then
  echo "JONAS_ROOT must be set."
  exit 1
else
  . $JONAS_ROOT/bin/unix/setenv
fi

# -----------------------------------------------------------------------
# Check FDF_LIB
# -----------------------------------------------------------------------

if [ -z "${FDF_LIB}" ]
then
  FDF_LIB=${JONAS_ROOT}/lib/fdf
fi

# -----------------------------------------------------------------------
# Set Fractal options
# -----------------------------------------------------------------------

JAVA_OPTS="\
-Djava.security.policy=${JONAS_ROOT}/conf/java.policy \
-Dfractal.provider=org.objectweb.fractal.julia.Julia \
-Djulia.config=${JONAS_ROOT}/conf/julia.cfg \
-Djulia.loader=org.objectweb.fractal.julia.loader.DynamicLoader \
-Djulia.loader.use-context-class-loader=true"

CLASS_TO_RUN=org.objectweb.fdf.adl.Launcher

# -----------------------------------------------------------------------
# Set FDF Explorer configuration
# -----------------------------------------------------------------------

EXPLORER_PARAMS="-fractal org.objectweb.fdf.explorer.Explorer(FDF-Explorer) r"

# -----------------------------------------------------------------------
# Set the JONAS_CLASSPATH
# -----------------------------------------------------------------------

JONAS_CLASSPATH=\
${JONAS_ROOT}/examples/fdf$SPS\
${JONAS_ROOT}/conf$SPS\
${JONAS_ROOT}/lib/tmf/asm-2.1.jar$SPS\
${FDF_LIB}/fractal/fractal.jar$SPS\
${FDF_LIB}/fractal-adl/dtdparser.jar$SPS\
${FDF_LIB}/fractal-adl/fractal-adl.jar$SPS\
${FDF_LIB}/fractal-adl/ow_deployment_scheduling.jar$SPS\
${FDF_LIB}/fractal-explorer/apollon/apollon-runtime.jar$SPS\
${FDF_LIB}/fractal-explorer/beanshell/bsh-2.0b1.jar$SPS\
${FDF_LIB}/fractal-explorer/explorer/ow_util_explorer.jar$SPS\
${FDF_LIB}/fractal-explorer/explorer/reflect-plugin.jar$SPS\
${FDF_LIB}/fractal-explorer/jgraph/jgraph-5.9.2.1.jar$SPS\
${FDF_LIB}/fractal-explorer/ow-util/ow_util_cmdline.jar$SPS\
${FDF_LIB}/fractal-explorer/ow-util/ow_util_misc.jar$SPS\
${FDF_LIB}/fractal-explorer/ow-util/ow_util_trace.jar$SPS\
${FDF_LIB}/fractal-explorer/fractal-explorer.jar$SPS\
${FDF_LIB}/julia/julia-asm-2.0.3.jar$SPS\
${FDF_LIB}/julia/julia-mixins-2.0.3.jar$SPS\
${FDF_LIB}/julia/julia-runtime-2.0.3.jar$SPS\
${JONAS_ROOT}/lib/commons/jonas/monolog/ow_util_log_api.jar$SPS\
${JONAS_ROOT}/lib/commons/jonas/monolog/ow_util_log_wrp_log4j.jar$SPS\
${FDF_LIB}/network-protocols/commons-net-1.4.1.jar$SPS\
${FDF_LIB}/network-protocols/jsch-0.1.26.jar$SPS\
${FDF_LIB}/network-protocols/jtelnet.jar$SPS\
${JONAS_ROOT}/lib/endorsed/xercesImpl.jar$SPS\
${FDF_LIB}/ow-fdf-2.0.0.jar

export JONAS_CLASSPATH

# -----------------------------------------------------------------------
# Parse command line arguments
# -----------------------------------------------------------------------

case "$1" in
  run)
    MODE=run
    DESCRIPTION=$2
    PROCEDURE=$3;;
  explorer)
    MODE=explorer
    ;;
  *)
    echo "Usage: fdf run|explorer [options]"
    echo "   Explorer mode: > fdf explorer"
    echo "                 (will display the GUI)"
    echo "   Console mode:  > fdf run description_file install|start|stop|uninstall"
    echo "                 (will perform the deployment in text mode)"
    exit 1
    ;;
esac

# -----------------------------------------------------------------------
# Run FDF
# -----------------------------------------------------------------------

case "$MODE" in
  run)
    if ! [ "$PROCEDURE" = "install" -o "$PROCEDURE" = "start" -o "$PROCEDURE" = "stop" -o "$PROCEDURE" = "uninstall" ]
    then
      echo "Authorized procedures are: install | start | stop | uninstall"
      exit 1
    fi
    LAUNCHER="-fractal org.objectweb.fdf.components.fdf.lib.runnable.Launcher($DESCRIPTION,$PROCEDURE,,,,) r"
    exec $JAVA -cp $JONAS_CLASSPATH $JAVA_OPTS $CLASS_TO_RUN $LAUNCHER
    ;;
  explorer)
    exec $JAVA $JAVA_OPTS -cp $JONAS_CLASSPATH $CLASS_TO_RUN $EXPLORER_PARAMS
    ;;
esac
