apply plugin: 'war'
dependencies {
compile fileTree(dir: rootProject.projectDir.absolutePath + '/lib', include: '**/*.jar', exclude:['dev-only/*.jar','jetty-ext/*.jar'])
providedCompile fileTree(dir: rootProject.projectDir.absolutePath + '/lib', include: ['dev-only/*.jar','jetty-ext/*.jar'])
}
war {
version = rootProject.novatarTargetVersion
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
destinationDir = rootProject.destinationDir
manifest {
attributes("Implementation-Title": "Gradle",
"Implementation-Version": rootProject.novatarTargetVersion,
"Company" : "SF Express",
"WarVersion" : "v" + rootProject.novatarTargetVersionWithDt)
}
exclude 'WEB-INF/classes'
exclude 'i18n-rs'
exclude 'framejs'
def pcRs = file(projectDir.absolutePath + '/src/main/webapp/pc-rs')
pcRs.eachDir { dir ->
if (dir.name != 'novatar.frameimpl' && dir.name != 'base') {
exclude ('pc-rs/' + dir.name)
}
}
def mobileRs = file(projectDir.absolutePath + '/src/main/webapp/mobile-rs')
mobileRs.eachDir { dir ->
if (dir.name != 'novatar.frameimpl' && dir.name != 'base') {
exclude ('mobile-rs/' + dir.name)
}
}
}
eclipse.classpath.defaultOutputDir = file("src/main/webapp/WEB-INF/classes")
task cleanWebappRuns << {
File destFile = file(projectDir.absolutePath + '/src/main/webapp/i18n-rs')
if (destFile.exists()) {
FileCollection files = files {destFile.listFiles()}
files.each {File file ->
if (file.name != 'readme.txt') {
delete file
}
}
}
destFile = file(projectDir.absolutePath + '/src/test/jetty-run')
if (destFile.exists()) {
FileCollection files = files {destFile.listFiles()}
files.each {File file ->
delete file
}
}
copy {
from projectDir.absolutePath + '/src/main/jetty-base/deploy/resources'
into projectDir.absolutePath + '/src/test/jetty-run'
include "novatarKeyStore"
}
destFile = file(projectDir.absolutePath + '/src/main/jetty-base/deploy/webapps')
if (destFile.exists()) {
FileCollection files = files {destFile.listFiles()}
files.each {File file ->
delete file
}
}
destFile = file(projectDir.absolutePath + '/src/main/webapp/framejs')
if (destFile.exists()) {
FileCollection files = files {destFile.listFiles()}
files.each {File file ->
delete file
}
}
destFile = file(projectDir.absolutePath + '/src/main/webapp/WEB-INF/classes')
if (destFile.exists()) {
FileCollection files = files {destFile.listFiles()}
files.each {File file ->
delete file
}
}
destFile = file(projectDir.absolutePath + '/src/main/webapp/pc-rs')
if (destFile.exists()) {
destFile.eachDir { dir ->
if (dir.name != 'novatar.frameimpl' && dir.name != 'base') {
delete dir
}
}
}
destFile = file(projectDir.absolutePath + '/src/main/webapp/mobile-rs')
if (destFile.exists()) {
destFile.eachDir { dir ->
if (dir.name != 'novatar.frameimpl' && dir.name != 'base') {
delete dir
}
}
}
}
clean.dependsOn cleanWebappRuns
task eclipseJettyLaunch << {
println 'launch file begin to generate'
Node xml = new XmlParser().parse(new File(rootProject.projectDir, "novatar-webapp.launch.tpl"))
def launchFile = new File ( projectDir, project.name + "-run.launch" )
if (launchFile.exists()) {
launchFile.delete()
}
xml.stringAttribute.find{it.@key == "net.sourceforge.eclipsejetty.launcher.context"}.attributes()['value'] = "/"
xml.stringAttribute.find{it.@key == "net.sourceforge.eclipsejetty.launcher.customWebDefaults.resource"}.attributes()['value'] = "/" + eclipse.project.name + "/src/main/jetty-base/etc/webdefault.xml"
xml.stringAttribute.find{it.@key == "net.sourceforge.eclipsejetty.launcher.jetty.config.path.1"}.attributes()['value'] = "/" + eclipse.project.name + "/src/main/jetty-base/deploy/resources/novatar-jndi-ds.xml"
xml.stringAttribute.find{it.@key == "net.sourceforge.eclipsejetty.launcher.jetty.path"}.attributes()['value'] = rootProject.novatarJettyPath
xml.stringAttribute.find{it.@key == "org.eclipse.jdt.launching.PROJECT_ATTR"}.attributes()['value'] = eclipse.project.name
xml.stringAttribute.find{it.@key == "org.eclipse.jdt.launching.WORKING_DIRECTORY"}.attributes()['value'] = "\${" + "workspace_loc:" + eclipse.project.name + "/src/test/jetty-run}"
def classEntry = xml.listAttribute[0].listEntry
classEntry[0].attributes()['value'] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?> <runtimeClasspathEntry containerPath=\""+rootProject.eclipseJreContainer+"\" javaProject=\""+eclipse.project.name+"\" path=\"1\" type=\"4\"/>"
classEntry[1].attributes()['value'] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?> <runtimeClasspathEntry id=\"org.eclipse.jdt.launching.classpathentry.defaultClasspath\"> <memento exportedEntriesOnly=\"false\" project=\""+eclipse.project.name+"\"/></runtimeClasspathEntry>"
classEntry[2].attributes()['value'] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?> <runtimeClasspathEntry internalArchive=\"/"+eclipse.project.name+"/src/main/jetty-base/deploy/resources\" path=\"3\" type=\"2\"/>"
classEntry[3].attributes()['value'] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?> <runtimeClasspathEntry internalArchive=\"/"+eclipse.project.name+"/src/main/jetty-base/resources\" path=\"3\" type=\"2\"/>"
new XmlNodePrinter(new PrintWriter(new FileWriter(launchFile))).print(xml)
println 'launch file generated'
}
eclipseJettyLaunch.onlyIf {rootProject.property('novatarJettyPath') != null}
task buildVersionNumber << {
ant.propertyfile(file: "src/main/jetty-base/deploy/resources/sysconfig.properties"){
entry(key: 'version.releaseDate', value: rootProject.novatarJarDate)
entry(key: 'version.number', value: rootProject.novatarTargetVersion)
}
}
task changeWebappXml {
def webappFile = new File(projectDir, "src/main/jetty-base/etc/novatar-webapp-sample.xml")
def destWebappFile = new File(projectDir, "src/main/jetty-base/deploy/webapps/" + war.archiveName[0..-4] + "xml");
ext.destWebappFile = destWebappFile
doLast {
destWebappFile.withWriter("UTF-8") { Writer writer ->
webappFile.withReader("UTF-8") { Reader reader ->
reader.transformLine(writer) { String line ->
line.replaceAll('@warArchiveName@', war.archiveName)
}
}
}
}
}
task warAndWebappXml {
dependsOn war, changeWebappXml
doLast{
changeWebappXml.destWebappFile.renameTo(file(rootProject.destinationDir.absolutePath + "/" + changeWebappXml.destWebappFile.name))
}
}
task releaseForRun(type: Zip) {
dependsOn buildVersionNumber, changeWebappXml
destinationDir = rootProject.destinationDir
baseName = project.name + '-jetty-base'
version = rootProject.novatarTargetVersion
into('/jetty-base/deploy/webapps'){
from war.outputs.files
}
into('/jetty-base/deploy/webapps') {
from changeWebappXml.destWebappFile
}
into('/jetty-base'){
from ('src/main/jetty-base')
exclude('deploy/resources/novatarKeyStore')
exclude('etc/novatar-webapp-sample.xml')
exclude('deploy/webapps/*.*')
}
into('jetty-base/lib/ext'){
from(rootProject.projectDir.absolutePath + '/lib/jetty-ext')
}
into('/jdk_policy'){
from(rootProject.projectDir.absolutePath + '/jdk_policy')
}
doLast {
if (changeWebappXml.destWebappFile.exists()) {
changeWebappXml.destWebappFile.delete()
}
}
}
task releaseTheDeploy(type: Zip) {
dependsOn buildVersionNumber, changeWebappXml
destinationDir = rootProject.destinationDir
baseName = project.name + '-deploy'
version = rootProject.novatarTargetVersion
into('/deploy/webapps'){
from war.outputs.files
}
into('/deploy/webapps') {
from changeWebappXml.destWebappFile
}
into('/deploy/resources'){
from ('src/main/jetty-base/deploy/resources')
exclude('novatarKeyStore')
}
doLast {
if (changeWebappXml.destWebappFile.exists()) {
changeWebappXml.destWebappFile.delete()
}
}
}