Update bat files to not use find_java.bat

find_java.bat is in the deprecated "tools" component and should no
longer be used. Switching to just looking for what's on the path or in
JAVA_HOME, as other tools do.

Bug: 150888434
Test: none
Change-Id: Idec6abc042efc10dffd3cc718b798134954daf58
Merged-In: Idec6abc042efc10dffd3cc718b798134954daf58
diff --git a/dx/etc/dx.bat b/dx/etc/dx.bat
index 6545886..f2e3857 100755
--- a/dx/etc/dx.bat
+++ b/dx/etc/dx.bat
@@ -22,12 +22,34 @@
 REM and set up progdir to be the fully-qualified pathname of its directory.

 set prog=%~f0

 

-rem Check we have a valid Java.exe in the path.

-set java_exe=

-if exist    "%~dp0..\tools\lib\find_java.bat" call    "%~dp0..\tools\lib\find_java.bat"

-if exist "%~dp0..\..\tools\lib\find_java.bat" call "%~dp0..\..\tools\lib\find_java.bat"

-if not defined java_exe goto :EOF

+@rem Find java.exe

+if defined JAVA_HOME goto findJavaFromJavaHome

 

+set JAVA_EXE=java.exe

+%JAVA_EXE% -version >NUL 2>&1

+if "%ERRORLEVEL%" == "0" goto init

+

+echo.

+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

+echo.

+echo Please set the JAVA_HOME variable in your environment to match the

+echo location of your Java installation.

+exit /b 1

+

+:findJavaFromJavaHome

+set JAVA_HOME=%JAVA_HOME:"=%

+set JAVA_EXE=%JAVA_HOME%/bin/java.exe

+

+if exist "%JAVA_EXE%" goto init

+

+echo.

+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%

+echo.

+echo Please set the JAVA_HOME variable in your environment to match the

+echo location of your Java installation.

+exit /b 1

+

+:init

 set jarfile=dx.jar

 set "frameworkdir=%~dp0"

 rem frameworkdir must not end with a dir sep.

diff --git a/dx/etc/mainDexClasses.bat b/dx/etc/mainDexClasses.bat
index dc5f2c3..232635c 100755
--- a/dx/etc/mainDexClasses.bat
+++ b/dx/etc/mainDexClasses.bat
@@ -16,12 +16,34 @@
 REM don't modify the caller's environment

 setlocal

 

-rem Check we have a valid Java.exe in the path.

-set java_exe=

-if exist    "%~dp0..\tools\lib\find_java.bat"    call    "%~dp0..\tools\lib\find_java.bat"

-if exist    "%~dp0..\..\tools\lib\find_java.bat" call    "%~dp0..\..\tools\lib\find_java.bat"

-if not defined java_exe goto :EOF

+@rem Find java.exe

+if defined JAVA_HOME goto findJavaFromJavaHome

 

+set JAVA_EXE=java.exe

+%JAVA_EXE% -version >NUL 2>&1

+if "%ERRORLEVEL%" == "0" goto init

+

+echo.

+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

+echo.

+echo Please set the JAVA_HOME variable in your environment to match the

+echo location of your Java installation.

+exit /b 1

+

+:findJavaFromJavaHome

+set JAVA_HOME=%JAVA_HOME:"=%

+set JAVA_EXE=%JAVA_HOME%/bin/java.exe

+

+if exist "%JAVA_EXE%" goto init

+

+echo.

+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%

+echo.

+echo Please set the JAVA_HOME variable in your environment to match the

+echo location of your Java installation.

+exit /b 1

+

+:init

 set baserules="%~dp0\mainDexClasses.rules"

 set extrarules="%~dp0\mainDexClassesNoAapt.rules"