@Echo off

rem ---------------------------------------------------------------------------
rem ObjectWeb Fractal Deployment Framework
rem Copyright (C) 2005 INRIA - Jacquard Team
rem Contact: architecture@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 Contributor(s): Areski Flissi, James Manley.
rem ---------------------------------------------------------------------------

rem ---------------------------------------------------------------------------
rem Check JONAS_ROOT variable
rem ---------------------------------------------------------------------------

if ["%JONAS_ROOT%"]==[""] goto :setjonasroot
goto :setjarsname

:setjonasroot
echo JONAS_ROOT is not set, please set it
goto :EOF

rem ---------------------------------------------------------------------------
rem Jar name setup
rem ---------------------------------------------------------------------------

:setjarsname

if [%JAVA_HOME%]==[] goto setjava
set JAVA="%JAVA_HOME%\bin\java"
goto checkarg

:setjava
echo JAVA_HOME is not set, please set it
goto :EOF

rem ---------------------------------------------------------------------------
rem Check argument
rem ---------------------------------------------------------------------------

:checkarg

if  [%1]==[launcher] goto launcher

goto usage

:launcher

set CLASSPATH=.
set MODE=%~1
shift
if not ["%1"] == ["-cp"] goto :nocp
set CLASSPATH=%~2
shift
shift

goto cp
:nocp


if ["%1"] == ["%~n1"] goto noclasspath

set CLASSPATH=%~d1%~p1;%CLASSPATH%

:noclasspath

:cp

set ARGS=-fractal %~n1 r %~2

shift
shift


:arg_loop

if [%1] == [] goto end_arg_loop

set ARGS=%ARGS% %~1
shift
goto arg_loop

:end_arg_loop

rem -----------------------------------------------------------------------
rem Check FDF_HOME
rem -----------------------------------------------------------------------

set FDF_HOME=%JONAS_ROOT%\lib\fdf

rem -----------------------------------------------------------------------
rem  Set Fractal options
rem -----------------------------------------------------------------------

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


rem ---------------------------------------------------------------------------
rem                         Classpath
rem ---------------------------------------------------------------------------
set CLASSPATH=%JONAS_ROOT%\examples\fdf\;%CLASSPATH%
set CLASSPATH=%ANT_HOME%\lib\ant.jar;%CLASSPATH%
set CLASSPATH=%FDF_HOME%\ant-jsch.jar;%CLASSPATH%
set CLASSPATH=%FDF_HOME%\asm-2.0.jar;%CLASSPATH%
set CLASSPATH=%JONAS_ROOT%\lib\commons\jonas\jakarta-commons\commons-codec-1.3.jar;%CLASSPATH%
set CLASSPATH=%FDF_HOME%\commons-httpclient-3.0.jar;%CLASSPATH%
set CLASSPATH=%FDF_HOME%\commons-logging.jar;%CLASSPATH%
set CLASSPATH=%FDF_HOME%\commons-net-1.4.1.jar;%CLASSPATH%
set CLASSPATH=%FDF_HOME%\dom4j-1.6.jar;%CLASSPATH%
set CLASSPATH=%FDF_HOME%\dtdparser.jar;%CLASSPATH%
set CLASSPATH=%FDF_HOME%\fdf.jar;%CLASSPATH%
set CLASSPATH=%FDF_HOME%\fractal-adl.jar;%CLASSPATH%
set CLASSPATH=%FDF_HOME%\fractal.jar;%CLASSPATH%
set CLASSPATH=%FDF_HOME%\ganymed-ssh2-build209.jar;%CLASSPATH%
set CLASSPATH=%FDF_HOME%\jsch-0.1.26.jar;%CLASSPATH%
set CLASSPATH=%FDF_HOME%\julia-asm-2.0.3.jar;%CLASSPATH%
set CLASSPATH=%FDF_HOME%\julia-mixins-2.0.3.jar;%CLASSPATH%
set CLASSPATH=%FDF_HOME%\julia-runtime-2.0.3.jar;%CLASSPATH%
set CLASSPATH=%FDF_HOME%\ow_deployment_scheduling.jar;%CLASSPATH%
set CLASSPATH=%FDF_HOME%\ow-monolog-2.1.1.jar;%CLASSPATH%
set CLASSPATH=%JONAS_ROOT%\lib\commons\jonas\monolog\ow_util_log_api.jar;%CLASSPATH%
set CLASSPATH=%FDF_HOME%\ow_util_trace.jar;%CLASSPATH%
set CLASSPATH=%JONAS_ROOT%\lib\commons\jonas\monolog\ow_util_log_file.jar;%CLASSPATH%
set CLASSPATH=%JONAS_ROOT%\lib\commons\jonas\monolog\ow_util_log_helper.jar;%CLASSPATH%
set CLASSPATH=%JONAS_ROOT%\lib\commons\jonas\monolog\ow_util_log_remote.jar;%CLASSPATH%
set CLASSPATH=%JONAS_ROOT%\lib\commons\jonas\monolog\ow_util_log_wrp_common.jar;%CLASSPATH%
set CLASSPATH=%JONAS_ROOT%\lib\commons\jonas\monolog\ow_util_log_wrp_javalog.jar;%CLASSPATH%
set CLASSPATH=%JONAS_ROOT%\lib\commons\jonas\monolog\ow_util_log_wrp_log4j.jar;%CLASSPATH%
set CLASSPATH=%JONAS_ROOT%\lib\commons\jonas\monolog\ow_util_log_wrp_p6spy.jar;%CLASSPATH%
set CLASSPATH=%JONAS_ROOT%\lib\commons\jonas\monolog\ow_util_log_wrp_pw.jar;%CLASSPATH%
set CLASSPATH=%JONAS_ROOT%\lib\commons\jonas\jakarta-commons\commons-logging-api.jar;%CLASSPATH%


rem -----------------------------------------------------------------------
rem Set the Fractal main class to run
rem -----------------------------------------------------------------------

if ![%MODE%] == [launcher] goto :usage

set CLASS_TO_RUN=org.objectweb.fractal.deployment.launcher.Launcher
 



rem ---------------------------------------------------------------------------
rem                         Run
rem ---------------------------------------------------------------------------

%JAVA% %FRACTAL_OPTS% -classpath "%CLASSPATH%" %CLASS_TO_RUN% %ARGS%
 
goto :EOF

rem ---------------------------------------------------------------------------
rem                         Usage
rem ---------------------------------------------------------------------------

:usage
echo "Usage: fdf launcher [-cp ADL_directory] ADL_name {install|start|stop|uninstall}"
goto :EOF

:EOF