@echo off
setlocal

set JAVA_HOME=c:\Program Files\Java\jdk1.6.0_18
set CXF_HOME=C:\java\apache-cxf-2.1.4

set JAVAC="%JAVA_HOME%\bin\javac.exe"
set CLASSPATH=.;%CXF_HOME%\lib\cxf-manifest.jar

if [%1]==[] (
    echo Usage: CreateAPIJar.cmd [HeadNode] [BrokerNode]
    echo compile test-src only: CreateAPIJar.cmd c
    echo Example: CreateAPIJar.cmd computer1 computer2
    echo Example: CreateAPIJar.cmd c
    exit /b 0
)

echo StartTime=%DATE% %TIME%

if not [%2]==[] (
    goto wsdljava
)

:testjava
echo Copy test java src code
xcopy /s /y src\exceptions com\microsoft\hpc\exceptions\ >nul 2>&1
xcopy /s /y src\scheduler com\microsoft\hpc\scheduler\   >nul 2>&1
xcopy /s /y src\SOATrace com\microsoft\hpc\SOATrace\     >nul 2>&1

echo Compiling test java src code
%JAVAC% .\com\microsoft\hpc\exceptions\*.java
%JAVAC% .\com\microsoft\hpc\scheduler\session\*.java
%JAVAC% .\com\microsoft\hpc\scheduler\session\internal\*.java
%JAVAC% .\com\microsoft\hpc\SOATrace\*.java

"%JAVA_HOME%\bin\jar.exe" cf Microsoft.Hpc.Scheduler.jar com org *.wsdl *.xsd

echo EndTime=%DATE% %TIME%
exit /b 0

:wsdljava
echo Create *.java from wsdl 
call %CXF_HOME%\bin\wsdl2java https:\\%1\SessionLauncher?wsdl            >logs.txt 2>&1
call %CXF_HOME%\bin\wsdl2java https:\\%2\BrokerLauncher?wsdl             >>logs.txt 2>&1
call %CXF_HOME%\bin\wsdl2java hpc.microsoft.com.brokercontroller.wsdl    >>logs.txt 2>&1

echo %JAVAC% .\com\microsoft\hpc\*.java
%JAVAC% .\com\microsoft\hpc\*.java

echo %JAVAC% .\com\microsoft\hpc\brokercontroller\*.java
%JAVAC% .\com\microsoft\hpc\brokercontroller\*.java

echo %JAVAC% .\com\microsoft\hpc\brokerlauncher\*.java
%JAVAC% .\com\microsoft\hpc\brokerlauncher\*.java

echo %JAVAC% .\com\microsoft\hpc\session\*.java
%JAVAC% .\com\microsoft\hpc\session\*.java

echo %JAVAC% .\com\microsoft\hpc\sessionlauncher\*.java
%JAVAC% .\com\microsoft\hpc\sessionlauncher\*.java

echo %JAVAC% schemas
FOR /F %%i IN ('dir /b/s com\microsoft\schemas\*.java') DO %javac% %%i

echo %JAVAC%  org
FOR /F %%i IN ('dir /b/s org\*.java') DO %javac% %%i

goto testjava



