Skip to content

Commit b5cf507

Browse files
committed
Add jacoco method filter.
1 parent bf3ceca commit b5cf507

File tree

6 files changed

+562
-32
lines changed

6 files changed

+562
-32
lines changed

.sbtrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ alias testIT=; testOnly *IntegrationTests
2727

2828
# Run all tests
2929
alias testAll=; testOnly *
30+
31+
# Jacoco Aliases
32+
alias jacoco=; jacocoOn; +clean; +test; jacocoReportAll; jacocoOff
33+
alias jacocoOff=; set every jacocoPluginEnabled := false
34+
alias jacocoOn=; set every jacocoPluginEnabled := true

build.sbt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
import Dependencies._
18-
import com.github.sbt.jacoco.report.JacocoReportSettings
1918

2019
lazy val scala211 = "2.11.12"
2120
lazy val scala212 = "2.12.18"
@@ -29,12 +28,6 @@ ThisBuild / scalaVersion := scala212
2928

3029
ThisBuild / versionScheme := Some("early-semver")
3130

32-
lazy val commonJacocoReportSettings: JacocoReportSettings = JacocoReportSettings(
33-
formats = Seq(JacocoReportFormats.HTML, JacocoReportFormats.XML)
34-
)
35-
36-
lazy val commonJacocoExcludes: Seq[String] = Seq()
37-
3831
lazy val balta = (project in file("balta"))
3932
.settings(
4033
name := "balta",
@@ -44,6 +37,5 @@ lazy val balta = (project in file("balta"))
4437
),
4538
crossScalaVersions := supportedScalaVersions,
4639
libraryDependencies ++= libDependencies,
47-
jacocoReportSettings := commonJacocoReportSettings.withTitle(s"balta - scala:${scalaVersion.value}"),
48-
jacocoExcludes := commonJacocoExcludes
4940
)
41+
.enablePlugins(FilteredJacocoAgentPlugin)

