ant 10 KB

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