@echo off
setlocal
cd /d "%~dp0"
set "POM=%~dp0pom.xml"
set "MVN_CMD="
if defined MAVEN_HOME if exist "%MAVEN_HOME%\bin\mvn.cmd" set "MVN_CMD=%MAVEN_HOME%\bin\mvn.cmd"
if not defined MVN_CMD where mvn >nul 2>&1 && set "MVN_CMD=mvn"
if not defined MVN_CMD for %%I in (
  "C:\Program Files\JetBrains\IntelliJ IDEA 2024.1.7\plugins\maven\lib\maven3\bin\mvn.cmd"
  "C:\Program Files\JetBrains\IntelliJ IDEA 2023.3.8\plugins\maven\lib\maven3\bin\mvn.cmd"
) do if exist %%~I set "MVN_CMD=%%~I"
if not defined MVN_CMD (
  echo Set MAVEN_HOME or add mvn to PATH.
  exit /b 1
)
call "%MVN_CMD%" -q -f "%POM%" generate-sources
set "ERR=%ERRORLEVEL%"
if not "%ERR%"=="0" exit /b %ERR%
echo Java sources: %~dp0target\generated-sources\protobuf\java
endlocal
exit /b 0
