Skip to content
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
15 changes: 12 additions & 3 deletions private/rules/has_maven_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ MavenInfo = provider(
# Fields to do with maven coordinates
"coordinates": "Maven coordinates for the project, which may be None",
"maven_deps": "Depset of first-order maven dependencies",
"maven_runtime_deps": "Depset of first-order maven runtime dependencies",
"as_maven_dep": "Depset of this project if used as a maven dependency",

# Fields used for generating artifacts
Expand Down Expand Up @@ -93,17 +94,22 @@ def calculate_artifact_source_jars(maven_info):
_gathered = provider(
fields = [
"all_infos",
"runtime_infos",
"label_to_javainfo",
"artifact_infos",
"transitive_exports",
"dep_infos",
],
)

def _extract_from(gathered, maven_info, dep, include_transitive_exports):
def _extract_from(gathered, maven_info, dep, include_transitive_exports, is_runtime_dep):
java_info = dep[JavaInfo] if dep and JavaInfo in dep else None

gathered.all_infos.append(maven_info)

if is_runtime_dep:
gathered.runtime_infos.append(maven_info)

gathered.label_to_javainfo.update(maven_info.label_to_javainfo)
if java_info:
if maven_info.coordinates:
Expand All @@ -127,6 +133,7 @@ def _has_maven_deps_impl(target, ctx):

gathered = _gathered(
all_infos = [],
runtime_infos = [],
artifact_infos = [target[JavaInfo]],
transitive_exports = [],
dep_infos = [],
Expand All @@ -137,20 +144,21 @@ def _has_maven_deps_impl(target, ctx):
for dep in getattr(ctx.rule.attr, attr, []):
if MavenHintInfo in dep:
for info in dep[MavenHintInfo].maven_infos.to_list():
_extract_from(gathered, info, None, attr == "exports")
_extract_from(gathered, info, None, attr == "exports", attr == "runtime_deps")

if not MavenInfo in dep:
continue

info = dep[MavenInfo]
_extract_from(gathered, info, dep, attr == "exports")
_extract_from(gathered, info, dep, attr == "exports", attr == "runtime_deps")

all_infos = gathered.all_infos
artifact_infos = gathered.artifact_infos
transitive_exports_from_deps = gathered.transitive_exports
dep_infos = gathered.dep_infos
label_to_javainfo = gathered.label_to_javainfo
maven_deps = depset(transitive = [i.as_maven_dep for i in all_infos])
maven_runtime_deps = depset(transitive = [i.as_maven_dep for i in gathered.runtime_infos])

transitive_exports_from_exports = depset()
if hasattr(ctx.rule.attr, "exports"):
Expand All @@ -163,6 +171,7 @@ def _has_maven_deps_impl(target, ctx):
info = MavenInfo(
coordinates = coordinates,
maven_deps = maven_deps,
maven_runtime_deps = maven_runtime_deps,
as_maven_dep = depset([coordinates]) if coordinates else maven_deps,
artifact_infos = depset(direct = artifact_infos),
dep_infos = depset(direct = dep_infos, transitive = [i.dep_infos for i in all_infos]),
Expand Down
17 changes: 12 additions & 5 deletions private/rules/maven_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def generate_pom(
parent = None,
versioned_dep_coordinates = [],
unversioned_dep_coordinates = [],
runtime_deps = [],
indent = 8):
unpacked_coordinates = unpack_coordinates(coordinates)
substitutions = {
Expand All @@ -111,12 +112,18 @@ def generate_pom(
substitutions.update({"{parent}": "".join(parts)})

deps = []
for dep in sorted(versioned_dep_coordinates):
for dep in sorted(versioned_dep_coordinates) + sorted(unversioned_dep_coordinates):
include_version = dep in versioned_dep_coordinates
unpacked = unpack_coordinates(dep)
deps.append(format_dep(unpacked, indent = indent))
for dep in sorted(unversioned_dep_coordinates):
unpacked = unpack_coordinates(dep)
deps.append(format_dep(unpacked, indent = indent, include_version = False))
new_scope = "runtime" if dep in runtime_deps else unpacked.scope
unpacked = struct(
groupId = unpacked.groupId,
artifactId = unpacked.artifactId,
type = unpacked.type,
scope = new_scope,
version = unpacked.version,
)
deps.append(format_dep(unpacked, indent = indent, include_version = include_version))

substitutions.update({"{dependencies}": "\n".join(deps)})

Expand Down
8 changes: 8 additions & 0 deletions private/rules/pom_file.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@ def _pom_file_impl(ctx):
additional_deps = determine_additional_dependencies(artifact_jars, ctx.attr.additional_dependencies)

all_maven_deps = info.maven_deps.to_list()
runtime_maven_deps = info.maven_runtime_deps.to_list()

for dep in additional_deps:
for coords in dep[MavenInfo].as_maven_dep.to_list():
all_maven_deps.append(coords)

expanded_maven_deps = [
ctx.expand_make_variables("additional_deps", coords, ctx.var)
for coords in all_maven_deps
]
expanded_runtime_deps = [
ctx.expand_make_variables("maven_runtime_deps", coords, ctx.var)
for coords in runtime_maven_deps
]

# Expand maven coordinates for any variables to be replaced.
coordinates = ctx.expand_make_variables("coordinates", info.coordinates, ctx.var)
Expand All @@ -28,6 +35,7 @@ def _pom_file_impl(ctx):
ctx,
coordinates = coordinates,
versioned_dep_coordinates = sorted(expanded_maven_deps),
runtime_deps = expanded_runtime_deps,
pom_template = ctx.file.pom_template,
out_name = "%s.xml" % ctx.label.name,
)
Expand Down