lately, there was a need to add a flex compilation feature to the Vine Toolkit build system. In the build scripts we're using Groovy as our extension to Ant scripts so I designed some additional logic to automatically choose source files and compile them in a special manner:
- compile only source files with the Vine Toolkit extensions,
- add locale bundles,
- add dependent source paths,
- add external libraries.
I'm presenting this code because not all options were mapped correctly in ant task def, especially the external library path was pretty troublesome :)
Here is the code snippet:
flexAppPath
- path to the flex sources.flexLocalePath
- path to the flex locale bundles.dependentSourcePath
- path to dependent flex sources.flexLibPath
- path to the external swc libraries.
antBuilder.fileset(id: "flexSourcesList", dir: flexAppPath,
includes: "**/*.mxml") {
antBuilder.contains(text: "VineApplication")
if (new File(flexLibPath).exists()) {
antBuilder.fileset(id: "flexLibList", dir: flexLibPath,
includes: "**/*.swc")
}
antBuilder.project.references.flexSourcesList.each {
println "Compiling " + it.name
antBuilder.mxmlc(
file: it) {
antBuilder.'use-network'('true')
antBuilder.'compiler.strict'('true')
antBuilder.'compiler.context-root'('gridsphere')
antBuilder.'compiler.services'(applicationBuild.getBuildAptPath() + '/WEB-INF/services-config.xml')
println "* Using services-config.xml file from: " + applicationBuild.getBuildAptPath() + '/WEB-INF/services-config.xml'
println "** Adding locale source path: " + flexLocalePath + '/{locale}'
antBuilder.'compiler.source-path'(flexLocalePath + '/{locale}')
new File(flexLocalePath).listFiles().each {
if (!it.name.startsWith(".")) {
println "** Adding locale: " + it.name
antBuilder.'compiler.locale'(it.name)
}
}
antBuilder.'compiler.source-path'('path-element': flexAppPath)
println "*** Adding dependency from: " + flexAppPath
usesProjectBuildList.each {
String dependentSourcePath = it + 'flex/src'
antBuilder.'compiler.source-path'('path-element': dependentSourcePath)
println "*** Adding dependency from: " + dependentSourcePath
}
antBuilder.project.references.flexLibList.each {
String libraryPath = it
println "**** Adding external library: " + libraryPath
antBuilder.'compiler.library-path'('file': libraryPath, 'append': 'true')
}
}
I especially like this code for listing files:
new File(flexLocalePath).listFiles().each {
if (!it.name.startsWith(".")) {
println "** Adding locale: " + it.name
antBuilder.'compiler.locale'(it.name)
}
}
This is the pure power of Groovy especially in conjunction with ant features.
Enjoy :)
No comments:
Post a Comment