addon/buildr/emma.rb in vic-buildr-1.3.3 vs addon/buildr/emma.rb in vic-buildr-1.3.4
- old
+ new
@@ -12,226 +12,11 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
-require 'buildr/java'
-
-
-module Buildr
-
- # Provides the <code>emma:html</code> and <code>emma:xml</code> tasks.
- # Require explicitly using <code>require "buildr/emma"</code>.
- #
- # You can generate emma reports for a single project
- # using the project name as prefix:
- #
- # project_name:emma:html
- #
- # You can also specify which classes to include/exclude from instrumentation by
- # passing a class name regexp to the <code>emma.include</code> or
- # <code>emma.exclude</code> methods.
- #
- # define 'someModule' do
- # emma.include 'some.package.*'
- # emma.exclude 'some.foo.util.SimpleUtil'
- # end
- module Emma
-
- class << self
-
- REQUIRES = ['emma:emma_ant:jar:2.0.5312', 'emma:emma:jar:2.0.5312'] unless const_defined?('REQUIRES')
-
- def requires()
- @requires ||= Buildr.artifacts(REQUIRES).each(&:invoke).map(&:to_s)
- end
-
- def report_to format=nil
- File.expand_path('reports/emma')
- end
-
- def data_file()
- File.join(report_to, 'coverage.es')
- end
-
- def ant
- Buildr.ant 'emma' do |ant|
- ant.taskdef :classpath=>requires.join(File::PATH_SEPARATOR), :resource=>'emma_ant.properties'
- ant.emma :verbosity=>(Buildr.application.options.trace ? 'verbose' : 'warning') do
- yield ant
- end
- end
- end
- end
-
- class EmmaConfig # :nodoc:
-
- def initialize(project)
- @project = project
- end
-
- attr_reader :project
- private :project
-
- attr_writer :metadata_file, :coverage_file, :instrumented_dir, :report_dir
-
- def coverage_file
- @coverage_file ||= File.join(report_dir, 'coverage.ec')
- end
-
- def metadata_file
- @metadata_file ||= File.join(report_dir, 'coverage.em')
- end
-
- def instrumented_dir
- @instrumented_dir ||= project.path_to(:target, :instrumented, :classes)
- end
-
- def report_dir
- @report_dir ||= project.path_to(:reports, :emma)
- end
-
- def report_to format
- report_dir
- end
-
- # :call-seq:
- # project.emma.include(*classPatterns)
- #
- def include(*classPatterns)
- includes.push(*classPatterns)
- self
- end
-
- def includes
- @includeClasses ||= []
- end
-
- # :call-seq:
- # project.emma.exclude(*classPatterns)
- #
- def exclude(*classPatterns)
- excludes.push(*classPatterns)
- self
- end
-
- def excludes
- @excludeClasses ||= []
- end
-
- def sources
- project.compile.sources
- end
- end
-
- module EmmaExtension # :nodoc:
- include Buildr::Extension
-
- def emma
- @emma_config ||= EmmaConfig.new(self)
- end
-
- after_define do |project|
- emma = project.emma
-
- namespace 'emma' do
- 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(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
- end
-
- task 'instrument' => instrumented
-
- # We now have two target directories with bytecode.
- project.test.dependencies.unshift emma.instrumented_dir
- project.test.with Emma.requires
- project.test.options[:properties]["emma.coverage.out.file"] = emma.coverage_file
-
- [:xml, :html].each do |format|
- task format => ['instrument', 'test'] do
- missing_required_files = [emma.metadata_file, emma.coverage_file].reject { |f| File.exist?(f) }
- if missing_required_files.empty?
- info "Creating test coverage reports in #{emma.report_dir}"
- mkdir_p emma.report_dir, :verbose=>false
- Emma.ant do |ant|
- ant.report do
- ant.infileset :file=>emma.metadata_file
- ant.infileset :file=>emma.coverage_file
- ant.send format, :outfile=>File.join(emma.report_to(format),"coverage.#{format}")
- ant.sourcepath do
- emma.sources.flatten.each do |src|
- ant.dirset(:dir=>src.to_s) if File.exist?(src.to_s)
- end
- end
- end
- end
- else
- info "No test coverage report for #{project}. Missing: #{missing_required_files.join(', ')}"
- end
- end
- end
- end
- end
-
- project.clean do
- rm_rf [emma.report_dir, emma.coverage_file, emma.metadata_file, emma.instrumented_dir], :verbose=>false
- end
-
- end
-
- end
-
- class Buildr::Project
- include EmmaExtension
- end
-
- namespace "emma" do
-
- Project.local_task('instrument') { |name| "Instrumenting #{name}" }
-
- [:xml, :html].each do |format|
- desc "Run the test cases and produce code coverage reports in #{format}"
- task format => ['instrument', 'test'] do
- info "Creating test coverage reports in #{format}"
- mkdir_p report_to(format), :verbose=>false
- Emma.ant do |ant|
- ant.merge :outfile=>data_file do
- Buildr.projects.each do |project|
- ant.fileset :file=>project.emma.metadata_file
- ant.fileset :file=>project.emma.coverage_file
- end
- end
- ant.report do
- ant.infileset :file=>data_file
- ant.send format, :outfile=>File.join(report_to(format), "coverage.#{format}")
- ant.sourcepath do
- Buildr.projects.map(&:emma).map(&:sources).flatten.map(&:to_s).each do |src|
- ant.dirset :dir=>src if File.exist?(src)
- end
- end
- end
- end
- end
- end
-
- task :clean do
- rm_rf [report_to, data_file], :verbose=>false
- end
- end
-
- task :clean do
- task('emma:clean').invoke if Dir.pwd == Rake.application.original_dir
- end
-
- end
+if Buildr::VERSION < '1.5'
+ Buildr.application.deprecated "'buildr/emma', use 'buildr/java/emma' instead"
+ require 'buildr/java/emma'
+else
+ raise "#{__FILE__} should be removed since its use is deprecated since version 1.3.4"
end