Commit 78a6ea50 authored by Misagh Moayyed's avatar Misagh Moayyed

move commands to gradle

parent 82045944
...@@ -4,14 +4,14 @@ import java.nio.file.* ...@@ -4,14 +4,14 @@ import java.nio.file.*
buildscript { buildscript {
repositories { repositories {
mavenLocal() mavenLocal()
mavenCentral()
jcenter() jcenter()
maven { url "https://repo.spring.io/libs-milestone" } maven { url "https://repo.spring.io/libs-milestone" }
maven { url "https://plugins.gradle.org/m2/" } maven { url "https://plugins.gradle.org/m2/" }
} }
dependencies { dependencies {
classpath "de.undercouch:gradle-download-task:${project.gradleDownloadTaskVersion}"
classpath "org.springframework.boot:spring-boot-gradle-plugin:${project.springBootVersion}" classpath "org.springframework.boot:spring-boot-gradle-plugin:${project.springBootVersion}"
classpath "de.undercouch:gradle-download-task:${project.gradleDownloadTaskVersion}" // used to download CAS shell
classpath "org.apache.ivy:ivy:${project.ivyVersion}" // used to download CAS shell from snapshot repo
classpath "gradle.plugin.com.google.cloud.tools:jib-gradle-plugin:${project.jibVersion}" classpath "gradle.plugin.com.google.cloud.tools:jib-gradle-plugin:${project.jibVersion}"
} }
} }
...@@ -26,17 +26,24 @@ repositories { ...@@ -26,17 +26,24 @@ repositories {
maven { url "https://oss.jfrog.org/artifactory/oss-snapshot-local" } maven { url "https://oss.jfrog.org/artifactory/oss-snapshot-local" }
} }
def casServerVersion = project.'cas.version'
def casWebApplicationBinaryName = "cas.war"
project.ext."casServerVersion" = casServerVersion
project.ext."casWebApplicationBinaryName" = casWebApplicationBinaryName
apply from: "https://dl.bintray.com/scalding/generic/waroverlay.gradle" apply from: "https://dl.bintray.com/scalding/generic/waroverlay.gradle"
apply from: rootProject.file("gradle/tasks.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"
apply plugin: "de.undercouch.download"
apply plugin: "com.google.cloud.tools.jib" apply plugin: "com.google.cloud.tools.jib"
def casServerVersion = project.'cas.version' tasks.findByName("jibDockerBuild")
def casWebApplicationBinaryName = "cas.war" .dependsOn(copyWebAppIntoJib, copyConfigIntoJib)
.finalizedBy(deleteWebAppFromJib)
tasks.findByName("build").mustRunAfter("setExecutable") tasks.findByName("build").mustRunAfter("setExecutable")
...@@ -142,236 +149,4 @@ jib { ...@@ -142,236 +149,4 @@ jib {
'/docker/entrypoint.sh': '755' '/docker/entrypoint.sh': '755'
] ]
} }
} }
\ No newline at end of file
task copyCasConfiguration(type: Copy, group: "build") {
from "etc/cas/config"
into "/etc/cas/config"
doFirst {
mkdir "/etc/cas/config"
}
}
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: "Docker") {
dependsOn build
from "etc/cas"
into "src/main/jib/docker/cas"
}
task deleteWebAppFromJib(type: Delete, group: "Docker", description: "Explodes the CAS web application archive") {
delete "src/main/jib/docker/cas"
}
tasks.findByName("jibDockerBuild")
.dependsOn(copyWebAppIntoJib, copyConfigIntoJib)
.finalizedBy(deleteWebAppFromJib)
task explodeWar(type: Copy, group: "build", description: "Explodes the CAS web application archive") {
dependsOn build
from zipTree("build/libs/${casWebApplicationBinaryName}")
into "${buildDir}/cas"
}
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".split(" "))
javaexec {
main = "-jar"
jvmArgs = casRunArgs
args = ["build/libs/${casWebApplicationBinaryName}"]
logger.info "Started ${commandLine}"
}
}
}
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"
jvmArgs = casArgs
debug = true
args = ["build/libs/${casWebApplicationBinaryName}"]
logger.info "Started ${commandLine}"
}
}
}
task downloadShell (group: "shell", description: "Download CAS shell jar from snapshot or release maven repo") {
doFirst {
mkdir "${project.shellDir}"
}
doLast {
def downloadFile
if (isRunningCasServerSnapshot(casServerVersion)) {
def snapshotDir = "https://oss.sonatype.org/content/repositories/snapshots/org/apereo/cas/cas-server-support-shell/${casServerVersion}/"
def files = new org.apache.ivy.util.url.ApacheURLLister().listFiles(new URL(snapshotDir))
files = files.sort{it.path}
files.each {
if (it.path.endsWith(".jar")) {
downloadFile = it
}
}
} else {
downloadFile = "https://repo1.maven.org/maven2/org/apereo/cas/cas-server-support-shell/${casServerVersion}/cas-server-support-shell-${casServerVersion}.jar"
}
logger.info "Downloading file: ${downloadFile}"
download {
src downloadFile
dest new File("${project.shellDir}", "cas-server-support-shell-${casServerVersion}.jar")
overwrite false
}
}
}
task runShell (group: "shell", description: "Run the CAS shell") {
dependsOn downloadShell
doLast {
def casShellArgs = Arrays.asList("-Xmx1500M".split(" "))
javaexec {
main = "-jar"
jvmArgs = casShellArgs
standardInput = System.in
args = ["${project.shellDir}/cas-server-support-shell-${casServerVersion}.jar", "--shell"]
}
}
}
task debugShell (group: "shell", description: "Run the CAS shell with debug options, wait for debugger on port 5005") {
dependsOn downloadShell
doLast {
def casArgs = Arrays.asList("-Xmx1500M ".split(" "))
javaexec {
main = "-jar"
jvmArgs = casArgs
debug = true
standardInput = System.in
args = ["${project.shellDir}/cas-server-support-shell-${casServerVersion}.jar", "--shell"]
}
}
}
task showConfiguration(group: "build", description: "Show configurations for each dependency, etc") {
doLast() {
def cfg = project.hasProperty("configuration") ? project.property("configuration") : "compile"
configurations.getByName(cfg).each { println it }
}
}
task allDependenciesInsight(group: "build", type: DependencyInsightReportTask, description: "Produce insight information for all dependencies") {}
task allDependencies(group: "build", type: DependencyReportTask, description: "Display a graph of all project dependencies") {}
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"
}
}
task listTemplateViews (group: "build", description: "List all CAS views") {
dependsOn explodeWar
doFirst {
def explodedDir="${buildDir}/cas"
fileTree(explodedDir).matching {
include "**/*.html"
}
.collect { it.name }
.toSorted()
.each { println it }
}
}
task getResource(group: "build", description: "Fetch a CAS resource and move it into the overlay") {
dependsOn explodeWar
doFirst {
def explodedDir="${buildDir}/cas"
def resourceName = project.getProperty("resourceName")
def results = fileTree(explodedDir).matching {
include "**/${resourceName}.*"
}
if (results.isEmpty()) {
println "No resources could be found matching ${resourceName}"
return
}
if (results.size() > 1) {
println "Multiple resources found matching ${resourceName}: ${results}"
return
}
def fromFile = explodedDir + "/WEB-INF/classes"
def resourcesDir = "src/main/resources"
mkdir resourcesDir
def resourceFile = results[0].canonicalPath
def toResourceFile = resourceFile.replace(fromFile, resourcesDir)
def parent = file(toResourceFile).getParent()
mkdir parent
Files.copy(Paths.get(resourceFile), Paths.get(toResourceFile), StandardCopyOption.REPLACE_EXISTING)
println "Copied file to ${toResourceFile}"
}
}
def isRunningCasServerSnapshot(casServerVersion) {
return "${casServerVersion}".contains("-SNAPSHOT")
}
buildscript {
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
dependencies {
classpath "org.apache.ivy:ivy:${project.ivyVersion}"
}
}
task copyCasConfiguration(type: Copy, group: "build") {
from "etc/cas/config"
into "/etc/cas/config"
doFirst {
mkdir "/etc/cas/config"
}
}
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: "Docker") {
dependsOn build
from "etc/cas"
into "src/main/jib/docker/cas"
}
task deleteWebAppFromJib(type: Delete, group: "Docker", description: "Explodes the CAS web application archive") {
delete "src/main/jib/docker/cas"
}
task explodeWar(type: Copy, group: "build", description: "Explodes the CAS web application archive") {
dependsOn build
from zipTree("build/libs/${casWebApplicationBinaryName}")
into "${buildDir}/cas"
}
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".split(" "))
javaexec {
main = "-jar"
jvmArgs = casRunArgs
args = ["build/libs/${casWebApplicationBinaryName}"]
logger.info "Started ${commandLine}"
}
}
}
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"
jvmArgs = casArgs
debug = true
args = ["build/libs/${casWebApplicationBinaryName}"]
logger.info "Started ${commandLine}"
}
}
}
task downloadShell (group: "shell", description: "Download CAS shell jar from snapshot or release maven repo") {
doFirst {
mkdir "${project.shellDir}"
}
doLast {
def downloadFile
if (isRunningCasServerSnapshot(casServerVersion)) {
def snapshotDir = "https://oss.sonatype.org/content/repositories/snapshots/org/apereo/cas/cas-server-support-shell/${casServerVersion}/"
def files = new org.apache.ivy.util.url.ApacheURLLister().listFiles(new URL(snapshotDir))
files = files.sort{it.path}
files.each {
if (it.path.endsWith(".jar")) {
downloadFile = it
}
}
} else {
downloadFile = "https://repo1.maven.org/maven2/org/apereo/cas/cas-server-support-shell/${casServerVersion}/cas-server-support-shell-${casServerVersion}.jar"
}
logger.info "Downloading file: ${downloadFile}"
download {
src downloadFile
dest new File("${project.shellDir}", "cas-server-support-shell-${casServerVersion}.jar")
overwrite false
}
}
}
task runShell (group: "shell", description: "Run the CAS shell") {
dependsOn downloadShell
doLast {
def casShellArgs = Arrays.asList("-Xmx1500M".split(" "))
javaexec {
main = "-jar"
jvmArgs = casShellArgs
standardInput = System.in
args = ["${project.shellDir}/cas-server-support-shell-${casServerVersion}.jar", "--shell"]
}
}
}
task debugShell (group: "shell", description: "Run the CAS shell with debug options, wait for debugger on port 5005") {
dependsOn downloadShell
doLast {
def casArgs = Arrays.asList("-Xmx1500M ".split(" "))
javaexec {
main = "-jar"
jvmArgs = casArgs
debug = true
standardInput = System.in
args = ["${project.shellDir}/cas-server-support-shell-${casServerVersion}.jar", "--shell"]
}
}
}
task showConfiguration(group: "build", description: "Show configurations for each dependency, etc") {
doLast() {
def cfg = project.hasProperty("configuration") ? project.property("configuration") : "compile"
configurations.getByName(cfg).each { println it }
}
}
task allDependenciesInsight(group: "build", type: DependencyInsightReportTask, description: "Produce insight information for all dependencies") {}
task allDependencies(group: "build", type: DependencyReportTask, description: "Display a graph of all project dependencies") {}
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"
}
}
task listTemplateViews (group: "build", description: "List all CAS views") {
dependsOn explodeWar
doFirst {
def explodedDir="${buildDir}/cas"
fileTree(explodedDir).matching {
include "**/*.html"
}
.collect { it.name }
.toSorted()
.each { println it }
}
}
task getResource(group: "build", description: "Fetch a CAS resource and move it into the overlay") {
dependsOn explodeWar
doFirst {
def explodedDir="${buildDir}/cas"
def resourceName = project.getProperty("resourceName")
def results = fileTree(explodedDir).matching {
include "**/${resourceName}.*"
}
if (results.isEmpty()) {
println "No resources could be found matching ${resourceName}"
return
}
if (results.size() > 1) {
println "Multiple resources found matching ${resourceName}: ${results}"
return
}
def fromFile = explodedDir + "/WEB-INF/classes"
def resourcesDir = "src/main/resources"
mkdir resourcesDir
def resourceFile = results[0].canonicalPath
def toResourceFile = resourceFile.replace(fromFile, resourcesDir)
def parent = file(toResourceFile).getParent()
mkdir parent
Files.copy(Paths.get(resourceFile), Paths.get(toResourceFile), StandardCopyOption.REPLACE_EXISTING)
println "Copied file to ${toResourceFile}"
}
}
def isRunningCasServerSnapshot(casServerVersion) {
return "${casServerVersion}".contains("-SNAPSHOT")
}
\ No newline at end of file
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