build.cmd 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. @echo off
  2. @set JAVA_ARGS=-Xms500m -Xmx1g
  3. @set CAS_DIR=\etc\cas
  4. @set CONFIG_DIR=\etc\cas\config
  5. @rem Call this script with DNAME and CERT_SUBJ_ALT_NAMES already set to override
  6. @if "%DNAME%" == "" set DNAME=CN=cas.example.org,OU=Example,OU=Org,C=US
  7. @rem List other host names or ip addresses you want in your certificate, may help with host name verification,
  8. @rem if client apps make https connection for ticket validation and compare name in cert (include sub. alt. names)
  9. @rem to name used to access CAS
  10. @if "%CERT_SUBJ_ALT_NAMES%" == "" set CERT_SUBJ_ALT_NAMES=dns:example.org,dns:localhost,dns:%COMPUTERNAME%,ip:127.0.0.1
  11. @rem Check for mvn in path, use it if found, otherwise use maven wrapper
  12. @set MAVEN_CMD=mvn
  13. @where /q mvn
  14. @if %ERRORLEVEL% neq 0 set MAVEN_CMD=.\mvnw.bat
  15. @if "%1" == "" call:help
  16. @if "%1" == "copy" call:copy
  17. @if "%1" == "clean" call:clean %2 %3 %4
  18. @if "%1" == "package" call:package %2 %3 %4
  19. @if "%1" == "bootrun" call:bootrun %2 %3 %4
  20. @if "%1" == "debug" call:debug %2 %3 %4
  21. @if "%1" == "run" call:run %2 %3 %4
  22. @if "%1" == "runalone" call:runalone %2 %3 %4
  23. @if "%1" == "help" call:help
  24. @if "%1" == "gencert" call:gencert
  25. @if "%1" == "cli" call:runcli %2 %3 %4
  26. @rem function section starts here
  27. @goto:eof
  28. :copy
  29. @echo "Creating configuration directory under %CONFIG_DIR%"
  30. if not exist %CONFIG_DIR% mkdir %CONFIG_DIR%
  31. @echo "Copying configuration files from etc/cas to /etc/cas"
  32. xcopy /S /Y etc\cas\* \etc\cas
  33. @goto:eof
  34. :help
  35. @echo "Usage: build.bat [copy|clean|package|run|debug|bootrun|gencert|cli] [optional extra args for maven or cli]"
  36. @echo "To get started on a clean system, run "build.bat copy" and "build.bat gencert", then "build.bat run"
  37. @echo "Note that using the copy or gencert arguments will create and/or overwrite the %CAS_DIR% which is outside this project"
  38. @goto:eof
  39. :clean
  40. call %MAVEN_CMD% clean %1 %2 %3
  41. exit /B %ERRORLEVEL%
  42. @goto:eof
  43. :package
  44. call %MAVEN_CMD% clean package -T 5 %1 %2 %3
  45. exit /B %ERRORLEVEL%
  46. @goto:eof
  47. :bootrun
  48. call %MAVEN_CMD% clean package spring-boot:run -T 5 %1 %2 %3
  49. exit /B %ERRORLEVEL%
  50. @goto:eof
  51. :debug
  52. call:package %1 %2 %3 & java %JAVA_ARGS% -Xdebug -Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=n -jar target/cas.war
  53. @goto:eof
  54. :run
  55. call:package %1 %2 %3 & java %JAVA_ARGS% -jar target/cas.war
  56. @goto:eof
  57. :runalone
  58. call:package %1 %2 %3 & target/cas.war
  59. @goto:eof
  60. :gencert
  61. where /q keytool
  62. if ERRORLEVEL 1 (
  63. @echo Java keytool.exe not found in path.
  64. exit /b 1
  65. ) else (
  66. if not exist %CAS_DIR% mkdir %CAS_DIR%
  67. @echo on
  68. @echo Generating self-signed SSL cert for %DNAME% in %CAS_DIR%\thekeystore
  69. keytool -genkeypair -alias cas -keyalg RSA -keypass changeit -storepass changeit -keystore %CAS_DIR%\thekeystore -dname %DNAME% -ext SAN=%CERT_SUBJ_ALT_NAMES%
  70. @echo Exporting cert for use in trust store (used by cas clients)
  71. keytool -exportcert -alias cas -storepass changeit -keystore %CAS_DIR%\thekeystore -file %CAS_DIR%\cas.cer
  72. )
  73. @goto:eof
  74. :runcli
  75. for /f %%i in ('call %MAVEN_CMD% -q --non-recursive "-Dexec.executable=cmd" "-Dexec.args=/C echo ${cas.version}" "org.codehaus.mojo:exec-maven-plugin:1.3.1:exec"') do set CAS_VERSION=%%i
  76. @set CAS_VERSION=%CAS_VERSION: =%
  77. @set DOWNLOAD_DIR=target
  78. @set COMMAND_FILE=cas-server-support-shell-%CAS_VERSION%.jar
  79. @if not exist %DOWNLOAD_DIR% mkdir %DOWNLOAD_DIR%
  80. @if not exist %DOWNLOAD_DIR%\%COMMAND_FILE% (
  81. @call mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.2:get -DgroupId=org.apereo.cas -DartifactId=cas-server-support-shell -Dversion=%CAS_VERSION% -Dpackaging=jar -DartifactItem.outputDirectory=%DOWNLOAD_DIR% -DartifactItem.destFileName=%COMMAND_FILE% -DremoteRepositories=central::default::http://repo1.maven.apache.org/maven2,snapshots::::https://oss.sonatype.org/content/repositories/snapshots -Dtransitive=false
  82. @call mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.2:copy -Dmdep.useBaseVersion=true -Dartifact=org.apereo.cas:cas-server-support-shell:%CAS_VERSION%:jar -DoutputDirectory=%DOWNLOAD_DIR%
  83. )
  84. @call java %JAVA_ARGS% -jar %DOWNLOAD_DIR%\%COMMAND_FILE% %1 %2 %3
  85. @goto:eof