Skip to content

DM-8566: build related fixes #266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ subprojects {

apply from: "$fireflyPath/buildScript/utils.gincl"

task purge << {
println('Removes all firefly build directories.')
delete "${fireflyPath}/build", "${fireflyPath}/jars/build", "${fireflyPath}/node_modules"
task purge {
description= 'Remove all build files from this project, including node_module.'
group = DEV_GROUP

doLast {
println('Removes all firefly build directories.')
delete "${fireflyPath}/build", "${fireflyPath}/jars/build", "${fireflyPath}/node_modules"
}
}
5 changes: 5 additions & 0 deletions buildScript/depends.gincl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ clean {
}

task buildClient (dependsOn: loadConfig) {
description= 'Build JavaScript portion of the application.'
group = MISC_GROUP

outputs.dir "${buildDir}/gwt/${project['app-name']}"
inputs.dir "${projectDir}/js"
Expand All @@ -124,6 +126,9 @@ task buildClient (dependsOn: loadConfig) {
}

task buildJsDoc (dependsOn: loadConfig) {
description= 'Build JSDoc.'
group = MISC_GROUP

def outdir = "${buildDir}/gwt/${project['app-name']}"

outputs.dir outdir
Expand Down
11 changes: 2 additions & 9 deletions buildScript/gwt.gincl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
def DEV_GROUP = "Development"

task gwt {
outputs.upToDateWhen { false }
Expand Down Expand Up @@ -89,7 +88,7 @@ task gwtCompile (type: JavaExec, dependsOn: [gwt, loadConfig]) {

task gwtRun (type: JavaExec, dependsOn: [gwt, loadConfig]) {
description= 'GWT DevMode'
group = DEV_GROUP
group = MISC_GROUP

inputs.source sourceSets.main.java.srcDirs
inputs.dir sourceSets.main.output.resourcesDir
Expand Down Expand Up @@ -133,7 +132,7 @@ task gwtRun (type: JavaExec, dependsOn: [gwt, loadConfig]) {

task gwtSuperDev (type: JavaExec, dependsOn: [gwt, loadConfig]) {
description= 'GWT SuperDev Mode'
group = DEV_GROUP
group = MISC_GROUP

inputs.source sourceSets.main.java.srcDirs
inputs.dir sourceSets.main.output.resourcesDir
Expand Down Expand Up @@ -176,9 +175,3 @@ task devMode (dependsOn: loadConfig) {
}


task immediateStart (dependsOn: gwt) << {
logger.info ">> running immediate-start-mod.sh on $gwt.warDir/${project['app-name']}.nocache"
exec {
commandLine "$fireflyPath/buildScript/immediate-start-mod.sh", "$gwt.warDir/${project['app-name']}.nocache"
}
}
106 changes: 69 additions & 37 deletions buildScript/gwt_webapp.gincl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
def WEBAPP_GROUP = "Webapp"

apply plugin: 'war'
apply from: "$fireflyPath/buildScript/gwt.gincl"

Expand Down Expand Up @@ -42,7 +40,15 @@ task jsTest (dependsOn: [loadConfig]) << {
}
}

clean {
description= 'Remove build files from this project'
group = DEV_GROUP
}

test {
description= 'Run Java and JavaScript unit test'
group = DEV_GROUP

dependsOn jsTest
// set a system property for the test JVM(s)
systemProperty 'some.prop', 'value'
Expand Down Expand Up @@ -70,7 +76,7 @@ test {

task prepareWebapp (type:Copy, dependsOn: [gwt, loadConfig, createVersionTag]) {
description= 'Generates the configuration files needed by the webapp, ie. app.prop, web.xml, etc.'
group = WEBAPP_GROUP
group = MISC_GROUP

// should rerun this everytime. properties could be modified from external files.
outputs.upToDateWhen { false }
Expand Down Expand Up @@ -126,6 +132,13 @@ task prepareWebapp (type:Copy, dependsOn: [gwt, loadConfig, createVersionTag]) {
into gwt.warDir
}

// temporary solution to extract fits_io.jar into WEB-INF/classes directory
// this fix the multiple nom.tam.fits issue
copy {
from zipTree(file("$fireflyPath/jars/fits-io/fits_io.jar"))
into "${gwt.warDir}/WEB-INF/classes"
}

if (project.appConfigProps["ehcache.replicate"] && !project.appConfigProps["ehcache.replicate"].toBoolean()) {
exclude "ehcache.xml"
}
Expand All @@ -142,7 +155,7 @@ task webapp {

war {
description= 'Build application. Creates a war file.'
group = WEBAPP_GROUP
group = MAIN_GROUP

dependsOn webapp, jar, gwtCompile, buildClient, prepareWebapp
outputs.dir gwt.warDir
Expand All @@ -161,7 +174,7 @@ clean {

task deploy (dependsOn: [loadConfig, webapp]) << {
description= 'Deploy webapp(war file) to Tomcat. Require ${tomcat_home} property'
group = WEBAPP_GROUP
group = MAIN_GROUP

if (!project.hasProperty("tomcat_home")) {
throw ProjectConfigurationException("tomcat_home property is not found.")
Expand All @@ -179,37 +192,48 @@ task deploy (dependsOn: [loadConfig, webapp]) << {
}
}

task warAll( dependsOn:[war, buildJsDoc] )
task buildAndDeploy( dependsOn:[war, deploy] )
task buildAllAndDeploy( dependsOn:[warAll, deploy] )
task warAll( dependsOn:[war, buildJsDoc] ) {
description= 'Build the war file with JSDoc generated.'
group = MAIN_GROUP
}
task buildAndDeploy( dependsOn:[war, deploy] ) {
description= 'Build the war file and then deploy it to a local tomcat server if successful. Property ${tomcat_home} is required'
group = MAIN_GROUP
}
task buildAllAndDeploy( dependsOn:[warAll, deploy] ) {
description= 'Run test and docs first, then build the war file. Deploy it to a local tomcat server if successful. Property ${tomcat_home} is required'
group = MAIN_GROUP
}

task buildAndPublish( dependsOn: war ) << {
description= 'Build the war file and then publish it to a remote host. Property ${publish_host} is required'
group = WEBAPP_GROUP
task buildAndPublish( dependsOn: war ) {
description= 'Build the war file and then publish it to a remote host. Property ${publish_host} is required.'
group = MAIN_GROUP

if (!file(war.archivePath).exists()) {
throw new StopExecutionException("$war.archivePath not found. Skipping sendArtifacts.")
}
if (!project.hasProperty("publish_host")) {
throw new StopExecutionException("publish_host not found. Skipping sendArtifacts.")
}
doLast {
if (!file(war.archivePath).exists()) {
throw new StopExecutionException("$war.archivePath not found. Skipping sendArtifacts.")
}
if (!project.hasProperty("publish_host")) {
throw new StopExecutionException("publish_host not found. Skipping sendArtifacts.")
}

def rhost = project.property("publish_host")
def reposRoot = "/hydra/repos/${project['app-name']}"
def major = appConfigProps.get('BuildMajor')
def minor = appConfigProps.get('BuildMinor')
def rev = appConfigProps.get('BuildRev')
def buildNum = appConfigProps.get('BuildNumber')
def dirName = "v$major.$minor.$rev.$buildNum"
def rhost = project.property("publish_host")
def reposRoot = "/hydra/repos/${project['app-name']}"
def major = appConfigProps.get('BuildMajor')
def minor = appConfigProps.get('BuildMinor')
def rev = appConfigProps.get('BuildRev')
def buildNum = appConfigProps.get('BuildNumber')
def dirName = "v$major.$minor.$rev.$buildNum"

exec {
commandLine "ssh", "$rhost", "mkdir -p $reposRoot/$dirName/"
}
exec {
commandLine "scp", "$war.archivePath", "$rhost:$reposRoot/$dirName/"
}
exec {
commandLine "ssh", "$rhost", "cd $reposRoot; rm current; ln -s $dirName current"
exec {
commandLine "ssh", "$rhost", "mkdir -p $reposRoot/$dirName/"
}
exec {
commandLine "scp", "$war.archivePath", "$rhost:$reposRoot/$dirName/"
}
exec {
commandLine "ssh", "$rhost", "cd $reposRoot; rm current; ln -s $dirName current"
}
}
}

Expand All @@ -226,6 +250,8 @@ def getVersionLabel() {
}

task publishToGithub (dependsOn: loadConfig) {
description = 'Publish the built artifacts as a GitHub release.'
group = MISC_GROUP

outputs.upToDateWhen { false }

Expand All @@ -240,12 +266,18 @@ task publishToGithub (dependsOn: loadConfig) {
throw new GradleException(">> Task failed due to missing node.js", e)
}

def relConfig = '{ "tag": "' + tag_label + '"' +
', "token": "' + project.property("github.auth.token") + '"' +
', "name": "' + rel_title + '"' +
', "assets": ["' + "${buildDir}/exec/${webapp.baseWarName}-exec.war" + '"]' +
"}"

def relConfig = sprintf("""
|{ "tag": "%s",
| "token": "%s",
| "name": "%s",
| "assets": ["%s", "%s"]
|}
""".stripMargin(),
tag_label,
project.property("github.auth.token"),
rel_title,
"${buildDir}/exec/${webapp.baseWarName}-exec.war", "${buildDir}/exec/${webapp.baseWarName}.war")
def res = exec {
environment 'NODE_PATH': "${fireflyPath}/node_modules"
executable "node"
Expand Down
57 changes: 32 additions & 25 deletions buildScript/init.gincl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
def INIT_GROUP = "Common initial setup for all gradle build."
ext.MAIN_GROUP = "~> Main"
ext.DEV_GROUP = "~> Development"
ext.MISC_GROUP = "~ Misc"

project.ext["app-name"] = name
project.ext.buildRoot = "$rootDir/build"
Expand All @@ -7,7 +9,7 @@ buildDir = "$buildRoot/${project.ext["app-name"]}"

task loadConfig {
description= 'Load build and app config files. Also, setup common properties like build_date, build_time, etc.'
group = INIT_GROUP
group = MISC_GROUP

project.ext.build_time = new Date().toString()
project.ext.build_date = new Date().format("yyyy-MM-dd")
Expand Down Expand Up @@ -47,6 +49,8 @@ task loadConfig {
}

task createVersionTag {
description = 'Creates version info used for tagging as well as build label.'
group = MISC_GROUP
dependsOn loadConfig

doLast {
Expand All @@ -70,34 +74,37 @@ ext.getVersionTag = { ->
return "$major.$minor.${rev}_${type}-$buildNum"
}

task createTag(dependsOn: loadConfig) << {
task createTag(dependsOn: loadConfig) {
description = 'Create and push a tag to remote repo. Optional properties: ${tag_name}, ${tag_file} if ${tag_name} is missing. defaults to build/version.tag, ${tag_remote} defaults to origin, ${tag_message}.'
group = MISC_GROUP

def tag_label = project.ext.createTagLabel();
println "tag: $tag_label"

exec {
executable 'git'
args 'tag'
args '-a'
args tag_label
args '-m'
if (project.hasProperty("tag_message")) {
args tag_message
} else {
args 'not given'
doLast {
def tag_label = project.ext.createTagLabel();
println "tag: $tag_label"

exec {
executable 'git'
args 'tag'
args '-a'
args tag_label
args '-m'
if (project.hasProperty("tag_message")) {
args tag_message
} else {
args 'not given'
}
}
}

exec {
executable 'git'
args 'push'
if (project.hasProperty("tag_remote")) {
args tag_remote
} else {
args 'origin'
exec {
executable 'git'
args 'push'
if (project.hasProperty("tag_remote")) {
args tag_remote
} else {
args 'origin'
}
args tag_label
}
args tag_label
}
}

Expand Down
37 changes: 20 additions & 17 deletions buildScript/utils.gincl
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,35 @@ def startTomcat(remoteHost) {
println ">> Starting Tomcat:.. $cmd ==> $desc"
}

task deployAllWars(dependsOn: loadConfig) << {
task deployAllWars(dependsOn: loadConfig) {
description= 'Deploy all of the built war files to Tomcat. Require ${tomcat_home} property. May include ${remoteHost} as well.'
group = MISC_GROUP

if (!project.hasProperty("tomcat_home")) {
throw ProjectConfigurationException("tomcat_home property is not found.")
}
doLast {
if (!project.hasProperty("tomcat_home")) {
throw ProjectConfigurationException("tomcat_home property is not found.")
}

def remoteHosts = project.hasProperty("remoteHost") ? remoteHost.split(",") : [null]
def remoteHosts = project.hasProperty("remoteHost") ? remoteHost.split(",") : [null]

for ( rhost in remoteHosts ) {
for (rhost in remoteHosts) {

println ">> deploying to host: $rhost"
println ">> deploying to host: $rhost"

// stop tomcat
stopTomcat(rhost)
// stop tomcat
stopTomcat(rhost)

execCmd(rhost, true, ["rm", "-r", "$tomcat_home/temp/ehcache"])
execCmd(rhost, true, ["rm", "-r", "$tomcat_home/temp/ehcache"])

// copy all of the war files
def wars = fileTree(dir:"${project.buildRoot}/libs", include: '*.war')
wars.each {File file ->
copyWar(file, rhost)
}
// copy all of the war files
def wars = fileTree(dir: "${project.buildRoot}/libs", include: '*.war')
wars.each { File file ->
copyWar(file, rhost)
}

// start tomcat
startTomcat(rhost)
// start tomcat
startTomcat(rhost)
}
}
}

Expand Down