malinskiy / danger-jacoco Goto Github PK
View Code? Open in Web Editor NEWdanger plugin to check against jacoco xml reports
License: MIT License
danger plugin to check against jacoco xml reports
License: MIT License
Hello,
Thanks for this plugin, i'm encountering this issue when using the plugin in my android app.
[!] The exception involves the following plugins:
- danger-jacoco
Traceback (most recent call last):
28: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `<main>'
27: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `eval'
26: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/bin/danger:23:in `<main>'
25: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/bin/danger:23:in `load'
24: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/bin/danger:5:in `<top (required)>'
23: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/claide-1.0.2/lib/claide/command.rb:334:in `run'
22: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/commands/pr.rb:63:in `run'
21: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/commands/local_helpers/local_setup.rb:43:in `setup'
20: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/commands/pr.rb:64:in `block in run'
19: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/danger_core/dangerfile.rb:273:in `run'
18: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/danger_core/dangerfile.rb:197:in `parse'
17: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/danger_core/dangerfile.rb:197:in `instance_eval'
16: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/danger_core/dangerfile.rb:200:in `block in parse'
15: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/danger_core/dangerfile.rb:297:in `eval_file'
14: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/danger_core/dangerfile.rb:297:in `eval'
13: from Dangerfile:23:in `eval_file'
12: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-jacoco-0.1.4/lib/jacoco/plugin.rb:52:in `report'
11: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/nokogiri-1.10.3/lib/nokogiri/xml/sax/parser.rb:81:in `parse'
10: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/nokogiri-1.10.3/lib/nokogiri/xml/sax/parser.rb:93:in `parse_io'
9: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/nokogiri-1.10.3/lib/nokogiri/xml/sax/parser.rb:93:in `parse_with'
8: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/nokogiri-1.10.3/lib/nokogiri/xml/sax/document.rb:116:in `start_element_namespace'
7: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-jacoco-0.1.4/lib/jacoco/sax_parser.rb:19:in `start_element'
6: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-jacoco-0.1.4/lib/jacoco/sax_parser.rb:41:in `start_class'
5: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/core_ext/file_list.rb:10:in `include?'
4: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/helpers/array_subclass.rb:19:in `method_missing'
3: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/helpers/array_subclass.rb:49:in `respond_to_method'
2: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/helpers/array_subclass.rb:49:in `each'
1: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/core_ext/file_list.rb:11:in `block in include?'
/Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/core_ext/file_list.rb:11:in `fnmatch': no implicit conversion of nil into String (TypeError)
28: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `<main>'
27: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `eval'
26: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/bin/danger:23:in `<main>'
25: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/bin/danger:23:in `load'
24: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/bin/danger:5:in `<top (required)>'
23: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/claide-1.0.2/lib/claide/command.rb:334:in `run'
22: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/commands/pr.rb:63:in `run'
21: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/commands/local_helpers/local_setup.rb:43:in `setup'
20: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/commands/pr.rb:64:in `block in run'
19: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/danger_core/dangerfile.rb:273:in `run'
18: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/danger_core/dangerfile.rb:197:in `parse'
17: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/danger_core/dangerfile.rb:197:in `instance_eval'
16: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/danger_core/dangerfile.rb:200:in `block in parse'
15: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/danger_core/dangerfile.rb:297:in `eval_file'
14: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/danger_core/dangerfile.rb:297:in `eval'
13: from Dangerfile:23:in `eval_file'
12: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-jacoco-0.1.4/lib/jacoco/plugin.rb:52:in `report'
11: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/nokogiri-1.10.3/lib/nokogiri/xml/sax/parser.rb:81:in `parse'
10: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/nokogiri-1.10.3/lib/nokogiri/xml/sax/parser.rb:93:in `parse_io'
9: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/nokogiri-1.10.3/lib/nokogiri/xml/sax/parser.rb:93:in `parse_with'
8: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/nokogiri-1.10.3/lib/nokogiri/xml/sax/document.rb:116:in `start_element_namespace'
7: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-jacoco-0.1.4/lib/jacoco/sax_parser.rb:19:in `start_element'
6: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-jacoco-0.1.4/lib/jacoco/sax_parser.rb:41:in `start_class'
5: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/core_ext/file_list.rb:10:in `include?'
4: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/helpers/array_subclass.rb:19:in `method_missing'
3: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/helpers/array_subclass.rb:49:in `respond_to_method'
2: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/helpers/array_subclass.rb:49:in `each'
1: from /Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/core_ext/file_list.rb:11:in `block in include?'
/Users/[redacted]/.rvm/gems/ruby-2.6.3/gems/danger-6.0.9/lib/danger/core_ext/file_list.rb:11:in `fnmatch': (Danger::DSLError)
any pointers on how to debug it or figure out what's wrong ?
This plugin is currently only compatible with Java files. It would be very helpful to add support for Kotlin files as well.
This line select only java files:
affected_files.select { |file| file.end_with? '.java' }
it would be nice to select .kt
files too.
And on extract_class
method, it removes the .java
string from filename with the following instruction, so for Kotlin files, it returns an incorrect file name.
file[0, file.length - 5].split(java_path_delimiter)[1]
Hi @Malinskiy .
I failed to launch locally danger-jacoco. Do you know if there is something special todo to launch it ?
I used this :
bundle exec danger local
Gemfile:
...
gem "danger-jacoco", :path => "../danger-jacoco"
...
Error exit:
/Library/Ruby/Gems/2.6.0/gems/danger-8.2.3/lib/danger/danger_core/dangerfile.rb:74:in `method_missing': (Danger::DSLError)
[!] Invalid `Dangerfile` file: undefined local variable or method `jacoco' for #<Danger::Dangerfile:0x00007fd02db4df20>
# from Dangerfile:72
# -------------------------------------------
# # Jacoco
> jacoco.minimum_project_coverage_percentage = 70
After digging deeper i have run :
bundle exec danger pr https://github.com/Citygo-team/Citygo-android/pull/244 --verbose
and the output is :
---------------------------------------------
Error loading the plugin `danger-jacoco-0.1.7`.
LoadError - cannot load such file -- nokogiri/nokogiri
/Library/Ruby/Gems/2.6.0/gems/nokogiri-1.11.7-arm64-darwin/lib/
I am working on macOS Mojave.
I'm trying to debug this plugin with my limited knowledge in Ruby. It works perfectly in a small test project but when I put it in a bigger, multi-module project, somehowminimum_package_coverage_map
doesn't work. This particular line (parser.classes
) always returns empty even though I have modified unit tests. Any idea why?
danger-jacoco/lib/jacoco/plugin.rb
Line 193 in 4b9ebdb
The output is basically just this
### JaCoCO Code Coverage 71.56% :white_check_mark:
| Class | Covered | Meta | Status |
|:---|:---:|:---:|:---:|
I have an Android app which has different modules so I want to detect the code pushed is of which module and then get a report for that module only so that I am not blocking the PR for other module unit tests.
Any help is appreciated
Hello, we have implemented Danger-jacoco on our project but we have an issue with the plugin
The message Class coverage is below minimum. Improve to at least 0%
keep showing on our PRs while we specify that the minimum coverage of classes is 0%.
Here is the full output :
Here is the configuration of jacoco in our Dangerfile :
# Jacoco
jacoco.minimum_project_coverage_percentage = 70
jacoco.minimum_package_coverage_map = {
'com/citygoo/app/data/fixtures/' => 0,
'com/citygoo/app/data/models/domainMappingProtocols/' => 80,
'com/citygoo/app/data/models/entities/' => 0,
'com/citygoo/app/data/modules/exceptions/' => 80,
'com/citygoo/app/data/repositories/' => 80,
'com/citygoo/app/data/utils/' => 0,
'com/citygoo/app/data/vendors/' => 80,
'com/citygoo/app/domain/' => 95,
#Presenter
'com/citygoo/app/presenter/models/' => 0,
'com/citygoo/app/presenter/modules/' => 70,
'com/citygoo/app/presenter/protocols/' => 70,
'com/citygoo/app/presenter/utils/' => 0
}
jacoco.minimum_class_coverage_percentage = 0
jacoco.report(
"app/build/reports/jacoco/jacocoDebugTestReport/jacocoDebugTestReport.xml",
"http://www.google.com",
fail_no_coverage_data_found: false
)
danger-jacoco v0.1.4
jacoco Gradle Plugin 0.8.7
danger 5.13.0
Unhandled NaN for floor
at line 100 in plugin.rb
# It returns a specific class code coverage and an emoji status as well
def report_class(jacoco_class)
report_result = {
covered: 'No coverage data found : -',
status: ':black_joker:',
required_coverage_percentage: 'No coverage data found : -'
}
counter = coverage_counter(jacoco_class)
unless counter.nil?
coverage = (counter.covered.fdiv(counter.covered + counter.missed) * 100).floor
Output
/vendor/ruby/2.7.0/gems/danger-jacoco-0.1.8/lib/jacoco/plugin.rb:100:in `floor': \e[31m (Danger::DSLError)
[!] Invalid `Dangerfile` file: NaN\e[0m
Any idea why it was implemented this way? Let's say I have com/example/File.kt
. It will return a blank string.
danger-jacoco/lib/jacoco/plugin.rb
Line 90 in 4b9ebdb
Since danger-jacoco searches classes in jacoco reports by a filename from git diff
it cannot find nested classes, f.ex:
Code:
package sample;
class A {
class B {}
}
Report:
Class: | Coverage:
sample.A | 100%
sample.A.B | 0%
Git modified files:
sample/A.java
Inner class B
will be ignored
It's even worst for kotlin classes because kotlin allows to put all classes into single file / High-Level functions / package != location / @JvmName
/ @JvmMulticlass
/ etc
Need to rewrite function classes()
(https://github.com/Malinskiy/danger-jacoco/blob/master/lib/jacoco/plugin.rb#L63) to make it able to find all classes inside modified files
For Java it can be just a mask something like class ([\w]+)
, but for kotlin much more effort is needed
I think the project could use more tests, to better explain the program, and also to protect the code.
Hello, I've implemented the plugin for my Android app and its been working well but sometimes I get the following failure
No Coverage data found for {class XYZ}
I noticed that this error happens when an interface is changed
Here is the full output in one case
Where CompositionView
is an interface
Here is the coverage data for CompositionView
Let me know if you need more snippets of data from the XML as it is quite big
<class name="com/wam/android/components/composition/view/CompositionView" sourcefilename="CompositionView.kt"/>
<sourcefile name="CompositeProgressLayoutView.kt">
<line nr="24" mi="3" ci="0" mb="0" cb="0"/>
<line nr="26" mi="4" ci="0" mb="0" cb="0"/>
<line nr="36" mi="6" ci="0" mb="0" cb="0"/>
<line nr="40" mi="6" ci="0" mb="0" cb="0"/>
<line nr="41" mi="10" ci="0" mb="0" cb="0"/>
<line nr="44" mi="6" ci="0" mb="0" cb="0"/>
<line nr="45" mi="6" ci="0" mb="0" cb="0"/>
<line nr="48" mi="9" ci="0" mb="0" cb="0"/>
<line nr="49" mi="3" ci="0" mb="0" cb="0"/>
<line nr="50" mi="3" ci="0" mb="0" cb="0"/>
<line nr="51" mi="3" ci="0" mb="0" cb="0"/>
<line nr="52" mi="3" ci="0" mb="0" cb="0"/>
<line nr="53" mi="7" ci="0" mb="0" cb="0"/>
<line nr="54" mi="11" ci="0" mb="0" cb="0"/>
<line nr="55" mi="5" ci="0" mb="0" cb="0"/>
<line nr="56" mi="5" ci="0" mb="0" cb="0"/>
<line nr="57" mi="1" ci="0" mb="0" cb="0"/>
<line nr="58" mi="4" ci="0" mb="0" cb="0"/>
<line nr="59" mi="1" ci="0" mb="0" cb="0"/>
<line nr="60" mi="7" ci="0" mb="0" cb="0"/>
<line nr="61" mi="4" ci="0" mb="0" cb="0"/>
<line nr="62" mi="1" ci="0" mb="0" cb="0"/>
<line nr="63" mi="1" ci="0" mb="0" cb="0"/>
<line nr="66" mi="4" ci="0" mb="0" cb="0"/>
<line nr="67" mi="2" ci="0" mb="0" cb="0"/>
<line nr="68" mi="1" ci="0" mb="0" cb="0"/>
<line nr="71" mi="6" ci="0" mb="0" cb="0"/>
<line nr="72" mi="4" ci="0" mb="0" cb="0"/>
<line nr="73" mi="4" ci="0" mb="0" cb="0"/>
<line nr="74" mi="1" ci="0" mb="0" cb="0"/>
<line nr="77" mi="20" ci="0" mb="0" cb="0"/>
<line nr="78" mi="1" ci="0" mb="0" cb="0"/>
<line nr="81" mi="17" ci="0" mb="0" cb="0"/>
<line nr="82" mi="11" ci="0" mb="0" cb="0"/>
<line nr="83" mi="1" ci="0" mb="0" cb="0"/>
<line nr="86" mi="8" ci="0" mb="0" cb="0"/>
<line nr="90" mi="3" ci="0" mb="0" cb="0"/>
<line nr="94" mi="13" ci="0" mb="0" cb="0"/>
<line nr="95" mi="3" ci="0" mb="0" cb="0"/>
<line nr="96" mi="3" ci="0" mb="0" cb="0"/>
<line nr="97" mi="4" ci="0" mb="0" cb="0"/>
<line nr="98" mi="6" ci="0" mb="0" cb="0"/>
<line nr="99" mi="1" ci="0" mb="0" cb="0"/>
<line nr="101" mi="13" ci="0" mb="0" cb="0"/>
<line nr="102" mi="3" ci="0" mb="0" cb="0"/>
<line nr="103" mi="3" ci="0" mb="0" cb="0"/>
<line nr="104" mi="3" ci="0" mb="0" cb="0"/>
<line nr="105" mi="4" ci="0" mb="0" cb="0"/>
<line nr="106" mi="1" ci="0" mb="0" cb="0"/>
<line nr="107" mi="1" ci="0" mb="0" cb="0"/>
<line nr="114" mi="8" ci="0" mb="0" cb="0"/>
<line nr="140" mi="1" ci="0" mb="0" cb="0"/>
<counter type="INSTRUCTION" missed="274" covered="0"/>
<counter type="LINE" missed="52" covered="0"/>
<counter type="COMPLEXITY" missed="12" covered="0"/>
<counter type="METHOD" missed="12" covered="0"/>
<counter type="CLASS" missed="1" covered="0"/>
</sourcefile>
<sourcefile name="CompositionView.kt"/>
<counter type="INSTRUCTION" missed="274" covered="0"/>
<counter type="LINE" missed="52" covered="0"/>
<counter type="COMPLEXITY" missed="12" covered="0"/>
<counter type="METHOD" missed="12" covered="0"/>
<counter type="CLASS" missed="1" covered="0"/>
jacoco.minimum_project_coverage_percentage = 0
jacoco.minimum_class_coverage_percentage = 0
jacoco.report(Dir.glob("**/reports/jacoco/testDebugUnitTestCoverage/testDebugUnitTestCoverage.xml").first)
danger-jacoco v0.1.4
jacoco Gradle Plugin 0.8.3
danger 5.13.0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.