jmf-rules.txt

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# jacoco-method-filter — Default Rules & HowTo (Scala)
2+
# [jmf:1.0.0]
3+
#
4+
# This file defines which methods should be annotated as *Generated so JaCoCo ignores them.
5+
# One rule per line.
6+
#
7+
# ─────────────────────────────────────────────────────────────────────────────
8+
# HOW TO USE (quick)
9+
# 1) Replace YOUR.PACKAGE.ROOT with your project’s package root (e.g., com.example.app).
10+
# 2) Start with the CONSERVATIVE section only.
11+
# 3) If clean, enable STANDARD. Use AGGRESSIVE only inside DTO/auto‑generated packages.
12+
# 4) Keep rules narrow (by package), prefer flags (synthetic/bridge) for compiler artifacts,
13+
# and add `id:` labels so logs are easy to read.
14+
#
15+
# ─────────────────────────────────────────────────────────────────────────────
16+
# ALLOWED SYNTAX (cheat sheet)
17+
#
18+
# General form:
19+
# <FQCN_glob>#<method_glob>(<descriptor_glob>) [FLAGS and PREDICATES...]
20+
#
21+
# FQCN_glob (dot form; $ allowed for inner classes):
22+
# Examples: *.model.*, com.example.*, *
23+
#
24+
# method_glob (glob on method name):
25+
# Examples: copy | $anonfun$* | get* | *_$eq
26+
#
27+
# descriptor_glob (JVM descriptor in (args)ret). You may omit it entirely.
28+
# • Omitting descriptor ⇒ treated as "(*)*" (any args, any return).
29+
# • Short/empty forms "", "()", "(*)" normalize to "(*)*".
30+
# Examples:
31+
# (I)I # takes int, returns int
32+
# (Ljava/lang/String;)V # takes String, returns void
33+
# () or (*) or omitted # any args, any return
34+
#
35+
# FLAGS (optional) — space or comma separated:
36+
# public | protected | private | synthetic | bridge | static | abstract
37+
#
38+
# PREDICATES (optional):
39+
# ret:<glob> # match return type only (e.g., ret:V, ret:I, ret:Lcom/example/*;)
40+
# id:<string> # identifier shown in logs/reports
41+
# name-contains:<s> # method name must contain <s>
42+
# name-starts:<s> # method name must start with <s>
43+
# name-ends:<s> # method name must end with <s>
44+
#
45+
# Notes
46+
# - Always use dot-form (com.example.Foo) for class names.
47+
# - Comments (# …) and blank lines are ignored.
48+
#
49+
# ─────────────────────────────────────────────────────────────────────────────
50+
# QUICK EXAMPLES
51+
#
52+
# Simple wildcards
53+
# *#*(*)
54+
# → Match EVERY method in EVERY class (any package). Useful only for diagnostics.
55+
# "(*)" normalizes to "(*)*" ⇒ any args, any return.
56+
# *.dto.*#*(*)
57+
# → Match every method on any class under any package segment named "dto".
58+
# Good when you treat DTOs as generated/boilerplate.
59+
60+
# Scala case class helpers
61+
# *.model.*#copy(*)
62+
# → Matches Scala case-class `copy` methods under `*.model.*`.
63+
# Hides boilerplate clones with any parameter list and any return.
64+
# *.model.*#productArity()
65+
# → Matches zero-arg `productArity` (case-class/Product API).
66+
# *.model.*#productElement(*)
67+
# → Matches `productElement(int)` (or any descriptor form) on case classes.
68+
# *.model.*#productPrefix()
69+
# → Matches `productPrefix()`; returns the case class' constructor name.
70+
71+
# Companion objects and defaults
72+
# *.model.*$*#apply(*)
73+
# → Matches companion `apply` factories under `*.model.*` (any args).
74+
# BE CAREFUL: can hide real factory logic; keep the package scope narrow.
75+
# *.model.*$*#unapply(*)
76+
# → Matches extractor `unapply` methods in companions under `*.model.*`.
77+
# *#*$default$*(*)
78+
# → Matches Scala-generated default-argument helpers everywhere.
79+
# Safe to keep enabled; they’re compiler-synthesized.
80+
81+
# Anonymous / synthetic / bridge
82+
# *#$anonfun$*
83+
# → Matches any method whose name contains `$anonfun$` (Scala lambdas).
84+
# Consider adding `synthetic` and/or a package scope in real configs.
85+
# *#*(*):synthetic # any synthetic
86+
# → Matches ANY method marked `synthetic` (compiler-generated).
87+
# Powerful; scope by package to avoid hiding intentional glue code.
88+
# *#*(*):bridge # any bridge
89+
# → Matches Java generic bridge methods the compiler inserts.
90+
# Usually safe globally, but scoping is still recommended.
91+
92+
# Setters / fluent APIs
93+
# *.dto.*#*_$eq(*)
94+
# → Matches Scala var setters in DTO packages (e.g., `name_=(...)`).
95+
# Good for excluding trivial field writes.
96+
# *.builder.*#with*(*)
97+
# → Matches builder-style fluent setters (`withXxx(...)`) in builder pkgs.
98+
# Treats chainable configuration as boilerplate.
99+
# *.client.*#with*(*) ret:Lcom/api/client/*
100+
# → Like above but ONLY when the return type matches your client package.
101+
# The `ret:` predicate protects real logic that returns other types.
102+
103+
# Return-type constraints
104+
# *.jobs.*#*(*):ret:V
105+
# → Any method under `*.jobs.*` returning `void` (`V`). Often orchestration.
106+
# *.math.*#*(*):ret:I
107+
# → Any method under `*.math.*` returning primitive int (`I`).
108+
# *.model.*#*(*):ret:Lcom/example/model/*
109+
# → Any method under `*.model.*` that returns a type in `com.example.model`.
110+
# Handy when the *return type* uniquely identifies boilerplate.
111+
112+
# ─────────────────────────────────────────────────────────────────────────────
113+
# GLOBALS RULES
114+
# ─────────────────────────────────────────────────────────────────────────────
115+
# ** all case class boilerplate
116+
117+
# Scala case class helpers
118+
*#canEqual(*) id:case-canequal
119+
*#equals(*) id:case-equals
120+
*#apply(*) id:case-apply
121+
*#unapply(*) id:case-unapply
122+
*#hashCode(*) id:case-hashcode
123+
*#copy(*) id:case-copy
124+
*#copy$default$*(*) id:case-copy-defaults
125+
*#productElement() id:case-prod-element
126+
*#productArity() id:case-prod-arity
127+
*#productPrefix() id:case-prod-prefix
128+
*#productIterator() id:case-prod-iterator
129+
*#tupled() id:case-tupled
130+
*#curried() id:case-curried
131+
*#toString() id:case-tostring
132+
*#name() id:case-name
133+
*#groups() id:case-groups
134+
*#optionalAttributes() id:case-optionalAttributes
135+
136+
# Companion objects, constructors, and static definitions
137+
*$#<init>(*) id:gen-ctor # constructors
138+
*$#<clinit>() id:gen-clinit # static initializer blocks
139+
140+
# Companion objects and defaults
141+
*$*#apply(*) id:comp-apply
142+
*$*#unapply(*) id:comp-unapply
143+
*$*#toString(*) id:comp-tostring
144+
*$*#readResolve(*) id:comp-readresolve
145+
146+
# anonymous class created by a macro expansion
147+
*$macro$*#$anonfun$inst$macro$* id:macro-inst
148+
*$macro$*#inst$macro$* id:macro-inst
149+
150+
# lambda
151+
*#* synthetic name-contains:$anonfun$ id:scala-anonfun
152+
153+
# ─────────────────────────────────────────────────────────────────────────────
154+
# PROJECT RULES
155+
# ─────────────────────────────────────────────────────────────────────────────

0 commit comments

Comments
 (0)