blob: edf9569642a5f3557fcd94fd7c2275498d90611c [file] [log] [blame]
Thomas Vachuska16b669f2018-07-20 09:32:51 -07001load("//tools/build/bazel:generate_workspace.bzl", "maven_coordinates")
2
3# Example invocation:
4# bazel build $(bazel query 'kind("_bnd rule", //...)') \
5# --aspects tools/build/bazel/publish_catalog.bzl%publish_catalog 2>&1 | \
6# egrep "DEBUG: .*mvn_jar.bzl" | cut -d\ -f3-
7
8def _remote(group_id, artifact_id, version, packaging, classifier):
Thomas Vachuska2988e142018-07-23 16:20:01 -07009 p = group_id.replace(".", "/") + "/" + artifact_id + "/" + version + "/" + artifact_id + "-" + version
Thomas Vachuska16b669f2018-07-20 09:32:51 -070010 if classifier != None:
Ray Milkey5063f5b2018-08-15 16:22:30 -070011 p += "-" + classifier
Thomas Vachuska16b669f2018-07-20 09:32:51 -070012 p += "." + packaging
13 return p
14
15def _impl(target, ctx):
16 coords = maven_coordinates(target.label)
17 mvn = coords.split(":")
18 group_id = mvn[1]
19 artifact_id = mvn[2]
20 version = mvn[len(mvn) - 1]
Thomas Vachuskab2f489f2018-08-10 11:03:44 -070021 packaging = "oar" if target.label.name.endswith("-oar") else "jar"
Thomas Vachuska16b669f2018-07-20 09:32:51 -070022 classifier = None
23
24 if len(mvn) > 4:
25 packaging = mvn[3]
26
27 c = artifact_id.split("-")
28
Ray Milkey5063f5b2018-08-15 16:22:30 -070029 if len(c) > 1 and c[len(c) - 1] in ("javadoc", "sources", "tests", "pom"):
30 classifier = c[len(c) - 1]
31 artifact_id = "-".join(c[:len(c) - 1])
Thomas Vachuska16b669f2018-07-20 09:32:51 -070032 if classifier == "pom":
33 packaging = classifier
34 classifier = None
35
36 for f in target.files:
Ray Milkey5063f5b2018-08-15 16:22:30 -070037 print("%s\t%s" % (f.path, _remote(group_id, artifact_id, version, packaging, classifier)))
Thomas Vachuska16b669f2018-07-20 09:32:51 -070038 return []
39
40publish_catalog = aspect(
41 implementation = _impl,
42)