:: conda-build should be taking care of this, but do it anyway
set JAVA_HOME=%LIBRARY_PREFIX%
set ANT_HOME=%LIBRARY_PREFIX%

:: Build the project
mkdir build
call ant build
if errorlevel 1 exit 1

:: Run some tests
call ant server_test
if errorlevel 1 exit 1

mkdir tools
cd tools

:: Download launch4j (look at refine script for default version)
set L4J_VERSION=3.8
curl -LO "http://downloads.sourceforge.net/project/launch4j/launch4j-3/%L4J_VERSION%/launch4j-%L4J_VERSION%-win32.zip"
if errorlevel 1 exit 1

unzip -q launch4j-%L4J_VERSION%-win32.zip
if errorlevel 1 exit 1
cd ..

:: Create and unzip the dist
mkdir dist
call ant -Dlaunch4j.dir=tools/launch4j -Dversion=%PKG_VERSION% windows
call ant server_test
if errorlevel 1 exit 1

unzip dist\openrefine-win-%PKG_VERSION%.zip -d %PREFIX%
if errorlevel 1 exit 1

move "%PREFIX%\openrefine-%PKG_VERSION%" "%PREFIX%\openrefine"

:: Entry point
echo %%CONDA_PREFIX%%\openrefine\refine.bat %%* > %LIBRARY_BIN%\refine.bat