lib/buildr/cobertura.rb in buildr-1.1.3 vs lib/buildr/cobertura.rb in buildr-1.2.0
- old
+ new
@@ -1,27 +1,25 @@
module Buildr
+
+ # Addes the <code>cobertura:html</code> and <code>cobertura:xml</code> tasks.
+ # Require explicitly using <code>require "buildr/cobertura"</code>.
module Cobertura
class << self
REQUIRES = ["cobertura:cobertura:jar:1.8", "log4j:log4j:jar:1.2.9", "asm:asm:jar:2.2.1", "oro:oro:jar:2.0.8"]
def requires()
@requires ||= Buildr.artifacts(REQUIRES).each(&:invoke).map(&:to_s)
end
- def ant_project()
- @ant_project ||= Buildr::Ant.executable("cobertura") { |ant|
- ant.taskdef(:classpath=>requires.join(File::PATH_SEPARATOR), :resource=>"tasks.properties" ) }
- end
-
def report_to(file = nil)
- File.expand_path(File.join(*["cobertura", file.to_s].compact))
+ File.expand_path(File.join(*["reports/cobertura", file.to_s].compact))
end
def data_file()
- File.expand_path("cobertura.ser")
+ File.expand_path("reports/cobertura.ser")
end
end
namespace "cobertura" do
@@ -30,42 +28,51 @@
Buildr.projects.each do |project|
unless project.compile.sources.empty?
# Instrumented bytecode goes in a different directory. This task creates before running the test
# cases and monitors for changes in the generate bytecode.
instrumented = project.file(project.path_to(:target, "instrumented")=>project.compile.target) do |task|
- ant_project.send "cobertura-instrument", :todir=>task.to_s, :datafile=>data_file do
- fileset(:dir=>project.compile.target.to_s) { include :name=>"**/*.class" }
+ Buildr.ant "cobertura" do |ant|
+ ant.taskdef :classpath=>requires.join(File::PATH_SEPARATOR), :resource=>"tasks.properties"
+ ant.send "cobertura-instrument", :todir=>task.to_s, :datafile=>data_file do
+ ant.fileset(:dir=>project.compile.target.to_s) { ant.include :name=>"**/*.class" }
+ end
end
touch task.to_s, :verbose=>false
end
# We now have two target directories with bytecode. It would make sense to remove compile.target
# and add instrumented instead, but apparently Cobertura only creates some of the classes, so
# we need both directories and instrumented must come first.
- project.test.junit.classpath.unshift file(instrumented)
- project.test.junit.with requires
+ project.test.classpath.unshift file(instrumented)
+ project.test.with requires
project.clean { rm_rf instrumented.to_s, :verbose=>false }
end
end
end
desc "Run the test cases and produce code coverage reports in #{report_to(:html)}"
- task "html"=>["instrument", "build"] do
+ task "html"=>["instrument", "test:all"] do
puts "Creating test coverage reports in #{report_to(:html)}"
projects = Buildr.projects
- ant_project.send "cobertura-report", :destdir=>report_to(:html), :format=>"html", :datafile=>data_file do
- projects.map(&:compile).map(&:sources).flatten.each do |src|
- fileset(:dir=>src.to_s) { include :name=>"**/*.java" } if File.exist?(src.to_s)
+ Buildr.ant "cobertura" do |ant|
+ ant.taskdef :classpath=>requires.join(File::PATH_SEPARATOR), :resource=>"tasks.properties"
+ ant.send "cobertura-report", :destdir=>report_to(:html), :format=>"html", :datafile=>data_file do
+ ant.projects.map(&:compile).map(&:sources).flatten.each do |src|
+ ant.fileset(:dir=>src.to_s) { ant.include :name=>"**/*.java" } if File.exist?(src.to_s)
+ end
end
end
end
desc "Run the test cases and produce code coverage reports in #{report_to(:xml)}"
- task "xml"=>["instrument", "build"] do
+ task "xml"=>["instrument", "test:all"] do
puts "Creating test coverage reports in #{report_to(:xml)}"
projects = Buildr.projects
- ant_project.send "cobertura-report", :destdir=>report_to(:xml), :format=>"xml", :datafile=>data_file do
- projects.map(&:compile).map(&:sources).flatten.each do |src|
- fileset :dir=>src.to_s if File.exist?(src.to_s)
+ Buildr.ant "cobertura" do |ant|
+ ant.taskdef :classpath=>requires.join(File::PATH_SEPARATOR), :resource=>"tasks.properties"
+ ant.send "cobertura-report", :destdir=>report_to(:xml), :format=>"xml", :datafile=>data_file do
+ ant.projects.map(&:compile).map(&:sources).flatten.each do |src|
+ ant.fileset :dir=>src.to_s if File.exist?(src.to_s)
+ end
end
end
end
task "clean" do