Commit 40a9be81 authored by Misagh Moayyed's avatar Misagh Moayyed

clean up overlay for gradle

parent 20d467c0
...@@ -10,11 +10,10 @@ Generic CAS WAR overlay to exercise the latest versions of CAS. This overlay cou ...@@ -10,11 +10,10 @@ Generic CAS WAR overlay to exercise the latest versions of CAS. This overlay cou
# Overview # Overview
The project structure contains two variants for Apache Maven and Gradle WAR overlays, inside `maven-overlay` and `gradle-overlay` respectively. You may invoke You may invoke build commands using the `build.sh` script to work with your chosen overlay using:
build commands using the `build.sh` script to work with your chosen overlay using:
```bash ```bash
./build.sh [maven|gradle] [command] ./build.sh [command]
``` ```
To see what commands are available to the build script, run: To see what commands are available to the build script, run:
...@@ -26,7 +25,34 @@ To see what commands are available to the build script, run: ...@@ -26,7 +25,34 @@ To see what commands are available to the build script, run:
# Configuration # Configuration
- The `etc` directory contains the configuration files and directories that need to be copied to `/etc/cas/config`. - The `etc` directory contains the configuration files and directories that need to be copied to `/etc/cas/config`.
- The mechanics of the build are controlled for both Apache Maven and Gradle using the `build.properties` file. - The specifics of the build are controlled using the `gradle.properties` file.
## Adding Modules
CAS modules may be specified under the `dependencies` block of the [Gradle build script](build.gradle):
```gradle
dependencies {
compile "org.apereo.cas:cas-server-some-module:${project.casVersion}"
...
}
```
Study material:
- https://docs.gradle.org/current/userguide/artifact_dependencies_tutorial.html
- https://docs.gradle.org/current/userguide/dependency_management.html
## Clear Gradle Cache
If you need to, on Linux/Unix systems, you can delete all the existing artifacts (artifacts and metadata) Gradle has downloaded using:
```bash
# Only do this when absolutely necessary!
rm -rf $HOME/.gradle/caches/
```
Same strategy applies to Windows too, provided you switch `$HOME` to its equivalent in the above command.
# Deployment # Deployment
......
...@@ -4,7 +4,7 @@ buildscript { ...@@ -4,7 +4,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:$System.env.springBootVersion" classpath "org.springframework.boot:spring-boot-gradle-plugin:${project.springBootVersion}"
} }
} }
...@@ -17,14 +17,12 @@ repositories { ...@@ -17,14 +17,12 @@ repositories {
} }
apply from: "https://dl.bintray.com/scalding/generic/waroverlay.gradle" apply from: "https://dl.bintray.com/scalding/generic/waroverlay.gradle"
apply plugin: "war" apply plugin: "war"
apply plugin: "org.springframework.boot" apply plugin: "org.springframework.boot"
apply plugin: "eclipse" apply plugin: "eclipse"
apply plugin: "idea" apply plugin: "idea"
sourceCompatibility=System.env.sourceCompatibility
targetCompatibility=System.env.targetCompatibility
def currentBranch = "master" def currentBranch = "master"
def currentVersion = "$System.env.casVersion" def currentVersion = "$System.env.casVersion"
if (!currentVersion.contains("RC")) { if (!currentVersion.contains("RC")) {
...@@ -77,11 +75,10 @@ bootRun { ...@@ -77,11 +75,10 @@ bootRun {
dependencies { dependencies {
if (project.hasProperty("external")) { if (project.hasProperty("external")) {
compile "org.apereo.cas:cas-server-webapp$System.env.appServer:$System.env.casVersion@war" compile "org.apereo.cas:cas-server-webapp${project.appServer}:${project.casVersion}@war"
} else { } else {
compile "org.apereo.cas:cas-server-webapp:$System.env.casVersion@war" compile "org.apereo.cas:cas-server-webapp:${project.casVersion}@war"
} }
// Other dependencies may be listed here... // Other dependencies may be listed here...
} }
...@@ -94,7 +91,8 @@ task explodeWar(type: Copy, group: "build", description: "Explodes the cas.war") ...@@ -94,7 +91,8 @@ task explodeWar(type: Copy, group: "build", description: "Explodes the cas.war")
task run(group: "build", description: "Run the CAS web application in embedded container mode") { task run(group: "build", description: "Run the CAS web application in embedded container mode") {
dependsOn build dependsOn build
doLast { doLast {
def casRunArgs = Arrays.asList("-Xmx2048M -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=y".split(" ")) def args = "-Xmx2048M -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=y"
def casRunArgs = Arrays.asList(args.split(" "))
javaexec { javaexec {
main = "-jar"; main = "-jar";
jvmArgs = casRunArgs jvmArgs = casRunArgs
...@@ -120,12 +118,12 @@ task debug(group: "build", description: "Debug the CAS web application in embedd ...@@ -120,12 +118,12 @@ task debug(group: "build", description: "Debug the CAS web application in embedd
} }
task wrapper(type: Wrapper, description: "Update the Gradle wrapper") { task wrapper(type: Wrapper, description: "Update the Gradle wrapper") {
gradleVersion = "4.9" gradleVersion = "${project.gradleVersion}"
} }
task casVersion(group: "build", description: "Display the current CAS version") { task casVersion(group: "build", description: "Display the current CAS version") {
doFirst { doFirst {
println "$System.env.casVersion" println "${project.casVersion}"
} }
} }
......
#!/bin/bash #!/bin/bash
while IFS='' read -r line || [[ -n "$line" ]]; do
if [ -n "$line" ] && [[ $line != \#* ]] ; then
IFS='=' read -r -a array <<< "$line"
varName=${array[0]}
varValue=${array[1]}
export "$varName"="$varValue"
fi
done < ./build.properties
function copy() { function copy() {
echo -e "Creating configuration directory under /etc/cas" echo -e "Creating configuration directory under /etc/cas"
mkdir -p /etc/cas/config mkdir -p /etc/cas/config
...@@ -28,7 +19,7 @@ function help() { ...@@ -28,7 +19,7 @@ function help() {
echo "- https://apereo.github.io/cas" echo "- https://apereo.github.io/cas"
echo "******************************************************************" echo "******************************************************************"
echo -e "Usage: build.sh [maven|gradle] [copy|clean|package|run|dependencies|update|debug|tomcat|gencert]\n" echo -e "Usage: build.sh [copy|clean|package|run|dependencies|update|debug|tomcat|gencert]\n"
echo -e "\tclean: \t\tClean Maven build directory" echo -e "\tclean: \t\tClean Maven build directory"
echo -e "\tcli: \t\tRun the CAS command line shell and pass commands" echo -e "\tcli: \t\tRun the CAS command line shell and pass commands"
echo -e "\tcopy: \t\tCopy config from the project's local etc/cas/config directory to the root /etc/cas/config" echo -e "\tcopy: \t\tCopy config from the project's local etc/cas/config directory to the root /etc/cas/config"
...@@ -45,46 +36,23 @@ function help() { ...@@ -45,46 +36,23 @@ function help() {
} }
function clean() { function clean() {
if [ "$buildTool" = "maven" ]; then ./gradlew clean "$@"
./mvnw clean "$@"
else
./gradlew clean "$@"
fi
} }
function package() { function package() {
if [ "$buildTool" = "maven" ]; then ./gradlew clean build "$@"
./mvnw clean package "$@"
else
./gradlew clean build "$@"
fi
} }
function update() { function update() {
clean ./gradlew clean build --refresh-dependencies "$@"
if [ "$buildTool" = "maven" ]; then
./mvnw package -U "$@"
else
./gradlew build --refresh-dependencies "$@"
fi
} }
function dependencies() { function dependencies() {
if [ "$buildTool" = "maven" ]; then ./gradlew allDependencies
./mvnw dependency:analyze "$@"
else
./gradlew allDependencies
fi
} }
function tomcat() { function tomcat() {
if [ "$buildTool" = "maven" ]; then ./gradlew clean build -Pexternal=true "$@"
./mvnw clean package -P external "$@"
else
./gradlew clean build -Pexternal=true "$@"
fi
pushd ..
if [ ! -f apache-tomcat.zip ]; then if [ ! -f apache-tomcat.zip ]; then
wget -O apache-tomcat.zip "http://www-eu.apache.org/dist/tomcat/tomcat-${tomcatVersion}/v${tomcatFullVersion}/bin/apache-tomcat-${tomcatFullVersion}.zip" wget -O apache-tomcat.zip "http://www-eu.apache.org/dist/tomcat/tomcat-${tomcatVersion}/v${tomcatFullVersion}/bin/apache-tomcat-${tomcatFullVersion}.zip"
...@@ -98,83 +66,46 @@ function tomcat() { ...@@ -98,83 +66,46 @@ function tomcat() {
echo "Attempting to shutdown Apache Tomcat..." echo "Attempting to shutdown Apache Tomcat..."
./apache-tomcat/bin/shutdown.sh 2>/dev/null ./apache-tomcat/bin/shutdown.sh 2>/dev/null
popd cp build/libs/cas.war ../apache-tomcat/webapps/
if [ "$buildTool" = "maven" ]; then
cp target/cas.war .../apache-tomcat/webapps/
else
cp build/libs/cas.war ../apache-tomcat/webapps/
fi
pushd ..
./apache-tomcat/bin/startup.sh ./apache-tomcat/bin/startup.sh
popd
tail -F ../apache-tomcat/logs/catalina.out tail -F ../apache-tomcat/logs/catalina.out
} }
function debug() { function debug() {
if [ "$buildTool" = "maven" ]; then casWar="build/libs/cas.war"
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 package && java -Xdebug -Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=n -jar $casWar
} }
function run() { function run() {
if [ "$buildTool" = "maven" ]; then casWar="build/libs/cas.war"
casWar="target/cas.war"
else
casWar="build/libs/cas.war"
fi
package && java -XX:TieredStopAtLevel=1 -Xverify:none -jar $casWar package && java -XX:TieredStopAtLevel=1 -Xverify:none -jar $casWar
} }
function runalone() { function runalone() {
if [ "$buildTool" = "maven" ]; then ./gradlew clean build -Pexecutable=true "$@"
./mvnw clean package -P default,exec "$@" casWar="build/libs/cas.war"
casWar="target/cas.war"
else
./gradlew clean build -Pexecutable=true "$@"
casWar="build/libs/cas.war"
fi
chmod +x $casWar chmod +x $casWar
$casWar $casWar
} }
function listviews() { function listviews() {
explodeapp explodeApp
if [ "$buildTool" = "maven" ]; then explodedDir=build/cas
explodedDir=target/cas
else
explodedDir=build/cas
fi
find $explodedDir -type f -name "*.html" | xargs -n 1 basename | sort | more find $explodedDir -type f -name "*.html" | xargs -n 1 basename | sort | more
} }
function explodeapp() { function explodeApp() {
if [ "$buildTool" = "maven" ]; then ./gradlew explodeWar
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." echo "Exploded the CAS web application file."
} }
function getview() { function getview() {
explodeapp explodeApp
echo "Searching for view name $@..." echo "Searching for view name $@..."
if [ "$buildTool" = "maven" ]; then explodedDir=build/cas
explodedDir=target/cas
else
explodedDir=build/cas
fi
results=`find $explodedDir -type f -name "*.html" | grep -i "$@"` results=`find $explodedDir -type f -name "*.html" | grep -i "$@"`
count=`wc -w <<< "$results"` count=`wc -w <<< "$results"`
if [ "$count" -eq 0 ];then if [ "$count" -eq 0 ];then
...@@ -183,11 +114,7 @@ function getview() { ...@@ -183,11 +114,7 @@ function getview() {
fi fi
echo -e "Found view(s): \n$results" echo -e "Found view(s): \n$results"
if [ "$count" -eq 1 ];then if [ "$count" -eq 1 ];then
if [ "$buildTool" = "maven" ]; then fromFile="build/cas/WEB-INF/classes"
fromFile="target/cas/WEB-INF/classes"
else
fromFile="build/cas/WEB-INF/classes"
fi
toFile="src/main/resources" toFile="src/main/resources"
overlayfile=`echo "${results/$fromFile/$toFile}"` overlayfile=`echo "${results/$fromFile/$toFile}"`
...@@ -221,12 +148,7 @@ function gencert() { ...@@ -221,12 +148,7 @@ function gencert() {
function cli() { function cli() {
rm -f *.log rm -f *.log
CAS_VERSION=$(./gradlew casVersion --quiet)
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" echo "CAS version: $CAS_VERSION"
JAR_FILE_NAME="cas-server-support-shell-${CAS_VERSION}.jar" JAR_FILE_NAME="cas-server-support-shell-${CAS_VERSION}.jar"
...@@ -242,11 +164,7 @@ function cli() { ...@@ -242,11 +164,7 @@ function cli() {
exit 0; exit 0;
fi fi
if [ "$buildTool" = "maven" ]; then DOWNLOAD_DIR=./build/libs
DOWNLOAD_DIR=./target
else
DOWNLOAD_DIR=./build/libs
fi
COMMAND_FILE="${DOWNLOAD_DIR}/${JAR_FILE_NAME}" COMMAND_FILE="${DOWNLOAD_DIR}/${JAR_FILE_NAME}"
if [ ! -f "$COMMAND_FILE" ]; then if [ ! -f "$COMMAND_FILE" ]; then
...@@ -260,27 +178,14 @@ function cli() { ...@@ -260,27 +178,14 @@ function cli() {
} }
if [ "$#" -lt 2 ]; then command=$1
buildTool=""
command=""
else
buildTool=$1
command=$2
fi
if [ -z "$command" ]; then if [ -z "$command" ]; then
echo "No commands provided. Defaulting to [run]" echo "No commands provided. Defaulting to [run]"
command="run" command="run"
fi fi
if [ -z "$buildTool" ]; then shift 1
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 case "$command" in
"copy") "copy")
...@@ -289,50 +194,40 @@ case "$command" in ...@@ -289,50 +194,40 @@ case "$command" in
"help") "help")
help help
;; ;;
*) "clean")
if [ "$buildTool" = "maven" ]; then clean "$@"
pushd maven-overlay ;;
else "package"|"build")
pushd gradle-overlay package "$@"
fi ;;
"debug")
case "$command" in debug "$@"
"clean") ;;
clean "$@" "run")
;; run "$@"
"package"|"build") ;;
package "$@" "gencert")
;; gencert "$@"
"debug") ;;
debug "$@" "cli")
;; cli "$@"
"run") ;;
run "$@" "update")
;; update "$@"
"gencert") ;;
gencert "$@" "dependencies")
;; update "$@"
"cli") ;;
cli "$@" "runalone")
;; runalone "$@"
"update") ;;
update "$@" "listviews")
;; listviews "$@"
"dependencies") ;;
update "$@" "getview")
;; getview "$@"
"runalone") ;;
runalone "$@" "tomcat")
;; tomcat
"listviews") ;;
listviews "$@"
;;
"getview")
getview "$@"
;;
"tomcat")
tomcat
;;
esac
popd
esac esac
\ No newline at end of file
# Versions # Versions
casVersion=6.0.0-RC1 casVersion=6.0.0-RC2-SNAPSHOT
springBootVersion=2.0.4.RELEASE springBootVersion=2.0.4.RELEASE
appServer=-tomcat appServer=-tomcat
tomcatVersion=9 tomcatVersion=9
tomcatFullVersion=9.0.10 tomcatFullVersion=9.0.10
sourceCompatibility=10 sourceCompatibility=10
targetCompatibility=10 targetCompatibility=10
gradleVersion=4.9
\ No newline at end of file
#Maven download properties
#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
#!/bin/sh
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Maven2 Start Up Batch script
#
# Required ENV vars:
# ------------------
# JAVA_HOME - location of a JDK home dir
#
# Optional ENV vars
# -----------------
# M2_HOME - location of maven2's installed home dir
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
if [ -z "$MAVEN_SKIP_RC" ] ; then
if [ -f /etc/mavenrc ] ; then
. /etc/mavenrc
fi
if [ -f "$HOME/.mavenrc" ] ; then
. "$HOME/.mavenrc"
fi
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
mingw=false
case "`uname`" in
CYGWIN*) cygwin=true ;;
MINGW*) mingw=true;;
Darwin*) darwin=true
#
# Look for the Apple JDKs first to preserve the existing behaviour, and then look
# for the new JDKs provided by Oracle.
#
if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then
#
# Apple JDKs
#
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
fi
if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then
#
# Apple JDKs
#
export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
fi
if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then
#
# Oracle JDKs
#
export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
fi
if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then
#
# Apple JDKs
#
export JAVA_HOME=`/usr/libexec/java_home`
fi
;;
esac
if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then
JAVA_HOME=`java-config --jre-home`
fi
fi
if [ -z "$M2_HOME" ] ; then
## resolve links - $0 may be a link to maven's home
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
M2_HOME=`dirname "$PRG"`/..
# make it fully qualified
M2_HOME=`cd "$M2_HOME" && pwd`
cd "$saveddir"
# echo Using m2 at $M2_HOME
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --unix "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
# For Migwn, ensure paths are in UNIX format before anything is touched
if $mingw ; then
[ -n "$M2_HOME" ] &&
M2_HOME="`(cd "$M2_HOME"; pwd)`"
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
# TODO classpath?
fi
if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`"
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
if $darwin ; then
javaHome="`dirname \"$javaExecutable\"`"
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
else
javaExecutable="`readlink -f \"$javaExecutable\"`"
fi
javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="`which java`"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly." >&2
echo " We cannot execute $JAVACMD" >&2
exit 1
fi
if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --path --windows "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&