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
# Overview
The project structure contains two variants for Apache Maven and Gradle WAR overlays, inside `maven-overlay` and `gradle-overlay` respectively. You may invoke
build commands using the `build.sh` script to work with your chosen overlay using:
You may invoke build commands using the `build.sh` script to work with your chosen overlay using:
```bash
./build.sh [maven|gradle] [command]
./build.sh [command]
```
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
- 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
......
......@@ -4,7 +4,7 @@ buildscript {
jcenter()
}
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 {
}
apply from: "https://dl.bintray.com/scalding/generic/waroverlay.gradle"
apply plugin: "war"
apply plugin: "org.springframework.boot"
apply plugin: "eclipse"
apply plugin: "idea"
sourceCompatibility=System.env.sourceCompatibility
targetCompatibility=System.env.targetCompatibility
def currentBranch = "master"
def currentVersion = "$System.env.casVersion"
if (!currentVersion.contains("RC")) {
......@@ -77,11 +75,10 @@ bootRun {
dependencies {
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 {
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...
}
......@@ -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") {
dependsOn build
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 {
main = "-jar";
jvmArgs = casRunArgs
......@@ -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") {
gradleVersion = "4.9"
gradleVersion = "${project.gradleVersion}"
}
task casVersion(group: "build", description: "Display the current CAS version") {
doFirst {
println "$System.env.casVersion"
println "${project.casVersion}"
}
}
......
#!/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() {
echo -e "Creating configuration directory under /etc/cas"
mkdir -p /etc/cas/config
......@@ -28,7 +19,7 @@ function help() {
echo "- https://apereo.github.io/cas"
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 "\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"
......@@ -45,46 +36,23 @@ function help() {
}
function clean() {
if [ "$buildTool" = "maven" ]; then
./mvnw clean "$@"
else
./gradlew clean "$@"
fi
./gradlew clean "$@"
}
function package() {
if [ "$buildTool" = "maven" ]; then
./mvnw clean package "$@"
else
./gradlew clean build "$@"
fi
./gradlew clean build "$@"
}
function update() {
clean
if [ "$buildTool" = "maven" ]; then
./mvnw package -U "$@"
else
./gradlew build --refresh-dependencies "$@"
fi
./gradlew clean build --refresh-dependencies "$@"
}
function dependencies() {
if [ "$buildTool" = "maven" ]; then
./mvnw dependency:analyze "$@"
else
./gradlew allDependencies
fi
./gradlew allDependencies
}
function tomcat() {
if [ "$buildTool" = "maven" ]; then
./mvnw clean package -P external "$@"
else
./gradlew clean build -Pexternal=true "$@"
fi
pushd ..
./gradlew clean build -Pexternal=true "$@"
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"
......@@ -98,83 +66,46 @@ function tomcat() {
echo "Attempting to shutdown Apache Tomcat..."
./apache-tomcat/bin/shutdown.sh 2>/dev/null
popd
if [ "$buildTool" = "maven" ]; then
cp target/cas.war .../apache-tomcat/webapps/
else
cp build/libs/cas.war ../apache-tomcat/webapps/
fi
pushd ..
cp build/libs/cas.war ../apache-tomcat/webapps/
./apache-tomcat/bin/startup.sh
popd
tail -F ../apache-tomcat/logs/catalina.out
}
function debug() {
if [ "$buildTool" = "maven" ]; then
casWar="target/cas.war"
else
casWar="build/libs/cas.war"
fi
casWar="build/libs/cas.war"
package && java -Xdebug -Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=n -jar $casWar
}
function run() {
if [ "$buildTool" = "maven" ]; then
casWar="target/cas.war"
else
casWar="build/libs/cas.war"
fi
casWar="build/libs/cas.war"
package && java -XX:TieredStopAtLevel=1 -Xverify:none -jar $casWar
}
function runalone() {
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
./gradlew clean build -Pexecutable=true "$@"
casWar="build/libs/cas.war"
chmod +x $casWar
$casWar
}
function listviews() {
explodeapp
if [ "$buildTool" = "maven" ]; then
explodedDir=target/cas
else
explodedDir=build/cas
fi
explodeApp
explodedDir=build/cas
find $explodedDir -type f -name "*.html" | xargs -n 1 basename | sort | more
}
function explodeapp() {
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
function explodeApp() {
./gradlew explodeWar
echo "Exploded the CAS web application file."
}
function getview() {
explodeapp
explodeApp
echo "Searching for view name $@..."
if [ "$buildTool" = "maven" ]; then
explodedDir=target/cas
else
explodedDir=build/cas
fi
explodedDir=build/cas
results=`find $explodedDir -type f -name "*.html" | grep -i "$@"`
count=`wc -w <<< "$results"`
if [ "$count" -eq 0 ];then
......@@ -183,11 +114,7 @@ function getview() {
fi
echo -e "Found view(s): \n$results"
if [ "$count" -eq 1 ];then
if [ "$buildTool" = "maven" ]; then
fromFile="target/cas/WEB-INF/classes"
else
fromFile="build/cas/WEB-INF/classes"
fi
fromFile="build/cas/WEB-INF/classes"
toFile="src/main/resources"
overlayfile=`echo "${results/$fromFile/$toFile}"`
......@@ -221,12 +148,7 @@ function gencert() {
function cli() {
rm -f *.log
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
CAS_VERSION=$(./gradlew casVersion --quiet)
echo "CAS version: $CAS_VERSION"
JAR_FILE_NAME="cas-server-support-shell-${CAS_VERSION}.jar"
......@@ -242,11 +164,7 @@ function cli() {
exit 0;
fi
if [ "$buildTool" = "maven" ]; then
DOWNLOAD_DIR=./target
else
DOWNLOAD_DIR=./build/libs
fi
DOWNLOAD_DIR=./build/libs
COMMAND_FILE="${DOWNLOAD_DIR}/${JAR_FILE_NAME}"
if [ ! -f "$COMMAND_FILE" ]; then
......@@ -260,27 +178,14 @@ function cli() {
}
if [ "$#" -lt 2 ]; then
buildTool=""
command=""
else
buildTool=$1
command=$2
fi
command=$1
if [ -z "$command" ]; then
echo "No commands provided. Defaulting to [run]"
command="run"
fi
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
shift 1
case "$command" in
"copy")
......@@ -289,50 +194,40 @@ case "$command" in
"help")
help
;;
*)
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
"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
\ No newline at end of file
# Versions
casVersion=6.0.0-RC1
casVersion=6.0.0-RC2-SNAPSHOT
springBootVersion=2.0.4.RELEASE
appServer=-tomcat
tomcatVersion=9
tomcatFullVersion=9.0.10
sourceCompatibility=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" ] &&
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
fi
# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
local basedir=$(pwd)
local wdir=$(pwd)
while [ "$wdir" != '/' ] ; do
wdir=$(cd "$wdir/.."; pwd)
if [ -d "$wdir"/.mvn ] ; then
basedir=$wdir
break
fi
done
echo "${basedir}"
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
echo "$(tr -s '\n' ' ' < "$1")"
fi
}
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# Provide a "standardized" way to retrieve the CLI args that will
# work with both Windows and non-Windows executions.
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
export MAVEN_CMD_LINE_ARGS
WRAPPER_LAUNCHER="org.apache.maven.wrapper.MavenWrapperMain"
exec "$JAVACMD" \
$MAVEN_OPTS \
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
-classpath \
"$MAVEN_PROJECTBASEDIR/maven/maven-wrapper.jar" \
${WRAPPER_LAUNCHER} "$@"
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM http://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven2 Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2