apply plugin: 'io.spring.convention.spring-sample-war'

def keystore = "$rootDir/samples/certificates/server.jks"
def password = 'password'

dependencies {
	compile "org.jasig.cas:cas-server-webapp:4.0.7@war"
	compile slf4jDependencies
	runtime 'org.aspectj:aspectjrt'
	runtime 'org.aspectj:aspectjtools'
	runtime 'org.aspectj:aspectjweaver'
}

project.tasks.withType(org.gradle.api.tasks.bundling.War) { war ->
	war.duplicatesStrategy = DuplicatesStrategy.EXCLUDE
	project.tasks.war.doFirst {
		war.classpath = war.classpath.filter { !it.name.endsWith(".war") }

		war.project.configurations.runtime.each {
			if (it.name.endsWith(".war")) {
				def fileList = war.project.zipTree(it)
				war.from fileList
			}
		}
	}
}

project.tasks.withType(org.akhikhl.gretty.StartBaseTask).all { task ->
	task.doFirst {
		def destinationDir = project.file("$buildDir/inplaceWebapp")
		project.configurations.runtime.each { dependency ->
			if (dependency.name.endsWith(".war")) {
				def warTree = project.zipTree(dependency)
				project.copy {
					from warTree
					into destinationDir
					eachFile {
						if (it.relativePath.getFile(destinationDir).exists()) {
							it.exclude()
						}
					}
				}
			}
		}
	}
}

gretty {
	contextPath = '/cas'
	httpsEnabled = true
	httpPort = 9090
	httpsPort = 9443
	sslKeyStorePath = keystore
	sslKeyStorePassword = password
	jvmArgs = ["-Djavax.net.ssl.trustStore=${keystore}", "-Djavax.net.ssl.trustStorePassword=${password}"]
}
