dita 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #! /bin/sh
  2. # This file is part of the DITA Open Toolkit project.
  3. # See the accompanying license.txt file for applicable licenses.
  4. # Derived from Apache Ant command line tool.
  5. # Licensed to the Apache Software Foundation (ASF) under one or more
  6. # contributor license agreements. See the NOTICE file distributed with
  7. # this work for additional information regarding copyright ownership.
  8. # The ASF licenses this file to You under the Apache License, Version 2.0
  9. # (the "License"); you may not use this file except in compliance with
  10. # the License. You may obtain a copy of the License at
  11. #
  12. # http://www.apache.org/licenses/LICENSE-2.0
  13. #
  14. # Unless required by applicable law or agreed to in writing, software
  15. # distributed under the License is distributed on an "AS IS" BASIS,
  16. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. # See the License for the specific language governing permissions and
  18. # limitations under the License.
  19. # Extract launch and ant arguments, (see details below).
  20. ant_exec_args=
  21. for arg in "$@" ; do
  22. if [ my"$arg" = my"--h" -o my"$arg" = my"--help" ] ; then
  23. ant_exec_args="$ant_exec_args -h"
  24. else
  25. ant_exec_args="$ant_exec_args \"$arg\""
  26. fi
  27. done
  28. # OS specific support. $var _must_ be set to either true or false.
  29. cygwin=false;
  30. darwin=false;
  31. mingw=false;
  32. case "`uname`" in
  33. CYGWIN*) cygwin=true ;;
  34. Darwin*) darwin=true
  35. if [ -z "$JAVA_HOME" ] ; then
  36. JAVA_HOME=`/usr/libexec/java_home`
  37. fi
  38. ;;
  39. MINGW*) mingw=true ;;
  40. esac
  41. if [ -z "$DITA_HOME" -o ! -d "$DITA_HOME" ] ; then
  42. ## resolve links - $0 may be a link to ant's home
  43. PRG="$0"
  44. progname=`basename "$0"`
  45. # need this for relative symlinks
  46. while [ -h "$PRG" ] ; do
  47. ls=`ls -ld "$PRG"`
  48. link=`expr "$ls" : '.*-> \(.*\)$'`
  49. if expr "$link" : '/.*' > /dev/null; then
  50. PRG="$link"
  51. else
  52. PRG=`dirname "$PRG"`"/$link"
  53. fi
  54. done
  55. DITA_HOME=`dirname "$PRG"`/..
  56. # make it fully qualified
  57. DITA_HOME=`cd "$DITA_HOME" > /dev/null && pwd`
  58. fi
  59. # Set environment variables
  60. . "$DITA_HOME/resources/env.sh"
  61. # Add build script to arguments
  62. ant_exec_args="$ant_exec_args \"-buildfile\" \"$DITA_HOME/build.xml\" \"-main\" \"org.dita.dost.invoker.Main\""
  63. # For Cygwin and Mingw, ensure paths are in UNIX format before
  64. # anything is touched
  65. if $cygwin ; then
  66. [ -n "$DITA_HOME" ] &&
  67. DITA_HOME=`cygpath --unix "$DITA_HOME"`
  68. [ -n "$JAVA_HOME" ] &&
  69. JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
  70. fi
  71. if $mingw ; then
  72. [ -n "$DITA_HOME" ] &&
  73. DITA_HOME="`(cd "$DITA_HOME"; pwd)`"
  74. [ -n "$JAVA_HOME" ] &&
  75. JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
  76. fi
  77. # set ANT_LIB location
  78. ANT_LIB="${DITA_HOME}/lib"
  79. if [ -z "$JAVACMD" ] ; then
  80. if [ -n "$JAVA_HOME" ] ; then
  81. # IBM's JDK on AIX uses strange locations for the executables
  82. if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
  83. JAVACMD="$JAVA_HOME/jre/sh/java"
  84. elif [ -x "$JAVA_HOME/jre/bin/java" ] ; then
  85. JAVACMD="$JAVA_HOME/jre/bin/java"
  86. else
  87. JAVACMD="$JAVA_HOME/bin/java"
  88. fi
  89. else
  90. JAVACMD=`which java 2> /dev/null `
  91. if [ -z "$JAVACMD" ] ; then
  92. JAVACMD=java
  93. fi
  94. fi
  95. fi
  96. if [ ! -x "$JAVACMD" ] ; then
  97. echo "Error: JAVA_HOME is not defined correctly."
  98. echo " We cannot execute $JAVACMD"
  99. exit 1
  100. fi
  101. # use launcher to determine classpaths
  102. if [ -z "$LOCALCLASSPATH" ] ; then
  103. LOCALCLASSPATH=$ANT_LIB/ant-launcher.jar
  104. else
  105. LOCALCLASSPATH=$ANT_LIB/ant-launcher.jar:$LOCALCLASSPATH
  106. fi
  107. # For Cygwin, switch paths to appropriate format before running java
  108. # For PATHs convert to unix format first, then to windows format to ensure
  109. # both formats are supported. Probably this will fail on directories with ;
  110. # in the name in the path. Let's assume that paths containing ; are more
  111. # rare than windows style paths on cygwin.
  112. if $cygwin; then
  113. if [ "$OS" = "Windows_NT" ] && cygpath -m .>/dev/null 2>/dev/null ; then
  114. format=mixed
  115. else
  116. format=windows
  117. fi
  118. [ -n "$DITA_HOME" ] && DITA_HOME=`cygpath --$format "$DITA_HOME"`
  119. ANT_LIB=`cygpath --$format "$ANT_LIB"`
  120. [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --$format "$JAVA_HOME"`
  121. LCP_TEMP=`cygpath --path --unix "$LOCALCLASSPATH"`
  122. LOCALCLASSPATH=`cygpath --path --$format "$LCP_TEMP"`
  123. if [ -n "$CLASSPATH" ] ; then
  124. CP_TEMP=`cygpath --path --unix "$CLASSPATH"`
  125. CLASSPATH=`cygpath --path --$format "$CP_TEMP"`
  126. fi
  127. CYGHOME=`cygpath --$format "$HOME"`
  128. fi
  129. # add a second backslash to variables terminated by a backslash under cygwin
  130. if $cygwin; then
  131. case "$DITA_HOME" in
  132. *\\ )
  133. DITA_HOME="$DITA_HOME\\"
  134. ;;
  135. esac
  136. case "$CYGHOME" in
  137. *\\ )
  138. CYGHOME="$CYGHOME\\"
  139. ;;
  140. esac
  141. case "$LOCALCLASSPATH" in
  142. *\\ )
  143. LOCALCLASSPATH="$LOCALCLASSPATH\\"
  144. ;;
  145. esac
  146. case "$CLASSPATH" in
  147. *\\ )
  148. CLASSPATH="$CLASSPATH\\"
  149. ;;
  150. esac
  151. fi
  152. # Execute ant using eval/exec to preserve spaces in paths,
  153. # java options, and ant args
  154. ant_sys_opts=
  155. if [ -n "$CYGHOME" ]; then
  156. ant_sys_opts="-Dcygwin.user.home=\"$CYGHOME\""
  157. fi
  158. ant_exec_command="exec \"$JAVACMD\" $ANT_OPTS -Djava.awt.headless=true -classpath \"$LOCALCLASSPATH\" -Dant.home=\"$DITA_HOME\" -Ddita.dir=\"$DITA_HOME\" -Dant.library.dir=\"$ANT_LIB\" $ant_sys_opts org.apache.tools.ant.launch.Launcher $ANT_ARGS -cp \"$CLASSPATH\""
  159. eval $ant_exec_command "$ant_exec_args"