Don't like ads? PRO users don't see any ads ;-)
Guest

Robert

By: a guest on Nov 18th, 2008  |  syntax: Groovy  |  size: 1.81 KB  |  hits: 877  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. includeTargets << gant.targets.Clean
  3.  
  4. def buildDir = 'gant'
  5. def classesDir = "${buildDir}/classes"
  6.  
  7. def sourceDir = "src"
  8. def testSourceDir = "test"
  9. def reportsDir = "reports"
  10.  
  11. def jarsDir = "lib"
  12. def testJarsDir = "${jarsDir}/test"
  13.  
  14. def distributables = "dist"
  15. def distributedJarName = "simple.jar"
  16. def distributedJarPath = "${distributables}/${distributedJarName}"
  17.  
  18. cleanDirectory << ["${buildDir}/**/*", "${distributables}/*"]
  19.  
  20. def jars = Ant.path(id: 'jars') {
  21.         fileset(dir: jarsDir) {
  22.                 include(name: '*.jar')
  23.         }
  24. }
  25.  
  26.  
  27. def source = Ant.path(id: 'source') {
  28.         dirset(dir: classesDir)
  29. }
  30.  
  31. target(initDirs: 'Create all the required directories') {
  32.         def dirs = [buildDir, classesDir, distributables]
  33.         dirs.each() { Ant.mkdir(dir: it) }
  34. }
  35.  
  36. target(compile: 'Build all the binary class files') {
  37.         depends(initDirs)
  38.        
  39.         Ant.javac(srcdir: sourceDir, destdir: classesDir)
  40.         Ant.javac(srcdir: testSourceDir, destdir: classesDir) {
  41.                 classpath() {
  42.                         path(refid: 'jars')
  43.                 }
  44.         }
  45. }
  46.  
  47. target(jar: 'Jar up the code') {
  48.         Ant.jar(basedir: classesDir,
  49.                         destfile: distributedJarPath,
  50.                         excludes: '**/*Test*') {
  51.                 manifest() {
  52.                         attribute(name: 'Main-Class',
  53.                                         value: 'example.Hello')
  54.                 }
  55.         }
  56. }
  57.  
  58. target(test: 'Run the test suite for the code') {
  59.         depends(compile)
  60.        
  61.         Ant.junit(haltonfailure: 'yes') {
  62.                 formatter(type: 'plain')
  63.                
  64.                 classpath() {
  65.                         path(refid: 'jars')
  66.                         path(refid: 'source')
  67.                 }
  68.                
  69.                 batchtest(todir: reportsDir) {
  70.                         fileset(dir: "${classesDir}") {
  71.                                 include(name: "**/*Test*")
  72.                         }
  73.                 }
  74.         }
  75. }
  76.  
  77. target(dist: 'Create release artefacts') {
  78.         depends(test)
  79.         depends(jar)
  80. }
  81.  
  82. target(run: 'Run the distributed jar') {
  83.         depends(dist)
  84.        
  85.         Ant.java(jar: distributedJarPath, fork: 'true')
  86. }
  87.  
  88. target(hello: 'Hello World') {
  89.         println("Hello World")
  90. }
  91.  
  92. setDefaultTarget(dist)