We Recommend

Beginning XML Beginning XML
The perfect resource for beginning XML programmers, this guidebook shows you what XML is, how to use it, and what technologies surround it. The authors build on the strengths of previous editions while covering the latest changes in the XML landscape such as XQuery, RSS and Atom, and Ajax.


Posted By

cfrias on 11/07/07


Tagged

ant junit maven


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

mykelalvis


Maven 2 Ant Task - MavenDependencyTest Script


Published in: Groovy 


  1. // no jfreechart imports required (we'll find them programmatically)
  2. import groovy.swing.SwingBuilder
  3. import static javax.swing.WindowConstants.EXIT_ON_CLOSE
  4.  
  5. class MavenDependencyTest extends GroovyTestCase {
  6.  
  7. void testSomething() {
  8. def classLoader = Thread.currentThread().contextClassLoader
  9.  
  10. // load jars and add to classpath
  11. def maven = MavenDependency.using(classLoader)
  12. maven.require(groupId:'jfree', artifactId:'jfreechart', version:'1.0.5')
  13. maven.require(groupId:'jfree', artifactId:'jcommon', version:'1.0.9')
  14.  
  15. // define used classes/instances programmatically
  16. def factoryClass = classLoader.loadClass('org.jfree.chart.ChartFactory')
  17. def orientationClass = classLoader.loadClass('org.jfree.chart.plot.PlotOrientation')
  18. def dataset = classLoader.loadClass('org.jfree.data.category.DefaultCategoryDataset').newInstance()
  19.  
  20. // normal code below here
  21. dataset.addValue 150, "no.1", "Jan"
  22. dataset.addValue 210, "no.1", "Feb"
  23. dataset.addValue 390, "no.1", "Mar"
  24. dataset.addValue 300, "no.2", "Jan"
  25. dataset.addValue 400, "no.2", "Feb"
  26. dataset.addValue 200, "no.2", "Mar"
  27.  
  28. def labels = ["Bugs", "Month", "Count"]
  29. def options = [true, true, true]
  30. def chart = factoryClass.createLineChart(*labels, dataset,
  31. orientationClass.VERTICAL, *options)
  32. def swing = new SwingBuilder()
  33. def frame = swing.frame(title:'Groovy LineChart',
  34. defaultCloseOperation:EXIT_ON_CLOSE) {
  35. panel(id:'canvas') { rigidArea(width:400, height:400) }
  36. }
  37. frame.pack()
  38. frame.show()
  39. chart.draw(swing.canvas.graphics, swing.canvas.bounds)
  40. }
  41.  
  42. }

Report this snippet 

You need to login to post a comment.