Author: lacton
Date: Sun Sep 28 06:38:07 2008
New Revision: 699816
URL: http://svn.apache.org/viewvc?rev=699816&view=rev
Log:
Cobertura and Emma instrumentation should handle gracefully a project with no
source file
Modified:
incubator/buildr/trunk/addon/buildr/cobertura.rb
incubator/buildr/trunk/addon/buildr/emma.rb
incubator/buildr/trunk/spec/addon/test_coverage_spec.rb
Modified: incubator/buildr/trunk/addon/buildr/cobertura.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/addon/buildr/cobertura.rb?rev=699816&r1=699815&r2=699816&view=diff
==============================================================================
--- incubator/buildr/trunk/addon/buildr/cobertura.rb (original)
+++ incubator/buildr/trunk/addon/buildr/cobertura.rb Sun Sep 28 06:38:07 2008
@@ -127,36 +127,39 @@
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 =>
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
+ unless project.compile.target.nil?
+ 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
+
+ task 'instrument' => instrumented
end
-
- task 'instrument' => instrumented
+
[:xml, :html].each do |format|
task format => ['instrument', 'test'] do
info "Creating test coverage reports in
#{cobertura.report_to(format)}"
Modified: incubator/buildr/trunk/addon/buildr/emma.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/addon/buildr/emma.rb?rev=699816&r1=699815&r2=699816&view=diff
==============================================================================
--- incubator/buildr/trunk/addon/buildr/emma.rb (original)
+++ incubator/buildr/trunk/addon/buildr/emma.rb Sun Sep 28 06:38:07 2008
@@ -136,20 +136,22 @@
namespace 'emma' 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(emma.instrumented_dir =>
project.compile.target) do |task|
- unless project.compile.sources.empty?
- info "Instrumenting classes with emma metadata file
#{emma.metadata_file}"
- Emma.ant do |ant|
- ant.instr :instrpath=>project.compile.target.to_s,
:destdir=>task.to_s, :metadatafile=>emma.metadata_file do
- ant.filter :includes=>emma.includes.join(', ') unless
emma.includes.empty?
- ant.filter :excludes=>emma.excludes.join(', ') unless
emma.excludes.empty?
+ unless project.compile.target.nil?
+ instrumented = project.file(emma.instrumented_dir =>
project.compile.target) do |task|
+ unless project.compile.sources.empty?
+ info "Instrumenting classes with emma metadata file
#{emma.metadata_file}"
+ Emma.ant do |ant|
+ ant.instr :instrpath=>project.compile.target.to_s,
:destdir=>task.to_s, :metadatafile=>emma.metadata_file do
+ ant.filter :includes=>emma.includes.join(', ') unless
emma.includes.empty?
+ ant.filter :excludes=>emma.excludes.join(', ') unless
emma.excludes.empty?
+ end
end
+ touch task.to_s, :verbose=>false
end
- touch task.to_s, :verbose=>false
end
+
+ task 'instrument' => instrumented
end
-
- task 'instrument' => instrumented
[:xml, :html].each do |format|
task format => ['instrument', 'test'] do
Modified: incubator/buildr/trunk/spec/addon/test_coverage_spec.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/addon/test_coverage_spec.rb?rev=699816&r1=699815&r2=699816&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/addon/test_coverage_spec.rb (original)
+++ incubator/buildr/trunk/spec/addon/test_coverage_spec.rb Sun Sep 28 06:38:07
2008
@@ -139,6 +139,12 @@
task("foo:#{toolname}:instrument").invoke
instrumented_dir.timestamp.should be_close(a_long_time_ago, 2)
end
+
+ it 'should not raise an error if project has no source files' do
+ rm 'src/main/java/Foo.java'
+ define('foo')
+ lambda { task("foo:#{toolname}:instrument").invoke }.should_not
raise_error(RuntimeError)
+ end
end
describe 'testing classpath' do