dita.bat 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. @echo off
  2. REM This file is part of the DITA Open Toolkit project.
  3. REM See the accompanying license.txt file for applicable licenses.
  4. REM Derived from Apache Ant command line tool.
  5. REM Licensed to the Apache Software Foundation (ASF) under one or more
  6. REM contributor license agreements. See the NOTICE file distributed with
  7. REM this work for additional information regarding copyright ownership.
  8. REM The ASF licenses this file to You under the Apache License, Version 2.0
  9. REM (the "License"); you may not use this file except in compliance with
  10. REM the License. You may obtain a copy of the License at
  11. REM
  12. REM http://www.apache.org/licenses/LICENSE-2.0
  13. REM
  14. REM Unless required by applicable law or agreed to in writing, software
  15. REM distributed under the License is distributed on an "AS IS" BASIS,
  16. REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. REM See the License for the specific language governing permissions and
  18. REM limitations under the License.
  19. if "%OS%"=="Windows_NT" @setlocal
  20. if "%OS%"=="WINNT" @setlocal
  21. if "%DITA_HOME%"=="" goto setDefaultDitaHome
  22. :setDefaultDitaHome
  23. rem %~dp0 is expanded pathname of the current script under NT
  24. set DITA_HOME=%~dp0..
  25. rem Slurp the command line arguments. This loop allows for an unlimited number
  26. rem of arguments (up to the command line limit, anyway).
  27. set DITA_CMD_LINE_ARGS=
  28. :setupArgs
  29. if ""%1""=="""" goto doneStart
  30. set DITA_CMD_LINE_ARGS=%DITA_CMD_LINE_ARGS% %1
  31. shift
  32. goto setupArgs
  33. rem This label provides a place for the argument list loop to break out
  34. rem and for NT handling to skip to.
  35. :doneStart
  36. :checkJava
  37. rem Set environment variables
  38. call "%DITA_HOME%\resources\env.bat"
  39. set _JAVACMD=%JAVACMD%
  40. if "%JAVA_HOME%" == "" goto noJavaHome
  41. if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
  42. if "%_JAVACMD%" == "" set _JAVACMD=%JAVA_HOME%\bin\java.exe
  43. :noJavaHome
  44. if "%_JAVACMD%" == "" set _JAVACMD=java.exe
  45. :runAnt
  46. "%_JAVACMD%" %ANT_OPTS% -Djava.awt.headless=true -classpath "%DITA_HOME%\lib\ant-launcher.jar" "-Dant.home=%DITA_HOME%" "-Ddita.dir=%DITA_HOME%" org.apache.tools.ant.launch.Launcher %ANT_ARGS% -cp "%CLASSPATH%" %DITA_CMD_LINE_ARGS% -buildfile "%DITA_HOME%\build.xml" -main "org.dita.dost.invoker.Main"
  47. rem Check the error code of the Ant build
  48. if not "%OS%"=="Windows_NT" goto onError
  49. set ANT_ERROR=%ERRORLEVEL%
  50. goto end
  51. :onError
  52. rem Windows 9x way of checking the error code. It matches via brute force.
  53. for %%i in (1 10 100) do set err%%i=
  54. for %%i in (0 1 2) do if errorlevel %%i00 set err100=%%i
  55. if %err100%==2 goto onError200
  56. if %err100%==0 set err100=
  57. for %%i in (0 1 2 3 4 5 6 7 8 9) do if errorlevel %err100%%%i0 set err10=%%i
  58. if "%err100%"=="" if %err10%==0 set err10=
  59. :onError1
  60. for %%i in (0 1 2 3 4 5 6 7 8 9) do if errorlevel %err100%%err10%%%i set err1=%%i
  61. goto onErrorEnd
  62. :onError200
  63. for %%i in (0 1 2 3 4 5) do if errorlevel 2%%i0 set err10=%%i
  64. if err10==5 for %%i in (0 1 2 3 4 5) do if errorlevel 25%%i set err1=%%i
  65. if not err10==5 goto onError1
  66. :onErrorEnd
  67. set ANT_ERROR=%err100%%err10%%err1%
  68. for %%i in (1 10 100) do set err%%i=
  69. :end
  70. rem bug ID 32069: resetting an undefined env variable changes the errorlevel.
  71. if not "%_JAVACMD%"=="" set _JAVACMD=
  72. if not "%_DITA_CMD_LINE_ARGS%"=="" set DITA_CMD_LINE_ARGS=
  73. if "%ANT_ERROR%"=="0" goto mainEnd
  74. goto omega
  75. :mainEnd
  76. rem If there were no errors, we run the post script.
  77. if "%OS%"=="Windows_NT" @endlocal
  78. if "%OS%"=="WINNT" @endlocal
  79. :omega
  80. exit /b %ANT_ERROR%