Skip to content

Commit

Permalink
Adds a flag to fetch javadoc targets (#494) (#495)
Browse files Browse the repository at this point in the history
Adds flag fetch_javadoc to maven_install rules. When used, javadoc for
all targets will be fetched by coursier and placed in a similarly
named filegroup.
  • Loading branch information
erickj committed Dec 4, 2020
1 parent d4a944a commit 6143a6e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
15 changes: 12 additions & 3 deletions coursier.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ def make_coursier_dep_tree(
version_conflict_policy,
fail_on_missing_checksum,
fetch_sources,
fetch_javadoc,
use_unsafe_shared_cache,
timeout,
report_progress_prefix="",
Expand Down Expand Up @@ -593,7 +594,7 @@ def make_coursier_dep_tree(
for coord in artifact_coordinates:
# Undo any `,classifier=` suffix from `utils.artifact_coordinate`.
cmd.extend(["--force-version", coord.split(",classifier=")[0]])
cmd.extend(["--artifact-type", ",".join(SUPPORTED_PACKAGING_TYPES + ["src"])])
cmd.extend(["--artifact-type", ",".join(SUPPORTED_PACKAGING_TYPES + ["src", "doc"])])
cmd.append("--verbose" if _is_verbose(repository_ctx) else "--quiet")
cmd.append("--no-default")
cmd.extend(["--json-output-file", "dep-tree.json"])
Expand All @@ -613,8 +614,11 @@ def make_coursier_dep_tree(
for a in excluded_artifacts:
cmd.extend(["--exclude", ":".join([a["group"], a["artifact"]])])

if fetch_sources:
cmd.append("--sources")
if fetch_sources or fetch_javadoc:
if fetch_sources:
cmd.append("--sources")
if fetch_javadoc:
cmd.append("--javadoc")
cmd.append("--default=true")

environment = {}
Expand All @@ -634,6 +638,7 @@ def make_coursier_dep_tree(
repository_ctx.report_progress(
"%sResolving and fetching the transitive closure of %s artifact(s).." % (
report_progress_prefix, len(artifact_coordinates)))

exec_result = repository_ctx.execute(
cmd,
timeout = timeout,
Expand Down Expand Up @@ -709,6 +714,7 @@ def _coursier_fetch_impl(repository_ctx):
repository_ctx.attr.version_conflict_policy,
repository_ctx.attr.fail_on_missing_checksum,
repository_ctx.attr.fetch_sources,
repository_ctx.attr.fetch_javadoc,
repository_ctx.attr.use_unsafe_shared_cache,
repository_ctx.attr.resolve_timeout,
)
Expand Down Expand Up @@ -739,6 +745,7 @@ def _coursier_fetch_impl(repository_ctx):
repository_ctx.attr.version_conflict_policy,
repository_ctx.attr.fail_on_missing_checksum,
repository_ctx.attr.fetch_sources,
repository_ctx.attr.fetch_javadoc,
repository_ctx.attr.use_unsafe_shared_cache,
repository_ctx.attr.resolve_timeout,
report_progress_prefix = "Second pass for Jetified Artifacts: ",
Expand Down Expand Up @@ -979,6 +986,7 @@ pinned_coursier_fetch = repository_rule(
"repositories": attr.string_list(), # list of repository objects, each as json
"artifacts": attr.string_list(), # list of artifact objects, each as json
"fetch_sources": attr.bool(default = False),
"fetch_javadoc": attr.bool(default = False),
"generate_compat_repositories": attr.bool(default = False), # generate a compatible layer with repositories for each artifact
"maven_install_json": attr.label(allow_single_file = True),
"override_targets": attr.string_dict(default = {}),
Expand Down Expand Up @@ -1007,6 +1015,7 @@ coursier_fetch = repository_rule(
"artifacts": attr.string_list(), # list of artifact objects, each as json
"fail_on_missing_checksum": attr.bool(default = True),
"fetch_sources": attr.bool(default = False),
"fetch_javadoc": attr.bool(default = False),
"use_unsafe_shared_cache": attr.bool(default = False),
"excluded_artifacts": attr.string_list(default = []), # list of artifacts to exclude
"generate_compat_repositories": attr.bool(default = False), # generate a compatible layer with repositories for each artifact
Expand Down
4 changes: 4 additions & 0 deletions defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def maven_install(
artifacts = [],
fail_on_missing_checksum = True,
fetch_sources = False,
fetch_javadoc = False,
use_unsafe_shared_cache = False,
excluded_artifacts = [],
generate_compat_repositories = False,
Expand All @@ -51,6 +52,7 @@ def maven_install(
Supports URLs with HTTP Basic Authentication, e.g. "https://username:password@example.com".
artifacts: A list of Maven artifact coordinates in the form of `group:artifact:version`.
fetch_sources: Additionally fetch source JARs.
fetch_javadoc: Additionally fetch javadoc JARs.
use_unsafe_shared_cache: Download artifacts into a persistent shared cache on disk. Unsafe as Bazel is
currently unable to detect modifications to the cache.
excluded_artifacts: A list of Maven artifact coordinates in the form of `group:artifact` to be
Expand Down Expand Up @@ -110,6 +112,7 @@ def maven_install(
artifacts = artifacts_json_strings,
fail_on_missing_checksum = fail_on_missing_checksum,
fetch_sources = fetch_sources,
fetch_javadoc = fetch_javadoc,
use_unsafe_shared_cache = use_unsafe_shared_cache,
excluded_artifacts = excluded_artifacts_json_strings,
generate_compat_repositories = generate_compat_repositories,
Expand All @@ -130,6 +133,7 @@ def maven_install(
artifacts = artifacts_json_strings,
maven_install_json = maven_install_json,
fetch_sources = fetch_sources,
fetch_javadoc = fetch_javadoc,
generate_compat_repositories = generate_compat_repositories,
override_targets = override_targets,
strict_visibility = strict_visibility,
Expand Down
4 changes: 4 additions & 0 deletions private/dependency_tree_parser.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ def _generate_imports(repository_ctx, dep_tree, explicit_artifacts, neverlink_ar
elif repository_ctx.attr.fetch_sources and get_classifier(artifact["coord"]) == "sources":
# We already processed the sources above, so skip them here.
pass
elif repository_ctx.attr.fetch_javadoc and get_classifier(artifact["coord"]) == "javadoc":
seen_imports[target_label] = True
all_imports.append(
"filegroup(\n\tname = \"%s\",\n\tsrcs = [\"%s\"],\n\ttags = [\"javadoc\"],\n)" % (target_label, artifact_path))
elif get_packaging(artifact["coord"]) == "json":
seen_imports[target_label] = True
versioned_target_alias_label = "%s_extension" % escape(artifact["coord"])
Expand Down

0 comments on commit 6143a6e

Please sign in to comment.