Skip to content
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

Implement Cobertura output option for #9275 #9325

Merged
merged 3 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/python/pants/backend/jvm/tasks/coverage/scoverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def scoverage_report_jar(**kwargs):
return JarDependency(
org="org.pantsbuild",
name="scoverage-report-generator_2.12",
rev="0.0.2",
rev="0.0.3",
**kwargs,
)

Expand Down Expand Up @@ -69,6 +69,14 @@ def scoverage_report_jar(**kwargs):
"filter.",
)

register(
"--output-as-cobertura",
type=bool,
default=False,
fingerprint=False,
help="Export cobertura formats which would allow users to merge with cobertura coverage for java targets.",
)

def create(self, settings, targets, execute_java_for_targets):
"""
:param settings: Generic code coverage settings.
Expand All @@ -87,6 +95,7 @@ def create(self, settings, targets, execute_java_for_targets):

opts = Scoverage.Factory.global_instance().get_options()
target_filters = opts.target_filters
output_as_cobertura = opts.output_as_cobertura
coverage_output_dir = settings.context.options.for_global_scope().pants_distdir

return Scoverage(
Expand All @@ -95,6 +104,7 @@ def create(self, settings, targets, execute_java_for_targets):
settings,
targets,
execute_java_for_targets,
output_as_cobertura,
coverage_output_dir=coverage_output_dir,
)

Expand All @@ -105,6 +115,7 @@ def __init__(
settings,
targets,
execute_java_for_targets,
output_as_cobertura,
coverage_output_dir=None,
):
"""
Expand All @@ -125,6 +136,7 @@ def __init__(
self._execute_java = functools.partial(execute_java_for_targets, targets)
self._coverage_force = settings.options.coverage_force
self._report_path = report_path
self._output_as_cobertura = output_as_cobertura
self._coverage_output_dir = coverage_output_dir

#
Expand Down Expand Up @@ -179,6 +191,7 @@ def report(self, output_dir, execution_failed_exception=None):

main = "org.pantsbuild.scoverage.report.ScoverageReport"
scoverage_cp = self._report_path
output_as_cobertura = self._output_as_cobertura
html_report_path = os.path.join(output_dir, "scoverage", "reports", "html")
xml_report_path = os.path.join(output_dir, "scoverage", "reports", "xml")
safe_mkdir(html_report_path, clean=True)
Expand All @@ -199,6 +212,9 @@ def report(self, output_dir, execution_failed_exception=None):
f"{','.join(final_target_dirs)}",
]

if output_as_cobertura:
args.append("--outputAsCobertura")

result = self._execute_java(
classpath=scoverage_cp,
main=main,
Expand Down
3 changes: 3 additions & 0 deletions src/python/pants/java/jar/jar_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class JarDependency:
intransitive: bool
excludes: Tuple[Exclude, ...]
base_path: str
output_as_cobertura: bool

def __init__(
self,
Expand All @@ -136,6 +137,7 @@ def __init__(
intransitive: bool = False,
excludes: Optional[Sequence[Exclude]] = None,
base_path: Optional[str] = None,
output_as_cobertura: bool = False,
) -> None:
self.org = org
self.base_name = name
Expand All @@ -152,6 +154,7 @@ def __init__(
if os.path.isabs(base_path):
base_path = os.path.relpath(base_path, get_buildroot())
self.base_path = base_path
self.output_as_cobertura = output_as_cobertura

def __str__(self):
return "JarDependency({})".format(self.coordinate)
Expand Down