@REM ----------------------------------------------------------------------------
@REM Copyright 2001-2004 The Apache Software Foundation.
@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      http://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

@echo off

set ERROR_CODE=0

:init
@REM Decide how to startup depending on the version of windows

@REM -- Win98ME
if NOT "%OS%"=="Windows_NT" goto Win9xArg

@REM set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" @setlocal

@REM -- 4NT shell
if "%eval[2+2]" == "4" goto 4NTArgs

@REM -- Regular WinNT shell
set CMD_LINE_ARGS=%*
goto WinNTGetScriptDir

@REM The 4NT Shell from jp software
:4NTArgs
set CMD_LINE_ARGS=%$
goto WinNTGetScriptDir

:Win9xArg
@REM Slurp the command line arguments.  This loop allows for an unlimited number
@REM of arguments (up to the command line limit, anyway).
set CMD_LINE_ARGS=
:Win9xApp
if %1a==a goto Win9xGetScriptDir
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
shift
goto Win9xApp

:Win9xGetScriptDir
set SAVEDIR=%CD%
%0\
cd %0\..\.. 
set BASEDIR=%CD%
cd %SAVEDIR%
set SAVE_DIR=
goto repoSetup

:WinNTGetScriptDir
set BASEDIR=%~dp0\..

:repoSetup


if "%JAVACMD%"=="" set JAVACMD=java

if "%REPO%"=="" set REPO=%BASEDIR%\repo

