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