@REM ----------------------------------------------------------------------------
@REM Apache Maven Wrapper startup batch script, version 3.3.2
@REM ----------------------------------------------------------------------------
@echo off
@setlocal

@REM ==== START VALIDATION ====
if not "%JAVA_HOME%"=="" goto OkJHome

@REM Try common Java 17 locations on this machine
if exist "D:\Program Files\Java\jdk-17\bin\java.exe" (
    set "JAVA_HOME=D:\Program Files\Java\jdk-17"
    goto OkJHome
)
if exist "C:\Program Files\Java\jdk-17\bin\java.exe" (
    set "JAVA_HOME=C:\Program Files\Java\jdk-17"
    goto OkJHome
)
if exist "C:\Program Files\Eclipse Adoptium\jdk-17\bin\java.exe" (
    set "JAVA_HOME=C:\Program Files\Eclipse Adoptium\jdk-17"
    goto OkJHome
)

echo.
echo Error: JAVA_HOME is not set and Java 17 was not found in common locations.
echo   Set JAVA_HOME to point to your Java 17 JDK installation.
echo.
exit /B 1

:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto Init

echo.
echo Error: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
exit /B 1

:Init
set _JAVACMD=%JAVA_HOME%\bin\java.exe
set MAVEN_WRAPPER_JAR=%~dp0.mvn\wrapper\maven-wrapper.jar
set MAVEN_WRAPPER_PROPERTIES=%~dp0.mvn\wrapper\maven-wrapper.properties

@REM Download wrapper jar if missing
if not exist "%MAVEN_WRAPPER_JAR%" (
    echo Downloading Maven Wrapper...
    "%_JAVACMD%" -classpath "%MAVEN_WRAPPER_JAR%" "-Dmaven.multiModuleProjectDirectory=%~dp0." ^
        org.apache.maven.wrapper.MavenWrapperMain %* 2>nul
    if errorlevel 1 (
        "%_JAVACMD%" ^
            -Dmaven.multiModuleProjectDirectory="%~dp0." ^
            -Dmaven.wrapper.launcher.url="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar" ^
            org.apache.maven.wrapper.MavenWrapperBootstrap %*
        if errorlevel 1 goto error
    )
)

@REM Execute Maven via wrapper
"%_JAVACMD%" ^
    -classpath "%MAVEN_WRAPPER_JAR%" ^
    "-Dmaven.multiModuleProjectDirectory=%~dp0." ^
    org.apache.maven.wrapper.MavenWrapperMain %*

if errorlevel 1 goto error
goto end

:error
set ERROR_CODE=1

:end
@endlocal & exit /B %ERROR_CODE%
