Hi,
So, a little bit of research myself got my understanding clear.
SOURCEFILE will take the whole Java file as one, despite the fact that Java file might have multiple classes in them. CLASS will take each class file individually despite the fact that they can be in the same Java file.
For example, here is an example Shape.java. It defines the main Java class as Shape and there is another sub-class Triangle which extends Shape.
public abstract class Shape {
}
class Triangle extends Shape {
}
My rule configuration he as below.
<rule>
<element>SOURCEFILE</element><!-- Here I change it for SOURCEFILE and CLASS values -->
<limits>
<limit>
<counter>INSTRUCTION</counter>
<value>TOTALCOUNT</value>
<maximum>1</maximum>
</limit>
</limits>
</rule>
Below is the output for SOURCEFILE config.
[WARNING] Rule violated for source file io/codejournal/maven/jacocodemo/Shape.java: instructions total count is 6, but expected maximum is 1
When I run the same thing with CLASS config, the output is for each class separately.
[WARNING] Rule violated for class io.codejournal.maven.jacocodemo.Triangle: instructions total count is 3, but expected maximum is 1
[WARNING] Rule violated for class io.codejournal.maven.jacocodemo.Shape: instructions total count is 3, but expected maximum is 1
Got it perfectly.
Thanks,
Code Journal