@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem      https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem  pdf4av-app startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables, and ensure extensions are enabled
setlocal EnableExtensions

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%..

@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

@rem Add default JVM options here. You can also use JAVA_OPTS and PDF4AV_APP_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

"%COMSPEC%" /c exit 1

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

"%COMSPEC%" /c exit 1

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\lib\pdf4av-app-0.0.1-SNAPSHOT.jar;%APP_HOME%\lib\pdf4av-0.0.1-SNAPSHOT.jar;%APP_HOME%\lib\picocli-4.7.7.jar;%APP_HOME%\lib\slf4j-api-2.0.17.jar;%APP_HOME%\lib\fop-2.11.jar;%APP_HOME%\lib\fop-core-2.11.jar;%APP_HOME%\lib\fop-events-2.11.jar;%APP_HOME%\lib\fop-util-2.11.jar;%APP_HOME%\lib\batik-extension-1.19.jar;%APP_HOME%\lib\batik-codec-1.19.jar;%APP_HOME%\lib\batik-transcoder-1.19.jar;%APP_HOME%\lib\batik-bridge-1.19.jar;%APP_HOME%\lib\batik-script-1.19.jar;%APP_HOME%\lib\batik-anim-1.19.jar;%APP_HOME%\lib\batik-gvt-1.19.jar;%APP_HOME%\lib\batik-svg-dom-1.19.jar;%APP_HOME%\lib\batik-parser-1.19.jar;%APP_HOME%\lib\batik-svggen-1.19.jar;%APP_HOME%\lib\batik-awt-util-1.19.jar;%APP_HOME%\lib\batik-dom-1.19.jar;%APP_HOME%\lib\batik-css-1.19.jar;%APP_HOME%\lib\xmlgraphics-commons-2.11.jar;%APP_HOME%\lib\commons-io-2.22.0.jar;%APP_HOME%\lib\Saxon-HE-12.9.jar;%APP_HOME%\lib\fop-hyph-2.0.jar;%APP_HOME%\lib\jts-core-1.20.0.jar;%APP_HOME%\lib\xmlresolver-5.3.3.jar;%APP_HOME%\lib\xmlresolver-5.3.3-data.jar;%APP_HOME%\lib\qdox-1.12.jar;%APP_HOME%\lib\fontbox-3.0.3.jar;%APP_HOME%\lib\pdfbox-io-3.0.3.jar;%APP_HOME%\lib\commons-logging-1.3.3.jar;%APP_HOME%\lib\batik-ext-1.19.jar;%APP_HOME%\lib\batik-xml-1.19.jar;%APP_HOME%\lib\batik-util-1.19.jar;%APP_HOME%\lib\batik-constants-1.19.jar;%APP_HOME%\lib\batik-i18n-1.19.jar;%APP_HOME%\lib\batik-shared-resources-1.19.jar


@rem Execute pdf4av-app
@rem endlocal doesn't take effect until after the line is parsed and variables are expanded
@rem which allows us to clear the local environment before executing the java command
endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %PDF4AV_APP_OPTS%  -classpath "%CLASSPATH%" ch.so.agi.av.webservice.Pdf4AvCli %* & call :exitWithErrorLevel

:exitWithErrorLevel
@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
"%COMSPEC%" /c exit %ERRORLEVEL%
