-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simple Command Line Interface for JaCoCo #525
Conversation
@mathjeff Can you please take a look and check whether your scenario is covered by this new PR? What is missing? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey thanks. This looks to me like most of what Android is looking for.
I think the main thing left to do before Android is able to use this is for classname filtering to be supported in the 'instrument' and 'report' goals similarly to what the Maven plugin does. The main reason that this would be good for Android is that it enables filtering out dependencies in a manner that's approximately api-compatible with EMMA, rather than having to move or copy all of the relevant class files into a separate directory.
The usage I imagine would be as in mathjeff@0e0c5ec#diff-eec9564b9926238a12deea932c4d57f6 with "-include" and "-exclude" options that filter on fully qualified classname.
Although it sounds just as reasonable to me for filtering to be part of a separate pull request.
Thanks!
} | ||
|
||
@Test | ||
public void shouldCreateCsvReport_whenXmlOptionIsProvided() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Xml" -> "Csv"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mathjeff Fixed.
*/ | ||
public class Instrument extends Command { | ||
|
||
@Option(name = "-destdir", usage = "directory to write instrumented Java classes to", metaVar = "<dir>", required = true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we remove the 'dir' from '-destdir', possibly calling it '-destpath', to clarify the case where the input files is a .jar file and the value of '-destdir' is a .jar file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mathjeff Correct, -dest
is the way to go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mathjeff Fixed.
command.printHelp(out); | ||
return 0; | ||
} else { | ||
return command.execute(out, err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll want to flush out and err somewhere, probably here; I was surprised that "[INFO] %s classes instrumented to %s.%n" wasn't getting displayed when I tested this. Of course, it's more convenient for Android if the output is empty, although I'm thinking that either we'll add a '-quiet' option to Jacoco or we'll redirect the output within Android.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mathjeff Not sure what the problem here is: in Main.main()
the PrintWriter
s are created with auto-flushing after every line. How do you reproduce this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I was surprised too. The simplest example I have is to ask jacoco to instrument itself:
/workspace/jacoco/org.jacoco.cli (work)$ java -jar target/org.jacoco.cli-0.7.10-SNAPSHOT-nodeps.jar instrument target/org.jacoco.cli-0.7.10-SNAPSHOT.jar -destdir /tmp/dummy.jar
, which doesn't give any output when I run it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marchof actually as far as I can see currently main
does new PrintWriter(System.out)
and JavaDoc says :
Creates a new PrintWriter, without automatic line flushing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mathjeff -quiet
option is now in place.
org.jacoco.cli.test/pom.xml
Outdated
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
--> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mathjeff I tried to directly test the "shaded" version. Unfortunatelly this does not work within the m2e IDE. Should be be removed of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mathjeff Fixed.
@mathjeff Hi, thanks for the detailled review! I will adress the issues you observed. Regarding filtering: I would prefer to handle this in a separate PR as it should then be consistently implemented for the other integrations. Also the core API should be improved for this. |
org.jacoco.build/pom.xml
Outdated
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>1.6.0</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marchof so far our lower bound of Maven version for build of project - is 3.0, which in his turn has Java 5 as lower bound, while exec-maven-plugin version 1.6.0 requires Java 7. This explains failure in Travis where we use JDK 6 to run Maven.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Godin Ok, thanks for the Info! We can execute the documentation as part of the test. Or is that too much of a hack?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marchof why not simply use 1.5.0 version of exec-maven-plugin that requires Java 5?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Godin ✅ Done.
org.jacoco.doc/docroot/index.html
Outdated
@@ -68,6 +68,12 @@ | |||
<td>Ant <i>(all other dependencies included)</i></td> | |||
</tr> | |||
<tr> | |||
<td><span class="el_jar">jacococli.jar</span></td> | |||
<td>no</td> | |||
<td>JaCoCo Ant tasks</td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marchof copy-paste detected 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Godin Thanks, fixed!
org.jacoco.cli/.gitignore
Outdated
@@ -0,0 +1,2 @@ | |||
/target | |||
/bin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marchof I don't think this is needed - we have consolidated .gitignore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Godin Thanks, fixed! (started this branch before we consolidates .gitignore
)
Resulting jacoco-xxx.zip files for different build:
Looks like we have constant overheads which sums up. master -> cli: 475 KB This is primarly due to a new all-in JAR and bigger coverage and test report. Java 5 -> Java 9: 417 KB The reason here is that the JavaDoc grows from 2,8MB to 4,1MB, probably as JavaDoc created with Java 9 comes with new features and bundles JQuery. For Java 9 and cli both effects add-up beyond our current check limit. As this is a pure sanity check I think we can safely lift the upper limit a bit. |
Hey thanks marchof@ for spending the time on this. Based on reading the code and trying out the resultant jar, this looks good to me. I'll leave the final approval/disapproval up to Godin@. Android won't be able to directly use this yet until filtering by classname is implemented in a subsequent pull request, but this pull request looks consistent and reasonable to me. Thanks! |
@mathjeff Thanks for your feedback! |
Otherwise output is not visible on the console.
@Godin Thanks for taking the time to perform such a detailed review! You identified quite a few relevant issues. I hope for every review remark I either fixed the issue or left a comment when I was unsure how to proceed with it. For me the remaining main issue is how the multi value arguments
|
execute("report", "--classfiles", getClassPath()); | ||
|
||
assertOk(); | ||
assertContains("[INFO] Writing report with 14 classes.", out); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marchof as discussed in #525 (comment) - Analyzing 14 classes.
sounds better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<td><a href="agent.html">JaCoCo Manual</a></td> | ||
<td></td> | ||
<td><a href="agent.html">JaCoCo Java agent</a>, <a href="cli.html">JaCoCo Command Line Interface</a></td> | ||
<td>Since version 0.8.0</td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marchof given that version is only about CLI, I think will be better to have separate entries for Agent and CLI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marchof Re multi value arguments: the use case that you described in #525 (comment) doesn't work as is for me:
And I personally was puzzled multiple times by empty output in console after forgetting to provide an argument:
And by an empty report after forgetting to provide exec files:
Hence warned that potentially this might become a source of common mistakes.
For the
So printing to console sounds like a good option. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marchof just few tiny remaining things to address:
- Simple Command Line Interface for JaCoCo #525 (comment)
- Simple Command Line Interface for JaCoCo #525 (comment)
- Simple Command Line Interface for JaCoCo #525 (comment)
and please respond on #525 (comment)
@Godin The |
Review comment by @Godin
@Godin I think I now fixed all issues identified by you. Thx again for the detailed review! |
A feature often asked for is a command line interface for JaCoCo. We have a pull request (#86) since quite some time, unfortunately without any tests and documentation. This is a new approach based on some ideas of #86.
To clearly manage expectations: The scope is about simple use cases only! For complex scenarios we have plugins to all common build systems.
Open Issues
-classfiles
)XmlDocumenation
or remove from test scope