Commit 5e274c5f authored by Misagh Moayyed's avatar Misagh Moayyed

working on combining builds

parent a0d8be87
#!/bin/bash
function copy() {
echo -e "Creating configuration directory under /etc/cas"
mkdir -p /etc/cas/config
echo -e "Copying configuration files from etc/cas to /etc/cas"
cp -rfv ../etc/cas/* /etc/cas
cp -rfv ./etc/cas/* /etc/cas
}
function help() {
echo "Usage: build.sh [copy|clean|package|run|debug|tomcat|gencert]"
echo " copy: Copy config from the project's local etc/cas/config directory to the root /etc/cas/config"
clear
echo "******************************************************************"
echo "Apereo CAS"
echo "Enterprise Single SignOn for all earthlings and beyond"
echo "- https://github.com/apereo/cas"
echo "- https://apereo.github.io/cas"
echo "******************************************************************"
echo -e "Usage: build.sh [maven|gradle] [copy|clean|package|run|update|debug|tomcat|gencert]\n"
echo " clean: Clean Maven build directory"
echo " cli: Run the CAS command line shell and pass commands"
echo " copy: Copy config from the project's local etc/cas/config directory to the root /etc/cas/config"
echo " debug: Run cas.war and listen for Java debugger on port 5000"
echo " dependencies: Get a report of all dependencies configured in the build"
echo " gencert: Create keystore with SSL certificate in location where CAS looks by default"
echo " getview: Ask for a view name to be included in the overlay for customizations"
echo " listviews: List all CAS views that ship with the web application and can be customized in the overlay"
echo " package: Clean and build CAS war"
echo " run: Build and run cas.war via Java"
echo " run: Build and run cas.war via Java as an executable war"
echo " runalone: Build and run cas.war on its own as a standalone executable"
echo " debug: Run CAS.war and listen for Java debugger on port 5000"
echo " tomcat: Deploy the CAS web application to an external Apache Tomcat server"
echo " listviews: List all CAS views that ship with the web application and can be customized in the overlay"
echo " getview: Ask for a view name to be included in the overlay for customizations"
echo " gencert: Create keystore with SSL certificate in location where CAS looks by default"
echo " cli: Run the CAS command line shell and pass commands"
echo " update: Package the CAS overlay by force-updating dependencies and SNAPSHOT versions"
}
function clean() {
shift
./mvnw clean "$@"
if [ "$buildTool" = "maven" ]; then
./mvnw clean "$@"
else
./gradlew clean "$@"
fi
}
function package() {
shift
./mvnw clean package -T 5 "$@"
# copy
clean
if [ "$buildTool" = "maven" ]; then
./mvnw package "$@"
else
./gradlew build "$@"
fi
}
function tomcat() {
shift
function update() {
clean
if [ "$buildTool" = "maven" ]; then
./mvnw package -U "$@"
else
./gradlew build --refresh-dependencies "$@"
fi
}
function dependencies() {
if [ "$buildTool" = "maven" ]; then
./mvnw dependency:analyze "$@"
else
./gradlew allDependencies
fi
}
function tomcat() {
export CATALINA_HOME=./apache-tomcat/
echo "Attempting to shutdown Apache Tomcat..."
./apache-tomcat/bin/shutdown.sh 2>/dev/null
......@@ -51,46 +81,84 @@ function tomcat() {
}
function debug() {
package && java -Xdebug -Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=n -jar target/cas.war
if [ "$buildTool" = "maven" ]; then
casWar="target/cas.war"
else
casWar="build/libs/cas.war"
fi
package && java -Xdebug -Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=n -jar $casWar
}
function run() {
package && java -XX:TieredStopAtLevel=1 -Xverify:none -jar target/cas.war
if [ "$buildTool" = "maven" ]; then
casWar="target/cas.war"
else
casWar="build/libs/cas.war"
fi
package && java -XX:TieredStopAtLevel=1 -Xverify:none -jar $casWar
}
function runalone() {
shift
./mvnw clean package -P default,exec "$@"
chmod +x target/cas.war
target/cas.war
if [ "$buildTool" = "maven" ]; then
./mvnw clean package -P default,exec "$@"
casWar="target/cas.war"
else
./gradlew clean build -Pexecutable=true "$@"
casWar="build/libs/cas.war"
fi
chmod +x $casWar
$casWar
}
function listviews() {
shift
explodeapp
find $PWD/target/cas -type f -name "*.html" | xargs -n 1 basename | sort | more
if [ "$buildTool" = "maven" ]; then
explodedDir=target/cas
else
explodedDir=build/cas
fi
find $explodedDir -type f -name "*.html" | xargs -n 1 basename | sort | more
}
function explodeapp() {
if [ ! -d $PWD/target/cas ];then
echo "Building the CAS web application and exploding the final war file..."
./mvnw clean package war:exploded "$@"
if [ "$buildTool" = "maven" ]; then
if [ ! -d $PWD/target/cas ];then
echo "Building the CAS web application and exploding the final war file..."
./mvnw clean package war:exploded "$@"
fi
else
./gradlew explodeWar
fi
echo "Exploded the CAS web application file."
}
function getview() {
shift
explodeapp
echo "Searching for view name $@..."
results=`find $PWD/target/cas -type f -name "*.html" | grep -i "$@"`
echo -e "Found view(s): \n$results"
if [ "$buildTool" = "maven" ]; then
explodedDir=target/cas
else
explodedDir=build/cas
fi
results=`find $explodedDir -type f -name "*.html" | grep -i "$@"`
count=`wc -w <<< "$results"`
if [ "$count" -eq 0 ];then
echo "No views could be found matching $@"
exit 1
fi
echo -e "Found view(s): \n$results"
if [ "$count" -eq 1 ];then
# echo "Found view $results to include in the overlay"
firststring="target/cas/WEB-INF/classes"
secondstring="src/main/resources"
overlayfile=`echo "${results/$firststring/$secondstring}"`
if [ "$buildTool" = "maven" ]; then
fromFile="target/cas/WEB-INF/classes"
else
fromFile="build/cas/WEB-INF/classes"
fi
toFile="src/main/resources"
overlayfile=`echo "${results/$fromFile/$toFile}"`
overlaypath=`dirname "${overlayfile}"`
# echo "Overlay file is $overlayfile to be created at $overlaypath"
mkdir -p $overlaypath
......@@ -122,7 +190,12 @@ function gencert() {
function cli() {
rm -f *.log
CAS_VERSION=$(./mvnw -q -Dexec.executable="echo" -Dexec.args='${cas.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec 2>/dev/null)
if [ "$buildTool" = "maven" ]; then
CAS_VERSION=$(./mvnw -q -Dexec.executable="echo" -Dexec.args='${cas.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec 2>/dev/null)
else
CAS_VERSION=$(./gradlew casVersion --quiet)
fi
echo "CAS version: $CAS_VERSION"
JAR_FILE_NAME="cas-server-support-shell-${CAS_VERSION}.jar"
echo "JAR name: $JAR_FILE_NAME"
......@@ -137,64 +210,92 @@ function cli() {
exit 0;
fi
DOWNLOAD_DIR=./target
if [ "$buildTool" = "maven" ]; then
DOWNLOAD_DIR=./target
else
DOWNLOAD_DIR=./build/libs
fi
COMMAND_FILE="${DOWNLOAD_DIR}/${JAR_FILE_NAME}"
if [ ! -f "$COMMAND_FILE" ]; then
mkdir -p $DOWNLOAD_DIR
./mvnw 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 -DremoteRepositories=central::default::http://repo1.maven.apache.org/maven2,snapshots::::https://oss.sonatype.org/content/repositories/snapshots -Dtransitive=false
./mvnw 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
wget "https://repo1.maven.org/maven2/${JAR_PATH}" -P ./target
fi
echo "Running $COMMAND_FILE"
java -jar $COMMAND_FILE "$@"
exit 0;
}
if [ $# -eq 0 ]; then
echo -e "No commands provided. Defaulting to [run]\n"
run
exit 0
buildTool=$1
command=$2
if [ -z "$command" ]; then
echo "No commands provided. Defaulting to [run]"
command="run"
fi
case "$1" in
if [ -z "$buildTool" ]; then
buildTool="maven"
echo "Build tool type is unspecified. Defaulting to [$buildTool]"
else
echo "Using build tool [$buildTool] to [$command] the CAS overlay"
fi
shift 2
case "$command" in
"copy")
copy
;;
"clean")
shift
clean "$@"
;;
"package")
shift
package "$@"
;;
"tomcat")
shift
tomcat "$@"
;;
"debug")
debug "$@"
;;
"run")
run "$@"
;;
"runalone")
runalone "$@"
;;
"listviews")
listviews "$@"
;;
"gencert")
gencert "$@"
;;
"getview")
getview "$@"
;;
"cli")
shift
cli "$@"
;;
*)
"help")
help
;;
esac
*)
if [ "$buildTool" = "maven" ]; then
pushd maven-overlay
else
pushd gradle-overlay
fi
case "$command" in
"clean")
clean "$@"
;;
"package"|"build")
package "$@"
;;
"debug")
debug "$@"
;;
"run")
run "$@"
;;
"gencert")
gencert "$@"
;;
"cli")
cli "$@"
;;
"update")
update "$@"
;;
"dependencies")
update "$@"
;;
"runalone")
runalone "$@"
;;
"listviews")
listviews "$@"
;;
"getview")
getview "$@"
;;
"tomcat")
tomcat
;;
esac
popd
esac
\ No newline at end of file
......@@ -85,11 +85,10 @@ task copyConfig(type: Copy, description: "Copy CAS configuration over to /etc/ca
}
task explodeWar(type: Copy, group: "build", description: "Explodes the cas.war") {
doLast {
from zipTree(project.war.outputs.files.singleFile)
into "${buildDir}/cas"
println "CAS web application artifact exploded into [cas/build/cas]"
}
dependsOn build
from zipTree("build/libs/cas.war")
into "${buildDir}/cas"
println "CAS web application artifact exploded into [cas/build/cas]"
}
task run(group: "build", description: "Run the CAS web application in embedded container mode") {
......
#!/bin/bash
function copy() {
echo -e "Creating configuration directory under /etc/cas"
mkdir -p /etc/cas/config
echo -e "Copying configuration files from etc/cas to /etc/cas"
cp -rfv ../etc/cas/* /etc/cas
}
function help() {
echo "Usage: build.sh [copy|clean|package|run|debug|gencert]"
echo " copy: Copy config from ../etc/cas/config to /etc/cas/config"
echo " clean: Clean build directory"
echo " package: Clean and build CAS war, also call copy"
echo " run: Build and run cas.war via Spring Boot"
echo " runalone: Build and run cas.war on its own"
echo " debug: Run CAS.war and listen for Java debugger on port 5005"
echo " gencert: Create keystore with SSL certificate in location where CAS looks by default"
echo " command: Run the CAS command line shell and pass commands"
}
function clean() {
./gradlew clean "$@"
}
function package() {
./gradlew clean build "$@"
# copy
}
function debug() {
package && java -Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n -jar build/libs/cas.war
}
function run() {
package && java -jar build/libs/cas.war
}
function runalone() {
./gradlew clean build -Pexecutable=true "$@"
chmod +x build/libs/cas.war
build/libs/cas.war
}
function gencert() {
if [[ ! -d /etc/cas ]] ; then
copy
fi
which keytool
if [[ $? -ne 0 ]] ; then
echo Error: Java JDK \'keytool\' is not installed or is not in the path
exit 1
fi
# override DNAME and CERT_SUBJ_ALT_NAMES before calling or use dummy values
DNAME="${DNAME:-CN=cas.example.org,OU=Example,OU=Org,C=US}"
CERT_SUBJ_ALT_NAMES="${CERT_SUBJ_ALT_NAMES:-dns:example.org,dns:localhost,ip:127.0.0.1}"
echo "Generating keystore for CAS with DN ${DNAME}"
keytool -genkeypair -alias cas -keyalg RSA -keypass changeit -storepass changeit -keystore /etc/cas/thekeystore -dname ${DNAME} -ext SAN=${CERT_SUBJ_ALT_NAMES}
keytool -exportcert -alias cas -storepass changeit -keystore /etc/cas/thekeystore -file /etc/cas/cas.cer
}
function cli() {
rm -f *.log
CAS_VERSION=$(./gradlew casVersion --quiet)
echo "CAS version: $CAS_VERSION"
JAR_FILE_NAME="cas-server-support-shell-${CAS_VERSION}.jar"
echo "JAR name: $JAR_FILE_NAME"
JAR_PATH="org/apereo/cas/cas-server-support-shell/${CAS_VERSION}/${JAR_FILE_NAME}"
echo "JAR path: $JAR_PATH"
JAR_FILE_LOCAL="$HOME/.m2/repository/$JAR_PATH";
echo "Local JAR file path: $JAR_FILE_LOCAL";
if [ -f "$JAR_FILE_LOCAL" ]; then
echo "Using JAR file locally at $JAR_FILE_LOCAL"
java -jar $JAR_FILE_LOCAL "$@"
exit 0;
fi
COMMAND_FILE="./target/${JAR_FILE_NAME}"
if [ ! -f "$COMMAND_FILE" ]; then
mkdir -p ./target
wget "https://repo1.maven.org/maven2/${JAR_PATH}" -P ./target
java -jar $COMMAND_FILE "$@"
exit 0;
fi
}
if [ $# -eq 0 ]; then
echo -e "No commands provided. Defaulting to [run]\n"
run
exit 0
fi
case "$1" in
"copy")
copy
;;
"clean")
shift
clean "$@"
;;
"package")
shift
package "$@"
;;
"debug")
debug "$@"
;;
"run")
run "$@"
;;
"runalone")
runalone "$@"
;;
"gencert")
gencert "$@"
;;
"cli")
shift
cli "$@"
;;
*)
help
;;
esac
@echo off
@set JAVA_ARGS=-Xms500m -Xmx1g
@set CAS_DIR=\etc\cas
@set CONFIG_DIR=\etc\cas\config
@rem Call this script with DNAME and CERT_SUBJ_ALT_NAMES already set to override
@if "%DNAME%" == "" set DNAME=CN=cas.example.org,OU=Example,OU=Org,C=US
@rem List other host names or ip addresses you want in your certificate, may help with host name verification,
@rem if client apps make https connection for ticket validation and compare name in cert (include sub. alt. names)
@rem to name used to access CAS
@if "%CERT_SUBJ_ALT_NAMES%" == "" set CERT_SUBJ_ALT_NAMES=dns:example.org,dns:localhost,dns:%COMPUTERNAME%,ip:127.0.0.1
@rem Check for mvn in path, use it if found, otherwise use maven wrapper
@set MAVEN_CMD=mvn
@where /q mvn
@if %ERRORLEVEL% neq 0 set MAVEN_CMD=.\mvnw.bat
@if "%1" == "" call:help
@if "%1" == "copy" call:copy
@if "%1" == "clean" call:clean %2 %3 %4
@if "%1" == "package" call:package %2 %3 %4
@if "%1" == "bootrun" call:bootrun %2 %3 %4
@if "%1" == "debug" call:debug %2 %3 %4
@if "%1" == "run" call:run %2 %3 %4
@if "%1" == "runalone" call:runalone %2 %3 %4
@if "%1" == "help" call:help
@if "%1" == "gencert" call:gencert
@if "%1" == "cli" call:runcli %2 %3 %4
@rem function section starts here
@goto:eof
:copy
@echo "Creating configuration directory under %CONFIG_DIR%"
if not exist %CONFIG_DIR% mkdir %CONFIG_DIR%
@echo "Copying configuration files from etc/cas to /etc/cas"
xcopy /S /Y etc\cas\* \etc\cas
@goto:eof
:help
@echo "Usage: build.bat [copy|clean|package|run|debug|bootrun|gencert|cli] [optional extra args for maven or cli]"
@echo "To get started on a clean system, run "build.bat copy" and "build.bat gencert", then "build.bat run"
@echo "Note that using the copy or gencert arguments will create and/or overwrite the %CAS_DIR% which is outside this project"
@goto:eof
:clean
call %MAVEN_CMD% clean %1 %2 %3
exit /B %ERRORLEVEL%
@goto:eof
:package
call %MAVEN_CMD% clean package -T 5 %1 %2 %3
exit /B %ERRORLEVEL%
@goto:eof
:bootrun
call %MAVEN_CMD% clean package spring-boot:run -T 5 %1 %2 %3
exit /B %ERRORLEVEL%
@goto:eof
:debug
call:package %1 %2 %3 & java %JAVA_ARGS% -Xdebug -Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=n -jar target/cas.war
@goto:eof
:run
call:package %1 %2 %3 & java %JAVA_ARGS% -jar target/cas.war
@goto:eof
:runalone
call:package %1 %2 %3 & target/cas.war
@goto:eof
:gencert
where /q keytool
if ERRORLEVEL 1 (
@echo Java keytool.exe not found in path.
exit /b 1
) else (
if not exist %CAS_DIR% mkdir %CAS_DIR%
@echo on
@echo Generating self-signed SSL cert for %DNAME% in %CAS_DIR%\thekeystore
keytool -genkeypair -alias cas -keyalg RSA -keypass changeit -storepass changeit -keystore %CAS_DIR%\thekeystore -dname %DNAME% -ext SAN=%CERT_SUBJ_ALT_NAMES%
@echo Exporting cert for use in trust store (used by cas clients)
keytool -exportcert -alias cas -storepass changeit -keystore %CAS_DIR%\thekeystore -file %CAS_DIR%\cas.cer
)
@goto:eof
:runcli
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
@set CAS_VERSION=%CAS_VERSION: =%
@set DOWNLOAD_DIR=target
@set COMMAND_FILE=cas-server-support-shell-%CAS_VERSION%.jar
@if not exist %DOWNLOAD_DIR% mkdir %DOWNLOAD_DIR%
@if not exist %DOWNLOAD_DIR%\%COMMAND_FILE% (
@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
@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%
)
@call java %JAVA_ARGS% -jar %DOWNLOAD_DIR%\%COMMAND_FILE% %1 %2 %3
@goto:eof
\ No newline at end of file
#Maven download properties
#Fri Dec 01 21:35:11 MST 2017
distributionUrl=https\://repository.apache.org/content/repositories/releases/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip
#Mon Jul 30 12:50:05 IRDT 2018
distributionUrl=https\://repository.apache.org/content/repositories/releases/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip
verifyDownload=true
checksumAlgorithm=MD5
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment