@Echo off
rem -----------------------------------------------------------------------
rem ObjectWeb Fractal Deployment Framework
rem Copyright (C) 2006-2007 INRIA - ADAM Team
rem Contact: fdf-users@lists.gforge.inria.fr
rem Copyright (C) 1999-2008 Bull S.A.S.
rem Contact: jonas-team@objectweb.org
rem
rem This library is free software; you can redistribute it and/or
rem modify it under the terms of the GNU Lesser General Public
rem License as published by the Free Software Foundation; either
rem version 2.1 of the License, or any later version.
rem
rem This library is distributed in the hope that it will be useful,
rem but WITHOUT ANY WARRANTY; without even the implied warranty of
rem MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
rem Lesser General Public License for more details.
rem
rem You should have received a copy of the GNU Lesser General Public
rem License along with this library; if not, write to the Free Software
rem Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
rem USA
rem
rem Initial developer(s): Philippe Merle.
rem
rem Contributor(s): Nicolas Dolet
rem        S. Ali Tokmen:
rem          - Automatic setting of JONAS_ROOT
rem          - Fixed issues when using this batch in a folder contaning spaces
rem -----------------------------------------------------------------------

Rem  Check for JONAS_ROOT, if not set set it to the default
if "%JONAS_ROOT%"=="" Goto SetJONAS_ROOT
echo JONAS_ROOT is set to %JONAS_ROOT%
Goto ExecuteBatch

Rem %~dp0 is the directory in which this batch file is,
Rem therefore JONAS_ROOT\bin\nt in our case.
:SetJONAS_ROOT
pushd "%~dp0"
cd ..
cd ..
@set JONAS_ROOT=%CD%
@echo Setting JONAS_ROOT to %JONAS_ROOT%
popd

:ExecuteBatch
call "%JONAS_ROOT%\bin\nt\setenv"

rem -----------------------------------------------------------------------
rem Check FDF_LIB
rem -----------------------------------------------------------------------

:checkFDFlib
if ["%FDF_LIB%"]==[""] goto :setFDFlib
goto :setJavaOpts

:setFDFlib
set FDF_LIB=%JONAS_ROOT%\lib\fdf

rem -----------------------------------------------------------------------
rem Set Java, Fractal and FDF options
rem -----------------------------------------------------------------------

:setJavaOpts
set JAVA_OPTS=-Djava.security.policy="%JONAS_ROOT%\conf\java.policy"
set JAVA_OPTS=%JAVA_OPTS% -Dfractal.provider=org.objectweb.fractal.julia.Julia
set JAVA_OPTS=%JAVA_OPTS% -Djulia.config="%JONAS_ROOT%\conf\julia.cfg"
set JAVA_OPTS=%JAVA_OPTS% -Djulia.loader=org.objectweb.fractal.julia.loader.DynamicLoader
set JAVA_OPTS=%JAVA_OPTS% -Djulia.loader.use-context-class-loader=true

set CLASS_TO_RUN=org.objectweb.fdf.adl.Launcher

rem -----------------------------------------------------------------------
rem Set FDF Explorer configuration
rem -----------------------------------------------------------------------

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

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

if [%1]==[run] goto console_mode
if [%1]==[explorer] goto explorer_mode
goto usage

:console_mode
set DESCRIPTION=%2
set PROCEDURE=%3

rem -----------------------------------------------------------------------
rem Check procedure
rem -----------------------------------------------------------------------

if [%PROCEDURE%]==[install] goto run
if [%PROCEDURE%]==[start] goto run
if [%PROCEDURE%]==[stop] goto run
if [%PROCEDURE%]==[uninstall] goto run
goto procedures

:run
set LAUNCHER=-fractal org.objectweb.fdf.components.fdf.lib.runnable.Launcher(%DESCRIPTION%,%PROCEDURE%,,,,) r

%JAVA% -classpath "%CLASSPATH%" %JAVA_OPTS% %CLASS_TO_RUN% %LAUNCHER%
goto :EOF

:procedures
echo "Authorized procedures are: install | start | stop | uninstall"
goto :EOF

:explorer_mode
%JAVA% -classpath "%CLASSPATH%" %JAVA_OPTS% %CLASS_TO_RUN% %EXPLORER_PARAMS%

goto :EOF

:usage
echo "Usage: fdf run|explorer"
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)"
