emma 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in emma.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2012 Jari Bakken.
2
+ See http://emma.sourceforge.net/license.html for the license info for the bundled EMMA jar.
3
+
4
+ MIT License
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Emma
2
+
3
+ Ruby gem wrapping the [EMMA library](http://emma.sourceforge.net/).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'emma'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install emma
18
+
19
+ ## Usage
20
+
21
+ TODO.
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,65 @@
1
+ require 'emma'
2
+ require 'optparse'
3
+ require 'tempfile'
4
+ require 'tmpdir'
5
+
6
+ def unpack_war(path)
7
+ destination = Dir.mktmpdir("emma-unzip")
8
+
9
+ Dir.chdir destination do
10
+ proc = ChildProcess.new("jar", "xf", path)
11
+ proc.io.inherit!
12
+
13
+ proc.start
14
+ proc.wait
15
+
16
+ raise "unpacking failed" if proc.exit_code != 0
17
+ end
18
+
19
+ destination
20
+ end
21
+
22
+ def pack_war(dir, dest)
23
+ proc = ChildProcess.new("jar", 'cf', dest, '-C', dir, '.')
24
+ proc.io.inherit!
25
+
26
+ proc.start
27
+ proc.wait
28
+
29
+ raise "packing failed" if proc.exit_code != 0
30
+ end
31
+
32
+ options = {}
33
+
34
+ parser = OptionParser.new do |opts|
35
+ opts.on("-f", "--filter FILTER") { |filter| options[:filter] = filter }
36
+ end
37
+
38
+ parser.parse!(ARGV)
39
+
40
+ war = ARGV.shift or abort(parser.to_s)
41
+ basename = File.basename war, '.war'
42
+ metadata = "#{basename}.em"
43
+ coverage = "#{basename}.ec"
44
+ instrumented = "#{basename}-instrumented.war"
45
+
46
+ emma = Emma::Control.new :metadata_file => metadata, :coverage_file => coverage
47
+
48
+ print "unpacking #{war}..."
49
+ exploded = unpack_war File.expand_path(war)
50
+ puts 'done.'
51
+
52
+ begin
53
+ puts "instrumenting #{war} [em=#{metadata}, ec=#{coverage}] with EMMA..."
54
+
55
+ jars = Dir[File.join(exploded, '**/*.jar')]
56
+ emma.instrument jars, :mode => :overwrite, :filter => options[:filter]
57
+ puts "done."
58
+
59
+ print "repacking to #{instrumented}..."
60
+ pack_war(exploded, instrumented)
61
+ puts "done."
62
+ ensure
63
+ FileUtils.rm_rf exploded
64
+ end
65
+
data/emma.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/emma/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Jari Bakken"]
6
+ gem.email = ["jari.bakken@gmail.com"]
7
+ gem.description = %q{CLI wrapper for the Emma Java library http://emma.sourceforge.net/}
8
+ gem.summary = %q{CLI wrapper for the Emma Java library http://emma.sourceforge.net/}
9
+ gem.homepage = "http://github.com/jarib/emma-rb"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "emma"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Emma::VERSION
17
+
18
+ gem.add_dependency "childprocess"
19
+ end
data/lib/emma.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "emma/version"
2
+ require 'childprocess'
3
+ require 'tempfile'
4
+ require 'emma/control'
5
+
6
+ module Emma
7
+ class Error < StandardError
8
+ end
9
+ end
@@ -0,0 +1,53 @@
1
+ module Emma
2
+ class Control
3
+ attr_accessor :debug, :em, :ec
4
+
5
+ JAR = File.expand_path("../emma.jar", __FILE__)
6
+
7
+ def initialize(opts = {})
8
+ @em = opts[:metadata_file] || Tempfile.new("emma-metadata").path
9
+ @ec = opts[:coverage_file] || Tempfile.new("emma-coverage").path
10
+ end
11
+
12
+ def get
13
+ emma "ctl", "-c" "coverage.get,#{@ec},true,true"
14
+ end
15
+
16
+ def report(opts = {})
17
+ format = opts[:format] || 'xml'
18
+
19
+ emma "report", "-r", format, "-input", @em, "-input", @ec
20
+ end
21
+
22
+ def reset
23
+ emma "ctl", "-c", "coverage.reset"
24
+ end
25
+
26
+ def instrument(paths, opts = {})
27
+ mode = opts[:mode] || 'fullcopy'
28
+ filter = opts[:filter] || '*'
29
+
30
+ inputs = paths.map { |path| ['-instrpath', path] }.flatten
31
+
32
+ emma 'instr',
33
+ '-outmode', mode,
34
+ '-outfile', @em,
35
+ '-merge', 'yes',
36
+ '-filter', filter,
37
+ *inputs
38
+ end
39
+
40
+ def emma(*args)
41
+ puts "emma #{args.join ' '}" if debug
42
+ proc = ChildProcess.new("java", "-cp", JAR, 'emma', *args.map { |e| e.to_s })
43
+ proc.io.inherit!
44
+
45
+ proc.start
46
+ proc.wait
47
+
48
+ if proc.exit_code != 0
49
+ raise Error, "emma failed with exit code"
50
+ end
51
+ end
52
+ end
53
+ end
data/lib/emma/emma.jar ADDED
Binary file
@@ -0,0 +1,3 @@
1
+ module Emma
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: emma
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Jari Bakken
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-02-07 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: childprocess
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: CLI wrapper for the Emma Java library http://emma.sourceforge.net/
35
+ email:
36
+ - jari.bakken@gmail.com
37
+ executables:
38
+ - emma-instrument-war
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - LICENSE
47
+ - README.md
48
+ - Rakefile
49
+ - bin/emma-instrument-war
50
+ - emma.gemspec
51
+ - lib/emma.rb
52
+ - lib/emma/control.rb
53
+ - lib/emma/emma.jar
54
+ - lib/emma/version.rb
55
+ homepage: http://github.com/jarib/emma-rb
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options: []
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ requirements: []
82
+
83
+ rubyforge_project:
84
+ rubygems_version: 1.8.15
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: CLI wrapper for the Emma Java library http://emma.sourceforge.net/
88
+ test_files: []
89
+
90
+ has_rdoc: