ant.bat 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. @echo off
  2. REM Licensed to the Apache Software Foundation (ASF) under one or more
  3. REM contributor license agreements. See the NOTICE file distributed with
  4. REM this work for additional information regarding copyright ownership.
  5. REM The ASF licenses this file to You under the Apache License, Version 2.0
  6. REM (the "License"); you may not use this file except in compliance with
  7. REM the License. You may obtain a copy of the License at
  8. REM
  9. REM http://www.apache.org/licenses/LICENSE-2.0
  10. REM
  11. REM Unless required by applicable law or agreed to in writing, software
  12. REM distributed under the License is distributed on an "AS IS" BASIS,
  13. REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. REM See the License for the specific language governing permissions and
  15. REM limitations under the License.
  16. REM This is an inordinately troublesome piece of code, particularly because it
  17. REM tries to work on both Win9x and WinNT-based systems. If we could abandon '9x
  18. REM support, things would be much easier, but sadly, it is not yet time.
  19. REM Be cautious about editing this, and only add WinNT specific stuff in code that
  20. REM only runs on WinNT.
  21. if "%HOME%"=="" goto homeDrivePathPre
  22. if exist "%HOME%\antrc_pre.bat" call "%HOME%\antrc_pre.bat"
  23. :homeDrivePathPre
  24. if "%HOMEDRIVE%%HOMEPATH%"=="" goto userProfilePre
  25. if "%HOMEDRIVE%%HOMEPATH%"=="%HOME%" goto userProfilePre
  26. if exist "%HOMEDRIVE%%HOMEPATH%\antrc_pre.bat" call "%HOMEDRIVE%%HOMEPATH%\antrc_pre.bat"
  27. :userProfilePre
  28. if "%USERPROFILE%"=="" goto alpha
  29. if "%USERPROFILE%"=="%HOME%" goto alpha
  30. if "%USERPROFILE%"=="%HOMEDRIVE%%HOMEPATH%" goto alpha
  31. if exist "%USERPROFILE%\antrc_pre.bat" call "%USERPROFILE%\antrc_pre.bat"
  32. :alpha
  33. if "%OS%"=="Windows_NT" @setlocal
  34. if "%OS%"=="WINNT" @setlocal
  35. if "%ANT_HOME%"=="" goto setDefaultAntHome
  36. :stripAntHome
  37. if not _%ANT_HOME:~-1%==_\ goto checkClasspath
  38. set ANT_HOME=%ANT_HOME:~0,-1%
  39. goto stripAntHome
  40. :setDefaultAntHome
  41. rem %~dp0 is expanded pathname of the current script under NT
  42. set ANT_HOME=%~dp0..
  43. :checkClasspath
  44. set _USE_CLASSPATH=yes
  45. rem CLASSPATH must not be used if it is equal to ""
  46. if "%CLASSPATH%"=="""" set _USE_CLASSPATH=no
  47. if "%CLASSPATH%"=="" set _USE_CLASSPATH=no
  48. rem Slurp the command line arguments. This loop allows for an unlimited number
  49. rem of arguments (up to the command line limit, anyway).
  50. set ANT_CMD_LINE_ARGS=
  51. :setupArgs
  52. if ""%1""=="""" goto doneStart
  53. if ""%1""==""-noclasspath"" goto clearclasspath
  54. set ANT_CMD_LINE_ARGS=%ANT_CMD_LINE_ARGS% %1
  55. shift
  56. goto setupArgs
  57. rem here is there is a -noclasspath in the options
  58. :clearclasspath
  59. set _USE_CLASSPATH=no
  60. shift
  61. goto setupArgs
  62. rem This label provides a place for the argument list loop to break out
  63. rem and for NT handling to skip to.
  64. :doneStart
  65. if "%_USE_CLASSPATH%"=="no" goto findAntHome
  66. :stripClasspath
  67. if not _%CLASSPATH:~-1%==_\ goto findAntHome
  68. set CLASSPATH=%CLASSPATH:~0,-1%
  69. goto stripClasspath
  70. :findAntHome
  71. rem find ANT_HOME if it does not exist due to either an invalid value passed
  72. rem by the user or the %0 problem on Windows 9x
  73. if exist "%ANT_HOME%\lib\ant.jar" goto checkJava
  74. rem check for ant in Program Files
  75. if not exist "%ProgramFiles%\ant" goto checkSystemDrive
  76. set ANT_HOME=%ProgramFiles%\ant
  77. goto checkJava
  78. :checkSystemDrive
  79. rem check for ant in root directory of system drive
  80. if not exist %SystemDrive%\ant\lib\ant.jar goto checkCDrive
  81. set ANT_HOME=%SystemDrive%\ant
  82. goto checkJava
  83. :checkCDrive
  84. rem check for ant in C:\ant for Win9X users
  85. if not exist C:\ant\lib\ant.jar goto noAntHome
  86. set ANT_HOME=C:\ant
  87. goto checkJava
  88. :noAntHome
  89. echo ANT_HOME is set incorrectly or ant could not be located. Please set ANT_HOME.
  90. goto end
  91. :checkJava
  92. set _JAVACMD=%JAVACMD%
  93. if "%JAVA_HOME%" == "" goto noJavaHome
  94. if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
  95. if "%_JAVACMD%" == "" set _JAVACMD=%JAVA_HOME%\bin\java.exe
  96. goto checkJikes
  97. :noJavaHome
  98. if "%_JAVACMD%" == "" set _JAVACMD=java.exe
  99. :checkJikes
  100. if not "%JIKESPATH%"=="" goto runAntWithJikes
  101. :runAnt
  102. if "%_USE_CLASSPATH%"=="no" goto runAntNoClasspath
  103. :runAntWithClasspath
  104. "%_JAVACMD%" %ANT_OPTS% -classpath "%ANT_HOME%\lib\ant-launcher.jar" "-Dant.home=%ANT_HOME%" org.apache.tools.ant.launch.Launcher %ANT_ARGS% -cp "%CLASSPATH%" %ANT_CMD_LINE_ARGS%
  105. rem Check the error code of the Ant build
  106. if not "%OS%"=="Windows_NT" goto onError
  107. set ANT_ERROR=%ERRORLEVEL%
  108. goto end
  109. :runAntNoClasspath
  110. "%_JAVACMD%" %ANT_OPTS% -classpath "%ANT_HOME%\lib\ant-launcher.jar" "-Dant.home=%ANT_HOME%" org.apache.tools.ant.launch.Launcher %ANT_ARGS% %ANT_CMD_LINE_ARGS%
  111. rem Check the error code of the Ant build
  112. if not "%OS%"=="Windows_NT" goto onError
  113. set ANT_ERROR=%ERRORLEVEL%
  114. goto end
  115. :runAntWithJikes
  116. if not _%JIKESPATH:~-1%==_\ goto checkJikesAndClasspath
  117. set JIKESPATH=%JIKESPATH:~0,-1%
  118. goto runAntWithJikes
  119. :checkJikesAndClasspath
  120. if "%_USE_CLASSPATH%"=="no" goto runAntWithJikesNoClasspath
  121. :runAntWithJikesAndClasspath
  122. "%_JAVACMD%" %ANT_OPTS% -classpath "%ANT_HOME%\lib\ant-launcher.jar" "-Dant.home=%ANT_HOME%" "-Djikes.class.path=%JIKESPATH%" org.apache.tools.ant.launch.Launcher %ANT_ARGS% -cp "%CLASSPATH%" %ANT_CMD_LINE_ARGS%
  123. rem Check the error code of the Ant build
  124. if not "%OS%"=="Windows_NT" goto onError
  125. set ANT_ERROR=%ERRORLEVEL%
  126. goto end
  127. :runAntWithJikesNoClasspath
  128. "%_JAVACMD%" %ANT_OPTS% -classpath "%ANT_HOME%\lib\ant-launcher.jar" "-Dant.home=%ANT_HOME%" "-Djikes.class.path=%JIKESPATH%" org.apache.tools.ant.launch.Launcher %ANT_ARGS% %ANT_CMD_LINE_ARGS%
  129. rem Check the error code of the Ant build
  130. if not "%OS%"=="Windows_NT" goto onError
  131. set ANT_ERROR=%ERRORLEVEL%
  132. goto end
  133. :onError
  134. rem Windows 9x way of checking the error code. It matches via brute force.
  135. for %%i in (1 10 100) do set err%%i=
  136. for %%i in (0 1 2) do if errorlevel %%i00 set err100=%%i
  137. if %err100%==2 goto onError200
  138. if %err100%==0 set err100=
  139. for %%i in (0 1 2 3 4 5 6 7 8 9) do if errorlevel %err100%%%i0 set err10=%%i
  140. if "%err100%"=="" if %err10%==0 set err10=
  141. :onError1
  142. for %%i in (0 1 2 3 4 5 6 7 8 9) do if errorlevel %err100%%err10%%%i set err1=%%i
  143. goto onErrorEnd
  144. :onError200
  145. for %%i in (0 1 2 3 4 5) do if errorlevel 2%%i0 set err10=%%i
  146. if err10==5 for %%i in (0 1 2 3 4 5) do if errorlevel 25%%i set err1=%%i
  147. if not err10==5 goto onError1
  148. :onErrorEnd
  149. set ANT_ERROR=%err100%%err10%%err1%
  150. for %%i in (1 10 100) do set err%%i=
  151. :end
  152. rem bug ID 32069: resetting an undefined env variable changes the errorlevel.
  153. if not "%_JAVACMD%"=="" set _JAVACMD=
  154. if not "%_ANT_CMD_LINE_ARGS%"=="" set ANT_CMD_LINE_ARGS=
  155. if "%ANT_ERROR%"=="0" goto mainEnd
  156. goto omega
  157. :mainEnd
  158. rem If there were no errors, we run the post script.
  159. if "%OS%"=="Windows_NT" @endlocal
  160. if "%OS%"=="WINNT" @endlocal
  161. if "%HOME%"=="" goto homeDrivePathPost
  162. if exist "%HOME%\antrc_post.bat" call "%HOME%\antrc_post.bat"
  163. :homeDrivePathPost
  164. if "%HOMEDRIVE%%HOMEPATH%"=="" goto userProfilePost
  165. if "%HOMEDRIVE%%HOMEPATH%"=="%HOME%" goto userProfilePost
  166. if exist "%HOMEDRIVE%%HOMEPATH%\antrc_post.bat" call "%HOMEDRIVE%%HOMEPATH%\antrc_post.bat"
  167. :userProfilePost
  168. if "%USERPROFILE%"=="" goto omega
  169. if "%USERPROFILE%"=="%HOME%" goto omega
  170. if "%USERPROFILE%"=="%HOMEDRIVE%%HOMEPATH%" goto omega
  171. if exist "%USERPROFILE%\antrc_post.bat" call "%USERPROFILE%\antrc_post.bat"
  172. :omega
  173. exit /b %ANT_ERROR%