set CLASSPATH="%BASEDIR%"\conf;"%REPO%"\org\apache\helix\metadata-store-directory-common\2.0.1\metadata-store-directory-common-2.0.1.jar;"%REPO%"\org\apache\httpcomponents\httpclient\4.5.14\httpclient-4.5.14.jar;"%REPO%"\org\apache\httpcomponents\httpcore\4.4.16\httpcore-4.4.16.jar;"%REPO%"\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;"%REPO%"\com\google\guava\guava\32.0.0-jre\guava-32.0.0-jre.jar;"%REPO%"\com\google\guava\failureaccess\1.0.1\failureaccess-1.0.1.jar;"%REPO%"\com\google\guava\listenablefuture\9999.0-empty-to-avoid-conflict-with-guava\listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar;"%REPO%"\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar;"%REPO%"\org\checkerframework\checker-qual\3.33.0\checker-qual-3.33.0.jar;"%REPO%"\com\google\errorprone\error_prone_annotations\2.18.0\error_prone_annotations-2.18.0.jar;"%REPO%"\com\google\j2objc\j2objc-annotations\2.8\j2objc-annotations-2.8.jar;"%REPO%"\org\yaml\snakeyaml\2.0\snakeyaml-2.0.jar;"%REPO%"\org\slf4j\slf4j-api\1.7.32\slf4j-api-1.7.32.jar;"%REPO%"\org\apache\logging\log4j\log4j-slf4j-impl\2.25.4\log4j-slf4j-impl-2.25.4.jar;"%REPO%"\org\apache\logging\log4j\log4j-api\2.25.4\log4j-api-2.25.4.jar;"%REPO%"\org\apache\logging\log4j\log4j-core\2.25.4\log4j-core-2.25.4.jar;"%REPO%"\org\apache\helix\helix-core\2.0.1\helix-core-2.0.1.jar;"%REPO%"\org\apache\helix\helix-common\2.0.1\helix-common-2.0.1.jar;"%REPO%"\org\apache\helix\metrics-common\2.0.1\metrics-common-2.0.1.jar;"%REPO%"\org\apache\helix\zookeeper-api\2.0.1\zookeeper-api-2.0.1.jar;"%REPO%"\org\apache\zookeeper\zookeeper\3.6.3\zookeeper-3.6.3.jar;"%REPO%"\org\apache\zookeeper\zookeeper-jute\3.6.3\zookeeper-jute-3.6.3.jar;"%REPO%"\org\apache\yetus\audience-annotations\0.5.0\audience-annotations-0.5.0.jar;"%REPO%"\io\netty\netty-handler\4.1.63.Final\netty-handler-4.1.63.Final.jar;"%REPO%"\io\netty\netty-common\4.1.63.Final\netty-common-4.1.63.Final.jar;"%REPO%"\io\netty\netty-resolver\4.1.63.Final\netty-resolver-4.1.63.Final.jar;"%REPO%"\io\netty\netty-buffer\4.1.63.Final\netty-buffer-4.1.63.Final.jar;"%REPO%"\io\netty\netty-transport\4.1.63.Final\netty-transport-4.1.63.Final.jar;"%REPO%"\io\netty\netty-codec\4.1.133.Final\netty-codec-4.1.133.Final.jar;"%REPO%"\io\netty\netty-transport-native-epoll\4.1.63.Final\netty-transport-native-epoll-4.1.63.Final.jar;"%REPO%"\io\netty\netty-transport-native-unix-common\4.1.63.Final\netty-transport-native-unix-common-4.1.63.Final.jar;"%REPO%"\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;"%REPO%"\com\fasterxml\jackson\core\jackson-core\2.18.6\jackson-core-2.18.6.jar;"%REPO%"\commons-io\commons-io\2.14.0\commons-io-2.14.0.jar;"%REPO%"\org\apache\commons\commons-math\2.1\commons-math-2.1.jar;"%REPO%"\org\apache\commons\commons-math3\3.6.1\commons-math3-3.6.1.jar;"%REPO%"\commons-codec\commons-codec\1.6\commons-codec-1.6.jar;"%REPO%"\io\dropwizard\metrics\metrics-core\4.1.14\metrics-core-4.1.14.jar;"%REPO%"\javax\xml\bind\jaxb-api\2.1\jaxb-api-2.1.jar;"%REPO%"\javax\xml\stream\stax-api\1.0-2\stax-api-1.0-2.jar;"%REPO%"\javax\activation\activation\1.1\activation-1.1.jar;"%REPO%"\org\xerial\snappy\snappy-java\1.1.10.4\snappy-java-1.1.10.4.jar;"%REPO%"\org\apache\commons\commons-lang3\3.18.0\commons-lang3-3.18.0.jar;"%REPO%"\org\eclipse\jetty\jetty-server\9.4.56.v20240826\jetty-server-9.4.56.v20240826.jar;"%REPO%"\javax\servlet\javax.servlet-api\3.1.0\javax.servlet-api-3.1.0.jar;"%REPO%"\org\eclipse\jetty\jetty-http\9.4.56.v20240826\jetty-http-9.4.56.v20240826.jar;"%REPO%"\org\eclipse\jetty\jetty-util\9.4.56.v20240826\jetty-util-9.4.56.v20240826.jar;"%REPO%"\org\eclipse\jetty\jetty-io\9.4.56.v20240826\jetty-io-9.4.56.v20240826.jar;"%REPO%"\org\glassfish\jersey\core\jersey-server\2.35\jersey-server-2.35.jar;"%REPO%"\org\glassfish\jersey\core\jersey-common\2.35\jersey-common-2.35.jar;"%REPO%"\org\glassfish\hk2\osgi-resource-locator\1.0.3\osgi-resource-locator-1.0.3.jar;"%REPO%"\org\glassfish\jersey\core\jersey-client\2.35\jersey-client-2.35.jar;"%REPO%"\jakarta\ws\rs\jakarta.ws.rs-api\2.1.6\jakarta.ws.rs-api-2.1.6.jar;"%REPO%"\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;"%REPO%"\org\glassfish\hk2\external\jakarta.inject\2.6.1\jakarta.inject-2.6.1.jar;"%REPO%"\jakarta\validation\jakarta.validation-api\2.0.2\jakarta.validation-api-2.0.2.jar;"%REPO%"\org\glassfish\jersey\test-framework\jersey-test-framework-core\2.35\jersey-test-framework-core-2.35.jar;"%REPO%"\jakarta\xml\bind\jakarta.xml.bind-api\2.3.3\jakarta.xml.bind-api-2.3.3.jar;"%REPO%"\jakarta\activation\jakarta.activation-api\1.2.2\jakarta.activation-api-1.2.2.jar;"%REPO%"\jakarta\servlet\jakarta.servlet-api\4.0.3\jakarta.servlet-api-4.0.3.jar;"%REPO%"\org\glassfish\jersey\media\jersey-media-jaxb\2.35\jersey-media-jaxb-2.35.jar;"%REPO%"\org\glassfish\jersey\containers\jersey-container-servlet-core\2.35\jersey-container-servlet-core-2.35.jar;"%REPO%"\org\glassfish\jersey\inject\jersey-hk2\2.35\jersey-hk2-2.35.jar;"%REPO%"\org\glassfish\hk2\hk2-locator\2.6.1\hk2-locator-2.6.1.jar;"%REPO%"\org\glassfish\hk2\external\aopalliance-repackaged\2.6.1\aopalliance-repackaged-2.6.1.jar;"%REPO%"\org\glassfish\hk2\hk2-api\2.6.1\hk2-api-2.6.1.jar;"%REPO%"\org\glassfish\hk2\hk2-utils\2.6.1\hk2-utils-2.6.1.jar;"%REPO%"\org\javassist\javassist\3.25.0-GA\javassist-3.25.0-GA.jar;"%REPO%"\org\eclipse\jetty\jetty-servlet\9.4.48.v20220622\jetty-servlet-9.4.48.v20220622.jar;"%REPO%"\org\eclipse\jetty\jetty-security\9.4.48.v20220622\jetty-security-9.4.48.v20220622.jar;"%REPO%"\org\eclipse\jetty\jetty-util-ajax\9.4.48.v20220622\jetty-util-ajax-9.4.48.v20220622.jar;"%REPO%"\com\thoughtworks\xstream\xstream\1.4.21\xstream-1.4.21.jar;"%REPO%"\io\github\x-stream\mxparser\1.2.2\mxparser-1.2.2.jar;"%REPO%"\xmlpull\xmlpull\1.1.3.1\xmlpull-1.1.3.1.jar;"%REPO%"\com\fasterxml\jackson\core\jackson-databind\2.18.6\jackson-databind-2.18.6.jar;"%REPO%"\com\fasterxml\jackson\core\jackson-annotations\2.18.6\jackson-annotations-2.18.6.jar;"%REPO%"\commons-cli\commons-cli\1.2\commons-cli-1.2.jar;"%REPO%"\io\dropwizard\metrics\metrics-jersey2\4.1.14\metrics-jersey2-4.1.14.jar;"%REPO%"\io\dropwizard\metrics\metrics-annotation\4.1.14\metrics-annotation-4.1.14.jar;"%REPO%"\io\dropwizard\metrics\metrics-jmx\4.1.14\metrics-jmx-4.1.14.jar;"%REPO%"\io\swagger\swagger-annotations\1.6.4\swagger-annotations-1.6.4.jar;"%REPO%"\io\swagger\swagger-core\1.6.4\swagger-core-1.6.4.jar;"%REPO%"\com\fasterxml\jackson\dataformat\jackson-dataformat-yaml\2.11.1\jackson-dataformat-yaml-2.11.1.jar;"%REPO%"\javax\validation\validation-api\1.1.0.Final\validation-api-1.1.0.Final.jar;"%REPO%"\io\swagger\swagger-jaxrs\1.6.4\swagger-jaxrs-1.6.4.jar;"%REPO%"\javax\ws\rs\jsr311-api\1.1.1\jsr311-api-1.1.1.jar;"%REPO%"\org\reflections\reflections\0.9.11\reflections-0.9.11.jar;"%REPO%"\io\swagger\swagger-models\1.6.4\swagger-models-1.6.4.jar;"%REPO%"\org\apache\helix\helix-rest\2.0.1\helix-rest-2.0.1.jar
set EXTRA_JVM_ARGUMENTS=-Dlog4j2.formatMsgNoLookups=true -Dlog4j2.configurationFile=file://"$BASEDIR"/conf/log4j2.properties
goto endInit

@REM Reaching here means variables are defined and arguments have been captured
:endInit

%JAVACMD% %JAVA_OPTS% %EXTRA_JVM_ARGUMENTS% -classpath %CLASSPATH_PREFIX%;%CLASSPATH% -Dapp.name="run-rest-admin" -Dapp.repo="%REPO%" -Dbasedir="%BASEDIR%" org.apache.helix.rest.server.HelixRestMain %CMD_LINE_ARGS%
if ERRORLEVEL 1 goto error
goto end

:error
if "%OS%"=="Windows_NT" @endlocal
set ERROR_CODE=1

:end
@REM set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" goto endNT

@REM For old DOS remove the set variables from ENV - we assume they were not set
@REM before we started - at least we don't leave any baggage around
set CMD_LINE_ARGS=
goto postExec

:endNT
@endlocal

:postExec

if "%FORCE_EXIT_ON_ERROR%" == "on" (
  if %ERROR_CODE% NEQ 0 exit %ERROR_CODE%
)

exit /B %ERROR_CODE%
