ant 9.8 KB

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