Skip to content

Commit

Permalink
[internal] java: add debug goal to dump first-party dep map (pantsbui…
Browse files Browse the repository at this point in the history
…ld#13314)

Add `java-dump-first-party-dep-map` goal to dump the `FirstPartyJavaPackageMapping` type used in dependency inference mapping for Java.

This is gated behind the `pants.backend.experimental.java.debug_goals` backend package so ordinary users won't see it.
  • Loading branch information
Tom Dyas authored Oct 22, 2021
1 parent f04f167 commit c83d604
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 1 deletion.
6 changes: 5 additions & 1 deletion build-support/bin/generate_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,11 @@ def create_parser() -> argparse.ArgumentParser:


def run_pants_help_all() -> dict[str, Any]:
deactivated_backends = ["internal_plugins.releases", "pants.backend.experimental.java"]
deactivated_backends = [
"internal_plugins.releases",
"pants.backend.experimental.java",
"pants.backend.experimental.java.debug_goals",
]
activated_backends = [
"pants.backend.codegen.protobuf.python",
"pants.backend.awslambda.python",
Expand Down
1 change: 1 addition & 0 deletions pants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ backend_packages.add = [
"pants.backend.experimental.docker",
"pants.backend.experimental.go",
"pants.backend.experimental.java",
"pants.backend.experimental.java.debug_goals",
"pants.backend.experimental.python",
"internal_plugins.releases",
]
Expand Down
4 changes: 4 additions & 0 deletions src/python/pants/backend/experimental/java/debug_goals/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

python_sources()
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
from pants.backend.java.goals import debug_goals


def rules():
return [*debug_goals.rules()]
4 changes: 4 additions & 0 deletions src/python/pants/backend/java/goals/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

python_sources()
Empty file.
36 changes: 36 additions & 0 deletions src/python/pants/backend/java/goals/debug_goals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

import json

from pants.backend.experimental.java.register import rules as java_rules
from pants.backend.java.dependency_inference.package_mapper import FirstPartyJavaPackageMapping
from pants.engine.console import Console
from pants.engine.goal import Goal, GoalSubsystem
from pants.engine.rules import collect_rules, goal_rule


class DumpFirstPartyDepMapSubsystem(GoalSubsystem):
name = "java-dump-first-party-dep-map"
help = "Dump dependency inference data for Java dep inference."


class DumpFirstPartyDepMap(Goal):
subsystem_cls = DumpFirstPartyDepMapSubsystem


@goal_rule
async def dump_dep_inference_data(
console: Console, first_party_dep_map: FirstPartyJavaPackageMapping
) -> DumpFirstPartyDepMap:
console.write_stdout(
json.dumps(first_party_dep_map.package_rooted_dependency_map.to_json_dict())
)
return DumpFirstPartyDepMap(exit_code=0)


def rules():
return [
*collect_rules(),
*java_rules(),
]
1 change: 1 addition & 0 deletions src/python/pants/init/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ target(
"src/python/pants/backend/experimental/docker/lint/hadolint",
"src/python/pants/backend/experimental/go",
"src/python/pants/backend/experimental/java",
"src/python/pants/backend/experimental/java/debug_goals",
"src/python/pants/backend/experimental/python",
"src/python/pants/backend/experimental/terraform",
"src/python/pants/backend/google_cloud_function/python",
Expand Down

0 comments on commit c83d604

Please sign in to comment.