addon/buildr/cobertura.rb in vic-buildr-1.3.1 vs addon/buildr/cobertura.rb in vic-buildr-1.3.3

- old
+ new

@@ -40,11 +40,11 @@ module Cobertura class << self REQUIRES = ["net.sourceforge.cobertura:cobertura:jar:1.9", "log4j:log4j:jar:1.2.9", - "asm:asm:jar:2.2.1", "asm:asm-tree:jar:2.2.1", "oro:oro:jar:2.0.8"] + "asm:asm:jar:2.2.1", "asm:asm-tree:jar:2.2.1", "oro:oro:jar:2.0.8"] unless const_defined?('REQUIRES') def requires() @requires ||= Buildr.artifacts(REQUIRES).each(&:invoke).map(&:to_s) end @@ -123,66 +123,69 @@ after_define do |project| cobertura = project.cobertura namespace 'cobertura' do - # 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(cobertura.instrumented_dir => file(project.compile.target)) do |task| - mkdir_p task.to_s, :verbose => false - unless project.compile.sources.empty? - puts "Instrumenting classes with cobertura data file #{cobertura.data_file}" - Buildr.ant "cobertura" do |ant| - ant.taskdef :classpath=>Cobertura.requires.join(File::PATH_SEPARATOR), :resource=>"tasks.properties" - ant.send "cobertura-instrument", :todir=>task.to_s, :datafile=>cobertura.data_file do - includes, excludes = cobertura.includes, cobertura.excludes - - classes_dir = project.compile.target.to_s - if includes.empty? && excludes.empty? - ant.fileset :dir => classes_dir do - ant.include :name => "**/*.class" - end - else - includes = [//] if includes.empty? - Dir.glob(File.join(classes_dir, "**/*.class")) do |cls| - cls_name = cls.gsub(/#{classes_dir}\/?|\.class$/, '').gsub('/', '.') - if includes.any? { |p| p === cls_name } && !excludes.any? { |p| p === cls_name } - ant.fileset :file => cls + unless project.compile.target.nil? + # 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(cobertura.instrumented_dir => project.compile.target) do |task| + mkdir_p task.to_s, :verbose => false + unless project.compile.sources.empty? + info "Instrumenting classes with cobertura data file #{cobertura.data_file}" + Buildr.ant "cobertura" do |ant| + ant.taskdef :classpath=>Cobertura.requires.join(File::PATH_SEPARATOR), :resource=>"tasks.properties" + ant.send "cobertura-instrument", :todir=>task.to_s, :datafile=>cobertura.data_file do + includes, excludes = cobertura.includes, cobertura.excludes + + classes_dir = project.compile.target.to_s + if includes.empty? && excludes.empty? + ant.fileset :dir => classes_dir do + ant.include :name => "**/*.class" end + else + includes = [//] if includes.empty? + Dir.glob(File.join(classes_dir, "**/*.class")) do |cls| + cls_name = cls.gsub(/#{classes_dir}\/?|\.class$/, '').gsub('/', '.') + if includes.any? { |p| p === cls_name } && !excludes.any? { |p| p === cls_name } + ant.fileset :file => cls + end + end end end end end + touch task.to_s, :verbose=>false end - touch task.to_s, :verbose=>false - end - - task 'instrument' => instrumented - [:xml, :html].each do |format| - task format => ['instrument', 'test'] do - puts "Creating test coverage reports in #{cobertura.report_to(format)}" - Buildr.ant "cobertura" do |ant| - ant.taskdef :classpath=>Cobertura.requires.join(File::PATH_SEPARATOR), :resource=>"tasks.properties" - ant.send "cobertura-report", :format=>format, - :destdir=>cobertura.report_to(format), :datafile=>cobertura.data_file do - cobertura.sources.flatten.each do |src| - ant.fileset(:dir=>src.to_s) if File.exist?(src.to_s) + + task 'instrument' => instrumented + + # 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.dependencies.unshift cobertura.instrumented_dir + project.test.with Cobertura.requires + project.test.options[:properties]["net.sourceforge.cobertura.datafile"] = cobertura.data_file + + [:xml, :html].each do |format| + task format => ['instrument', 'test'] do + info "Creating test coverage reports in #{cobertura.report_to(format)}" + Buildr.ant "cobertura" do |ant| + ant.taskdef :classpath=>Cobertura.requires.join(File::PATH_SEPARATOR), :resource=>"tasks.properties" + ant.send "cobertura-report", :format=>format, + :destdir=>cobertura.report_to(format), :datafile=>cobertura.data_file do + cobertura.sources.flatten.each do |src| + ant.fileset(:dir=>src.to_s) if File.exist?(src.to_s) + end end end end end end 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.dependencies.unshift cobertura.instrumented_dir - project.test.with Cobertura.requires - project.test.options[:properties]["net.sourceforge.cobertura.datafile"] = cobertura.data_file - project.clean do rm_rf [cobertura.report_to, cobertura.data_file, cobertura.instrumented_dir], :verbose=>false end end @@ -205,10 +208,10 @@ [:xml, :html].each do |format| report_target = report_to(format) desc "Run the test cases and produce code coverage reports in #{report_target}" task format => ["instrument", "test"] do - puts "Creating test coverage reports in #{report_target}" + info "Creating test coverage reports in #{report_target}" Buildr.ant "cobertura" do |ant| ant.taskdef :classpath=>requires.join(File::PATH_SEPARATOR), :resource=>"tasks.properties" ant.send "cobertura-report", :destdir=>report_target, :format=>format, :datafile=>data_file do Buildr.projects.map(&:cobertura).map(&:sources).flatten.each do |src| ant.fileset :dir=>src.to_s if File.exist?(src.to_s)