ant 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. #! /bin/sh
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. # Extract launch and ant arguments, (see details below).
  17. ant_exec_args=
  18. no_config=false
  19. use_jikes_default=false
  20. ant_exec_debug=false
  21. show_help=false
  22. for arg in "$@" ; do
  23. if [ "$arg" = "--noconfig" ] ; then
  24. no_config=true
  25. elif [ "$arg" = "--usejikes" ] ; then
  26. use_jikes_default=true
  27. elif [ "$arg" = "--execdebug" ] ; then
  28. ant_exec_debug=true
  29. elif [ my"$arg" = my"--h" -o my"$arg" = my"--help" ] ; then
  30. show_help=true
  31. ant_exec_args="$ant_exec_args -h"
  32. else
  33. if [ my"$arg" = my"-h" -o my"$arg" = my"-help" ] ; then
  34. show_help=true
  35. fi
  36. ant_exec_args="$ant_exec_args \"$arg\""
  37. fi
  38. done
  39. # Source/default ant configuration
  40. if $no_config ; then
  41. rpm_mode=false
  42. usejikes=$use_jikes_default
  43. else
  44. # load system-wide ant configuration (ONLY if ANT_HOME has NOT been set)
  45. if [ -z "$ANT_HOME" -o "$ANT_HOME" = "/usr/share/ant" ]; then
  46. if [ -f "/etc/ant.conf" ] ; then
  47. . /etc/ant.conf
  48. fi
  49. fi
  50. # load user ant configuration
  51. if [ -f "$HOME/.ant/ant.conf" ] ; then
  52. . $HOME/.ant/ant.conf
  53. fi
  54. if [ -f "$HOME/.antrc" ] ; then
  55. . "$HOME/.antrc"
  56. fi
  57. # provide default configuration values
  58. if [ -z "$rpm_mode" ] ; then
  59. rpm_mode=false
  60. fi
  61. if [ -z "$usejikes" ] ; then
  62. usejikes=$use_jikes_default
  63. fi
  64. fi
  65. # Setup Java environment in rpm mode
  66. if $rpm_mode ; then
  67. if [ -f /usr/share/java-utils/java-functions ] ; then
  68. . /usr/share/java-utils/java-functions
  69. set_jvm
  70. set_javacmd
  71. fi
  72. fi
  73. # OS specific support. $var _must_ be set to either true or false.
  74. cygwin=false;
  75. darwin=false;
  76. mingw=false;
  77. case "`uname`" in
  78. CYGWIN*) cygwin=true ;;
  79. Darwin*) darwin=true
  80. if [ -z "$JAVA_HOME" ] ; then
  81. if [ -x '/usr/libexec/java_home' ] ; then
  82. JAVA_HOME=`/usr/libexec/java_home`
  83. elif [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" ]; then
  84. JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
  85. fi
  86. fi
  87. ;;
  88. MINGW*) mingw=true ;;
  89. esac
  90. if [ -z "$ANT_HOME" -o ! -d "$ANT_HOME" ] ; then
  91. ## resolve links - $0 may be a link to ant's home
  92. PRG="$0"
  93. progname=`basename "$0"`
  94. # need this for relative symlinks
  95. while [ -h "$PRG" ] ; do
  96. ls=`ls -ld "$PRG"`
  97. link=`expr "$ls" : '.*-> \(.*\)$'`
  98. if expr "$link" : '/.*' > /dev/null; then
  99. PRG="$link"
  100. else
  101. PRG=`dirname "$PRG"`"/$link"
  102. fi
  103. done
  104. ANT_HOME=`dirname "$PRG"`/..
  105. # make it fully qualified
  106. ANT_HOME=`cd "$ANT_HOME" > /dev/null && pwd`
  107. fi
  108. # For Cygwin and Mingw, ensure paths are in UNIX format before
  109. # anything is touched
  110. if $cygwin ; then
  111. [ -n "$ANT_HOME" ] &&
  112. ANT_HOME=`cygpath --unix "$ANT_HOME"`
  113. [ -n "$JAVA_HOME" ] &&
  114. JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
  115. fi
  116. if $mingw ; then
  117. [ -n "$ANT_HOME" ] &&
  118. ANT_HOME="`(cd "$ANT_HOME"; pwd)`"
  119. [ -n "$JAVA_HOME" ] &&
  120. JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
  121. fi
  122. # set ANT_LIB location
  123. ANT_LIB="${ANT_HOME}/lib"
  124. if [ -z "$JAVACMD" ] ; then
  125. if [ -n "$JAVA_HOME" ] ; then
  126. # IBM's JDK on AIX uses strange locations for the executables
  127. if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
  128. JAVACMD="$JAVA_HOME/jre/sh/java"
  129. elif [ -x "$JAVA_HOME/jre/bin/java" ] ; then
  130. JAVACMD="$JAVA_HOME/jre/bin/java"
  131. else
  132. JAVACMD="$JAVA_HOME/bin/java"
  133. fi
  134. else
  135. JAVACMD=`which java 2> /dev/null `
  136. if [ -z "$JAVACMD" ] ; then
  137. JAVACMD=java
  138. fi
  139. fi
  140. fi
  141. if [ ! -x "$JAVACMD" ] ; then
  142. echo "Error: JAVA_HOME is not defined correctly."
  143. echo " We cannot execute $JAVACMD"
  144. exit 1
  145. fi
  146. # Build local classpath using just the launcher in non-rpm mode or
  147. # use the Jpackage helper in rpm mode with basic and default jars
  148. # specified in the ant.conf configuration. Because the launcher is
  149. # used, libraries linked in ANT_HOME/lib will also be included, but this
  150. # is discouraged as it is not java-version safe. A user should
  151. # request optional jars and their dependencies via the OPT_JAR_LIST
  152. # variable
  153. if $rpm_mode && [ -x /usr/bin/build-classpath ] ; then
  154. LOCALCLASSPATH="$(/usr/bin/build-classpath ant ant-launcher jaxp_parser_impl xml-commons-apis)"
  155. # If no optional jars have been specified then build the default list
  156. if [ -z "$OPT_JAR_LIST" ] ; then
  157. for file in /etc/ant.d/*; do
  158. if [ -f "$file" ]; then
  159. case "$file" in
  160. *~) ;;
  161. *#*) ;;
  162. *.rpmsave) ;;
  163. *.rpmnew) ;;
  164. *)
  165. for dep in `cat "$file"`; do
  166. OPT_JAR_LIST="$OPT_JAR_LIST${OPT_JAR_LIST:+ }$dep"
  167. done
  168. esac
  169. fi
  170. done
  171. fi
  172. # If the user requested to try to add some other jars to the classpath
  173. if [ -n "$OPT_JAR_LIST" ] ; then
  174. _OPTCLASSPATH="$(/usr/bin/build-classpath $OPT_JAR_LIST 2> /dev/null)"
  175. if [ -n "$_OPTCLASSPATH" ] ; then
  176. LOCALCLASSPATH="$LOCALCLASSPATH:$_OPTCLASSPATH"
  177. fi
  178. fi
  179. # Explicitly add javac path to classpath, assume JAVA_HOME set
  180. # properly in rpm mode
  181. if [ -f "$JAVA_HOME/lib/tools.jar" ] ; then
  182. LOCALCLASSPATH="$LOCALCLASSPATH:$JAVA_HOME/lib/tools.jar"
  183. fi
  184. if [ -f "$JAVA_HOME/lib/classes.zip" ] ; then
  185. LOCALCLASSPATH="$LOCALCLASSPATH:$JAVA_HOME/lib/classes.zip"
  186. fi
  187. # if CLASSPATH_OVERRIDE env var is set, LOCALCLASSPATH will be
  188. # user CLASSPATH first and ant-found jars after.
  189. # In that case, the user CLASSPATH will override ant-found jars
  190. #
  191. # if CLASSPATH_OVERRIDE is not set, we'll have the normal behaviour
  192. # with ant-found jars first and user CLASSPATH after
  193. if [ -n "$CLASSPATH" ] ; then
  194. # merge local and specified classpath
  195. if [ -z "$LOCALCLASSPATH" ] ; then
  196. LOCALCLASSPATH="$CLASSPATH"
  197. elif [ -n "$CLASSPATH_OVERRIDE" ] ; then
  198. LOCALCLASSPATH="$CLASSPATH:$LOCALCLASSPATH"
  199. else
  200. LOCALCLASSPATH="$LOCALCLASSPATH:$CLASSPATH"
  201. fi
  202. # remove class path from launcher -cp option
  203. CLASSPATH=""
  204. fi
  205. else
  206. # not using rpm_mode; use launcher to determine classpaths
  207. if [ -z "$LOCALCLASSPATH" ] ; then
  208. LOCALCLASSPATH=$ANT_LIB/ant-launcher.jar
  209. else
  210. LOCALCLASSPATH=$ANT_LIB/ant-launcher.jar:$LOCALCLASSPATH
  211. fi
  212. fi
  213. if [ -n "$JAVA_HOME" ] ; then
  214. # OSX hack to make Ant work with jikes
  215. if $darwin ; then
  216. OSXHACK="${JAVA_HOME}/../Classes"
  217. if [ -d "${OSXHACK}" ] ; then
  218. for i in "${OSXHACK}"/*.jar
  219. do
  220. JIKESPATH="$JIKESPATH:$i"
  221. done
  222. fi
  223. fi
  224. fi
  225. # Allow Jikes support (off by default)
  226. if $usejikes; then
  227. ANT_OPTS="$ANT_OPTS -Dbuild.compiler=jikes"
  228. fi
  229. # For Cygwin, switch paths to appropriate format before running java
  230. # For PATHs convert to unix format first, then to windows format to ensure
  231. # both formats are supported. Probably this will fail on directories with ;
  232. # in the name in the path. Let's assume that paths containing ; are more
  233. # rare than windows style paths on cygwin.
  234. if $cygwin; then
  235. if [ "$OS" = "Windows_NT" ] && cygpath -m .>/dev/null 2>/dev/null ; then
  236. format=mixed
  237. else
  238. format=windows
  239. fi
  240. [ -n "$ANT_HOME" ] && ANT_HOME=`cygpath --$format "$ANT_HOME"`
  241. ANT_LIB=`cygpath --$format "$ANT_LIB"`
  242. [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --$format "$JAVA_HOME"`
  243. LCP_TEMP=`cygpath --path --unix "$LOCALCLASSPATH"`
  244. LOCALCLASSPATH=`cygpath --path --$format "$LCP_TEMP"`
  245. if [ -n "$CLASSPATH" ] ; then
  246. CP_TEMP=`cygpath --path --unix "$CLASSPATH"`
  247. CLASSPATH=`cygpath --path --$format "$CP_TEMP"`
  248. fi
  249. CYGHOME=`cygpath --$format "$HOME"`
  250. fi
  251. # Show script help if requested
  252. if $show_help ; then
  253. echo $0 '[script options] [options] [target [target2 [target3] ..]]'
  254. echo 'Script Options:'
  255. echo ' --help, --h print this message and ant help'
  256. echo ' --noconfig suppress sourcing of /etc/ant.conf,'
  257. echo ' $HOME/.ant/ant.conf, and $HOME/.antrc'
  258. echo ' configuration files'
  259. echo ' --usejikes enable use of jikes by default, unless'
  260. echo ' set explicitly in configuration files'
  261. echo ' --execdebug print ant exec line generated by this'
  262. echo ' launch script'
  263. echo ' '
  264. fi
  265. # add a second backslash to variables terminated by a backslash under cygwin
  266. if $cygwin; then
  267. case "$ANT_HOME" in
  268. *\\ )
  269. ANT_HOME="$ANT_HOME\\"
  270. ;;
  271. esac
  272. case "$CYGHOME" in
  273. *\\ )
  274. CYGHOME="$CYGHOME\\"
  275. ;;
  276. esac
  277. case "$JIKESPATH" in
  278. *\\ )
  279. JIKESPATH="$JIKESPATH\\"
  280. ;;
  281. esac
  282. case "$LOCALCLASSPATH" in
  283. *\\ )
  284. LOCALCLASSPATH="$LOCALCLASSPATH\\"
  285. ;;
  286. esac
  287. case "$CLASSPATH" in
  288. *\\ )
  289. CLASSPATH="$CLASSPATH\\"
  290. ;;
  291. esac
  292. fi
  293. # Execute ant using eval/exec to preserve spaces in paths,
  294. # java options, and ant args
  295. ant_sys_opts=
  296. if [ -n "$CYGHOME" ]; then
  297. if [ -n "$JIKESPATH" ]; then
  298. ant_sys_opts="-Djikes.class.path=\"$JIKESPATH\" -Dcygwin.user.home=\"$CYGHOME\""
  299. else
  300. ant_sys_opts="-Dcygwin.user.home=\"$CYGHOME\""
  301. fi
  302. else
  303. if [ -n "$JIKESPATH" ]; then
  304. ant_sys_opts="-Djikes.class.path=\"$JIKESPATH\""
  305. fi
  306. fi
  307. ant_exec_command="exec \"$JAVACMD\" $ANT_OPTS -classpath \"$LOCALCLASSPATH\" -Dant.home=\"$ANT_HOME\" -Dant.library.dir=\"$ANT_LIB\" $ant_sys_opts org.apache.tools.ant.launch.Launcher $ANT_ARGS -cp \"$CLASSPATH\""
  308. if $ant_exec_debug ; then
  309. echo $ant_exec_command $ant_exec_args
  310. fi
  311. eval $ant_exec_command "$ant_exec_args"