Thomas Vachuska | 16b669f | 2018-07-20 09:32:51 -0700 | [diff] [blame] | 1 | load("//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 | |
| 8 | def _remote(group_id, artifact_id, version, packaging, classifier): |
Thomas Vachuska | 2988e14 | 2018-07-23 16:20:01 -0700 | [diff] [blame] | 9 | p = group_id.replace(".", "/") + "/" + artifact_id + "/" + version + "/" + artifact_id + "-" + version |
Thomas Vachuska | 16b669f | 2018-07-20 09:32:51 -0700 | [diff] [blame] | 10 | if classifier != None: |
| 11 | p += "-" + classifier |
| 12 | p += "." + packaging |
| 13 | return p |
| 14 | |
| 15 | def _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] |
| 21 | packaging = "jar" |
| 22 | classifier = None |
| 23 | |
| 24 | if len(mvn) > 4: |
| 25 | packaging = mvn[3] |
| 26 | |
| 27 | c = artifact_id.split("-") |
| 28 | |
Ray Milkey | 7f46b1f | 2018-07-24 19:01:58 -0700 | [diff] [blame] | 29 | if len(c) > 1 and c[len(c)-1] in ("javadoc", "sources", "tests", "pom"): |
Thomas Vachuska | 16b669f | 2018-07-20 09:32:51 -0700 | [diff] [blame] | 30 | classifier = c[len(c)-1] |
| 31 | artifact_id = "-".join(c[:len(c)-1]) |
| 32 | if classifier == "pom": |
| 33 | packaging = classifier |
| 34 | classifier = None |
| 35 | |
| 36 | for f in target.files: |
| 37 | print ("%s\t%s" % (f.path, _remote(group_id, artifact_id, version, packaging, classifier))) |
| 38 | return [] |
| 39 | |
| 40 | publish_catalog = aspect( |
| 41 | implementation = _impl, |
| 42 | ) |