Commit 95510177 authored by Misagh Moayyed's avatar Misagh Moayyed

move shell commands to gradle

parent a98d4dd1
import org.apache.tools.ant.taskdefs.condition.Os
buildscript {
repositories {
mavenLocal()
......@@ -25,7 +27,6 @@ repositories {
apply from: "https://dl.bintray.com/scalding/generic/waroverlay.gradle"
apply plugin: "war"
apply plugin: "org.springframework.boot"
apply plugin: "eclipse"
......@@ -36,6 +37,8 @@ apply plugin: "com.google.cloud.tools.jib"
def casServerVersion = project.'cas.version'
def casWebApplicationBinaryName = "cas.war"
tasks.findByName("build").mustRunAfter("setExecutable")
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
......@@ -64,14 +67,18 @@ springBoot {
}
bootWar {
if (project.hasProperty("executable")) {
launchScript()
}
archiveName "${casWebApplicationBinaryName}"
baseName "cas"
excludeDevtools = false
doFirst {
def executable = project.hasProperty("executable") && Boolean.valueOf(project.getProperty("executable"))
if (executable) {
logger.info "Including launch script for executable WAR artifact"
launchScript()
} else {
logger.info "WAR artifact is not marked as an executable"
}
archiveName "${casWebApplicationBinaryName}"
baseName "cas"
excludeDevtools = true
}
}
bootRun {
......@@ -135,19 +142,19 @@ task copyCasConfiguration(type: Copy, group: "build") {
}
}
task copyWebAppIntoJib(type: Copy, group: "build") {
task copyWebAppIntoJib(type: Copy, group: "Docker", description: "Copy the CAS configuration from this project to /etc/cas/config") {
dependsOn build
from "build/libs/${casWebApplicationBinaryName}"
into "src/main/jib/docker/cas/war"
}
task copyConfigIntoJib(type: Copy, group: "build") {
task copyConfigIntoJib(type: Copy, group: "Docker") {
dependsOn build
from "etc/cas"
into "src/main/jib/docker/cas"
}
task deleteWebAppFromJib(type: Delete, group: "build") {
task deleteWebAppFromJib(type: Delete, group: "Docker", description: "Explodes the CAS web application archive") {
delete "src/main/jib/docker/cas"
}
......@@ -174,9 +181,29 @@ task run(group: "build", description: "Run the CAS web application in embedded c
}
}
task setExecutable(group: "build", description: "Configure the project to run in executable mode") {
doFirst {
project.setProperty("executable", "true")
logger.info "Configuring the project as executable"
}
}
task executable(type:Exec, group: "build", description: "Run the CAS web application in standalone executable mode") {
dependsOn setExecutable, build
doFirst {
workingDir "."
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine "chmod", "+x", bootWar.archivePath
}
logger.info "Running" + bootWar.archivePath
commandLine bootWar.archivePath
}
}
task debug(group: "build", description: "Debug the CAS web application in embedded mode on port 5005") {
dependsOn build
doLast {
logger.info "Debugging process is started in a suspended state, listening on port 5005."
def casArgs = Arrays.asList("-Xmx2048M".split(" "))
javaexec {
main = "-jar"
......@@ -206,7 +233,7 @@ task downloadShell (group: "shell", description: "Download CAS shell jar from sn
} else {
downloadFile = "https://repo1.maven.org/maven2/org/apereo/cas/cas-server-support-shell/${casServerVersion}/cas-server-support-shell-${casServerVersion}.jar"
}
println "Downloading file: ${downloadFile}"
logger.info "Downloading file: ${downloadFile}"
download {
src downloadFile
dest new File("${project.shellDir}", "cas-server-support-shell-${casServerVersion}.jar")
......@@ -257,6 +284,35 @@ task casVersion (group: "build", description: "Display the current CAS version")
doFirst { println casServerVersion }
}
task createKeystore (type:Exec, group: "build", description: "Create CAS keystore") {
doFirst {
mkdir "/etc/cas"
workingDir "."
def keystorePath = "/etc/cas/thekeystore"
def dn = "CN=cas.example.org,OU=Example,OU=Org,C=US"
if (project.hasProperty("certificateDn")) {
dn = project.getProperty("certificateDn")
}
def subjectAltName = "dns:example.org,dns:localhost,ip:127.0.0.1"
if (project.hasProperty("certificateSubAltName")) {
subjectAltName = project.getProperty("certificateSubAltName")
}
logger.info "Generating keystore for CAS with DN ${dn}"
commandLine "keytool", "-genkeypair", "-alias", "cas",
"-keyalg", "RSA",
"-keypass", "changeit", "-storepass", "changeit",
"-keystore", keystorePath,
"-dname", dn, "-ext", "SAN=${subjectAltName}"
logger.info "Exporting keystore..."
commandLine "keytool", "-exportcert", "-alias", "cas",
"-storepass", "changeit", "-keystore", keystorePath,
"-file", "/etc/cas/cas.cer"
}
}
def isRunningCasServerSnapshot(casServerVersion) {
return "${casServerVersion}".contains("-SNAPSHOT")
}
......@@ -5,10 +5,11 @@ function copy() {
}
function help() {
casVersion=$(./gradlew casVersion --quiet)
clear
echo "******************************************************************"
tput setaf 2
echo "Apereo CAS ${casVersion}"
echo "Apereo CAS $casVersion"
echo "Enterprise Single SignOn for all earthlings and beyond"
tput sgr 0
echo "- https://github.com/apereo/cas"
......@@ -72,20 +73,15 @@ function tomcat() {
}
function debug() {
casWar="build/libs/cas.war"
package && java -Xdebug -Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=n -jar $casWar
./gradlew debug "$@"
}
function run() {
casWar="build/libs/cas.war"
package && java -XX:TieredStopAtLevel=1 -Xverify:none -jar $casWar
./gradlew run "$@"
}
function runalone() {
./gradlew clean build -Pexecutable=true "$@"
casWar="build/libs/cas.war"
chmod +x $casWar
$casWar
./gradlew clean executable
}
function jibdocker() {
......@@ -164,52 +160,11 @@ function getview() {
}
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
./gradlew createKeystore "$@"
}
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
DOWNLOAD_DIR=./build/libs
COMMAND_FILE="${DOWNLOAD_DIR}/${JAR_FILE_NAME}"
if [ ! -f "$COMMAND_FILE" ]; then
mkdir -p $DOWNLOAD_DIR
wget "https://repo1.maven.org/maven2/${JAR_PATH}" -P ./target
fi
echo "Running $COMMAND_FILE"
java -jar $COMMAND_FILE "$@"
exit 0;
./gradlew downloadShell runShell "$@"
}
command=$1
......
......@@ -3,6 +3,7 @@ cas.version=6.0.0-RC4-SNAPSHOT
springBootVersion=2.1.0.RELEASE
appServer=-tomcat
executable=false
gradleVersion=5.0
tomcatVersion=9
......
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