cobertura_xml_merger 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +27 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/cobertura_xml_merger.gemspec +23 -0
- data/exe/cobertura_xml_merger +4 -0
- data/lib/cobertura_xml_merger.rb +112 -0
- data/lib/cobertura_xml_merger/version.rb +3 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3dbc6dab79a03768be5cb4d3e81d938c72d5e233
|
4
|
+
data.tar.gz: 666f412066520f8f5fcb6803589755e4315488e8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 21bed2d5c70367eefb2603bd19e1e22b9cf93b117d9c7db2f63bcf04c48ea1b9d6c5bcb9df6c9bc4fa461cc70e44c2474168f07d1d396fa2acdc7d48fdd4d8c5
|
7
|
+
data.tar.gz: fc2a5788dfd4dba5769f26307f48566d9d966cfc2d28edacb78ef4e7eb0a51c179d5ba994d0053f4c9a44522185ed1b4377ebe709394aae9e2f60ee22dd5d3be
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016 Juan Germán Castañeda Echevarría
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# CoberturaXmlMerger
|
2
|
+
|
3
|
+
Merge Cobertura XML reports into a single file.
|
4
|
+
|
5
|
+
## Limitations
|
6
|
+
|
7
|
+
1) It assumes you used the simplecov-cobertura gem to generate the reports which means only one package
|
8
|
+
per report.
|
9
|
+
|
10
|
+
2) It assumes your code is the same, so all reports should have the same number of classes and lines
|
11
|
+
in each class
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
$ gem install cobertura_xml_merger
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
cobertura_xml_merger -o merged_output.xml directory
|
20
|
+
|
21
|
+
## Development
|
22
|
+
|
23
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/juanger/cobertura_xml_merger.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "cobertura_xml_merger"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cobertura_xml_merger/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'cobertura_xml_merger'
|
8
|
+
spec.version = CoberturaXmlMerger::VERSION
|
9
|
+
spec.authors = ["Juan Germán Castañeda Echevarría"]
|
10
|
+
spec.email = ['juanger@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Merge two or more Cobertura XML reports'
|
13
|
+
spec.homepage = 'https://github.com/juanger/cobertura_xml_merger'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test)/}) }
|
16
|
+
spec.bindir = 'exe'
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
21
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
22
|
+
spec.add_dependency 'nokogiri', '~> 1.6'
|
23
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'cobertura_xml_merger/version'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
module CoberturaXmlMerger
|
5
|
+
# Command Line Interface
|
6
|
+
class Cli
|
7
|
+
def self.start
|
8
|
+
require 'optparse'
|
9
|
+
|
10
|
+
options = {}
|
11
|
+
OptionParser.new do |opts|
|
12
|
+
opts.banner = 'Usage: cobertura_xml_merger [options] DIRECTORY'
|
13
|
+
|
14
|
+
opts.on('-v', '--[no-]verbose', 'Run verbosely (default false)') do |v|
|
15
|
+
options[:verbose] = v
|
16
|
+
end
|
17
|
+
|
18
|
+
opts.on('-o',
|
19
|
+
'--output_file [FILE]',
|
20
|
+
'File to write your merged xml (default cobertura_merged.xml)') do |o|
|
21
|
+
options[:output] = o
|
22
|
+
end
|
23
|
+
end.parse!
|
24
|
+
directory = ARGV.first
|
25
|
+
|
26
|
+
Merger.new(directory, options).merge!
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class Merger
|
31
|
+
def initialize(directory = '', verbose: false, output: 'cobertura_merged.xml')
|
32
|
+
@dir = directory
|
33
|
+
@verbose = verbose
|
34
|
+
@output = output
|
35
|
+
end
|
36
|
+
|
37
|
+
def merge!
|
38
|
+
# @logger.info "Merging xml reports in #{@dir}"
|
39
|
+
puts "Merging xml reports in #{@dir}" if @verbose
|
40
|
+
save(merge_files(files))
|
41
|
+
end
|
42
|
+
|
43
|
+
def files
|
44
|
+
return [] unless Dir.exist?(@dir)
|
45
|
+
Dir["#{@dir}/*.xml"]
|
46
|
+
end
|
47
|
+
|
48
|
+
# Merges all the files supplied
|
49
|
+
def merge_files(files)
|
50
|
+
files.reduce(nil) do |merged, file|
|
51
|
+
puts "Merging #{file}" if @verbose
|
52
|
+
merge(merged, file)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Takes two files with xml reports and merges them into a string
|
57
|
+
def merge(xml1, file2)
|
58
|
+
xml2 = File.read(file2)
|
59
|
+
return xml2 unless xml1
|
60
|
+
|
61
|
+
merge_xml(xml1, xml2)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Takes two xml reports as strings and merges them into a new string
|
65
|
+
def merge_xml(string1, string2)
|
66
|
+
xml1 = Nokogiri::XML(string1)
|
67
|
+
xml2 = Nokogiri::XML(string2)
|
68
|
+
|
69
|
+
# Only supports one package
|
70
|
+
package1 = xml1.xpath('//package').first
|
71
|
+
package2 = xml2.xpath('//package').first
|
72
|
+
merged_package = merge_packages(package1, package2)
|
73
|
+
|
74
|
+
xml1.css('coverage packages').first.content = ''
|
75
|
+
merged_package.parent = xml1.css('coverage packages').first
|
76
|
+
xml1.to_s
|
77
|
+
end
|
78
|
+
|
79
|
+
# This method modifies package2 to include package 1 line hits
|
80
|
+
def merge_packages(package1, package2)
|
81
|
+
klasses = {}
|
82
|
+
package1.css('class').each do |klass|
|
83
|
+
lines = {}
|
84
|
+
klass.css('line').each do |line|
|
85
|
+
lines[line['number']] = line['hits'].to_i
|
86
|
+
end
|
87
|
+
klasses[klass['filename']] = lines
|
88
|
+
end
|
89
|
+
|
90
|
+
package2.css('class').each do |klass|
|
91
|
+
klass.css('line').each do |line|
|
92
|
+
lines = klasses[klass['filename']]
|
93
|
+
begin
|
94
|
+
line['hits'] = lines[line['number']] + line['hits'].to_i
|
95
|
+
rescue => e
|
96
|
+
puts "error matching #{klass['filename']} line #{line['number']}" if @verbose
|
97
|
+
puts lines.inspect if @verbose
|
98
|
+
throw e
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
package2
|
104
|
+
end
|
105
|
+
|
106
|
+
def save(xml)
|
107
|
+
File.open(@output, 'w') do |output_file|
|
108
|
+
output_file.puts(xml)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cobertura_xml_merger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Juan Germán Castañeda Echevarría
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- juanger@gmail.com
|
58
|
+
executables:
|
59
|
+
- cobertura_xml_merger
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- cobertura_xml_merger.gemspec
|
71
|
+
- exe/cobertura_xml_merger
|
72
|
+
- lib/cobertura_xml_merger.rb
|
73
|
+
- lib/cobertura_xml_merger/version.rb
|
74
|
+
homepage: https://github.com/juanger/cobertura_xml_merger
|
75
|
+
licenses: []
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.6.2
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Merge two or more Cobertura XML reports
|
97
|
+
test_files: []
|